Klasse zum Kreieren der XML-Datei

Klasse Z_CM_CL_BERK_XML_MANAGE

Methoden:

CONVERT_DOCUMENT2XML Instance Method Public    von BIN lesen und in XML Format convertieren
CONSTRUCTOR Instance Method Public  CONSTRUCTOR

INSERT_TAB2DOCUMENT Instance Method Public                                 eine Tabelle an das bestehende XML-Documnet anhängen

RENDER_2_TABLE Instance Method Public                                 XML-Document in die Int- Tabelle

DISPLAY Instance Method Public                                 Display

INSERT_TAB_AS_ACHILD_2NODE Instance Method Public                                 Tabelle an das best.Tabelle  XML-Documnet anhängen als Node

 

Attribute:

GR_XML_DOC Instance Attribute Public Type Ref To CL_XML_DOCUMENT XML-Dokument für WF- WEB-Aktivität
GR_NODE_INP Instance Attribute Private Type Ref To IF_IXML_NODE Knoten eines DOM

 

METHOD convert_document2xml.
DATAlr_convin                 TYPE REF TO cl_abap_conv_in_ce,
lt_table                  TYPE swxmlcont,
lv_text_line              TYPE char1024,
lv_text_line_1            TYPE char255,
lv_text_line_buffer       TYPE char255,
lv_search_parser          TYPE char255,
lv_search_parser_gruppe   TYPE char255,
lv_search_parser_gruppe_2 TYPE char255,
lv_search_parser_gruppe_3 TYPE char255,
lv_search_parser_gruppe_4 TYPE char255,
lv_search_parser_gruppe_5 TYPE char255,
lv_search_parser_gruppe_6 TYPE char255,
lv_string_out             TYPE char50,
lv_line                   TYPE i,
lv_line_1                 TYPE i,
lv_line_2                 TYPE i,
lv_line_3                 TYPE i,
lv_line_4                 TYPE i,
lv_line_g1                TYPE i,
lv_line_g2                TYPE i,
lv_rc                     TYPE sysubrc.

TRY.
lt_table =  me->render_2_table).
CATCH cx_sy_ref_is_initial.
RAISE EXCEPTION TYPE zcx_berk_exception.
ENDTRY.

lv_rc   lineslt_table ).

*    TRANSLATE   lv_string_in TO LOWER CASE.

LOOP AT lt_table ASSIGNING FIELDSYMBOL(<ls_xstring>).

CALL METHOD cl_abap_conv_in_ce=>create
EXPORTING
encoding    ‚UTF-8‘
endian      ‚L‘
ignore_cerr ‚X‘
replacement ‚#‘
input       <ls_xstring> “ Xstring
RECEIVING
conv        lr_convin.              “ Xstring

CALL METHOD lr_convin->read
IMPORTING
data lv_text_line_1.

lv_text_line  =  lv_text_line_1.

IF sytabix 1.

IF  iv_string_in IS NOT INITIAL.
FIND FIRST OCCURRENCE OF  ‚<?xml version=“1.0″?>‘  IN lv_text_line  MATCH OFFSET lv_line_1 IN CHARACTER MODE.
IF sysubrc 0.
lv_text_line_buffer  ‚<?xml version=“1.0″ ‚ && ‚ ‚ && iv_string_in  &&  ‚“?>‘ .
SHIFT lv_text_line_buffer+19 RIGHT .
*****************************************************
TRANSLATE lv_text_line_buffer TO LOWER CASE.
*************************************************

APPEND  lv_text_line_buffer TO rt_secundary_tab.

CLEARlv_text_line(21),
lv_text_line_buffer,
lv_line_1.
SHIFT lv_text_line LEFT DELETING LEADING space.
ENDIF.
ENDIF.

FIND FIRST OCCURRENCE OF ‚<XML>‘ IN lv_text_line  MATCH OFFSET lv_line_1 IN CHARACTER MODE.
IF sysubrc 0.
lv_text_line_buffer  ‚<xml>‘.
APPEND  lv_text_line_buffer TO rt_secundary_tab.

