Store/persist XML file on ABAP stack

Hi everybody,
as the ABAP Database is a relational DB, I wonder where to store a XML file. Is there a dedicated table?
Thanks
Regards Mario
Edited by: Mario Müller on Sep 10, 2008 2:21 AM

hi
try with this function module SMUM_XML_PARSE for parsing xml document into a table structure
also check this document for how an abap prog take xml and convert into an abap internal table
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/f50dcd4e-0501-0010-3596-b686a7b51492
convert an xml file into abap internal table using sap dom approach
XML DOM Processing in ABAP part II - Convert an XML file into an ABAP table using SAP DOM Approach.
regards
kummari

Similar Messages

  • Simple Transformation to deserialize an XML file into ABAP data structures?

    I'm attempting to write my first simple transformation to deserialize
    an XML file into ABAP data structures and I have a few questions.
    My simple transformation contains code like the following
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates"
                  xmlns:pp="http://www.sap.com/abapxml/types/defined" >
    <tt:type name="REPORT" line-type="?">
      <tt:node name="COMPANY_ID" type="C" length="10" />
      <tt:node name="JOB_ID" type="C" length="20" />
      <tt:node name="TYPE_CSV" type="C" length="1" />
      <tt:node name="TYPE_XLS" type="C" length="1" />
      <tt:node name="TYPE_PDF" type="C" length="1" />
      <tt:node name="IS_NEW" type="C" length="1" />
    </tt:type>
    <tt:root name="ROOT2" type="pp:REPORT" />
        <QueryResponse>
        <tt:loop ref="ROOT2" name="line">
          <QueryResponseRow>
            <CompanyID>
              <tt:value ref="$line.COMPANY_ID" />
            </CompanyID>
            <JobID>
              <tt:value ref="$line.JOB_ID" />
            </JobID>
            <ExportTypes>
              <tt:loop>
                <ExportType>
                   I don't know what to do here (see item 3, below)
                </ExportType>
              </tt:loop>
            </ExportTypes>
            <IsNew>
              <tt:value ref="$line.IS_NEW"
              map="val(' ') = xml('false'), val('X') = xml('true')" />
            </IsNew>
          </QueryResponseRow>
          </tt:loop>
        </QueryResponse>
        </tt:loop>
    1. In a DTD, an element can be designated as occurring zero or one
    time, zero or more times, or one or more times. How do I write the
    simple transformation to accommodate these possibilities?
    2. In trying to accommodate the "zero or more times" case, I am trying
    to use the <tt:loop> instruction. It occurs several layers deep in the
    XML hierarchy, but at the top level of the ABAP table. The internal
    table has a structure defined in the ABAP program, not in the data
    dictionary. In the simple transformation, I used <tt:type> and
    <tt:node> to define the structure of the internal table and then
    tried to use <tt:loop ref="ROOT2" name="line"> around the subtree that
    can occur zero or more times. But every variation I try seems to get
    different errors. Can anyone supply a working example of this?
    3. Among the fields in the internal table, I've defined three
    one-character fields named TYPE_CSV, TYPE_XLS, and TYPE_PDF. In the
    XML file, I expect zero to three elements of the form
    <ExportType exporttype='csv' />
    <ExportType exporttype='xls' />
    <ExportType exporttype='pdf' />
    I want to set field TYPE_CSV = 'X' if I find an ExportType element
    with its exporttype attribute set to 'csv'. I want to set field
    TYPE_XLS = 'X' if I find an ExportType element with its exporttype
    attribute set to 'xls'. I want to set field TYPE_PDF = 'X' if I find
    an ExportType element with its exporttype attribute set to 'pdf'. How
    can I do that?
    4. For an element that has a value like
    <ErrorCode>123</ErrorCode>
    in the simple transformation, the sequence
    <ErrorCode>  <tt:value ref="ROOT1.CODE" />  </ErrorCode>
    seems to work just fine.
    I have other situations where the XML reads
    <IsNew value='true' />
    I wanted to write
    <IsNew>
            <tt:value ref="$line.IS_NEW"
            map="val(' ') = xml('false'), val('X') = xml('true')" />
           </IsNew>
    but I'm afraid that the <tt:value> fails to deal with the fact that in
    the XML file the value is being passed as the value of an attribute
    (named "value"), rather than the value of the element itself. How do
    you handle this?

    Try this code below:
    data  l_xml_table2  type table of xml_line with header line.
    W_filename - This is a Path.
      if w_filename(02) = '
        open dataset w_filename for output in binary mode.
        if sy-subrc = 0.
          l_xml_table2[] = l_xml_table[].
          loop at l_xml_table2.
            transfer l_xml_table2 to w_filename.
          endloop.
        endif.
        close dataset w_filename.
      else.
        call method cl_gui_frontend_services=>gui_download
          exporting
            bin_filesize = l_xml_size
            filename     = w_filename
            filetype     = 'BIN'
          changing
            data_tab     = l_xml_table
          exceptions
            others       = 24.
        if sy-subrc <> 0.
          message id sy-msgid type sy-msgty number sy-msgno
                     with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        endif.

  • Creating an xml file from abap code

    Hello All,
    Please let me know which FM do I need to execute in order to create an XML file from my ABAP code ?
    Thanks in advance,
    Paul.

    This has been discussed before
    XML files from ABAP programs

  • Create XML file from ABAP with SOAP Details

    Hi,
    I am new to XML and I am not familiar with JAVA or Web Service. I have searched in SDN and googled for a sample program for creating XML document from ABAP with SOAP details. Unfortunately I couldn't find anything.
    I have a requirement for creating an XML file from ABAP with SOAP details. I have the data in the internal table. There is a Schema which the client provided and the file generated from SAP should be validating against that Schema. Schema contains SOAP details like Envelope, Header & Body.
    My question is can I generate the XML file using CALL TRANSFORMATION in SAP with the SOAP details?
    I have tried to create Transformation (Transaction XSLT_TOOL) in SAP with below code. Also in CALL transformation I am not able to change the encoding to UTF-8. It's always show UTF-16.
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
      <xsl:template match="/">
        <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
          <SOAP:Header>
            <CUNS:HeaderInfo>
              <CUNS:InterfaceTypeId>10006</InterfaceTypeId>
              <CUNS:BusinessPartnerID>11223344</BusinessPartnerID>
              <CUNS:SchemaVersion>1.0</SchemaVersion>
              <CUNS:DateTime>sy-datum</DateTime>
            </CUNS:HeaderInfo>
          </SOAP:Header>
          <SOAP:Body>
            <xsl:copy-of select="*"/>
          </SOAP:Body>
        </SOAP:Envelope>
      </xsl:template>
    </xsl:transform>
    In ABAP program, I have written below code for calling above Transformation.
      call transformation ('Z_ID')
           source tab = im_t_output[]
           result xml xml_out.
      call function 'SCMS_STRING_TO_FTEXT'
        exporting
          text      = xml_out
        tables
          ftext_tab = ex_t_xml_data.
    Please help me how to generate XML file with SOAP details from ABAP. If anybody have a sample program, please share with me.
    Is there any easy way to create the XML file in CALL Transformation. Please help.
    Thanks

    Try ABAP forum, as it seems not to be PI related.

  • How to read the data from Excel file and Store in XML file using java

    Hi All,
    I got a problem with Excel file.
    My problem is how to read the data from Excel file and Store in XML file using java excel api.
    For getting the data from Excel file what are all the steps i need to follow to get the correct result.
    Any body can send me the code (with java code ,Excel sheet) to this mail id : [email protected]
    Thanks & Regards,
    Sreenu,
    [email protected],
    india,

    If you want someone to do your work, please have the courtesy to provide payment.
    http://www.rentacoder.com

  • Transforming XML File to abap structure

    Hello,
    I am working in a new project for making an input interface.
    The problem to resolv is :
    1>Reading an XML file on a unix Server
    2>Transforming this file in abap structure with the instruction
    call transformation.
    Format of the input file :
    <LISTEART>
    <ART code="A01" label="Designation A01"/>
    <ART code="A02" label="Designation A02"/>
    <ART code="A03" label="Designation A03"/>
    <ART code="A04" label="Designation A04"/>
    <ART code="A05" label="Designation A05"/>
    </LISTEART>
    Format of the abap structure :
    DATA : BEGIN OF ws_art,
      code(4)      TYPE c,
      label(3)  TYPE c,
    END OF ws_art.
    DATA : wt_art LIKE ws_art OCCURS 0 WITH HEADER LINE.
    is it possible to transform the input file to an internal table
    with the call transformation ?
    CALL TRANSFORMATION transfo
       SOURCE XML xml_string
       RESULT para = result.
    Somebody can explain me how to create links between xml file
    and abap structure ?
    with regards 
    JLuc Ledoux
    [email protected]

    Hi,
    try like this.
    TYPES: BEGIN OF day,
    name TYPE string,
    work(1) TYPE c,
    END OF day.
    DATA: BEGIN OF week,
    day1 TYPE day,
    day2 TYPE day,
    day3 TYPE day,
    day4 TYPE day,
    day5 TYPE day,
    day6 TYPE day,
    day7 TYPE day,
    END OF week.
    DATA xml_string TYPE string.
    DATA result LIKE week.
    week-day1-name = 'Monday'. week-day1-work = 'X'.
    week-day2-name = 'Tuesday'. week-day2-work = 'X'.
    week-day3-name = 'Wednesday'. week-day3-work = 'X'.
    week-day4-name = 'Thursday'. week-day4-work = 'X'.
    week-day5-name = 'Friday'. week-day5-work = 'X'.
    week-day6-name = 'Saturday'. week-day6-work = ' '.
    week-day7-name = 'Sunday'. week-day7-work = ' '.
    CALL TRANSFORMATION ...
    SOURCE root = week
    RESULT XML xml_string.
    CALL TRANSFORMATION ...
    SOURCE XML xml_string
    RESULT root = result.
    Regards,
    Vijay

  • I want to store an xml file into database, and transport it to the XI.

    tell me  in how many ways we can store a xml file in database.
    one i know is.- create a table with field same as that of XML. store XML file data in it
    and at the time of transfering data to XI fatch data from table and create an XML file and transfer...
    tell me if u know some more

    Dear Swethi,
    You can move images to SAP using SE78. then u can use them where ever u you require them.
    SE78->GRAPHICS->BMAP here give ur image name and click on save
    Rgds,
    Kiran
    Edited by: Kiran on Jun 11, 2009 7:15 AM

  • Parsing XML Files to ABAP

    Hello All,
    There is a requirement for parsing of XML files to ABAP.
    1.How do we pick an XML file from Application server and also from FTP server?
    2.After picking the XML file how to parse that XML file to process it to create material master?

    Hi,
    Ur scenario is File to R/3
    For creating material master ..i guess there is IDoc named MATMAS.
    U can make use of it and execute File to IDoc Scenario.
    link for File to IDoc--
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/xi/fileToIDOC&
    U need to pick XML file from FTP server...No need to parse XML file...just create data type which represents ur xml file structure and map it to IDoc fields.
    regards,
    Manisha

  • Import XML file into ABAP WD

    Hi,
    Is there any way to upload an XML file into ABAP WD?
    I just saw a blog for Java WD.
    <a href="/people/johann.marty/blog/2006/10/03/create-a-web-dynpro-tree-from-an-xml-file:///people/johann.marty/blog/2006/10/03/create-a-web-dynpro-tree-from-an-xml-file
    Is there a similar facility in ABAP WD?
    Regards,
    Haresh.

    hey u can do this by using CALL Transformation id.. command..
    here is the example code where i wrote this to convert it DATA to XML format...it may help u..
      DATA : BEGIN OF l_xml_tab OCCURS 0,
              a(100) TYPE c,
             END OF l_xml_tab.
      DATA : xml_out TYPE string .
      DATA : lw_xml_tab LIKE LINE OF l_xml_tab.
    XML
      CALL TRANSFORMATION id "('ID')
      SOURCE tab = gt_outtab[]
      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         = l_xml_tab.
      OPEN DATASET p_lgfil1 FOR OUTPUT IN BINARY MODE.
      LOOP AT l_xml_tab INTO lw_xml_tab.
        TRANSFER lw_xml_tab TO p_lgfil1.
      ENDLOOP.
      CLOSE DATASET p_lgfil1.

  • XML file or Configuration stack file for Ehp inclusion in Upgradation

    Hi,
    We are Upgrading 4.7 to Ecc 6.0, we want to include Ehp3 in the Upgradation but we are not able to generate XML or Configuration stack file, can anybody please help me to get XML file or Configuration stack file for Ehp inclusion in Upgradation.
    Regards,

    Hi Aashish,
    can you please provide some further information?
    What exactly are you doing in the SAP Solution Manager - Maintenance Optimizer?
    I assume that you are at least on SP 15 which is a prerequisite.
    Currently a common error is a wrong maintained SMSY: Please check SAP note 1022072 for details.
    Best regards,
    Christian.

  • Urgent : XML File to ABAP

    Hi Experts,
    My requirement is I have to process one XML file(idoc) in ABAP program and to store the contents of the XML file in internal table.
    Pls help.
    Any Useful inputs on this will be rewarded with points.
    Rgds,
    Lakshmiraj.A

    Check this code.
    if you are not comfortable with XSLT do the following
    1. read the xml into a string
    2. convert the string to xstring using SCMS_STRING_TO_XSTRING
    3. now use FM SMUM_XML_PARSE and pass the xstring xml_input parameter of that function.
    this will parse the whole xml and give you an itab of element name value pairs which you can read easily
    As i told you, the ABAP CALL TARNSFORMATION command is very simple (with F1 help you will deal with it).
    But if you don't know the XLST language perphaps you should use the moderator advice. An example wouldn't help you at this time because it's not that easy to adapt it.
    I've commented several lines. Here is an example:
    *& Report z_xit_xml_check
    report z_xit_xml_check.
    class cl_ixml definition load.
    type-pools: ixml.
    types: begin of t_xml_line,
    data(256) type x,
    end of t_xml_line,
    begin of tsfixml,
    data(1024) type c,
    end of tsfixml.
    data: l_ixml type ref to if_ixml,
    l_streamfactory type ref to if_ixml_stream_factory,
    l_parser type ref to if_ixml_parser,
    l_istream type ref to if_ixml_istream,
    l_document type ref to if_ixml_document,
    l_node type ref to if_ixml_node,
    l_xmldata type string.
    data: l_elem type ref to if_ixml_element,
    l_root_node type ref to if_ixml_node,
    l_next_node type ref to if_ixml_node,
    l_name type string,
    l_iterator type ref to if_ixml_node_iterator.
    data: l_xml_table type table of t_xml_line,
    l_xml_line type t_xml_line,
    l_xml_table_size type i.
    data: l_filename type string.
    parameters: pa_file type char1024 default
    'd:\joao\desenvolvimentos\fi\fact\teste.xml'.
    Validation of XML file: Only DTD included in xml document is supported
    parameters: pa_val type char1 as checkbox.
    start-of-selection.
    Creating the main iXML factory
    l_ixml = cl_ixml=>create( ).
    Creating a stream factory
    l_streamfactory = l_ixml->create_stream_factory( ).
    perform get_xml_table changing l_xml_table_size l_xml_table.
    wrap the table containing the file into a stream
    l_istream = l_streamfactory->create_istream_itable( table =
    l_xml_table
    size =
    l_xml_table_size ).
    Creating a document
    l_document = l_ixml->create_document( ).
    Create a Parser
    l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
    istream = l_istream
    document = l_document ).
    Validate a document
    if pa_val eq 'X'.
    l_parser->set_validating( mode = if_ixml_parser=>co_validate ).
    endif.
    Parse the stream
    if l_parser->parse( ) ne 0.
    if l_parser->num_errors( ) ne 0.
    data: parseerror type ref to if_ixml_parse_error,
    str type string,
    i type i,
    count type i,
    index type i.
    count = l_parser->num_errors( ).
    write: count, ' parse errors have occured:'.
    index = 0.
    while index < count.
    parseerror = l_parser->get_error( index = index ).
    i = parseerror->get_line( ).
    write: 'line: ', i.
    i = parseerror->get_column( ).
    write: 'column: ', i.
    str = parseerror->get_reason( ).
    write: str.
    index = index + 1.
    endwhile.
    endif.
    endif.
    Process the document
    if l_parser->is_dom_generating( ) eq 'X'.
    perform process_dom using l_document.
    endif.
    *& Form get_xml_table
    form get_xml_table changing l_xml_table_size type i
    l_xml_table type standard table.
    Local variable declaration
    data: l_len type i,
    l_len2 type i,
    l_tab type tsfixml,
    l_content type string,
    l_str1 type string,
    c_conv TYPE REF TO cl_abap_conv_in_ce,
    l_itab type table of string.
    l_filename = pa_file.
    upload a file from the client's workstation
    call method cl_gui_frontend_services=>gui_upload
    exporting
    filename = l_filename
    filetype = 'BIN'
    importing
    filelength = l_xml_table_size
    changing
    data_tab = l_xml_table
    exceptions
    others = 19.
    if sy-subrc 0.
    message id sy-msgid type sy-msgty number sy-msgno
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
    Writing the XML document to the screen
    CLEAR l_str1.
    LOOP AT l_xml_table INTO l_xml_line.
    c_conv = cl_abap_conv_in_ce=>create( input = l_xml_line-data
    *replacement = space ).
    c_conv->read( IMPORTING data = l_content len = l_len ).
    CONCATENATE l_str1 l_content INTO l_str1.
    ENDLOOP.
    l_str1 = l_str1+0(l_xml_table_size).
    SPLIT l_str1 AT cl_abap_char_utilities=>cr_lf INTO TABLE l_itab.
    WRITE: /.
    WRITE: /' XML File'.
    WRITE: /.
    LOOP AT l_itab INTO l_str1.
    REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab
    *IN
    l_str1 WITH space.
    WRITE: / l_str1.
    ENDLOOP.
    WRITE: /.
    endform. "get_xml_table
    *& Form process_dom
    form process_dom using document type ref to if_ixml_document.
    data: node type ref to if_ixml_node,
    iterator type ref to if_ixml_node_iterator,
    nodemap type ref to if_ixml_named_node_map,
    attr type ref to if_ixml_node,
    name type string,
    prefix type string,
    value type string,
    indent type i,
    count type i,
    index type i.
    data: name2 type string,
    name_root type string,
    node_parent type ref to if_ixml_node,
    node_root type ref to if_ixml_node,
    num_children type i.
    node ?= document.
    check not node is initial.
    uline.
    write: /.
    write: /' DOM-TREE'.
    write: /.
    if node is initial. exit. endif.
    create a node iterator
    iterator = node->create_iterator( ).
    get current node
    node = iterator->get_next( ).
    loop over all nodes
    while not node is initial.
    indent = node->get_height( ) * 2.
    indent = indent + 20.
    num_children = node->num_children( ).
    case node->get_type( ).
    when if_ixml_node=>co_node_element.
    element node
    name = node->get_name( ).
    nodemap = node->get_attributes( ).
    node_root = node->get_root( ).
    name_root = node_root->get_name( ).
    write: / 'ELEMENT :'.
    write: at indent name color col_positive inverse.
    write: 'NUM_CHILDREN:', num_children.
    write: 'ROOT:', name_root.
    node_parent = node->get_parent( ).
    name2 = node_parent->get_name( ).
    write: 'NAME2: ' , name2.
    if not nodemap is initial.
    attributes
    count = nodemap->get_length( ).
    do count times.
    index = sy-index - 1.
    attr = nodemap->get_item( index ).
    name = attr->get_name( ).
    prefix = attr->get_namespace_prefix( ).
    value = attr->get_value( ).
    write: / 'ATTRIBUTE:'.
    write: at indent name color col_heading inverse, '=',
    value color col_total inverse.
    enddo.
    endif.
    when if_ixml_node=>co_node_text or
    if_ixml_node=>co_node_cdata_section.
    text node
    value = node->get_value( ).
    write: / 'VALUE :'.
    mjprocha
    node_parent = node->get_parent( ).
    write: at indent value color col_group inverse.
    name2 = node_parent->get_name( ).
    write: 'NAME2: ' , name2.
    endcase.
    advance to next node
    node = iterator->get_next( ).
    endwhile.
    endform. "process_dom
    Also, check this blog:
    /people/r.eijpe/blog/2005/11/21/xml-dom-processing-in-abap-part-ii--convert-an-xml-file-into-an-abap-table-using-sap-dom-approach
    Hope this resolves your query.
    Reward all the helpful answers.
    Regards
    Edited by: sharad narayan on Apr 4, 2008 8:23 AM

  • Issue in Creation of XML file from ABAP data

    Hi,
    I need to create a XML file, but am not facing some issues in creation of XML file, the in the required format.
    The required format is
    -<Header1 1st field= u201CValueu201D 2nd field= u201CValueu201D>
       - <Header2 1st field= u201CValueu201D 2nd field= u201CValueu201Du2026u2026. Upto 10 fields>
              <Header3 1st field= u201CValueu201D 2nd field= u201CValueu201Du2026u2026. Upto 6 fields/>
              <Header4  1st field= u201CValueu201D 2nd field= u201CValueu201Du2026u2026. Upto 4 fields/.>
               <Header5 1st field= u201CValueu201D 2nd field= u201CValueu201Du2026u2026. Upto 6 fields/>
          </Header2>
       </Header1>
    Iu2019m using the call transformation to convert ABAP data to XML file.
    So please anybody can help how to define XML structure in transaction XSLT_TOOL.
    And one more thing, here I need to put the condition to display the Header 3, Header 4, Header 5 values. If there is no record for a particular line item in header 3, 4 & 5, I donu2019t want to display full line items; this is only for Header 3, 4 & 5.
    Please help me in this to get it resolved.

    Hello,
    you can use CALL TRANSFORMATION id, which will create a exact "print" of the ABAP data into the XML.
    If you need to change the structure of XML, you can alter your ABAP structure to match the requirements.
    Of course you can create your own XSLT but that is not that easy to describe and nobody will do that for you around here. If you would like to start with XSLT, you´d better start the search.
    Regards Otto

  • Can we do a Secure FTP for an XML file from ABAP when firewall is enabled?

    Hi all,
    I have a requirement to send an XML file to an External FTP Server which is out of our corporate network and our firewall is enabled.
    I have to send an XML file with Purchase Order details. I completed that with the help of this blog https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/2657. [original link is broken] [original link is broken] [original link is broken]
    Now I need to FTP the XML file that is generated. How should I be doing this? Can some of help me with this?
    I need to do a Secure FTP to the external non SAP server which is out of our corporate network and our firewall is enabled. Can some one tell me if SFTP is possible in ABAP.
    This is not a web service. I am working on dropping an XML file in an external FTP serveru2026 I have searched the forums but still in a confusion if weather Secure FTP is possible in ABAP  or not when our company firewall is enabledu2026
    If some one encountered this situation earlier please help,,,..any help will be highly appreciated.
    Regards,
    Jessica Sam

    Thanks a lot for your valuable suggestions Richu2026
    I agree with you Rich that web services would be a better option. But I need to send this file to an external third party and they dont have web services.
    They are telling us that either we can send them an XML file or a CSV file in the format that they want. We decided to go with XML file format.
    I am done with formatting the Purchase Order details in the format that they want. Now the challenge is that I need to send this FTP file to them and it should be a Secure FTP when our fire wall is enabled,
    When you say
    1) Run an ABAP program to generate the XML file and put it on the local PC
    2) Log into the FTP site via some FTP client, could simply be windows as well.
    3) Manually cut/paste the file from the PC to the FTP site.
    For Step 1 running ABAP Program can I schedule a batch job?
    For Step 2 and Step 3 can I automate it in any other way..if not in ABAP?
    Can I advice my company to follow any alternate method in which they can automate this step 2 and step 3u2026if not in ABAP can it be possible in any other way as the third party does not have web services I now have no other alternative.
    Please Helpu2026
    Regards,
    Jessica Sam

  • Reading XML file to ABAP internal table

    Hi all,
    Iam trying to convert a XLM file into abap internal table , am using XSLT transformation to parse the XML file and i am using "CALL METHOD cl_gui_frontend_services=>gui_upload" for reading the XML file.
    below is the XML file.
    ===========================================================================
    - <PIXBridge version="2.2" timestamp="2003-04-09T15:27:00">
    - <PIX>
      <TransactionType>605</TransactionType>
      <TransactionCode>98</TransactionCode>
      <TransactionNumber>6888965</TransactionNumber>
      <SequenceNumber>40001</SequenceNumber>
    - <SKUDefinition>
      <Company>GZL</Company>
      <Division>BMD</Division>
      <Season />
      <SeasonYear />
      <Style>ORT002A</Style>
      <StyleSuffix />
      <Color>K13</Color>
      <ColorSuffix />
      <SecDimension />
      <Quality />
      <SizeRangeCode />
      <SizeDesc>M</SizeDesc>
      <SkuID>200140577</SkuID>
      </SKUDefinition>
      </PIX>
      </PIXBridge>
    =================================================================
    and my Transformation code is as below
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
      <xsl:strip-space elements="*"/>
      <xsl:template match="/">
        <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
          <asx:values>
            <IPIX>
              <xsl:apply-templates select="//PIX"/>
            </IPIX>
          </asx:values>
        </asx:abap>
      </xsl:template>
      <xsl:template match="PIX">
        <item>
          <TRANSACTIONTYPE>
            <xsl:value-of select="TransactionType"/>
          </TRANSACTIONTYPE>
          <TRANSACTIONCODE>
            <xsl:value-of select="TransactionCode"/>
          </TRANSACTIONCODE>
          <TRANSACTIONNUMBER>
            <xsl:value-of select="TransactionNumber"/>
          </TRANSACTIONNUMBER>
          <SEQUENCENUMBER>
            <xsl:value-of select="SequenceNumber"/>
          </SEQUENCENUMBER>
          <SKUDEFINITION>
            <COMPANY>
              <xsl:value-of select="Company"/>
            </COMPANY>
            <DIVISION>
              <xsl:value-of select="Division"/>
            </DIVISION>
            <SEASON/>
            <SEASONYEAR/>
            <STYLE>
              <xsl:value-of select="Style"/>
            </STYLE>
            <STYLESUFFIX/>
            <COLOR>
            <xsl:value-of select="Color"/>
            </COLOR>
            <COLORSUFFIX/>
            <SECDIMENSION/>
            <QUANTITY/>
            <SIZERANGECODE/>
            <SIZEDESC>
              <xsl:value-of select="SizeDesc"/>
            </SIZEDESC>
            <SKUID>
              <xsl:value-of select="SkuID"/>
            </SKUID>
          </SKUDEFINITION>
          </item>
        </xsl:template>
    When i run my program i am getting the values only till the sequence number part and im not getting any values  that is read in between <SKUDEFINITION> ..... </SKUDEFINITION>
    I need help to sort this , kindly help me in this.
    regs,
    raja

    I am not able to get a clue out of that, can Get Durairaj Athavan Raja in to loop for sorting this out.
    I made changes to my transformation program , but still not getting the output of the components inside the
    <SKUDefinition> , but when i debug  the transformation i can able to see the output values for those components but when i get the values in the result table im not getting values of those components.
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
      <xsl:strip-space elements="*"/>
      <xsl:template match="/">
        <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
          <asx:values>
            <IPIX>
              <xsl:apply-templates select="//PIX"/>
            </IPIX>
          </asx:values>
        </asx:abap>
      </xsl:template>
      <xsl:template match="PIX">
        <item>
          <TRANSACTIONTYPE>
            <xsl:value-of select="TransactionType"/>
          </TRANSACTIONTYPE>
          <TRANSACTIONCODE>
            <xsl:value-of select="TransactionCode"/>
          </TRANSACTIONCODE>
          <TRANSACTIONNUMBER>
            <xsl:value-of select="TransactionNumber"/>
          </TRANSACTIONNUMBER>
          <SEQUENCENUMBER>
            <xsl:value-of select="SequenceNumber"/>
          </SEQUENCENUMBER>
          <xsl:for-each select="SKUDefinition">
          <SKUDEFINITION>
          <COMPANY>
              <xsl:value-of select="Company"/>
          </COMPANY>
          <DIVISION>
              <xsl:value-of select="Division"/>
          </DIVISION>
          <SEASON/>
          <SEASONYEAR/>
          <STYLE>
            <xsl:value-of select="Style"/>
          </STYLE>
          <STYLESUFFIX/>
          <COLOR>
            <xsl:value-of select="Color"/>
          </COLOR>
          <COLORSUFFIX/>
          <SECDIMENSION/>
          <QUANTITY/>
          <SIZERANGECODE/>
          <SIZEDESC>
              <xsl:value-of select="SizeDesc"/>
          </SIZEDESC>
          <SKUID>
              <xsl:value-of select="SkuID"/>
          </SKUID>
          </SKUDEFINITION>
          </xsl:for-each>
        </item>
      </xsl:template>
    </xsl:transform>
    ==================
    Below is my main program
    ===================
    TYPE-POOLS abap.
    CONSTANTS gs_file TYPE string VALUE 'C:\XMLABAP1.xml'.
    This is the structure for the data from the XML file
    TYPES: BEGIN OF ty_text,
             TransactionType(3) type n,
             TransactionCode(2) type n,
             TransactionNumber(7) type n,
             SequenceNumber(5) type n,
             Company(3) type c,
             Division(3) type c,
             Season(3) type c,
             SeasonYear(4) type c,
             Style(8) type c,
             Color(3) type c,
             SecDimension(3) type c,
             Quality(3) type n,
             SizeRangeCode(2) type c,
             SizeDesc(1) type c,
             SkuID(10) type c,
           END OF ty_text.
    Table for the XML content
    DATA: gt_itab       TYPE STANDARD TABLE OF char2048.
    data: xmlstr        TYPE XSTRING.
    Table and work ares for the data from the XML file
    DATA: gt_person     TYPE STANDARD TABLE OF ty_text,
          gs_person     TYPE ty_text.
    Result table that contains references
    of the internal tables to be filled
    DATA: gt_result_xml TYPE abap_trans_resbind_tab,
          gs_result_xml TYPE abap_trans_resbind.
    For error handling
    DATA: gs_rif_ex     TYPE REF TO cx_root,
          gs_var_text   TYPE string.
    Get the XML file from your client
    CALL METHOD cl_gui_frontend_services=>gui_upload
      EXPORTING
        filename                = gs_file
      CHANGING
        data_tab                = gt_itab
      EXCEPTIONS
        file_open_error         = 1
        file_read_error         = 2
        no_batch                = 3
        gui_refuse_filetransfer = 4
        invalid_type            = 5
        no_authority            = 6
        unknown_error           = 7
        bad_data_format         = 8
        header_not_allowed      = 9
        separator_not_allowed   = 10
        header_too_long         = 11
        unknown_dp_error        = 12
        access_denied           = 13
        dp_out_of_memory        = 14
        disk_full               = 15
        dp_timeout              = 16
        not_supported_by_gui    = 17
        error_no_gui            = 18
        OTHERS                  = 19.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    Fill the result table with a reference to the data table.
    Within the XSLT stylesheet, the data table can be accessed with
    "IPERSON".
    GET REFERENCE OF gt_person INTO gs_result_xml-value.
    gs_result_xml-name = 'IPIX'.
    APPEND gs_result_xml TO gt_result_xml.
    Perform the XSLT stylesheet
    TRY.
        CALL TRANSFORMATION ZAUM_MANH_SYNC_RPT
        SOURCE XML XMLSTR
        RESULT (gt_result_xml).
      CATCH cx_root INTO gs_rif_ex.
        gs_var_text = gs_rif_ex->get_text( ).
        MESSAGE gs_var_text TYPE 'E'.
    ENDTRY.
    Now let's see what we got from the file
    LOOP AT gt_person INTO gs_person.
    WRITE: / 'Transaction Type:', gs_person-TransactionType.
      WRITE: / 'Transaction Code :', gs_person-TransactionCode.
      WRITE: / 'Transaction Number :', gs_person-TransactionNumber.
       WRITE: / 'SequenceNumber :', gs_person-SequenceNumber.
       WRITE: / 'Company : ', gs_person-Company.
      WRITE : /.
    ENDLOOP. "gt_person.

  • Reading XML files into ABAP

    Hello folks,
    I've been struggling and I need to figure out how to read a field from an XML field into ABAP. I'm writing this method and I need to call this field from my XML file. Can you guys please give me suggestions? Please advise. I will appreciate your time. Thanks in advance.
    Ol.

    *& Report z_xit_xml_check
    report z_xit_xml_check.
    class cl_ixml definition load.
    type-pools: ixml.
    types: begin of t_xml_line,
    data(256) type x,
    end of t_xml_line,
    begin of tsfixml,
    data(1024) type c,
    end of tsfixml.
    data: l_ixml type ref to if_ixml,
    l_streamfactory type ref to if_ixml_stream_factory,
    l_parser type ref to if_ixml_parser,
    l_istream type ref to if_ixml_istream,
    l_document type ref to if_ixml_document,
    l_node type ref to if_ixml_node,
    l_xmldata type string.
    data: l_elem type ref to if_ixml_element,
    l_root_node type ref to if_ixml_node,
    l_next_node type ref to if_ixml_node,
    l_name type string,
    l_iterator type ref to if_ixml_node_iterator.
    data: l_xml_table type table of t_xml_line,
    l_xml_line type t_xml_line,
    l_xml_table_size type i.
    data: l_filename type string.
    parameters: pa_file type char1024 default
    'd:\joao\desenvolvimentos\fi\fact\teste.xml'.
    Validation of XML file: Only DTD included in xml document is supported
    parameters: pa_val type char1 as checkbox.
    start-of-selection.
    Creating the main iXML factory
    l_ixml = cl_ixml=>create( ).
    Creating a stream factory
    l_streamfactory = l_ixml->create_stream_factory( ).
    perform get_xml_table changing l_xml_table_size l_xml_table.
    wrap the table containing the file into a stream
    l_istream = l_streamfactory->create_istream_itable( table =
    l_xml_table
    size =
    l_xml_table_size ).
    Creating a document
    l_document = l_ixml->create_document( ).
    Create a Parser
    l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
    istream = l_istream
    document = l_document ).
    Validate a document
    if pa_val eq 'X'.
    l_parser->set_validating( mode = if_ixml_parser=>co_validate ).
    endif.
    Parse the stream
    if l_parser->parse( ) ne 0.
    if l_parser->num_errors( ) ne 0.
    data: parseerror type ref to if_ixml_parse_error,
    str type string,
    i type i,
    count type i,
    index type i.
    count = l_parser->num_errors( ).
    write: count, ' parse errors have occured:'.
    index = 0.
    while index < count.
    parseerror = l_parser->get_error( index = index ).
    i = parseerror->get_line( ).
    write: 'line: ', i.
    i = parseerror->get_column( ).
    write: 'column: ', i.
    str = parseerror->get_reason( ).
    write: str.
    index = index + 1.
    endwhile.
    endif.
    endif.
    Process the document
    if l_parser->is_dom_generating( ) eq 'X'.
    perform process_dom using l_document.
    endif.
    *& Form get_xml_table
    form get_xml_table changing l_xml_table_size type i
    l_xml_table type standard table.
    Local variable declaration
    data: l_len type i,
    l_len2 type i,
    l_tab type tsfixml,
    l_content type string,
    l_str1 type string,
    c_conv TYPE REF TO cl_abap_conv_in_ce,
    l_itab type table of string.
    l_filename = pa_file.
    upload a file from the client's workstation
    call method cl_gui_frontend_services=>gui_upload
    exporting
    filename = l_filename
    filetype = 'BIN'
    importing
    filelength = l_xml_table_size
    changing
    data_tab = l_xml_table
    exceptions
    others = 19.
    if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
    Writing the XML document to the screen
    CLEAR l_str1.
    LOOP AT l_xml_table INTO l_xml_line.
    c_conv = cl_abap_conv_in_ce=>create( input = l_xml_line-data
    *replacement = space ).
    c_conv->read( IMPORTING data = l_content len = l_len ).
    CONCATENATE l_str1 l_content INTO l_str1.
    ENDLOOP.
    l_str1 = l_str1+0(l_xml_table_size).
    SPLIT l_str1 AT cl_abap_char_utilities=>cr_lf INTO TABLE l_itab.
    WRITE: /.
    WRITE: /' XML File'.
    WRITE: /.
    LOOP AT l_itab INTO l_str1.
    REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab
    *IN
    l_str1 WITH space.
    WRITE: / l_str1.
    ENDLOOP.
    WRITE: /.
    endform. "get_xml_table
    *& Form process_dom
    form process_dom using document type ref to if_ixml_document.
    data: node type ref to if_ixml_node,
    iterator type ref to if_ixml_node_iterator,
    nodemap type ref to if_ixml_named_node_map,
    attr type ref to if_ixml_node,
    name type string,
    prefix type string,
    value type string,
    indent type i,
    count type i,
    index type i.
    data: name2 type string,
    name_root type string,
    node_parent type ref to if_ixml_node,
    node_root type ref to if_ixml_node,
    num_children type i.
    node ?= document.
    check not node is initial.
    uline.
    write: /.
    write: /' DOM-TREE'.
    write: /.
    if node is initial. exit. endif.
    create a node iterator
    iterator = node->create_iterator( ).
    get current node
    node = iterator->get_next( ).
    loop over all nodes
    while not node is initial.
    indent = node->get_height( ) * 2.
    indent = indent + 20.
    num_children = node->num_children( ).
    case node->get_type( ).
    when if_ixml_node=>co_node_element.
    element node
    name = node->get_name( ).
    nodemap = node->get_attributes( ).
    node_root = node->get_root( ).
    name_root = node_root->get_name( ).
    write: / 'ELEMENT :'.
    write: at indent name color col_positive inverse.
    write: 'NUM_CHILDREN:', num_children.
    write: 'ROOT:', name_root.
    node_parent = node->get_parent( ).
    name2 = node_parent->get_name( ).
    write: 'NAME2: ' , name2.
    if not nodemap is initial.
    attributes
    count = nodemap->get_length( ).
    do count times.
    index = sy-index - 1.
    attr = nodemap->get_item( index ).
    name = attr->get_name( ).
    prefix = attr->get_namespace_prefix( ).
    value = attr->get_value( ).
    write: / 'ATTRIBUTE:'.
    write: at indent name color col_heading inverse, '=',
    value color col_total inverse.
    enddo.
    endif.
    when if_ixml_node=>co_node_text or
    if_ixml_node=>co_node_cdata_section.
    text node
    value = node->get_value( ).
    write: / 'VALUE :'.
    mjprocha
    node_parent = node->get_parent( ).
    write: at indent value color col_group inverse.
    name2 = node_parent->get_name( ).
    write: 'NAME2: ' , name2.
    endcase.
    advance to next node
    node = iterator->get_next( ).
    endwhile.
    endform. "process_dom

Maybe you are looking for