Code: Alles auswählen.
FUNCTION zide_get_xml_overview.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" EXPORTING
*" VALUE(ET_DATA) TYPE ZIDE_GET_XML_OVERVIEW_T
*" VALUE(RETURN) TYPE CHAR70
*"----------------------------------------------------------------------
* for checking the import-parameter (convert time stamp)
DATA lv_time TYPE t.
DATA lv_date TYPE d.
* for get xml-data
DATA: lv_message TYPE REF TO if_xms_message.
* dataara for et_data
DATA es_data LIKE LINE OF et_data.
* Definitionen für interne XML Inhalt
TYPE-POOLS: ixml.
CLASS cl_ixml DEFINITION LOAD.
DATA: li_ifmsg TYPE REF TO if_xms_message,
li_msg TYPE REF TO if_xms_message_xmb,
li_pay TYPE REF TO if_xms_payload,
lv_payxstr TYPE xstring,
li_ixmlfactory TYPE REF TO if_ixml,
iparser TYPE REF TO if_ixml_parser,
li_streamfactory TYPE REF TO if_ixml_stream_factory,
istream TYPE REF TO if_ixml_istream,
idocument TYPE REF TO if_ixml_document,
lv_xpath TYPE string,
root TYPE REF TO if_ixml_element,
el TYPE REF TO if_ixml_element,
vl TYPE string.
*
* initial tables
*
CLEAR gt_header[].
CLEAR et_data[].
*
* Kopfsätze lesen
*
SELECT * FROM sxmspmast INTO TABLE gt_header.
* Test
* DELETE gt_header WHERE msgguid <> '449A7E24772041FBE10000000A010029'.
*
* for xml-content-read
*
li_ixmlfactory = cl_ixml=>create( ).
li_streamfactory = li_ixmlfactory->create_stream_factory( ).
*
* Selectierte Sätze abarbeiten
*
LOOP AT gt_header ASSIGNING <gs_header>.
* only if correct xi-system
SELECT SINGLE msgguid FROM sxmspemas
INTO <gs_header>-msgguid
WHERE msgguid = <gs_header>-msgguid
AND ib_system = iv_xi_system.
CHECK sy-subrc = 0.
* Nur Order_CreateOrChangeVendorView_Out berücksichtigen
SELECT SINGLE msgguid FROM sxmspemas
INTO <gs_header>-msgguid
WHERE msgguid = <gs_header>-msgguid
AND ob_name = 'Order_CreateOrChangeVendorView_Out'.
CHECK sy-subrc = 0.
CLEAR es_data.
MOVE-CORRESPONDING <gs_header> TO es_data.
*
* XML Inhalt lesen
*
TRY.
IF gcl_xms_persist IS INITIAL.
CREATE OBJECT gcl_xms_persist.
ENDIF.
CALL METHOD gcl_xms_persist->read_msg
EXPORTING
im_msgguid = <gs_header>-msgguid
im_pid = <gs_header>-pid
* im_version = lv_last_version
im_version = 0
IMPORTING
ex_message = li_ifmsg.
CATCH cx_xms_persist .
CATCH cx_xms_system_error .
ENDTRY.
li_msg ?= li_ifmsg.
li_pay = li_msg->getpayloadwithmaindocument( ).
TRY.
lv_payxstr = li_pay->getbinarycontent( ).
CATCH cx_xms_exception.
CATCH cx_xms_system_error.
CATCH cx_sy_ref_is_initial. "keine Daten gefunden
return = text-e05.
es_data-error = text-e05.
APPEND es_data TO et_data.
CONTINUE. "next record - keine Daten in XML?
ENDTRY.
* Create DOM
CALL METHOD li_streamfactory->create_istream_xstring
EXPORTING
string = lv_payxstr
RECEIVING
rval = istream.
* istream = streamfactory->create_istream_xstring( lv_payxstr ).
idocument = li_ixmlfactory->create_document( ).
iparser = li_ixmlfactory->create_parser( stream_factory = li_streamfactory
istream = istream
document = idocument ).
iparser->parse( ).
root = idocument->get_root_element( ).
*
* Object-ID = Order-Number
*
lv_xpath = '/ns1:Order/OrderHeader/OrderID'.
el = root->find_from_path( path = lv_xpath ).
IF el IS BOUND.
es_data-object_id = el->get_value( ).
ENDIF.
*
* Member-Number
*
lv_xpath = '/ns1:Order/OrderHeader/UserDefinedExtension'. "[Name="ZMITGLIED"]/Value'.
el = root->find_from_path( path = lv_xpath ).
DO .
IF el IS BOUND.
DATA: udename TYPE string,
udevalue TYPE string,
elname TYPE REF TO if_ixml_element,
elvalue TYPE REF TO if_ixml_element.
elname = el->find_from_path( path = 'Name' ).
IF elname IS BOUND.
udename = elname->get_value( ).
CASE udename.
WHEN 'ZMITGLIED'.
elvalue = el->find_from_path( path = 'Value' ).
IF elvalue IS BOUND.
es_data-zmitglied = elvalue->get_value( ).
ENDIF.
WHEN 'ZWEMPF'.
elvalue = el->find_from_path( path = 'Value' ).
IF elvalue IS BOUND.
es_data-zwempf = elvalue->get_value( ).
ENDIF.
ENDCASE.
IF NOT es_data-zwempf IS INITIAL AND NOT es_data-zmitglied IS INITIAL.
EXIT.
ENDIF.
ELSE.
EXIT.
ENDIF.
* konvertiere IF_IXML_NODE nach IF_IXML_ELEMENT
DATA: elnode TYPE REF TO if_ixml_node.
elnode = el->get_next( ).
IF NOT elnode IS BOUND.
EXIT.
ENDIF.
el ?= elnode->query_interface( ixml_iid_element ).
ELSE.
EXIT.
ENDIF.
ENDDO.
IF es_data-zwempf IS INITIAL.
es_data-zwempf = es_data-zmitglied.
ENDIF.
APPEND es_data TO et_data.
ENDLOOP.
ENDFUNCTION.
Code: Alles auswählen.
FUNCTION Z_XML_OVERVIEW .
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(DELETEDATABEFORE) TYPE STRING OPTIONAL
*" VALUE(CREATENEWDATA) TYPE STRING DEFAULT 'X'
*" VALUE(WRITENEWDATAINDB) TYPE STRING DEFAULT 'X'
*" VALUE(GETDATABACKNEWDATA) TYPE STRING DEFAULT 'X'
*" VALUE(GETDATABACKOLDDATA) TYPE STRING DEFAULT 'X'
*" EXPORTING
*" REFERENCE(ERRORS) TYPE STRING
*" TABLES
*" ET STRUCTURE Z_XMLDATA OPTIONAL
*"----------------------------------------------------------------------
DATA: gt_header TYPE table of sxmspmast.
data: gs_header like line of gt_header.
field-symbols: <fsheader> like gs_header.
data: gt_new type table of z_xmldata.
data: gs_new like line of gt_new.
data: gt_old like gt_new.
data: gs_old like gs_new.
TYPE-POOLS: ixml.
CLASS cl_ixml DEFINITION LOAD.
DATA: li_ifmsg TYPE REF TO if_xms_message,
li_msg TYPE REF TO if_xms_message_xmb,
li_pay TYPE REF TO if_xms_payload,
lv_payxstr TYPE xstring,
li_ixmlfactory TYPE REF TO if_ixml,
iparser TYPE REF TO if_ixml_parser,
li_streamfactory TYPE REF TO if_ixml_stream_factory,
istream TYPE REF TO if_ixml_istream,
idocument TYPE REF TO if_ixml_document,
lv_xpath TYPE string,
root TYPE REF TO if_ixml_element,
el TYPE REF TO if_ixml_element,
vl TYPE string.
*
* Löschen komplette Tabelle
*
if deletedatabefore = 'X'.
delete from z_xmldata.
endif.
*
* Neue Sätze ermitteln
*
if createnewdata = 'X'.
* letztes Erstelldatum ermitteln
select INITTIMEST into gs_old-inittimest from z_xmldata order by inittimest descending.
exit.
endselect.
* Daten ab ermitteltem letzten Erstelldatum lesen
select * from sxmspmast as sxmspmast
join sxmspemas as sxmspemas
on sxmspmast~msgguid = sxmspemas~msgguid
and sxmspmast~pid = sxmspemas~pid
into corresponding fields of table gt_header
where inittimest ge gs_old-inittimest
and PARENTMSG = ' '
and ob_name like 'Order%'
and ob_system like 'SRM_%'
order by inittimest.
* break spranz.
* Sicherheitshalber nochmals nachschauen, ob Daten schon in Tabelle
loop at gt_header assigning <fsheader>.
select single * from z_xmldata into gs_old where msgguid = <fsheader>-msgguid and pid = <fsheader>-pid.
if sy-subrc = 0.
delete gt_header. "Satz löschen, da er sonst doppelt wäre
continue.
endif.
* Daten der XML zuusammenstellen
CLEAR gs_new.
MOVE-CORRESPONDING <fsheader> TO gs_new.
*----------
* Beginn Durchparsen der XML
*----------
*
* XML Inhalt lesen
*
******
TRY.
IF gcl_xms_persist IS INITIAL.
CREATE OBJECT gcl_xms_persist.
ENDIF.
CALL METHOD gcl_xms_persist->read_msg_all
EXPORTING
im_msgguid = <fsheader>-msgguid
im_pid = <fsheader>-pid
* im_version = lv_last_version
im_version = 0
IMPORTING
ex_message = li_ifmsg.
catch cx_xms_syserr_persist.
ENDTRY.
li_msg ?= li_ifmsg.
*****************************************
li_pay = li_msg->GET_PAYLOAD_WITH_MAIN_DOCUMENT( ).
*
TRY.
lv_payxstr = li_pay->getbinarycontent( ).
CATCH cx_xms_exception.
CATCH cx_xms_system_error.
CATCH cx_sy_ref_is_initial. "keine Daten gefunden
errors = 'Es sind Fehler die aus den Tabelleinhalten ersichtlich sind'.
gs_new-error = 'Fehler bei der Payloadermittlung |'.
CONTINUE. "next record - keine Daten in XML?
ENDTRY.
* Create DOM
li_ixmlfactory = cl_ixml=>create( ).
li_streamfactory = li_ixmlfactory->create_stream_factory( ).
*****
CALL METHOD li_streamfactory->create_istream_xstring
EXPORTING
string = lv_payxstr
RECEIVING
rval = istream.
* istream = streamfactory->create_istream_xstring( lv_payxstr ).
idocument = li_ixmlfactory->create_document( ).
iparser = li_ixmlfactory->create_parser( stream_factory = li_streamfactory
istream = istream
document = idocument ).
iparser->parse( ).
root = idocument->get_root_element( ).
**
** Object-ID = Order-Number
**
lv_xpath = '/ns1:Order/OrderHeader/OrderID'.
el = root->find_from_path( path = lv_xpath ).
IF el IS BOUND.
gs_new-object_id = el->get_value( ).
ENDIF.
**
** Member-Number
**
lv_xpath = '/ns1:Order/OrderHeader/UserDefinedExtension'. "[Name="ZMITGLIED"]/Value'.
el = root->find_from_path( path = lv_xpath ).
DO .
IF el IS BOUND.
DATA: udename TYPE string,
udevalue TYPE string,
elname TYPE REF TO if_ixml_element,
elvalue TYPE REF TO if_ixml_element.
elname = el->find_from_path( path = 'Name' ).
IF elname IS BOUND.
udename = elname->get_value( ).
CASE udename.
WHEN 'ZMITGLIED'.
elvalue = el->find_from_path( path = 'Value' ).
IF elvalue IS BOUND.
gs_new-zmitglied = elvalue->get_value( ).
ENDIF.
WHEN 'ZZILN_KUNDE'.
elvalue = el->find_from_path( path = 'Value' ).
IF elvalue IS BOUND.
gs_new-mitglied_iln = elvalue->get_value( ).
ENDIF.
WHEN 'ZWEMPF'.
elvalue = el->find_from_path( path = 'Value' ).
IF elvalue IS BOUND.
gs_new-zwempf = elvalue->get_value( ).
ENDIF.
WHEN 'ZZILN_WE'.
elvalue = el->find_from_path( path = 'Value' ).
IF elvalue IS BOUND.
gs_new-WEMPF_ILN = elvalue->get_value( ).
ENDIF.
ENDCASE.
IF NOT gs_new-zwempf IS INITIAL AND NOT gs_new-zmitglied IS INITIAL.
EXIT.
ENDIF.
ELSE.
EXIT.
ENDIF.
* konvertiere IF_IXML_NODE nach IF_IXML_ELEMENT
DATA: elnode TYPE REF TO if_ixml_node.
elnode = el->get_next( ).
IF NOT elnode IS BOUND.
EXIT.
ENDIF.
el ?= elnode->query_interface( ixml_iid_element ).
*
ELSE.
EXIT.
ENDIF.
ENDDO.
*
IF gs_new-zwempf IS INITIAL.
gs_new-zwempf = gs_new-zmitglied.
ENDIF.
if gs_new-wempf_Iln is initial.
gs_new-wempf_iln = gs_new-mitglied_iln.
endif.
if gs_new-zmitglied is initial.
concatenate gs_new-error
'Mitgliedsnummer in XML ist leer |'
into gs_new-error.
endif.
if gs_new-mitglied_iln is initial.
concatenate gs_new-error
'Mitgliedsnummer ILN in XML ist leer |'
into gs_new-error.
endif.
if gs_new-zwempf is initial.
concatenate gs_new-error
'Warenempfänger in XML ist leer |'
into gs_new-error.
endif.
if gs_new-wempf_iln is initial.
concatenate gs_new-error
'Warenempfänger ILN in XML ist leer |'
into gs_new-error.
endif.
APPEND gs_new TO gt_new.
**********************************
endloop.
endif.
*
* Sollen neu ermittelte Daten zurückgegeben werden
*
if GETDATABACKNEWDATA = 'X'.
et[] = gt_new[].
endif.
*
* Sollen alte (die schon in der Datenbanktabelle vorhandene Einträge) zurückgegeben werden
*
if GETDATABACKOLDDATA = 'X'.
select * from z_xmldata appending table et.
endif.
*
* Sollen die neu ermittelten Daten auf die Datenbanktabelle geschrieben werden
*
if WRITENEWDATAINDB = 'X'.
insert z_xmldata from table gt_new[].
endif.
ENDFUNCTION.
Code: Alles auswählen.