CLEARlv_text_line+lv_line_1(5),
lv_text_line_buffer.
SHIFT lv_text_line+lv_line_1 LEFT DELETING LEADING space.
ENDIF.
ENDIF.

IF sytabix lv_rc.

FIND FIRST OCCURRENCE OF ‚</XML>‘ IN lv_text_line  MATCH OFFSET lv_line_1 IN CHARACTER MODE.
IF sysubrc 0.
CLEAR lv_text_line+lv_line_1(5).
ENDIF.
ENDIF.

IF  it_string_out[] IS NOT INITIAL.
LOOP AT  it_string_out INTO lv_string_out.
CHECK lv_string_out IS NOT INITIAL.
*       TRANSLATE   lv_string_out TO LOWER CASE.
REPLACE ALL OCCURRENCES OF lv_string_out IN lv_text_line  WITH space.

ENDLOOP.
ENDIF.

* Main-Part
IF lv_text_line_buffer IS NOT INITIAL.
lv_text_line lv_text_line_buffer && lv_text_line.
CLEAR lv_text_line_buffer.
ENDIF.
lv_line 0.
DO.

****************************************************** FeldGruppe -Ende

IF lv_search_parser_gruppe_6 IS NOT INITIAL.
FIND FIRST OCCURRENCE OF  lv_search_parser_gruppe_6 IN  lv_text_line+lv_line MATCH OFFSET lv_line_1 MATCH LENGTH lv_line_2.
IF sysubrc AND lv_line_1 0.
lv_line lv_line + lv_line_2.
TRANSLATE lv_search_parser_gruppe_6  TO LOWER CASE.
APPEND lv_search_parser_gruppe_6 TO rt_secundary_tab.
CLEAR lv_search_parser_gruppe_6.
ENDIF.
ENDIF.
IF lv_search_parser_gruppe_5 IS NOT INITIAL.
FIND FIRST OCCURRENCE OF  lv_search_parser_gruppe_5 IN  lv_text_line+lv_line MATCH OFFSET lv_line_1 MATCH LENGTH lv_line_2.
IF sysubrc AND lv_line_1 0.
lv_line lv_line + lv_line_2.
TRANSLATE lv_search_parser_gruppe_5  TO LOWER CASE.
APPEND lv_search_parser_gruppe_5 TO rt_secundary_tab.
CLEAR lv_search_parser_gruppe_5.
ENDIF.
ENDIF.
IF lv_search_parser_gruppe_4 IS NOT INITIAL.
FIND FIRST OCCURRENCE OF  lv_search_parser_gruppe_4 IN  lv_text_line+lv_line MATCH OFFSET lv_line_1 MATCH LENGTH lv_line_2.
IF sysubrc AND lv_line_1 0.
lv_line lv_line + lv_line_2.
TRANSLATE lv_search_parser_gruppe_4  TO LOWER CASE.
APPEND lv_search_parser_gruppe_4 TO rt_secundary_tab.
CLEAR lv_search_parser_gruppe_4.
ENDIF.
ENDIF.

IF lv_search_parser_gruppe_3 IS NOT INITIAL.
FIND FIRST OCCURRENCE OF  lv_search_parser_gruppe_3 IN  lv_text_line+lv_line MATCH OFFSET lv_line_1 MATCH LENGTH lv_line_2.
IF sysubrc AND lv_line_1 0.
lv_line lv_line + lv_line_2.
TRANSLATE lv_search_parser_gruppe_3  TO LOWER CASE.
APPEND lv_search_parser_gruppe_3 TO rt_secundary_tab.
CLEAR lv_search_parser_gruppe_3.
ENDIF.
ENDIF.

