ITAB to XML

Hi,
I want to conver my itab data into XML. is there any standard FM available fo this purpose.
SA

Hi,
Check the following program, it might use.
Export an internal table to XML document *
NO BORRAR ESTE CODIGO *
REPORT ZPRUEBA_MML_13.
PANTALLA SELECCION *
PARAMETERS: GK_RUTA TYPE RLGRAP-FILENAME.
PANTALLA SELECCION *
TYPE TURNOS *
TYPES: BEGIN OF TURNOS,
LU LIKE T552A-TPR01,
MA LIKE T552A-TPR01,
MI LIKE T552A-TPR01,
JU LIKE T552A-TPR01,
VI LIKE T552A-TPR01,
SA LIKE T552A-TPR01,
DO LIKE T552A-TPR01,
END OF TURNOS.
TYPE TURNOS *
TYPE SOCIO *
TYPES: BEGIN OF SOCIO,
NUMERO LIKE PERNR-PERNR,
REPOSICION LIKE PA0050-ZAUVE,
NOMBRE LIKE PA0002-VORNA,
TURNOS TYPE TURNOS,
END OF SOCIO.
TYPE SOCIO *
ESTRUCTURA ACCESOS *
DATA: BEGIN OF ACCESOS OCCURS 0,
SOCIO TYPE SOCIO,
END OF ACCESOS.
ESTRUCTURA ACCESOS *
START OF SELECTION *
START-OF-SELECTION.
PERFORM LLENA_ACCESOS.
PERFORM DESCARGA_XML.
END-OF-SELECTION.
END OF SELECTION *
FORM LLENA_ACCESOS *
FORM LLENA_ACCESOS.
REFRESH ACCESOS.
CLEAR ACCESOS.
MOVE: '45050' TO ACCESOS-SOCIO-NUMERO,
'MOISES MORENO' TO ACCESOS-SOCIO-NOMBRE,
'0' TO ACCESOS-SOCIO-REPOSICION,
'T1' TO ACCESOS-SOCIO-TURNOS-LU,
'T2' TO ACCESOS-SOCIO-TURNOS-MA,
'T3' TO ACCESOS-SOCIO-TURNOS-MI,
'T4' TO ACCESOS-SOCIO-TURNOS-JU,
'T5' TO ACCESOS-SOCIO-TURNOS-VI,
'T6' TO ACCESOS-SOCIO-TURNOS-SA,
'T7' TO ACCESOS-SOCIO-TURNOS-DO.
APPEND ACCESOS.
CLEAR ACCESOS.
MOVE: '45051' TO ACCESOS-SOCIO-NUMERO,
'RUTH PEÑA' TO ACCESOS-SOCIO-NOMBRE,
'0' TO ACCESOS-SOCIO-REPOSICION,
'T1' TO ACCESOS-SOCIO-TURNOS-LU,
'T2' TO ACCESOS-SOCIO-TURNOS-MA,
'T3' TO ACCESOS-SOCIO-TURNOS-MI,
'T4' TO ACCESOS-SOCIO-TURNOS-JU,
'T5' TO ACCESOS-SOCIO-TURNOS-VI,
'T6' TO ACCESOS-SOCIO-TURNOS-SA,
'T7' TO ACCESOS-SOCIO-TURNOS-DO.
APPEND ACCESOS.
ENDFORM.
FORM LLENA_ACCESOS *
FORM DESCARGA_XML *
FORM DESCARGA_XML.
DATA: L_DOM TYPE REF TO IF_IXML_ELEMENT,
M_DOCUMENT TYPE REF TO IF_IXML_DOCUMENT,
G_IXML TYPE REF TO IF_IXML,
W_STRING TYPE XSTRING,
W_SIZE TYPE I,
W_RESULT TYPE I,
W_LINE TYPE STRING,
IT_XML TYPE DCXMLLINES,
S_XML LIKE LINE OF IT_XML,
W_RC LIKE SY-SUBRC.
DATA: XML TYPE DCXMLLINES.
DATA: RC TYPE SY-SUBRC,
BEGIN OF XML_TAB OCCURS 0,
D LIKE LINE OF XML,
END OF XML_TAB.
CLASS CL_IXML DEFINITION LOAD.
G_IXML = CL_IXML=>CREATE( ).
CHECK NOT G_IXML IS INITIAL.
M_DOCUMENT = G_IXML->CREATE_DOCUMENT( ).
CHECK NOT M_DOCUMENT IS INITIAL.
WRITE: / 'Converting DATA TO DOM 1:'.
CALL FUNCTION 'SDIXML_DATA_TO_DOM'
EXPORTING
NAME = 'ACCESOS'
DATAOBJECT = ACCESOS[]
IMPORTING
DATA_AS_DOM = L_DOM
CHANGING
DOCUMENT = M_DOCUMENT
EXCEPTIONS
ILLEGAL_NAME = 1
OTHERS = 2.
IF SY-SUBRC = 0.
WRITE 'Ok'.
ELSE.
WRITE: 'Err =',
SY-SUBRC.
ENDIF.
CHECK NOT L_DOM IS INITIAL.
W_RC = M_DOCUMENT->APPEND_CHILD( NEW_CHILD = L_DOM ).
IF W_RC IS INITIAL.
WRITE 'Ok'.
ELSE.
WRITE: 'Err =',
W_RC.
ENDIF.
CALL FUNCTION 'SDIXML_DOM_TO_XML'
EXPORTING
DOCUMENT = M_DOCUMENT
IMPORTING
XML_AS_STRING = W_STRING
SIZE = W_SIZE
TABLES
XML_AS_TABLE = IT_XML
EXCEPTIONS
NO_DOCUMENT = 1
OTHERS = 2.
IF SY-SUBRC = 0.
WRITE 'Ok'.
ELSE.
WRITE: 'Err =',
SY-SUBRC.
ENDIF.
LOOP AT IT_XML INTO XML_TAB-D.
APPEND XML_TAB.
ENDLOOP.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
BIN_FILESIZE = W_SIZE
FILENAME = GK_RUTA
FILETYPE = 'BIN'
TABLES
DATA_TAB = XML_TAB
EXCEPTIONS
OTHERS = 10.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
FORM DESCARGA_XML *
If helpful please award points.
Thanks,
Rani.

