Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Question about XML mapping to ABAP internal table

Former Member
0 Likes
1,046

Hi experts.

I'm trying to XML mapping. But it doesn't work well. Assume there are XML file as below.

<HEADER>

<ITEM>

<FOO>123</FOO>

<BAR>ABC</BAR>

</ITEM>

<ITEM>

<FOO>456</FOO>

<BAR>DEF</BAR>

</ITEM>

<HEADER>

and I want to trasformation it as below.

ITAB

-


FOO | BAR

-


123 | ABC

-


456 | DEF

How could I trasformation using "call transformation"?

Regards.

1 ACCEPTED SOLUTION
Read only

athavanraja
Active Contributor
0 Likes
711

Hi experts.

I'm trying to XML mapping. But it doesn't work well. Assume there are XML file as below.

<HEADER>

<ITEM>

<FOO>123</FOO>

<BAR>ABC</BAR>

</ITEM>

<ITEM>

<FOO>456</FOO>

<BAR>DEF</BAR>

</ITEM>

<HEADER>

and I want to trasformation it as below.

ITAB

-


FOO | BAR

-


123 | ABC

-


456 | DEF

How could I trasformation using "call transformation"?

Regards.

2 REPLIES 2
Read only

athavanraja
Active Contributor
0 Likes
712
Read only

Former Member
0 Likes
711

Hi,

REPORT zind_xml_to_sap NO STANDARD PAGE HEADING.

************************************************************************

  • Data Declaration *

************************************************************************

DATA: client TYPE REF TO if_http_client, "Interface

host TYPE string,

port TYPE string,

proxy_host TYPE string,

proxy_port TYPE string,

path TYPE string,

scheme TYPE i,

xml TYPE xstring,

response TYPE string.

DATA: t_xml TYPE smum_xmltb OCCURS 0 WITH HEADER LINE. "XML Table structure used

"for retreive and output XML doc

DATA: g_stream_factory TYPE REF TO if_ixml_stream_factory. "Interface

DATA : return LIKE bapiret2 OCCURS 0 WITH HEADER LINE. "XML Table structure used for retreive

"and output XML doc

************************************************************************

  • Parameters *

************************************************************************

PARAMETER : p_add TYPE string LOWER CASE ,

p_dfile LIKE rlgrap-filename.

************************************************************************

  • AT Selection-Screen on value-request for file *

************************************************************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dfile.

  • Get file

PERFORM 100_get_file.

************************************************************************

  • Start-of-Selection *

************************************************************************

START-OF-SELECTION.

  • Perform to upload xml data from URL to SAP internal table

PERFORM 200_xml_upload.

IF t_xml[] IS NOT INITIAL.

  • Perform to Download data from Internal Table to a text file in local drive

PERFORM 300_download.

write : / 'Data Uploaded to Internal Table Successfully'.

write : / 'XML Data Downloaded to Local path', p_dfile.

else.

write : / 'No Data for upload'.

ENDIF.

*if t_xml[] is INITIAL.

  • WRITE : address, 'Given URl cannot be Converted' .

  • else.

  • LOOP AT t_xml .

  • WRITE: t_xml-cname, t_xml-cvalue.

  • ENDLOOP.

  • endif.

&----


*& Form get_file

&----


  • Get File

----


FORM 100_get_file .

CALL FUNCTION 'F4_FILENAME'

  • EXPORTING

  • PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

IMPORTING

file_name = p_dfile

.

ENDFORM. " 100_get_file

&----


*& Form 200_xml_upload

&----


  • form to upload xml data from URL to SAP internal table

----


FORM 200_xml_upload .

*Check HTTP:// and concatenate

IF p_add NS 'http://' OR p_add NS 'HTTP://'.

CONCATENATE 'http://' p_add

INTO p_add.

ENDIF.

  • Fetching the address of the URL

CALL METHOD cl_http_client=>create_by_url

EXPORTING

url = p_add

IMPORTING

client = client.

*Structure of HTTP Connection and Dispatch of Data

client->send( ).

*Receipt of HTTP Response

CALL METHOD client->receive

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2

http_processing_failed = 3

OTHERS = 4.

IF sy-subrc <> 0.

IF sy-subrc = 1.

MESSAGE 'HTTP COMMUNICATION FAILURE' TYPE 'I' DISPLAY LIKE 'E'.

EXIT.

ELSEIF sy-subrc = 2.

MESSAGE 'HTTP INVALID STATE' TYPE 'I' DISPLAY LIKE 'E'.

EXIT.

ELSEIF sy-subrc = 3.

MESSAGE 'HTTP PROCESSING FAILED' TYPE 'I' DISPLAY LIKE 'E'.

EXIT.

ELSE.

MESSAGE 'Problem in HTTP Request' TYPE 'I' DISPLAY LIKE 'E'.

EXIT.

ENDIF.

ENDIF.

  • Get data of the xml to Response

response = client->response->get_cdata( ).

*FM converting the XML format to abap

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

text = response

IMPORTING

buffer = xml.

*FM converting XMl to readable format to a internal table.

CALL FUNCTION 'SMUM_XML_PARSE'

EXPORTING

xml_input = xml

TABLES

xml_table = t_xml

return = return.

ENDFORM. " 200_xml_upload

&----


*& Form 300_download

&----


*form to Download data from Internal Table to a text file in local drive

----


FORM 300_download .

DATA filename TYPE string.

filename = p_dfile.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = filename

WRITE_FIELD_SEPARATOR = 'X'

TABLES

data_tab = t_xml

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

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.