IF lv_search_parser_gruppe_2 IS NOT INITIAL.
FIND FIRST OCCURRENCE OF  lv_search_parser_gruppe_2 IN  lv_text_line+lv_line MATCH OFFSET lv_line_1 MATCH LENGTH lv_line_2.
IF sysubrc AND lv_line_1 0.
lv_line lv_line + lv_line_2.
TRANSLATE lv_search_parser_gruppe_2  TO LOWER CASE.
APPEND lv_search_parser_gruppe_2 TO rt_secundary_tab.
CLEAR lv_search_parser_gruppe_2.
ENDIF.
ENDIF.

IF lv_search_parser_gruppe IS NOT INITIAL.
FIND FIRST OCCURRENCE OF  lv_search_parser_gruppe IN  lv_text_line+lv_line MATCH OFFSET lv_line_1 MATCH LENGTH lv_line_2.
IF sysubrc AND lv_line_1 0.
lv_line lv_line + lv_line_2.
TRANSLATE lv_search_parser_gruppe  TO LOWER CASE.
APPEND lv_search_parser_gruppe TO rt_secundary_tab.
CLEAR lv_search_parser_gruppe.
ENDIF.
ENDIF.

*************************************************************************************************************
FIND FIRST OCCURRENCE OF REGEX ‚[<]{1}[\w]{1,}[>]{1}‘ IN lv_text_line+lv_line MATCH OFFSET lv_line_1 MATCH LENGTH lv_line_2.

IF sysubrc 0.

