2009 Apr 02 1:21 PM
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
2009 Apr 02 1:28 PM
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.
2009 Apr 02 1:28 PM
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.
2009 Apr 02 2:12 PM
2009 Apr 03 7:17 AM
is there any way of creating multiple dynamic tables with different fields(that will also we known during runtime) at runtime?
2009 Apr 03 8:10 AM
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