Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag:
Anita57
Code: Alles auswählen.
LOOP AT lt_dom INTO ls_dom where name eq 'data'.
if ls_dom-parent is initial.
parent = 'P_GS_ZEIT_GESAMT'.
clear lt_parent.
assign parent to <parent>.
assign (lt_parent) to <lt_parent>.
else.
append <parent> to <lt_PARENT>.
READ TABLE lt_dom INDEX ls_dom-parent INTO ls_dom_parent.
parent+0(2) = 'LS_'.
parent+2(30) = ls_dom_parent-name.
lt_parent = parent.
lt_parent+0(2) = 'LT'.
assign parent to <parent>.
assign (lt_parent) to <lt_parent>.
endif.
Code: Alles auswählen.
data: parent(35) type c,
*...
field-symbols: <parent> type any.
Code: Alles auswählen.
ASSIGN parent TO <parent>
Code: Alles auswählen.
FUNCTION ZADS_PARSE_DYN_PDF.
*"--------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" REFERENCE(IP_PDF) TYPE XSTRING
*" CHANGING
*" REFERENCE(LT_NAME_VALUE) TYPE ZADS_XML_RESOLVE_T
*" REFERENCE(P_GS_ZEIT_GESAMT) TYPE ZPT_ADS_ZEIT_GESAMT
*"--------------------------------------------------------------------
CLASS cl_fp DEFINITION LOAD.
**********************************************************************
*--------------- Type and data declerations--------------------------*
**********************************************************************
TYPES: ty_raw(255) TYPE x,
ty_tab TYPE STANDARD TABLE OF ty_raw.
DATA: lr_dom TYPE REF TO if_ixml_mini_dom,
lr_fp TYPE REF TO if_fp,
lr_fpex TYPE REF TO cx_fp_runtime,
lr_parser TYPE REF TO if_ixml_mini_parser,
lr_pdfobj TYPE REF TO if_fp_pdf_object.
DATA: ls_address TYPE bapiaddr3,
ls_address_new TYPE bapiaddr3,
ls_address_x TYPE bapiaddr3x,
ls_dom TYPE ixmltdom,
ls_dom_parent TYPE ixmltdom,
ls_dom_child TYPE ixmltdom,
lt_dom TYPE STANDARD TABLE OF ixmltdom,
lt_dom_child TYPE STANDARD TABLE OF ixmltdom,
ls_dom_2 TYPE ixmltdom,
ls_name_value TYPE ZADS_XML_RESOLVE,"sspiuiddlb,
* lt_name_value TYPE TABLE OF ZADS_XML_RESOLVE,"tspiuiddlb,
ls_tsad3t TYPE tsad3t,
ls_act_groups TYPE bapiagr,
lt_act_groups TYPE table of bapiagr,
lv_string TYPE string,
lv_xstring TYPE xstring,
ls_tline TYPE tline,
lt_tline TYPE tsftext,
ls_tdline TYPE tdline,
lt_tdline TYPE TABLE OF tdline,
ls_picture TYPE xstring,
lt_picture TYPE TABLE OF xstring,
ls_return TYPE bapiret2,
lt_return TYPE STANDARD TABLE OF bapiret2,
gt_return TYPE STANDARD TABLE OF bapiret2,
lt_signatures TYPE tfpsignature,
ls_attachments TYPE sfpattachments,
lt_attachments TYPE tfpattachments,
lv_filename_pdf TYPE string,
lv_numversions TYPE i,
lv_pdf TYPE xstring,
lv_xml_data TYPE xstring,
lv_review_copy TYPE xstring,
lv_pdl TYPE xstring,
lv_xdcname TYPE string.
data: parent(35) type c,
lt_parent(35) type c,
a type i.
field-symbols: <parent> type any,
<LT_PARENT> type Table.
DATA: ls_name TYPE zads_xml_resolve.
DATA: ls_schichtplan TYPE zads_schichtplan.
DATA: lt_schichtplan TYPE zads_schichtplan_t."SchichtplanDaten P
DATA: lt_personen TYPE zads_personen_t. "Betroffene Personen
DATA: ls_personen TYPE zads_personen.
DATA: lv_feld(30) TYPE c,
lv_erste_pernr(1) TYPE c. "Kennzeichen bei erste PErsonalnummer
FIELD-SYMBOLS: <lf_feld> TYPE ANY.
* get FP reference
lr_fp = cl_fp=>get_reference( ).
TRY.
* create PDF object
lr_pdfobj = lr_fp->create_pdf_object( connection = 'ADS' ).
* set the pdf document
lr_pdfobj->set_document( pdfdata = ip_pdf ).
* set data extraction task
lr_pdfobj->set_task_extractdata( ).
* execute, call ADS
lr_pdfobj->execute( ).
* get the data context in XML format
CALL METHOD lr_pdfobj->get_data
IMPORTING
formdata = lv_xml_data.
CATCH cx_fp_runtime_internal INTO lr_fpex.
* PERFORM error USING lr_fpex 'INTERNAL ERROR'.
CATCH cx_fp_runtime_system INTO lr_fpex.
* PERFORM error USING lr_fpex 'SYSTEM ERROR'.
CATCH cx_fp_runtime_usage INTO lr_fpex.
* PERFORM error USING lr_fpex 'USAGE ERROR'.
ENDTRY.
lr_parser = cl_ixml_mini=>create_parser( ).
CALL METHOD lr_parser->parse_xstring
EXPORTING
stream = lv_xml_data
IMPORTING
dom = lr_dom
EXCEPTIONS
parse_error = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* save DOM Table
lt_dom[] = lr_dom->dom_table[].
* get the data
LOOP AT lt_dom INTO ls_dom WHERE name <> '#text'.
CLEAR: ls_dom_2, ls_name_value.
* read the child object
READ TABLE lt_dom INDEX ls_dom-firstchild INTO ls_dom_2.
* transfet to name/value table
* IF sy-subrc = 0.
CASE ls_dom-name.
WHEN 'LONGTEXT'.
MOVE: ls_dom-name TO ls_name_value-name,
ls_dom_2-value TO ls_name_value-string.
WHEN 'PICTURE'.
MOVE: ls_dom-name TO ls_name_value-name,
ls_dom_2-value TO ls_name_value-string.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = ls_name_value-string
* MIMETYPE = ' '
* ENCODING =
IMPORTING
buffer = ls_name_value-xstring
EXCEPTIONS
failed = 1
OTHERS = 2.
WHEN OTHERS.
MOVE: ls_dom-name TO ls_name_value-name,
ls_dom_2-value TO ls_name_value-value.
ENDCASE.
APPEND ls_name_value TO lt_name_value.
* ENDIF.
ENDLOOP.
REFRESH lt_personen.
CLEAR ls_personen.
REFRESH lt_schichtplan.
CLEAR ls_schichtplan.
CLEAR ls_name.
CLEAR lv_erste_pernr.
refresh lt_dom_child.
lt_dom_child[] = lt_dom[].
clear parent.
clear lt_parent.
LOOP AT lt_dom INTO ls_dom where name eq 'data'.
if ls_dom-parent is initial.
parent = 'P_GS_ZEIT_GESAMT'.
clear lt_parent.
assign parent to <parent>.
assign (lt_parent) to <lt_parent>.
else.
append <parent> to <lt_PARENT>.
READ TABLE lt_dom INDEX ls_dom-parent INTO ls_dom_parent.
parent+0(2) = 'LS_'.
parent+2(30) = ls_dom_parent-name.
lt_parent = parent.
lt_parent+0(2) = 'LT'.
assign parent to <parent>.
assign (lt_parent) to <lt_parent>.
endif.
* holen alle Children DAten zu dieser 'parent'.
loop at lt_dom_child into ls_dom_child
where parent = ls_dom-firstchild
and ( name <> '#text'
and name <> 'dataNode'
and name <> 'xfa' )
and nextsib ne '0'.
* Value für das FEld holen
READ TABLE lt_dom INDEX ls_dom_child-firstchild INTO ls_dom_2.
ASSIGN COMPONENT ls_dom_child-name
* of structure p_gs_zeit_gesamt to <lf_feld>.
OF STRUCTURE <parent> TO <lf_feld>.
MOVE ls_dom_2-value TO <lf_feld>.
clear: ls_dom_2 , ls_dom_child.
endloop.
endloop.
if <parent> is assigned and <lt_parent> is assigned.
append <parent> to <LT_PARENT>.
endif.
Code: Alles auswählen.
ASSIGN COMPONENT NAME "der direkte Name der Komponente in der Struktur <parent>
OF STRUCTURE <parent> TO <lf_feld>.
Code: Alles auswählen.
ASSIGN <parent>->* TO <fs_neu>
Code: Alles auswählen.
field-symbols: <parent> type any.
FIELD-SYMBOLS: <lf_feld> TYPE ANY,
<fs_neu> type ANY.
parent = 'P_GS_ZEIT_GESAMT'.
assign (parent) to <parent>.
[color=#FF0000] ASSIGN <parent>->* TO <fs_neu>.[/color] [*][color=#FF4000]hier Dump[/color]
loop at lt_dom_child into ls_dom_child
where parent = ls_dom-firstchild
and ( name <> '#text'
and name <> 'dataNode'
and name <> 'xfa' )
and nextsib ne '0'.
* Value für das FEld holen
READ TABLE lt_dom INDEX ls_dom_child-firstchild INTO ls_dom_2.
ASSIGN COMPONENT ls_dom_child-name
* of structure p_gs_zeit_gesamt to <lf_feld>.
OF STRUCTURE <fs_neu> TO <lf_feld>.
MOVE ls_dom_2-value TO <lf_feld>.
clear: ls_dom_2 , ls_dom_child.
endloop.
Code: Alles auswählen.
REFRESH lt_personen.
CLEAR ls_personen.
REFRESH lt_schichtplan.
CLEAR ls_schichtplan.
CLEAR ls_name.
CLEAR lv_erste_pernr.
REFRESH lt_dom_child.
lt_dom_child[] = lt_dom[].
CLEAR parent.
CLEAR lt_parent.
LOOP AT lt_dom INTO ls_dom WHERE ( name EQ 'data' or
name eq 'DATA').
IF ls_dom-parent IS INITIAL.
parent = 'P_GS_ZEIT_GESAMT'.
CLEAR lt_parent.
ASSIGN (parent) TO <parent>.
* assign (lt_parent) to <lt_parent>.
ELSE.
* bevor den Loop hier ankommt, ist der zu erst in der erste if
* Bedingung gelaufen, also ist in dem Moment <parent> immer
* zugewiesen.
IF <lt_parent> IS ASSIGNED AND <parent> IS ASSIGNED.
APPEND <parent> TO <lt_parent>.
ENDIF.
READ TABLE lt_dom INDEX ls_dom-parent INTO ls_dom_parent.
parent+0(2) = 'LS_'.
parent+2(30) = ls_dom_parent-name.
lt_parent = parent.
lt_parent+0(2) = 'LT'.
ASSIGN (parent) TO <parent>.
ASSIGN (lt_parent) TO <lt_parent>.
ENDIF.
* holen alle Children DAten zu dieser 'parent'.
LOOP AT lt_dom_child INTO ls_dom_child
WHERE parent = ls_dom-firstchild
AND ( name <> '#text'
AND name <> 'dataNode'
AND name <> 'xfa' )
AND nextsib NE '0'.
* Value für das FEld holen
READ TABLE lt_dom INDEX ls_dom_child-firstchild INTO ls_dom_2.
ASSIGN COMPONENT ls_dom_child-name
OF STRUCTURE <parent> TO <lf_feld>.
MOVE ls_dom_2-value TO <lf_feld>.
CLEAR: ls_dom_2 , ls_dom_child.
ENDLOOP.
ENDLOOP.
IF <parent> IS ASSIGNED AND <lt_parent> IS ASSIGNED.
APPEND <parent> TO <lt_parent>.
ENDIF.