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

XML to Internal tables

Former Member
0 Likes
1,041

Hi,

Our scenairo is to retreive the data from XML file and convert it into Idoc for inbound processing.

I need to get the data from xml to the internal tables so that i can convert them to idoc through Function Modules.

My issue is XML file is not fixed nor the message type and the idoc type. Everything is dynamic.

I am currently tryin by creating dynamic internal table but i think i need to create multiple dynamic tables from a dynamic table.

Please suggest the path forward.

Thanks,

Varun

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
919

hi,

check the below code.

this will convert XML data into an internal table. From this internal table u can manipulate and get desired results.

*Generated from XML file (upload)

CALL METHOD xml->import_from_file

EXPORTING

filename = p_file

RECEIVING

retcode = ret.

*convert to string

CALL METHOD xml->render_2_string

IMPORTING

retcode = ret

stream = stream

  • size =

.

*convert to xstring

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

text = stream

IMPORTING

buffer = xstring

EXCEPTIONS

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.

*Extract data from xsting to internal table

CALL FUNCTION 'SMUM_XML_PARSE'

EXPORTING

xml_input = xstring

TABLES

xml_table = it_data

return = it_ret.

Regards,

Aswin.

Hi,

Our scenairo is to retreive the data from XML file and convert it into Idoc for inbound processing.

I need to get the data from xml to the internal tables so that i can convert them to idoc through Function Modules.

My issue is XML file is not fixed nor the message type and the idoc type. Everything is dynamic.

I am currently tryin by creating dynamic internal table but i think i need to create multiple dynamic tables from a dynamic table.

Please suggest the path forward.

Thanks,

Varun

4 REPLIES 4
Read only

Former Member
0 Likes
920

hi,

check the below code.

this will convert XML data into an internal table. From this internal table u can manipulate and get desired results.

*Generated from XML file (upload)

CALL METHOD xml->import_from_file

EXPORTING

filename = p_file

RECEIVING

retcode = ret.

*convert to string

CALL METHOD xml->render_2_string

IMPORTING

retcode = ret

stream = stream

  • size =

.

*convert to xstring

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

text = stream

IMPORTING

buffer = xstring

EXCEPTIONS

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.

*Extract data from xsting to internal table

CALL FUNCTION 'SMUM_XML_PARSE'

EXPORTING

xml_input = xstring

TABLES

xml_table = it_data

return = it_ret.

Regards,

Aswin.

Read only

Former Member
0 Likes
919

which type-pool will be used as call methods not working

Read only

Former Member
0 Likes
919

is there any way of creating multiple dynamic tables with different fields(that will also we known during runtime) at runtime?

Read only

uwe_schieferstein
Active Contributor
0 Likes
919

Hello Varun

Another option would be to make an XSLT transformation into the corresponding XML-IDoc and send it via XML port. Some characteristics within the input XML file should allow you to identify which transformation you need to call.

Regards

Uwe