Skip to Content
author's profile photo Former Member
Former Member

Creating Simple transformation for an XML data having deep structure

Hi

I have the following XML structure..

<REQUESTS>

<REQUESTNAME>REQ123</REQUESTNAME>

<REQUESTID>1234</REQUESTID>

<CITY>NEWYORK</CITY>

<ZIPCODE>123456</ZIPCODE>

<COMPETENCIES>

<LANGUAGES>

<COMPETENCY>

<SKILL>SAP</SKILL>

<PROFICIENCY>TEST</PROFICIENCY>

<SKILL>JAVA</SKILL>

<PROFICIENCY>TEST123</PROFICIENCY>

  • (here we may have any number of records for SKILL&PROFICIENCY...)*

</COMPETENCIES>

</LANGUAGES>

</COMPETENCY>

</REQUESTS>

My requirement is to read the above data from an URL and push it into an internal table.

For this I'm trying to use Simple transformations but I'm facing difficulty in doing this.

Can you pl. guide me how to create the transformation and the corresponding code for this.

Best Regards

Anil

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Dec 14, 2010 at 03:11 AM

    Howdy,

    Firstly you should post your attempt here so that people can help adapt it rather than starting from scratch.

    Secondly the reason you are probably having trouble is because the XML is badly formed - the end tags are not in the correct order.

    I suggest you check the source XML and make sure it is as you have posted it because you won't be able to write a simple transformation based on it.

    Cheers

    Alex

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi

      Here is the actual XML structure..

      - <REQUEST>

      <COUNTRY />

      <ADDRESS />

      <CITY />

      <ASSIGNTYPE>IP</ASSIGNTYPE>

      <CHARGETYPE>CH</CHARGETYPE>

      <REMOTEALLOWED>Y</REMOTEALLOWED>

      <SALESRATE>EUR</SALESRATE>

      <SECURITY>NO</SECURITY>

      <TRAVELEXP>Y</TRAVELEXP>

      <MAXDAILYRATE />

      <CREDENTIALS />

      <EXPENDDATE />

      <NEWENDDATE />

      <NEWEXPENDDATE />

      <REPLYBEFORE>2010-11-30</REPLYBEFORE>

      <STARTDATE>2010-01-01</STARTDATE>

      <ENDDATE>2010-12-31</ENDDATE>

      <GCMTYPE>PM</GCMTYPE>

      <GCMLEVELFROM>02</GCMLEVELFROM>

      <GCMLEVELTO>08</GCMLEVELTO>

      <LOCATION>FR43</LOCATION>

      <MOBILITY>04</MOBILITY>

      <ZIPCODE />

      - <COMPETENCIES>

      - <LANGUAGES>

      - <COMPETENCY>

      <SKILL>01106034</SKILL>

      <PROFICIENCY>005103</PROFICIENCY>

      </COMPETENCY>

      </LANGUAGES>

      - <ACTIVITIES>

      - <COMPETENCY>

      <SKILL>01105500</SKILL>

      <PROFICIENCY>004507</PROFICIENCY>

      </COMPETENCY>

      </ACTIVITIES>

      - <BUSINESS>

      - <COMPETENCY>

      <SKILL>01105729</SKILL>

      <PROFICIENCY>004605</PROFICIENCY>

      </COMPETENCY>

      </BUSINESS>

      - <INDUSTRIES>

      - <COMPETENCY>

      <SKILL>01105491</SKILL>

      <PROFICIENCY>004901</PROFICIENCY>

      </COMPETENCY>

      </INDUSTRIES>

      - <METHODS>

      - <COMPETENCY>

      <SKILL>01105591</SKILL>

      <PROFICIENCY>004805</PROFICIENCY>

      </COMPETENCY>

      </METHODS>

      - <OFFERINGS>

      - <COMPETENCY>

      <SKILL>01105840</SKILL>

      <PROFICIENCY>005002</PROFICIENCY>

      </COMPETENCY>

      </OFFERINGS>

      - <PRODUCTS>

      - <COMPETENCY>

      <SKILL>01107304</SKILL>

      <PROFICIENCY>004703</PROFICIENCY>

      </COMPETENCY>

      </PRODUCTS>

      </COMPETENCIES>

      <CANDIDATES />

      </REQUEST>

      Here..... <SKILL></SKILL> <PROFICIENCY></PROFICIENCY> can be more than 1 entry...

      For this I have created a simple transformation like below..

      I have used the tcode 'XSLT_TOOL '..

      In SE11 I have created a Table type 'ZCOMPETENCIES' which is having a line type 'ZLANGS'.

      ZLANGS is a structure which has another structure called 'ZCOMPETENCY' and this 'ZCOMPETENCY' is having fields

      SKILL & PROFICIENCY.

      I have used the wizard button which u can find 'XSLT_TOOL '.. and provided the table type ZCOMPETENCIES' and it has automatically created the following transformation...

      <?sap.transform simple?>

      http://www.sap.com/transformation-templates" xmlns:ddic=" http://www.sap.com/abapxml/types/dictionary" xmlns:def=" http://www.sap.com/abapxml/types/defined">

      <tt:root name="ROOT" type="?"/>

      <tt:root name="COMPETENCIES" type="ddic:ZCOMPETENCIES"/>

      <tt:template>

      <COMPETENCIES>

      <tt:loop ref=".COMPETENCIES">

      <ZLANGS>

      <COMPETENCY>

      <SKILL tt:value-ref="COMPETENCY.SKILL"/>

      <PROF tt:value-ref="COMPETENCY.PROF"/>

      </COMPETENCY>

      </ZLANGS>

      </tt:loop>

      </COMPETENCIES>

      </tt:template>

      </tt:transform>

      -


      I have written following code to get the data

      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.

      GET REFERENCE OF gt_person INTO gs_result_xml-value.

      gs_result_xml-name = 'COMPETENCIES'.

      APPEND gs_result_xml TO gt_result_xml.

      TRY.

      CALL TRANSFORMATION ZTEST_TRAN

      SOURCE XML gt_itab

      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.

      Please let me know if you need any further details..

      Best Regards

      Anil

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.