lv_line_g1 lv_line_1 + + lv_line.
lv_line_g2   lv_line_2 – 2.
lv_search_parser lv_text_line+lv_line_g1(lv_line_g2.
****************************************************** FeldGruppe
FIND REGEX ‚[a-z]{1,}‘ IN lv_search_parser.
IF sysubrc .
lv_line_1 lv_line_1 + lv_line.
lv_search_parser lv_text_line+lv_line_1(lv_line_2.
IF lv_search_parser_gruppe IS INITIAL.
lv_search_parser_gruppe lv_search_parser.
SHIFT lv_search_parser_gruppe+1 RIGHT BY PLACES.
lv_search_parser_gruppe+1(1=   ‚/‘.
ELSEIF lv_search_parser_gruppe_2 IS INITIAL.
lv_search_parser_gruppe_2 lv_search_parser.
SHIFT lv_search_parser_gruppe_2+1 RIGHT BY PLACES.
lv_search_parser_gruppe_2+1(1=   ‚/‘.
ELSEIF lv_search_parser_gruppe_3 IS INITIAL.
lv_search_parser_gruppe_3 lv_search_parser.
SHIFT lv_search_parser_gruppe_3+1 RIGHT BY PLACES.
lv_search_parser_gruppe_3+1(1=   ‚/‘.
ELSEIF lv_search_parser_gruppe_4 IS INITIAL.
lv_search_parser_gruppe_4 lv_search_parser.
SHIFT lv_search_parser_gruppe_4+1 RIGHT BY PLACES.
lv_search_parser_gruppe_4+1(1=   ‚/‘.
ELSEIF lv_search_parser_gruppe_5 IS INITIAL.
lv_search_parser_gruppe_5 lv_search_parser.
SHIFT lv_search_parser_gruppe_5+1 RIGHT BY PLACES.
lv_search_parser_gruppe_5+1(1=   ‚/‘.
ELSEIF lv_search_parser_gruppe_6 IS INITIAL.
lv_search_parser_gruppe_6 lv_search_parser.
SHIFT lv_search_parser_gruppe_6+1 RIGHT BY PLACES.
lv_search_parser_gruppe_6+1(1=   ‚/‘.
ENDIF.
lv_search_parser lv_text_line+lv_line_1(lv_line_2.
TRANSLATE lv_search_parser  TO LOWER CASE.
APPEND  lv_search_parser TO rt_secundary_tab.
CLEAR  lv_search_parser.
lv_line lv_line_1 + lv_line_2.
CONTINUE.
ENDIF.
*******************************************************
lv_line_1 lv_line_1 + lv_line.
lv_search_parser lv_text_line+lv_line_1(lv_line_2.
SHIFT lv_search_parser+1 RIGHT BY PLACES.
lv_search_parser+1(1=   ‚/‘.
FIND FIRST OCCURRENCE OF lv_search_parser   IN lv_text_line+lv_line  MATCH OFFSET lv_line_3 MATCH LENGTH lv_line_4.
IF sysubrc 0.
TRANSLATE lv_text_line+lv_line_1(lv_line_2)  TO LOWER CASE.
lv_line_3 lv_line_3 + lv_line.
TRANSLATE lv_text_line+lv_line_3(lv_line_4)  TO LOWER CASE.
lv_line lv_line_3 + lv_line_4.
lv_line_2 lv_line_3 + lv_line_4 – lv_line_1.
lv_text_line_buffer lv_text_line+lv_line_1(lv_line_2).
APPEND lv_text_line_buffer TO rt_secundary_tab.
CLEAR lv_text_line_buffer.
ELSE.
* Fehlt second part
lv_text_line_buffer  lv_text_line+lv_line.
EXIT.
ENDIF.

ELSE.
* Fehlt first part
lv_text_line_buffer  lv_text_line+lv_line.
EXIT.
ENDIF.
IF    lv_line GE 1024.
CLEAR lv_text_line_buffer.
EXIT.
ENDIF.
ENDDO.

* the final step

lv_rc =  lv_rc – 1.
IF  lv_rc 0.

lv_text_line_buffer  ‚</xml>‘.
APPEND  lv_text_line_buffer TO rt_secundary_tab.
ENDIF.

ENDLOOP.

ENDMETHOD.

 METHOD constructor.
DATAlv_rval     TYPE sysubrc,
lr_node_new TYPE REF TO if_ixml_node,
lr_node     TYPE REF TO if_ixml_node.
CREATE OBJECT gr_xml_doc.

CALL METHOD gr_xml_doc->create_with_datadataobject it_main_data[] ).

TRY.
lr_node gr_xml_doc->m_document->get_root).
CATCH cx_sy_ref_is_initial.“ INTO DATA(lr_cx) .
RAISE EXCEPTION TYPE zcx_berk_exception.
ENDTRY.

TRY.
gr_node_inp =  lr_node->get_first_child).
CATCH cx_sy_ref_is_initial.
RAISE EXCEPTION TYPE zcx_berk_exception.
ENDTRY.

CALL METHOD gr_node_inp->set_name
EXPORTING
name iv_header
RECEIVING
rval lv_rval.
IF lv_rval NE 0.
RAISE EXCEPTION TYPE zcx_berk_exception.
ENDIF.
TRY.
lr_node_new gr_node_inp->get_first_child).
CATCH cx_sy_ref_is_initial.
RAISE EXCEPTION TYPE zcx_berk_exception.
ENDTRY.
CHECK  lr_node_new IS BOUND.
CALL METHOD lr_node_new->set_name
EXPORTING
name iv_header_line
RECEIVING
rval lv_rval.
CHECK lv_rval NE 0.
RAISE EXCEPTION TYPE zcx_berk_exception.
ENDMETHOD.

 METHOD insert_tab2document.
DATA:
lr_xml_buffer   TYPE REF TO cl_xml_document,
lv_str          TYPE  string,
lr_node_new_1   TYPE REF TO if_ixml_node,
lr_node_item    TYPE REF TO if_ixml_node,
lv_line         TYPE syindex  VALUE 0,
lr_subnode_list TYPE REF TO if_ixml_node_list,
lv_rc           TYPE sysubrc.

CREATE OBJECT lr_xml_buffer.

CALL METHOD lr_xml_buffer->create_with_datadataobject it_secundary_tab[] ).
CALL METHOD gr_xml_doc->insert_document_as_child
EXPORTING
node     gr_node_inp
document lr_xml_buffer
RECEIVING
retcode  lv_rc.

TRY.
lr_node_new_1 gr_node_inp->get_last_child).
CATCH cx_sy_ref_is_initial.“ INTO DATA(lr_cx) .
RAISE EXCEPTION TYPE zcx_berk_exception.
ENDTRY.

CALL METHOD lr_node_new_1->set_name
EXPORTING
name iv_label_header
RECEIVING
rval lv_rc.

IF lv_rc NE 0.
RAISE EXCEPTION TYPE zcx_berk_exception.
ENDIF.

lr_subnode_list =  lr_node_new_1->get_children).

LOOP AT it_secundary_tab ASSIGNING FIELDSYMBOL(<ls_sub_line>).
lr_node_item lr_subnode_list->get_itemindex  =   lv_line  ).

CALL METHOD lr_node_item->set_name
EXPORTING
name iv_label_item
RECEIVING
rval lv_rc.

IF lv_rc NE 0.
RAISE EXCEPTION TYPE zcx_berk_exception.
ENDIF.
ADD TO   lv_line.
ENDLOOP.

FREE  lr_xml_buffer.
ENDMETHOD.

  METHOD render_2_table.
DATAlv_size            TYPE i.
CALL METHOD gr_xml_doc->render_2_table
IMPORTING
table rt_xml_tab
size  lv_size.

ENDMETHOD.

  METHOD display.
CALL METHOD gr_xml_doc->display).
ENDMETHOD.

 METHOD insert_tab_as_achild_2node.
DATA:
lr_xml_buffer        TYPE REF TO cl_xml_document,
lr_node_new_1        TYPE REF TO if_ixml_node,
lr_node_new_2        TYPE REF TO if_ixml_node,
lr_node_item         TYPE REF TO if_ixml_node,
lv_line              TYPE syindex  VALUE 0,
lr_subnode_list      TYPE REF TO if_ixml_node_list,
lr_subnode_list_last TYPE REF TO if_ixml_node_list,
lv_node_name         TYPE string,
lv_rc                TYPE sysubrc.

CREATE OBJECT lr_xml_buffer.

CALL METHOD lr_xml_buffer->create_with_datadataobject it_secundary_tab[] ).

TRY.
lr_node_new_1 gr_node_inp->get_last_child).
CATCH cx_sy_ref_is_initial.“ INTO DATA(lr_cx) .
RAISE EXCEPTION TYPE zcx_berk_exception.
ENDTRY.

