adesso orange🍊Stellenangebote:
Software Engineer Trainee · Senior
| (Senior) Cloud Software Engineer BTP
(Senior) Consultant Technologie · Consultant ABAP
Werkstudent Softwareentwicklung · Fiori / UI5 · Consulting · Application Management
Konvertierung XML zu interne Tabelle
Aus SAP Wiki ツ
Parameter der Methode
IV_XML_AS_UPLOAD TYPE CHAR01 OPTIONAL X = XML als Upload IV_XML_FROM_APPLSERVER TYPE LOCALFILE OPTIONAL Pfad zur XML-Datei in AL11 value( ET_ITAB ) TYPE TT_TAB_XML
Codeschnipsel
TYPES tyt_tab_xml TYPE TABLE OF smum_xmltb.
DATA: lv_xml_xstring TYPE xstring,
lt_xml_tab TYPE TABLE OF smum_xmltb,
lv_filename TYPE localfile,
lo_xml_document TYPE REF TO cl_xml_document,
lv_subrc TYPE sy-subrc,
lv_size TYPE sy-tabix.
CHECK iv_xml_as_upload = abap_true AND iv_xml_from_applserver IS INITIAL OR
iv_xml_as_upload = abap_false AND iv_xml_from_applserver IS NOT INITIAL.
"== create the object
CREATE OBJECT lo_xml_document.
"== XML from Upload
IF iv_xml_as_upload = abap_true.
DATA: lt_filetable TYPE filetable,
lv_anz_dat TYPE i,
lv_windows_title TYPE string.
lv_windows_title = TEXT-001.
cl_gui_frontend_services=>file_open_dialog(
EXPORTING
window_title = lv_windows_title
default_filename = 'C:\test.xml'
initial_directory = 'C:\'
CHANGING
file_table = lt_filetable
rc = lv_anz_dat
EXCEPTIONS
OTHERS = 5 ).
READ TABLE lt_filetable INTO lv_filename INDEX 1.
"== Upload xml file
lo_xml_document->import_from_file(
EXPORTING
filename = lv_filename
RECEIVING
retcode = lv_subrc ).
CHECK lv_subrc = 0.
"== Convert to xstring
CALL METHOD lo_xml_document->render_2_xstring
IMPORTING
retcode = lv_subrc
stream = lv_xml_xstring
size = lv_size.
CHECK lv_subrc = 0.
ELSEIF iv_xml_from_applserver IS NOT INITIAL.
"== Read XML from applserver
OPEN DATASET iv_xml_from_applserver FOR INPUT IN BINARY MODE.
READ DATASET iv_xml_from_applserver INTO lv_xml_xstring.
CLOSE DATASET iv_xml_from_applserver.
CALL METHOD lo_xml_document->parse_xstring
EXPORTING
stream = lv_xml_xstring
RECEIVING
retcode = lv_subrc.
CHECK lv_subrc = 0.
ENDIF.
"== Convert XML to itab
DATA: lt_return TYPE TABLE OF bapiret2.
CALL FUNCTION 'SMUM_XML_PARSE'
EXPORTING
xml_input = lv_xml_xstring
TABLES
xml_table = lt_xml_tab
return = lt_return.
CHECK sy-subrc = 0.
et_itab = lt_xml_tab.