Flexible conversion of Internal Table values to XML format

...Previous

Step 4: Splitting of XML records in Application Server  

The splitting of XML records in application server will help the testing team members who are checking the XML records in application server. To break the XML_OUT string into multiple units we have to follow the method which is shown as below:  

*&-----------------------------------------------------------&*
*&-- OPENING THE DATASET--&*
  OPEN DATASET p_appl FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
  IF sy-subrc = 0.
    SHIFT xml_out UP TO '<'.
    DATA : lt_spl TYPE swastrtab OCCURS 0 WITH HEADER LINE.
    CALL FUNCTION 'SWA_STRING_SPLIT'
      EXPORTING
        input_string                 = xml_out
        max_component_length         = 255
        terminating_separators       = '>'
      TABLES
        string_components            = lt_spl
      EXCEPTIONS
        max_component_length_invalid = 1
        OTHERS                       = 2.
    LOOP AT lt_spl.
      TRANSFER lt_spl-str TO p_appl.
    ENDLOOP.
    CLEAR : lt_spl[].
  ENDIF.
  CLOSE DATASET p_file.

Now the XML records are converted as per the user requirement and got split by 255 characters per line in application server.   

Step 5: Testing of XML files in desktop machine  

To test the XML file as per the requirement, download the application server file to local machine and double click it to view it in the Internet Explorer.  

Related Content  

To convert XML files into ABAP internal tables following codes can be used.  

XML to ABAP itab: 

REPORT  YREPORT2.
*&-- SELECTION SCREEN PARAMETERS --&*
PARAMETERS: P_FILNAM TYPE LOCALFILE OBLIGATORY.
*&-- Data Declaration --&*
  TYPES: BEGIN OF TY_TAB,
          NAME  TYPE STRING,
          VALUE TYPE STRING,
         END OF TY_TAB.
  DATA: LCL_XML_DOC  TYPE REF TO CL_XML_DOCUMENT,
        V_SUBRC      TYPE SYSUBRC,
        V_NODE       TYPE REF TO IF_IXML_NODE,
        V_CHILD_NODE TYPE REF TO IF_IXML_NODE,
        V_ROOT       TYPE REF TO IF_IXML_NODE,
        V_ITERATOR   TYPE REF TO IF_IXML_NODE_ITERATOR,
        V_NODEMAP    TYPE REF TO IF_IXML_NAMED_NODE_MAP,
        V_COUNT      TYPE I,
        V_INDEX      TYPE I,
        V_ATTR       TYPE REF TO IF_IXML_NODE,
        V_NAME       TYPE STRING,
        V_PREFIX     TYPE STRING,
        V_VALUE      TYPE STRING,
        V_CHAR       TYPE CHAR2.
  DATA: ITAB TYPE STANDARD TABLE OF TY_TAB,
             WA   TYPE TY_TAB.
*&--AT SELECTION SCREEN--&*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILNAM.
  DATA: L_V_FIELDNAME TYPE DYNFNAM.
 	       L_V_FIELDNAME = P_FILNAM.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      PROGRAM_NAME  = SYST-CPROG
      DYNPRO_NUMBER = SYST-DYNNR
      FIELD_NAME    = L_V_FIELDNAME
    IMPORTING
      FILE_NAME     = P_FILNAM.
*&--START OF SELECTION-&*
START-OF-SELECTION.
CREATE OBJECT LCL_XML_DOC.
*&--CONVERSION OF XML TO ITAB PROCESS--&*
  CALL METHOD LCL_XML_DOC->IMPORT_FROM_FILE
    EXPORTING
      FILENAME = P_FILNAM
    RECEIVING
      RETCODE  = V_SUBRC.
  CHECK V_SUBRC = 0.
  V_NODE = LCL_XML_DOC->M_DOCUMENT.
  CHECK NOT V_NODE IS INITIAL.
  V_ITERATOR = V_NODE->CREATE_ITERATOR( ).
  V_NODE = V_ITERATOR->GET_NEXT( ).
  WHILE NOT V_NODE IS INITIAL.
    CASE V_NODE->GET_TYPE( ).
      WHEN IF_IXML_NODE=>CO_NODE_ELEMENT.
        V_NAME = V_NODE->GET_NAME( ).
        V_NODEMAP = V_NODE->GET_ATTRIBUTES( ).
        IF NOT V_NODEMAP IS INITIAL.
* attributes
          V_COUNT = V_NODEMAP->GET_LENGTH( ).
          DO V_COUNT TIMES.
            V_INDEX = SY-INDEX - 1.
            V_ATTR = V_NODEMAP->GET_ITEM( V_INDEX ).
            V_NAME = V_ATTR->GET_NAME( ).
            V_PREFIX = V_ATTR->GET_NAMESPACE_PREFIX( ).
            V_VALUE = V_ATTR->GET_VALUE( ).
          ENDDO.
        ENDIF.
      WHEN IF_IXML_NODE=>CO_NODE_TEXT OR
       IF_IXML_NODE=>CO_NODE_CDATA_SECTION.
* text node
       V_VALUE = V_NODE->GET_VALUE( ).
        MOVE V_VALUE TO V_CHAR.
        IF V_CHAR <> CL_ABAP_CHAR_UTILITIES=>CR_LF.
          WA-NAME  = V_NAME.
          WA-VALUE = V_VALUE.
          APPEND WA TO ITAB.
          CLEAR  WA.
        ENDIF.
    ENDCASE.
* advance to next node
    V_NODE = V_ITERATOR->GET_NEXT( ).
  ENDWHILE.
*&-- WRITING ITAB FILES IN OUTPUT--&*
  LOOP AT ITAB INTO WA.
    WRITE :/1 WA-NAME,20 WA-VALUE.
  ENDLOOP.

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image