* for later remove
CALL METHOD lr_node_new_1->get_name
RECEIVING
rval lv_node_name.

lr_subnode_list =  lr_node_new_1->get_children).

TRY.
lr_node_item lr_subnode_list->get_itemindex  =   iv_line_idx  ).
CATCH cx_sy_ref_is_initial.“ INTO lr_cx .
RAISE EXCEPTION TYPE zcx_berk_exception.
ENDTRY.

CALL METHOD gr_xml_doc->insert_document_as_child
EXPORTING
node     lr_node_item
document lr_xml_buffer
RECEIVING
retcode  lv_rc.

TRY.
lr_node_new_2 lr_node_item->get_last_child).
CATCH cx_sy_ref_is_initial„INTO lr_cx .
RAISE EXCEPTION TYPE zcx_berk_exception.
ENDTRY.

CHECK   lr_node_new_2 IS BOUND.
*  for later remove
CALL METHOD lr_node_new_2->get_name
RECEIVING
rval lv_node_name.

CALL METHOD lr_node_new_2->set_name
EXPORTING
name iv_label_header
RECEIVING
rval lv_rc.

lr_subnode_list_last =  lr_node_new_2->get_children).
LOOP AT it_secundary_tab ASSIGNING FIELDSYMBOL(<ls_sub_line>).
lr_node_item lr_subnode_list_last->get_itemindex  =   lv_line  ).
CALL METHOD lr_node_item->set_name
EXPORTING
name iv_label_item
RECEIVING
rval lv_rc.
ADD TO   lv_line.
ENDLOOP.
IF lv_rc NE 0.
RAISE EXCEPTION TYPE zcx_berk_exception.
ENDIF.
FREE  lr_xml_buffer.
ENDMETHOD.

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden /  Ändern )

Google Foto

Du kommentierst mit Deinem Google-Konto. Abmelden /  Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )

Verbinde mit %s