Similar Messages

  • Upload XML file from server to itab

    After failed to get a answer about download data from xml file in server to my itab, and searching and searching in hundred of post and threads i try my own solution for this issue.
    I read the file with:
    OPEN DATASET FICHERO FOR INPUT IN TEXT MODE ENCODING DEFAULT.
    In this case the result is a table filled with register type string like this:
    #<label>22222</label>
    I need a table with this kind of value (example):
    label   | 22222
    label2 | John
    label3 | Smith
    Therefore i have to parse the data of my table, i try with the FM:
    TEXT_CONVERT_XML_TO_SAP
    But dont works for me,
    I am too new in ABAP.
    The code for my report is very simple:
    REPORT ZPRUEBA_XML.
    DATA: BEGIN OF TABLA OCCURS 1,
    TEXTO(256) TYPE C,
    END OF TABLA.
    DATA: FICHERO LIKE RLGRAP-FILENAME.
    OPEN DATASET FICHERO FOR INPUT IN TEXT MODE ENCODING DEFAULT.
    IF SY-SUBRC NE 0.
      WRITE:/ 'ERROR'.
    ENDIF.
    FREE TABLA.
    DO.
      READ DATASET FICHERO INTO TABLA.
      IF SY-SUBRC NE 0.
        EXIT.
      ELSE.
        APPEND TABLA.
        WRITE: TABLA-TEXTO.
      ENDIF.
    ENDDO.
    CLOSE DATASET FICHERO.
    And my ".xml" in the server is very simple too.
    <label>222222</label>
    <name>John</name>
    <street>Smith, 23, NY</street>
    Anyone can help me?
    Thanks

    Hi,
    You could use a transformation to do that, or call FM 'TEXT_CONVERT_XML_TO_SAP'... you also have the class IF_IXML that should help you and a lot of threads on the subject, such as:
    convert XML data into ABAP internal table
    ABAP Class to convert XML to itab
    Upload XML to internal table and vice versa in SAP 4.6C
    http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e66701fc-0d01-0010-9c9a-f8a36c4e87ba
    Kr,
    Manu.

  • Error while downloading data from internal table into XML file

    hi all,
    i developed a program to download data from into internal table to xml file like this.
    tables: mara.
    parameters: p_matnr like mara-matnr.
    data: begin of itab_mara occurs 0,
                matnr like mara-matnr,
                ernam like mara-ernam,
                aenam like mara-aenam,
                vpsta like mara-vpsta,
          end of itab_mara.
    data: lv_field_seperator type c,     " value 'X',
          lv_xml_doc_name(30) type c,    " string value ‘my xml file’,
          lv_result type i.
          lv_field_seperator = 'x'.
          lv_xml_doc_name = 'my xml file'.
    types: begin of truxs_xml_line,
              data(256) type x,
          end of truxs_xml_line.
    types:truxs_xml_table type table of truxs_xml_line.
    data:lv_tab_converted_data type truxs_xml_line,
         lt_tab_converted_data type truxs_xml_table.
    data: lv_xml_file type rlgrap-filename value 'c:\simp.xml'.
    select matnr ernam aenam vpsta from mara into table itab_mara up to 5
           rows where matnr = p_matnr.
    CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'
    EXPORTING
       I_FIELD_SEPERATOR          = lv_field_seperator
      I_LINE_HEADER              =
      I_FILENAME                 =
      I_APPL_KEEP                = ' '
       I_XML_DOC_NAME             = lv_xml_doc_name
    IMPORTING
       PE_BIN_FILESIZE            = lv_result
      TABLES
        I_TAB_SAP_DATA             = itab_mara
    CHANGING
       I_TAB_CONVERTED_DATA       = lt_tab_converted_data
    EXCEPTIONS
      CONVERSION_FAILED          = 1
      OTHERS                     = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    open dataset lv_xml_file for output in binary mode.
    loop at lt_tab_converted_data into lv_tab_converted_data.
    transfer lv_tab_converted_data to lv_xml_file.
    endloop.
    close dataset lv_xml_file.
    this program is syntactically correct and getting executed, but when i open the target xml file it is showing the following error.
    The XML page cannot be displayed
    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
    XML document must have a top level element. Error processing resource 'file:///C:/simp.xml'.
    will anyone show me the possible solution to rectify this error
    thanks and regards,
    anil.

    Hi,
    Here is a small sample program to convert data in an internal table into XML format and display it.
    DATA: itab  TYPE TABLE OF spfli,
          l_xml TYPE REF TO cl_xml_document.
    * Read data into a ITAB
    SELECT * FROM spfli INTO TABLE itab.
    * Create the XML Object
    CREATE OBJECT l_xml.
    * Convert data in ITAB to XML
    CALL METHOD l_xml->create_with_data( name = 'Test1'
                                         dataobject = t_goal[] ).
    * Display XML Document
    CALL METHOD l_xml->display.
    Here are some other sample SAP programs to handle XML in ABAP:
    BCCIIXMLT1, BCCIIXMLT2, and BCCIIXMLT3.
    Hope this helps,
    Sumant.

  • Error while downloading the xml file

    i am having a internal table which contains data in xml format but i am unable to download the data into local system by using 'GUI_DOWNLOAD' fn. module
    its error its showing is as :
    The XML page cannot be displayed
    Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
    A name contained an invalid character. Error processing resource 'file:///D:/XX.XML'. Line 4, Position 4
    MOD/><RPTSX/><MANDT/><SYPSY/><SYSID/><SAPRL/></T682><T682><KVEWE>A</KV...

    hello Durairaj,
    i am fwd the code go thru it and check why the xml file is not downloading,
    and after downloading the file i want that file to be in displayed in  .pdf.
    REPORT  ZCCSV_TO_XML.
    DATA : BEGIN OF TABLE OCCURS 0,
            TABNAME(15) TYPE C,
           END OF TABLE.
    DATA : BEGIN OF HEADER_NAMTAB OCCURS 0,
            NAMTAB TYPE STRING,
           END OF HEADER_NAMTAB.
    DATA : BEGIN OF CONVERT_ITAB_TO_XML OCCURS 0,
            FIELDNAME(255) TYPE C,
           END OF CONVERT_ITAB_TO_XML .
    DATA : BEGIN OF CONVERT_XML_TO_ITAB OCCURS 0,
            FIELDNAME(255) TYPE C,
           END OF CONVERT_XML_TO_ITAB.
    DATA DREF TYPE REF TO DATA.
    DATA TNAME LIKE DD02L-TABNAME.
    DATA BEGIN OF ZDFIES OCCURS 0.
            INCLUDE STRUCTURE DFIES.
    DATA END OF ZDFIES.
    DATA: xml_out TYPE string .
    DATA: xml_TO_ITAB TYPE string .
    data : wa_indx type indx.
    DATA : DETAIL(30).
    DATA : DATA1 TYPE STRING.
    DATA : COMMA . "VALUE ','.
    DATA : DBTAB1(15) TYPE C.
    FIELD-SYMBOLS: <ITAB> TYPE ANY TABLE,
                   <WA>    TYPE ANY,
                    <WA1> TYPE ANY .
    SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME,
                       SKIP 1.
    PARAMETERS : SPOOL    RADIOBUTTON GROUP rad1 DEFAULT 'X',
                 CSV      RADIOBUTTON GROUP rad1 ,
                 XMLTOPDF RADIOBUTTON GROUP rad1.
    SELECTION-SCREEN : SKIP 1,
                       END OF BLOCK b1.
        TABLE-TABNAME = 'T681'.
        APPEND TABLE.
        TABLE-TABNAME = 'T682'.
        APPEND TABLE.
      IF SPOOL = 'X'.
       PERFORM SPOOL.
      ELSEIF CSV = 'X'.
        PERFORM CSV.
      ELSEIF XMLTOPDF = 'X'.
        PERFORM XMLTOPDF.
      ENDIF.
    *&      Form  CSV
    form CSV .
    LOOP AT TABLE.
      dbtab1 = TABLE-TABNAME.
      TNAME = dbtab1.
      PERFORM GETFIELDS.
      LOOP AT HEADER_NAMTAB.
       WRITE: HEADER_NAMTAB-NAMTAB, COMMA.
      ENDLOOP.
      PERFORM GET_DETAIL_LIST.
    ENDLOOP.
    endform.                    " CSV
    form XMLTOPDF .
    LOOP AT TABLE.
      PERFORM GET_DETAIL_LIST.
    ENDLOOP.
    endform.                    " XMLTOPDF
    GETTING THE HEADER OF THE TABLE                                     *
    FORM GETFIELDS.
      REFRESH HEADER_NAMTAB.
      CALL FUNCTION 'GET_FIELDTAB'
       EXPORTING
           LANGU              = SY-LANGU
           ONLY               = SPACE
           TABNAME            = TNAME
           WITHTEXT           = 'X'
       TABLES
           FIELDTAB           = ZDFIES
       EXCEPTIONS
           INTERNAL_ERROR      = 01
           NO_TEXTS_FOUND      = 02
           TABLE_HAS_NO_FIELDS = 03
           TABLE_NOT_ACTIV     = 04.
      CASE SY-SUBRC.
        WHEN 0.
          LOOP AT ZDFIES.
            HEADER_NAMTAB-NAMTAB = ZDFIES-SCRTEXT_M.
            APPEND HEADER_NAMTAB.
          ENDLOOP.
        WHEN OTHERS.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
           WITH  SY-SUBRC.
      ENDCASE.
    ENDFORM.                  " GETFIELEDS
    *&      Form  GET_DETAIL_LIST
    form GET_DETAIL_LIST .
      CREATE DATA DREF TYPE STANDARD TABLE OF (TABLE)
                                WITH NON-UNIQUE DEFAULT KEY.
      ASSIGN DREF->* TO <ITAB> .
      SELECT * FROM (TABLE) INTO TABLE <ITAB>.
      CALL TRANSFORMATION ('ID')
      SOURCE tab = <ITAB>[]
      RESULT XML xml_out.
    Convert to TABLE
    CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'
    EXPORTING
    i_string = xml_out
    i_tabline_length = 100
    TABLES
    et_table = CONVERT_ITAB_TO_XML.
    Download
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    filetype = 'ASC'
    filename = 'D:\XX.XML'
    TABLES
    data_tab = CONVERT_ITAB_TO_XML
    endform.

  • Upload xml file from aplication server using read dataset, parser error.

    Hi,
    I would like to upload xml file from app. server but parser failed. If I upload this xml file from workstation (using ws_upload) it is correct. For uploading xml file from app. server I use open dataset... read dataset. In loop section I remove '#' char. How do You upload xml file from app server? What Could be incorrect.
    I try to open dataset in binary mode, text mode...
    TYPES: BEGIN OF xml_line,
            data(255) TYPE c,
          END OF xml_line.
    DATA: gt_xml_table TYPE TABLE OF xml_line,
          gs_xml_structure TYPE  xml_line,
          gv_xml_table_size TYPE i.
    OPEN DATASET s FOR INPUT IN BINARY MODE.
      IF sy-subrc <> 0.
        MESSAGE e001(zet) WITH '....'.
      ENDIF.
      DO.
        READ DATASET s INTO gs_xml_structure.
        IF sy-subrc <> 0.
          EXIT.
        ELSE.
         len = STRLEN( gs_xml_structure ).
         len = len - 1.
         check len > 0.
         WRITE gs_xml_structure(len) TO gs_xml_structure.
          APPEND gs_xml_structure TO gt_xml_table.
        ENDIF.
      ENDDO.

    You Can do this too
    parameters: p_file like rlgrap-filename.
    data: subrc like sy-subrc.
      create object me.
      REFRESH t_data.
    *  Open XML File
      CALL METHOD me->CREATE_WITH_FILE
        EXPORTING
          filename = p_file
        RECEIVING
          retcode  = subrc.
    * Saves Data in an itab from XML File.
      CALL METHOD me->get_data
        IMPORTING
          retcode    = subrc
        CHANGING
          dataobject = t_data[].
    Regards,
    Claudio.

  • Simple Transformation - ABAP 2 XML

    Dear all,
    Finally I was able to transform an internal table to xml using ST. The question is: Can I create different structured XML-files using the same (structured) internal table. Or is there some kind of a 1:1 relationship (between an ITAB structure + XML structure)?
    1) Data declaration
    TYPES: BEGIN OF ty_curr,
           tcurr  TYPE tcurr_curr,
           gdatu  TYPE gdatu_inv,
           ukurs  TYPE ukurs_curr.
    TYPES: END OF ty_curr.
    DATA: gt_tcurr TYPE TABLE OF ty_curr.
    2) Data selection
    Select * into corresponding fields of table gt_tcurr from tcurr where...
    3) Transformation ABAP 2 XML
          CALL TRANSFORMATION z_tcurr
            SOURCE root = gt_tcurr
            RESULT XML    g_xml_string.
    <?sap.transform simple?>
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
      <tt:root name="ROOT"/>
      <tt:template>
        <tt:serialize>
          <rates>
            <tt:loop name="line" ref=".ROOT">
              <currency>
                <tt:value ref="$line.tcurr"/>
              </currency>
              <date>
                <tt:value ref="$line.gdatu"/>
              </date>
              <rate>
                <tt:value ref="$line.ukurs"/>
              </rate>
            </tt:loop>
          </rates>
        </tt:serialize>
      </tt:template>
    </tt:transform>
    Result (XML)
      <?xml version="1.0" encoding="utf-8" ?>
    - <rates>
      <currency>USD</currency>
      <date>01.01.2010</date>
      <rate>-1.1868</rate>
      <currency>EUR</currency>
      <date>01.01.2010</date>
      <rate>-1.1791</rate>
      <currency>USD</currency>
      <date>02.01.2010</date>
      <rate>-1.1864</rate>
      <currency>EUR</currency>
      <date>02.01.2010</date>
      <rate>-1.1864</rate>
      </rates>:
    so far so good... BUT; if I want to get another XML structure
    Example 1)  -> sorted by currency
    <?xml version="1.0" encoding="utf-8" ?>
    - <rates>
      <currency>USD
      <date>01.01.2010</date>
      <rate>-1.1868</rate>
      <date>02.01.2010</date>
      <rate>-1.1868</rate>
      </currency>
      <currency>EUR
      <date>01.01.2010</date>
      <rate>-1.1868</rate>
      <date>02.01.2010</date>
      <rate>-1.1868</rate>
      </currency>
      </rates>
    Example 2) -> sored by date
    <?xml version="1.0" encoding="utf-8" ?>
    - <rates>
      <date>01.01.2010</date> 
       <currency>USD</currency>
      <rate>-1.1868</rate>
       <currency>EUR</currency>
      <rate>-1.1868</rate>
      <date>02.01.2010</date>
       <currency>USD</currency>
      <rate>-1.1868</rate>
       <currency>EUR</currency>
      <rate>-1.1868</rate>
      </rates>
    How can I achieve output example 1+2  using the same internal table as a source? Is this possible? I guess this can be solved within the transformation, right? Any help appreciated.
    Best regards
    Benno

    Thanks for all answers so far. Changing the sequence is not a "problem". What I want to achieve is to change hierarchy of the xml. I'll try to explain again with a simple example:
    ITAB (structure):
    name; birthday; ***; first name
    ITAB (content):
    Smith; 01.01.1970; M; Paul
    Smith; 01.01.1970; F; Stefanie
    Smith; 01.02.1980; F; Barbara
    White; 01.02.1980; M; Steve
    I want to pass the itab exactly the way it is (ok, sorting is allowed). Question: Can I achieve the following XML's using ST? I guess/hope this can be solved with variables/groups/condition statements within the transformation coding?
    Example xml- 1) Sorted/Grouped by Name/***
    <person>
                    <name>Smith
                                 <***>M    
                                       <birthday>01.01.1970</birthday><first name>Paul</first name>                            
                                 </***>
                                 <***>F 
                                       <birthday>01.01.1970</birthday><first name>Stefanie</first name>   
                                       <birthday>01.02.1980</birthday><first name>Barbara</first name>                                  
                                 </***>
                    </name>
                    <name>White
                                 <***>M    
                                       <birthday>01.02.1980</birthday><first name>Steve</first name>                            
                                 </***>
                    </name>
    </person>
    Exampe xml-2 ) Sorted/Grouped by Birthday (Names only)
    <person>
                    <birthday>01.01.1970
                                 <first name>Paul</first name>
                                 <first name>Stefanie</first name>                                 
                    </birthday>
                    <birthday>01.02.1980
                                 <first name>Barbara</first name>
                                 <first name>Steve</first name>                                 
                    </birthday>                        
    </person>

  • Simple Transformation from ABAP to XML and back

    Hi experts,
    Can anyone provide me a simple example of a 'simple transformation' that will convert and internal table with more than one column into XML via a simple transformation.
    I've spend days now reading SAP help and e-learning examples, but this just won't work and I am getting short dumps saying 'The goal was to access variable "ROOT". However, this access was notv possible.'
    Here is my ABAP:
    data: begin of struc,
               counter type i,
               aname type string,
               aname2 type string,
          end of struc.
    data: cnt_c type c.
    data: itab like table of struc with HEADER LINE,
          xml_string type xstring.
    do 3 times.
         move sy-index to: itab-counter, cnt_c.
         concatenate 'nameA' cnt_c into itab-aname.
         concatenate 'nameB' cnt_c into itab-aname2.
         append itab.
    enddo.
    CALL TRANSFORMATION Z_ST_TEST5
           SOURCE  ROOT = itab
           RESULT XML xml_string.
    CALL FUNCTION 'DISPLAY_XML_STRING'
      EXPORTING
        XML_STRING            = xml_string.
    skip 1.
    and here is my ST:
    <?sap.transform simple?>
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
      <tt:root name="ROOT"/>
        <tt:template>
         <TABLE>
          <tt:loop ref=".ROOT" name="line">
            <ITEM>
              <counter>
                <tt:value ref="$line.aname" />
              </counter>
              <name>
                <tt:value ref="$line.aname" />
              </name>
              <name2>
                <tt:value ref="$line.aname2" />
              </name2>
            </ITEM>
          </tt:loop>
         </TABLE>
        </tt:template>
    </tt:transform>

    Figured it out. The interla tables used in teh call transformation statement can never have a header line.

  • Need help with xml mapping

    HI All,
    i have sap internal table with this value and i want to mapp it to xml file like below,
    Name             value
    User                     1234
    DueDate                    yyyyy
    <User>1234</User>
    <DueDate>yyyyy</DueDate>
    the problem is when i use call transformation i get in the table
    <name>1234</name>
    <value>yyyyy</value>
    how can i get the mapp that i need ?
    Regards
    JOy
    Edited by: Joy Stpr on Aug 10, 2009 2:56 PM
    Edited by: Joy Stpr on Aug 10, 2009 3:47 PM

    Check this
    Program Code
    report zars
      no standard page heading line-size 255.
    data: xml_out type string .
    data: begin of ty_data,
          name type string,
          value type string,
    end of ty_data.
    types: begin of ty_user,
           user type sy-uname,
           duedate type sy-datum,
           end   of ty_user.
    data: itab type standard table of ty_user,
          la_tab like line of itab,
          xmlstr type xstring.
    la_tab-user = 'TEST1'.
    la_tab-duedate = '200908101'.
    append la_tab to itab.
    clear la_tab.
    la_tab-user = 'TEST2'.
    la_tab-duedate = '200909101'.
    append la_tab to itab.
    clear la_tab.
    data : itab1 type  swbhtmltable.
    data: it_data like  table of  ty_data,
          wa_data like line of it_data.
    data result type string.
    call transformation zaRs
    source table = itab
    result xml xml_out.
    call function 'SWA_STRING_TO_TABLE'
      exporting
        character_string = xml_out
      importing
        character_table  = itab1.
    call function 'GUI_DOWNLOAD'
      exporting
        filetype = 'BIN'
        filename = 'c:xx.xml'
      tables
        data_tab = itab1.
    XLST Program
    <?sap.transform simple?>
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
      <tt:root name="table"></tt:root>
      <tt:template>
        <table>
          <tt:loop ref=".table">
            <item>
              <USER>
                <tt:value ref="USER"></tt:value>
              </USER>
            </item>
            <item>
              <DUEDATE>
                <tt:value ref="DUEDATE"></tt:value>
              </DUEDATE>
            </item>
          </tt:loop>
        </table>
      </tt:template>
    </tt:transform>
    Result XML File
    <?xml version="1.0" encoding="iso-8859-1" ?>
    - <table>
    - <item>
      <USER>TEST1</USER>
      </item>
    - <item>
      <DUEDATE>2009-08-10</DUEDATE>
      </item>
    - <item>
      <USER>TEST2</USER>
      </item>
    - <item>
      <DUEDATE>2009-09-10</DUEDATE>
      </item>
      </table>

  • Closing tag in xml transformation

    Hi experts,
    I have the following ABAP code:
    ABAP itab to XML string
      CALL TRANSFORMATION id SOURCE data = ti_stocks[]
                             RESULT XML    ps_output.
    The result in ps_output should be an xml like this
    <?xml version="1.0" encoding="utf-16" ?>
    <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
    <asx:values>
    <DATA>
    <ZTABLE_STO>
      <FIELD1 /> ABC</FIELD1>
      <FIELD2 />0300</FIELD2>
      <FIELD3 />1</FIELD3>
      </ZTABLE_STO>
    etc.
    However, if my internal table ti_stocks contains the field1 with an empty value then the xml is incorrect without its corresponding closing tag:
    <?xml version="1.0" encoding="utf-16" ?>
    <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
    <asx:values>
    <DATA>
    <ZTABLE_STO>
      <FIELD1 />
      <FIELD2 />0300</FIELD2>
      <FIELD3 />1</FIELD3>
      </ZTABLE_STO>
    etc.
    How can I resolve this problem? I would like to have an open tag and a closing tag for every field.
    FIELD1 is a char type field.
    Thank you,
    Oscar
    Edited by: Oscar Arranz on Jan 26, 2012 2:46 PM

    Hello everyone, sorry for my english, I had the same requeriment for the end tag, the simple transformation give this result <xxx/> when the value was empty, and I did something similar to Oscar,
    i did the simple transformation and the result whas and xstring, i used a function to pass it to string, and then I make a replacement.
    here is some code:
    *  Genera XML
       data: xml_xstring          type xstring.
       data: w_xml                 type string.
       data: ixml                    type ref to if_ixml,
               streamfactory      type ref to if_ixml_stream_factory,
               encoding             type ref to if_ixml_encoding,
               ixml_ostream      type ref to if_ixml_ostream.
       data: resstream           type ref to if_ixml_ostream.
    ****Create an instance of the Ixml Processor
       ixml = cl_ixml=>create( ).
    *  ****Create the Stream Factory
       streamfactory = ixml->create_stream_factory( ).
    *  ****Create an Endcoding and Byte Order
       encoding = ixml->create_encoding( character_set = 'ISO-8859-1' byte_order = 0 ).
    *  *  ****Create the output stream with a pointer to our binary string
       ixml_ostream = streamfactory->create_ostream_xstring( xml_xstring ).
    *  ****Set the Encoding into a stream
       ixml_ostream->set_encoding( encoding = encoding ).
    ****Call simple Transformation
       call transformation zdte_libros
       source zcaratula = x_doc
       result xml ixml_ostream.
    *From xstring to string.
       call function 'HR_RU_CONVERT_HEX_TO_STRING'
              exporting
                     xstring = xml_xstring
              importing
                     cstring = w_xml.
    * <xxx/> to <xxx><xxx/>
       replace all occurrences of regex '<([^><\s]+)( [^><]+)?/>' in w_xml with '<$1$2></$1>'.
    Hope it helps someone with the same problem .

  • Converting an sap file output program into xml output

    Hi,
    I have developed a program from which i am able to generate outptut as a file. Since this file is going to be used by the third party system, user has come back asking me to generate an conversion program into xml of the file output.
    Since i have not handled previously about generating the xml conversion program. Please let me know how to do this or if you could provide me the sample program it will be great.
    Thanks in advance.
    Sunil Kumar

    Hello
    Just for example:
    data: itab type standard table of sflight.
    data: xml_out type string,xmltab type swbhtmltable.
    select * from sflight into table itab.
    call transformation ('ID')
    source tab = itab[]
    result xml xml_out.
    call function 'SWA_STRING_TO_TABLE'
    exporting
    character_string = xml_out
    importing
    character_table = xmltab.
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    call function 'GUI_DOWNLOAD'
    exporting
    filetype = 'BIN'
    filename = 'C:\xmlfile.xml'
    tables
    data_tab = xmltab.
    P.s. search SDN for CALL TRANSFORMATION

  • Help with ABAP Structure to XML - Simple Transformation

    Hi guys,
    I need help with a Simple Transformation. I am trying to convert a structure in ABAP to XML String but i ma getting short dumps...
    Can any of you help.
    Thanks in advance.
    *& Report  ZTESTXML
    REPORT  ZTESTXML.
    class demo DEFINITION.
       PUBLIC SECTION.
       CLASS-METHODS main.
       ENDCLASS.
       CLASS demo IMPLEMENTATION.
         method main.
           data : begin of account,
                    partner type bu_partner,
                    primary(1),
                    update(3),
                    email(50),
                    memberid(4),
                    telephone(12),
                    fax(10),
                    dept(20),
                    end of account.
            data : xmlstr type xstring.
                    account-partner = '12345'.
                    account-primary = 'N'.
                    account-update = 'Yes'.
                    account-email = 'zz at hotmail.com'.
                    account-memberid = '555'.
                    account-telephone = '123-448-6710'.
                    account-fax = '345-123-7899'.
                    account-dept = 'Info Systems'.
                    call TRANSFORMATION ztest_inttable
                                        SOURCE account = 'account'
                                        result XML xmlstr.
           call FUNCTION 'DISPLAY_XML_STRING'
               EXPORTING xml_string = xmlstr.
           ENDMETHOD.
           ENDCLASS.
           start-of-SELECTION.
             demo=>main( ).
    Transformation
    <?sap.transform simple?>
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
      <tt:root name="account"/>
      <tt:template>
        <IGT_CRM_AccountInfo>
          <Account>
            <tt:ref name=".account">
              <tt:attribute name="Id" value-ref="PARTNER"/>
              <tt:attribute name="Primary" value-ref="primary"/>
              <tt:attribute name="Update" value-ref="update"/>
              <Contact>
                <tt:attribute name="EMail" value-ref="email"/>
                <tt:attribute name="Member Id" value-ref="memberid"/>
              </Contact>
              <Communications>
                <tt:attribute name="Telephone" value-ref="telephone"/>
                <tt:attribute name="Fax" value-ref="fax"/>
              </Communications>
              <IGT>
                <tt:attribute name="Department" value-ref="dept"/>
              </IGT>
            </tt:ref>
          </Account>
        </IGT_CRM_AccountInfo>
      </tt:template>
    </tt:transform>
    Dump message
    An exception occurred that is explained in detail below.
    The exception, which is assigned to class 'CX_ST_REF_ACCESS', was not caught in
    procedure "MAIN" "(METHOD)", nor was it propagated by a RAISING clause.
    Since the caller of the procedure could not have anticipated that the
    exception would occur, the current program is terminated.
    The reason for the exception is:
    The goal was to access variable "PARTNER". However, this access was not
    possible.

    to convert abap itab or variable into xml string use ABAP key word call transformation.
    call transformation (`ID`)
                source output = itab[]
                result xml xml_out.
    where itab is your internal table or any abap variable.
    xml_out is type string which will hold the resulting xml.
    ID is the transformation program. if you wanto use your own transformation, use your XSLT or ST program there.
    Raja

  • XML conversion for special charaters & , , etc..

    Hi ,
    I'm trying to generate a XML file to send the sales order details , in the when ever there are special charaters like & < etc..
    it's getting converted to &amp; LT; etc...
    I'm using IF_IXML interface and create_text method to convert the text in R/3 to XML.
    Any idea how to over come this?
    Regards,
    Raghavendra

    Hello Raghavendra,
    You can use identical transformation which is easy and will convert all the special chars while creating xml file.
    CALL TRANSFORMATION ID
                 SOURCE ITAB = ITAB[]
                 RESULT XML XML_STRING.
    Here xml_string will contain full xml file with all conversion taken care.
    You can refer to SAP help on identical transformation.
    Hope this helps!
    Thanks,
    Augustin.

  • XML Conversion

    Hi ,
    XML does not allow the use of characters: &, u2018, u201C, <, and >.  in data we can have these characters.
    Please provide your suggestions to resolve this problem.
    Also , provide your suggestions  to convert the Line feeds in Standard text to line feeds in XML.
    Thanks.

    Hello Rathesh,
    Starting from SAP 4.7 version you can use identical transformation to convert ABAP data into XML file.
    Transformation also takes care of the special chars those are not allowed to use in XML.
    Following is the sample code:
    DATA ITAB TYPE TABLE OF .......
    DATA xml_string TYPE STRING.
    CALL TRANSFORMATION ID
                   SOURCE TABLE = ITAB[]
                   RESULT XML xml_string.
    xml_string will contain full xml file after transformation.
    For more details you can refere to syntax help for CALL TRANSFORMATION.
    Thanks,
    Augustin.

  • Generation of XML

    I need to download the table data into XML Format.
    For that we can use Transformations. But i am using 4.6c. Here i think some of the classes wont available to use that statement.
    Kindly sugggest how to approach

    Hi
    Use the function module
    SAP_CONVERT_TO_XML_FORMAT
    Example
    TYPE-POOLS truxs.
    DATA:
      itab TYPE TABLE OF spfli,
      itab1 TYPE truxs_xml_table,
      fs TYPE truxs_xml_line,
      w_xml TYPE xstring.
    SELECT * FROM spfli INTO TABLE itab.
    CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'
    * EXPORTING
    *   I_FIELD_SEPERATOR          =
    *   I_LINE_HEADER              =
    *   I_FILENAME                 =
    *   I_APPL_KEEP                = ' '
    *   I_XML_DOC_NAME             =
    * IMPORTING
    *   PE_BIN_FILESIZE            =
      TABLES
        i_tab_sap_data             = itab
    CHANGING
       i_tab_converted_data       = itab1
    * EXCEPTIONS
    *   CONVERSION_FAILED          = 1
    *   OTHERS                     = 2
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    LOOP AT itab1 INTO fs.
      WRITE:/ fs-data.
    ENDLOOP.
    the above works the same as this,
    CALL TRANSFORMATION id SOURCE
                            source = itab
                            RESULT XML w_xml.
    ULINE.
    WRITE:/ w_xml.
    regards
    sarves

  • Sending data from final internal table  to application server in xml format

    hi to all ,
    can anyone send details about send data from final internal table to application server in xml format.right now i am able to download data to presentation server in xml format . love to here soon from all the abap gigs.

    welcome to SDN.
    are you using call transformation to convert itab to XML? the XML string is in which format?
    convert it to xstring and then use the following code to store it in application server.
    OPEN DATASET fname FOR OUTPUT IN BINARY MODE.
    TRANSFER XML_content TO FNAME.
    CLOSE DATASET FNAME.
    where fname is the path to the file name.
    Regards
    Raja

Maybe you are looking for

  • Close Front Panel Causes System Hang.

    I have an application where there are several front panels that I would like to have open at once, but where when they stop they would close.  I was using the scripting function fp.close - but as the application has got more complicated this seems to

  • Creation of multiple PO IDOCs for multiple vendors in one directory

    Hi , I got a scenario to download all the vendor related PO and RFQ IDOCs to one common directory .i.e EDI Port path: /sap/xxxx.I cannot create partner profile LI for each and every vendor. Would be appreciated if any one can suggest alternative for

  • Scenario – Multi Tenant ConfigMgr 2012 R2 and Same IP Address range for multiple customer

    The service provider plans on managing customer's workstation/desktop via ConfigMgr 2012 R2 CU3 which is hosted at Service Provider's network however the Secondary Site (MP/DP Role) is hosted at customer's physical location and on their network but n

  • BPM Configuration

    Hi Guru's My client wants to implement BPM in Solution manager 7.0. Want to see look feel about it. Is there any Prototype setup document to show what and all we get after implementing BPM. I mean is there any Configuration Blog for BPM? Please reply

  • Unable to register a managed account

    hi, when i tried register a managed account in my central admin, i am getting error "Requested registry access is not allowed. " may i know how to resolve this error. i have full control on my sp server which has windows server 2012,  sp 2013, vs 201