Vous êtes sur la page 1sur 17

*&---------------------------------------------------------------------*

*& Report Z_IN_BACK


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT Z_IN_BACK_JSON3.
CLASS json_demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main
IMPORTING json1 TYPE string
CHANGING data1 TYPE any..
ENDCLASS.

CLASS json_demo IMPLEMENTATION.


METHOD main.
DATA(out) = cl_demo_output=>new(
)->begin_section( `JSON-Data` ).
*data:json TYPE string.
*json = json1.
* DATA(json) = json1.
DATA(json) = cl_abap_codepage=>convert_to( json1 ).
out->write_json( json ).

out->next_section( `Parsed Nodes of the JSON-Data` ).


DATA: BEGIN OF node_wa,
node_type TYPE string,
prefix TYPE string,
name TYPE string,
nsuri TYPE string,
value TYPE string,
value_raw TYPE xstring,
END OF node_wa,

nodes LIKE TABLE OF node_wa.


DATA(reader) = cl_sxml_string_reader=>create( json ).
DATA(writer) =
CAST if_sxml_writer( cl_sxml_string_writer=>create( ) ).
TRY.
DO.
CLEAR node_wa.
DATA(node) = reader->read_next_node( ).
IF node IS INITIAL.
EXIT.
ENDIF.
writer->write_node( node ).
CASE node->type.
WHEN if_sxml_node=>co_nt_element_open.
DATA(open_element) = CAST if_sxml_open_element( node ).
node_wa-node_type = `open element`.
node_wa-prefix = open_element->prefix.
node_wa-name = open_element->qname-name.
node_wa-nsuri = open_element->qname-namespace.
DATA(attributes) = open_element->get_attributes( ).
APPEND node_wa TO nodes.
LOOP AT attributes INTO DATA(attribute).
node_wa-node_type = `attribute`.
node_wa-prefix = attribute->prefix.
node_wa-name = attribute->qname-name.
node_wa-nsuri = attribute->qname-namespace.
IF attribute->value_type = if_sxml_value=>co_vt_text.
node_wa-value = attribute->get_value( ).
ELSEIF attribute->value_type =
if_sxml_value=>co_vt_raw.
node_wa-value_raw = attribute->get_value_raw( ).
ENDIF.
APPEND node_wa TO nodes.
ENDLOOP.
CONTINUE.
WHEN if_sxml_node=>co_nt_element_close.
DATA(close_element) = CAST if_sxml_close_element( node ).
node_wa-node_type = `close element`.
node_wa-prefix = close_element->prefix.
node_wa-name = close_element->qname-name.
node_wa-nsuri = close_element->qname-namespace.
APPEND node_wa TO nodes.
CONTINUE.
WHEN if_sxml_node=>co_nt_value.
DATA(value_node) = CAST if_sxml_value_node( node ).
node_wa-node_type = `value`.
IF value_node->value_type = if_sxml_value=>co_vt_text.
node_wa-value = value_node->get_value( ).
ELSEIF value_node->value_type = if_sxml_value=>co_vt_raw.
node_wa-value_raw = value_node->get_value_raw( ).
ENDIF.
APPEND node_wa TO nodes.
CONTINUE.
WHEN OTHERS.
node_wa-node_type = `Error`.
APPEND node_wa TO nodes.
EXIT.
ENDCASE.
ENDDO.
CATCH cx_sxml_parse_error INTO DATA(parse_error).
out->write_text( parse_error->get_text( ) ).
ENDTRY.
out->write_data( nodes ).

out->next_section(
`JSON-XML-Representation of the JSON-Data` ).
out->write_xml(
CAST cl_sxml_string_writer( writer )->get_output( ) ).

out->display( ).
ENDMETHOD.
ENDCLASS.
* Rather use https://gist.github.com/mydoghasworms/4888a832e28491c3fe47
* The alternative is a better parser although it is not an emmitter)
*----------------------------------------------------------------------*
* CLASS json_util DEFINITION
*---------------------------------------------------------------------*
*REPORT Z_IN_BACK_JSON3.
data: ZTEST_TT_001 TYPE STANDARD TABLE OF zit11 WITH HEADER LINE.
CLASS json_util DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
data_to_json IMPORTING data TYPE any
RETURNING value(json) TYPE string,

json_to_data IMPORTING json TYPE string


CHANGING data TYPE any.

ENDCLASS. "json_util DEFINITION

*----------------------------------------------------------------------*
* CLASS json_util IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS json_util IMPLEMENTATION.
METHOD data_to_json.
DATA: lr_desc TYPE REF TO cl_abap_typedescr.
DATA: lr_elem TYPE REF TO cl_abap_elemdescr.
DATA: lr_sdes TYPE REF TO cl_abap_structdescr.
DATA: ls_comp TYPE cl_abap_structdescr=>component.
DATA: lt_comp TYPE cl_abap_structdescr=>component_table.
DATA: lv_json TYPE string.
DATA: lv_field TYPE string.
DATA: lv_value TYPE text255.

FIELD-SYMBOLS: <field> TYPE any.

DATA: lt_x031l TYPE dd_x031l_table.


DATA: ls_x031l TYPE x031l.
DATA: ls_dfies TYPE dfies.
DATA: lv_meth(30) TYPE c VALUE 'GET_DDIC_FIELD'.
DATA: lv_date TYPE d.
DATA: lv_date_c(10) TYPE c.
DATA: lv_time TYPE t.
DATA: lv_time_c(8) TYPE c.
DATA: lv_tabix TYPE i.
DATA: lv_index TYPE i.
DATA: lv_passed1st TYPE boole_d.

lr_desc = cl_abap_typedescr=>describe_by_data( data ).

CASE lr_desc->type_kind.

WHEN cl_abap_typedescr=>typekind_struct1 OR
cl_abap_typedescr=>typekind_struct2.
json = '{'.
* Use RTTI to discover structure members and process them individually
lr_sdes ?= lr_desc.
lt_comp = lr_sdes->get_components( ).
LOOP AT lt_comp INTO ls_comp.

ASSIGN COMPONENT ls_comp-name OF STRUCTURE data

TO <field>.

IF sy-subrc = 0 AND <field> IS NOT INITIAL.

* For consecutive elements, add a comma separator after the previous value
IF lv_passed1st = 'X'.

CONCATENATE json ',' INTO json.


ENDIF.

lv_json = data_to_json( data = <field> ).

CONCATENATE json ' "' ls_comp-name '": ' lv_json INTO json.

lv_passed1st = 'X'.

ENDIF.

ENDLOOP.

CONCATENATE json '}' INTO json.

WHEN cl_abap_typedescr=>typekind_table.

DATA: ld_line TYPE REF TO data.

FIELD-SYMBOLS: <tab> TYPE ANY TABLE.

FIELD-SYMBOLS: <line> TYPE any.

ASSIGN data TO <tab>.

CREATE DATA ld_line LIKE LINE OF <tab>.

ASSIGN ld_line->* TO <line>.

* Open array for table entries

json = '['.

LOOP AT <tab> INTO <line>.

lv_json = data_to_json( data = <line> ).

CONCATENATE json lv_json INTO json SEPARATED BY space.

AT LAST.

CONTINUE.

ENDAT.

* Separate consecutive values by commas


CONCATENATE json ',' INTO json.

ENDLOOP.

* Close array for table entries

CONCATENATE json ']' INTO json SEPARATED BY space.

WHEN cl_abap_typedescr=>typekind_dref.

* For data references, dereference the data and call method again

FIELD-SYMBOLS: <data> TYPE any.

ASSIGN data->* TO <data>.

IF sy-subrc = 0.

json = data_to_json( data = <data> ).

ELSE.

json = '{}'. "Will produce empty JS object

ENDIF.

WHEN OTHERS.

* For elementary types, we merely return a text representation of the value

json = data.

CONDENSE json.

* Escape special characters

REPLACE ALL OCCURRENCES OF '\' IN json


WITH '\\'.

REPLACE ALL OCCURRENCES OF '"' IN json


WITH '\"'.

REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>newline IN json


WITH '\n'.

REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab IN json


WITH '\t'.

REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>form_feed IN json


WITH '\f'.

REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>vertical_tab IN json


WITH '\v'.
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>backspace IN json
WITH '\b'.

* Numeric values do not need to be escaped

IF lr_desc->type_kind NE cl_abap_typedescr=>typekind_num AND

lr_desc->type_kind NE cl_abap_typedescr=>typekind_packed AND

lr_desc->type_kind NE cl_abap_typedescr=>typekind_float AND

lr_desc->type_kind NE cl_abap_typedescr=>typekind_int AND

lr_desc->type_kind NE cl_abap_typedescr=>typekind_int1 AND

lr_desc->type_kind NE cl_abap_typedescr=>typekind_int2.

CONCATENATE '"' json '"' INTO json.

ENDIF.

ENDCASE.

ENDMETHOD. "data_to_json

METHOD json_to_data.

DATA: lv_off TYPE i.

DATA: lv_len TYPE i.

DATA: lv_key TYPE string.

DATA: lv_value TYPE string.

DATA: lv_char TYPE char1. "Current chacater

DATA: lv_pchar TYPE char1. "Previous character

DATA: lv_instr TYPE boole_d. "Indicator: cursor in string

DATA: lv_level TYPE i. "Depth inside a block

DATA: lv_table TYPE boole_d.

FIELD-SYMBOLS: <fk> TYPE string.

FIELD-SYMBOLS: <data> TYPE any.

FIELD-SYMBOLS: <table> TYPE ANY TABLE.


FIELD-SYMBOLS: <sotab> TYPE SORTED TABLE.

FIELD-SYMBOLS: <sttab> TYPE STANDARD TABLE.

FIELD-SYMBOLS: <line> TYPE any.

DATA: ls_line TYPE REF TO data.

DATA: lr_td TYPE REF TO cl_abap_typedescr.

DATA: lr_ttd TYPE REF TO cl_abap_tabledescr.

* If the incoming json contains no '{}[]', we are dealing with

* a basic (scalar) value that is simply assigned to the data

* and then we return

IF json NA '{}[]'.

* Replace escape characters (TODO: Check if there are more!)

lv_value = json.

REPLACE ALL OCCURRENCES OF '\n' IN lv_value WITH


cl_abap_char_utilities=>newline.

REPLACE ALL OCCURRENCES OF '\t' IN lv_value WITH


cl_abap_char_utilities=>horizontal_tab.

REPLACE ALL OCCURRENCES OF '\f' IN lv_value WITH


cl_abap_char_utilities=>form_feed.

REPLACE ALL OCCURRENCES OF '\v' IN lv_value WITH


cl_abap_char_utilities=>vertical_tab.

REPLACE ALL OCCURRENCES OF '\b' IN lv_value WITH


cl_abap_char_utilities=>backspace.

REPLACE ALL OCCURRENCES OF '\\' IN lv_value WITH '\'.

* TODO: Deal with specific data types, e.g. dates etc.

data = lv_value.

EXIT.

ENDIF.

lv_len = strlen( json ).

* Check if we are dealing with a table


lr_td = cl_abap_typedescr=>describe_by_data( data ).

IF lr_td->type_kind = cl_abap_typedescr=>typekind_table.

* This information is used later...

lv_table = 'X'.

ASSIGN data TO <table>.

CREATE DATA ls_line LIKE LINE OF <table>.

ASSIGN ls_line->* TO <line>.

ELSE.

lv_table = ' '.

ENDIF.

* Reset counters/flags

lv_off = 0.

lv_instr = ' '.

lv_level = 0.

ASSIGN lv_key TO <fk>.

WHILE lv_off < lv_len.

lv_char = json+lv_off(1).

**********************************************************************

* IN STRING

**********************************************************************

* Character is in a string delimited by double quotes

IF lv_instr = 'X'.

IF lv_char = '"'.

* Switch out of delimited character string

IF lv_pchar NE '\'.

lv_instr = ' '.


ELSE.

CONCATENATE <fk> lv_char INTO <fk> RESPECTING BLANKS.

ENDIF.

ELSE.

CONCATENATE <fk> lv_char INTO <fk> RESPECTING BLANKS.

ENDIF.

**********************************************************************

* OUTSIDE STRING

**********************************************************************

* Character is not in a string delimited by double quotes

ELSE.

* On opening character, shift level up

IF lv_char CA '{['.

ADD 1 TO lv_level.

ENDIF.

* When the value is contained in a {}/[], the entire value must

* be passed to the next level of processing

IF lv_level > 1.

CONCATENATE <fk> lv_char INTO <fk> RESPECTING BLANKS.

ELSE.

IF lv_char CA '[{'. "<- Chars ignored outside of str

ELSEIF lv_char = ':'.

ASSIGN lv_value TO <fk>.

* The key collected up to now is assigned to the data member

TRANSLATE lv_key TO UPPER CASE.

SHIFT lv_key LEFT DELETING LEADING space.

ASSIGN COMPONENT lv_key OF STRUCTURE data TO <data>.


* End of a key/value pair (we bump up against delimiter) - pass to next level

ELSEIF ( lv_char = ',' OR lv_char = '}' ) AND lv_table = space.

* Process collected value

SHIFT lv_value LEFT DELETING LEADING space.

json_to_data( EXPORTING json = lv_value CHANGING data = <data> ).

* Clear key and value

CLEAR: lv_key, lv_value.

ASSIGN lv_key TO <fk>.

CLEAR: lv_key, lv_value.

* End of a key/value pair (we bump up against delimiter) - pass to next level

* But in table mode, we pass an instance of a row of the table, and afterward

* add it to the table

ELSEIF ( lv_char = ',' OR lv_char = ']' ) AND lv_table = 'X'.

* Process collected value

* Inside array in JSON, there are no keys, only list of values, the collected

* value is in lv_key

SHIFT lv_key LEFT DELETING LEADING space.

json_to_data( EXPORTING json = lv_key CHANGING data = <line> ).

* On return: if dealing with table, add the record to the table

lr_ttd ?= lr_td.

IF lr_ttd->table_kind = cl_abap_tabledescr=>tablekind_sorted
OR lr_ttd->table_kind = cl_abap_tabledescr=>tablekind_hashed.

ASSIGN data TO <sotab>.

INSERT <line> INTO TABLE <sotab>.

ELSE.

ASSIGN data TO <sttab>.

APPEND <line> TO <sttab>.

ENDIF.

CLEAR <line>.

* Clear key and value

CLEAR: lv_key, lv_value.

ASSIGN lv_key TO <fk>.

CLEAR: lv_key, lv_value.

* Switch cursor into delimited string; consecutive characters

* are then treated as part of a key or value, even if they are

* special characters

ELSEIF lv_char = '"'.

lv_instr = 'X'.

* Other chars processed as either key or value

ELSE.

CONCATENATE <fk> lv_char INTO <fk> RESPECTING BLANKS.

ENDIF.

ENDIF.

* On closing character, shift level down again


IF lv_char CA '}]'.

SUBTRACT 1 FROM lv_level.

ENDIF.

* END: Are we in string or out?

ENDIF.

lv_pchar = lv_char.

ADD 1 TO lv_off.

ENDWHILE.

ENDMETHOD. "json_to_data

ENDCLASS. "json_util IMPLEMENTATION

TABLES: TEVEN,PA9005.
DATA: HTTP_CLIENT TYPE REF TO IF_HTTP_CLIENT .
DATA: WF_STRING TYPE STRING ,
RESULT TYPE STRING ,
R_STR TYPE STRING ,
H_SMS_MSG TYPE CLS_STRING_250.
DATA: PERNR TYPE PA0001-PERNR.
DATA: RESULT_TAB TYPE TABLE OF STRING.

DATA: TIME_10 TYPE STANDARD TABLE OF TEVEN WITH HEADER LINE.


DATA: TIME_20 TYPE STANDARD TABLE OF TEVEN WITH HEADER LINE.
DATA: C_10 TYPE I.
DATA: C_20 TYPE I.

START-OF-SELECTION.
CLEAR WF_STRING .

* SELECT-OPTIONS: pernr1 FOR pernr.


* wf_string = 'http://THESMS.IN//send.php?
usr=12452&pwd=9979187925&ph=9825606746&text=This Message Send From SAPDEV.You Can
Send SMS .25 Paise But it Will be send through API.'.
* CONCATENATE 'http://THESMS.IN//send.php?usr=12452&pwd=9979187925&ph=' H_Mobile
'&text=' H_SMS_MSG INTO wf_string .

WF_STRING = 'http://167.0.0.250/cosec/api.svc/attendance-daily?action=get;date-
range=26072011-26072011;range=all;format=xml'.
* CALL METHOD cl_http_client=>create_by_url
* EXPORTING url = wf_string
* IMPORTING client = http_client
* EXCEPTIONS argument_not_found = 1
*plugin_not_active = 2
*internal_error = 3
*OTHERS = 4.
*
*CALL METHOD http_client->send
*EXCEPTIONS
*http_communication_failure = 1
* http_invalid_state = 2.
*
* CALL METHOD http_client->receive
* EXCEPTIONS
* http_communication_failure = 1
*http_invalid_state = 2
* http_processing_failed = 3.
* CLEAR result .
* CLEAR result1.
* result = http_client->response->get_cdata( ).
* result1 = result.

DATA: URL TYPE STRING.


DATA: D1 TYPE STRING.
DATA: D2 TYPE STRING.
DATA: T TYPE SY-UZEIT.
DATA: T1 TYPE SY-UZEIT.
DATA: T2 TYPE SY-UZEIT.
DATA: T3 TYPE SY-UZEIT.
DATA: T4 TYPE SY-UZEIT VALUE '240000'.

CONCATENATE SY-DATUM+6 SY-DATUM+4(2) SY-DATUM(4) INTO D1.


CONCATENATE SY-DATUM+6 SY-DATUM+4(2) SY-DATUM(4) INTO D2.
"changes made by Malay for current time 12:00:00 AM to current time range 17th nov
2011
T = '000000'.

CONCATENATE D1 T INTO D1.


CONCATENATE D2 SY-UZEIT INTO D2.
*CONCATENATE 'http://167.0.0.250/cosec/api.svc/attendance-daily?action=get;date-
range='d1'-'d2';range=all;format=xml'
*INTO url.
*url = 'http://167.0.0.6/cosec/api.svc/event-ta-date?action=get;date-
range=21092011063000-21092011204000;format=xml'.

*CONCATENATE 'http://167.0.0.19/cosec/api.svc/event-ta-date?action=get;date-
range='D1'-'D2';format=xml'
*INTO URL.
url =
'http://106.51.130.67:3030/yaragoemrjavaclient/EMRServlet_3/AccountantReport.do?
dateOfReport=2019-07-26&branchdid=-1'.

* url = 'http://167.0.0.250/cosec/api.svc/attendance-daily?action=get;date-
range=26072011-26072011;range=all;format=xml'.

DATA: "http_client TYPE REF TO IF_HTTP_CLIENT,


RETURN_CODE TYPE I,
CONTENT TYPE STRING.
CL_HTTP_CLIENT=>CREATE_BY_URL( EXPORTING URL = URL IMPORTING CLIENT = HTTP_CLIENT
).
* call method cl_http_client=>create
* exporting
* host = url
* service = '80'
* scheme = '1'
* importing
* client = http_client.
*
*http_client->propertytype_logon_popup = http_client->co_disabled.

*CALL METHOD HTTP_CLIENT->AUTHENTICATE


* EXPORTING
* USERNAME = 'sa'
* PASSWORD = 'admin'.

HTTP_CLIENT->SEND( ).
HTTP_CLIENT->RECEIVE( ).
HTTP_CLIENT->RESPONSE->GET_STATUS( IMPORTING CODE = RETURN_CODE ).
CONTENT = HTTP_CLIENT->RESPONSE->GET_CDATA( ).
HTTP_CLIENT->CLOSE( ).
IF RETURN_CODE <> 200.
" damm....
ENDIF.

DATA: lv_json TYPE /ui2/cl_json=>json,


lr_data TYPE REF TO data.
FIELD-SYMBOLS:
<data> TYPE data,
<struct> TYPE any,
<field> TYPE any.

*lv_json = content.
*lr_data = /ui2/cl_json=>generate( json = lv_json ).
*
*IF lr_data IS BOUND.
* ASSIGN lr_data->* TO <data>.
* ASSIGN COMPONENT 'PROPERTIES' OF STRUCTURE <data> TO <field>.
* IF <field> IS ASSIGNED.
* lr_data = <field>.
* ASSIGN lr_data->* TO <data>.
* ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <data> TO <field>.
* IF <field> IS ASSIGNED.
* lr_data = <field>.
* ASSIGN lr_data->* TO <data>.
* WRITE: <data>. " We got it -> Value1
* ENDIF.
* ENDIF.
*ENDIF.
TYPES: BEGIN OF T_BLOG,
BillAmount(100),
*{ INSERT GAPK901906 1
EID TYPE P LENGTH 10,
*} INSERT
USERID TYPE STRING,
PUNCH1 TYPE STRING,
ENTRY TYPE STRING,
ID TYPE STRING,
DID TYPE STRING,
* description TYPE string,
* creator TYPE string,
* date TYPE string,
END OF T_BLOG,
T_BLOGS TYPE TABLE OF T_BLOG.

DATA: BLOGS TYPE T_BLOGS.


DATA: IT_BLOGS TYPE STANDARD TABLE OF T_BLOG WITH HEADER LINE.
FIELD-SYMBOLS: <BLOG> TYPE T_BLOG.
TYPES: BEGIN OF node3,
BillAmount(20),
BillType(20), "OPD"
BillTypeId(20), "1"
BillRefundAmount(20), "0"
TotalAmount(20),

END OF node3.
TYPES: BEGIN OF node2,
DepartmentWiseRevenueArr(20),
totRefundAmount(20),
totBillAmount(20),
advanceConsumed(20), "0"
InsuranceAmt(20), "0"
cashAmt(20), "0"
advanceCollected(20), "0"
DueAmount(20), "0"
otherModeAmt(20), "0"
CreditAmount(20), "0"
CoPayAmt(20), "0"
advanceAdjusted(20), "0"
cardAmt(20), "0"
chequeAmt(20), "0"
totalAdvanceCollected(20),
END OF node2.
TYPES: BEGIN OF node1,
DepartmentWiseRevenue(20),
PharmacyRevenue(20),
AccessKeyId(20),
surgeryDetails(20),
CollectionDetails(20),
OpticalRevenu(20),
end of node1.
DATA : xml TYPE string.
DATA : gv_json TYPE string,

gt_itab TYPE zit00.


* data:it1 TYPE zit00 .
CALL METHOD cl_fdt_json=>json_to_data
EXPORTING
iv_json = CONTENT
CHANGING
ca_data = gt_itab..

DATA : go_json TYPE REF TO json_util.


DATA : go_json1 TYPE REF TO json_demo.

/ui2/cl_json=>deserialize( EXPORTING json = content pretty_name =


/ui2/cl_json=>pretty_mode-camel_case CHANGING data = gt_itab ).

CREATE OBJECT go_json.


CREATE OBJECT go_json1.

gv_json = content.
*REPLACE ALL OCCURRENCES OF REGEX '[ ]' IN gv_json WITH ``.
*REPLACE all occurrences of cl_abap_char_utilities=>newline in gv_json with ''.
CALL METHOD go_json->json_to_data

EXPORTING

json = gv_json

CHANGING

data = gt_itab.

CALL METHOD go_json1->main

EXPORTING

json1 = gv_json

CHANGING

data1 = gt_itab.

*
CALL TRANSFORMATION wdr_json_xml_to_upper SOURCE XML gv_json
RESULT
XML xml.
*DATA: IXML TYPE REF TO IF_IXML,
* STREAMFACTORY TYPE REF TO IF_IXML_STREAM_FACTORY,
* ISTREAM TYPE REF TO IF_IXML_ISTREAM,
* PARSER TYPE REF TO IF_IXML_PARSER,
* DOCUMENT TYPE REF TO IF_IXML_DOCUMENT.
*
*IXML = CL_IXML=>CREATE( ).
* STREAMFACTORY = IXML->CREATE_STREAM_FACTORY( ).
* ISTREAM = STREAMFACTORY->CREATE_ISTREAM_CSTRING( xml ).
* DOCUMENT = IXML->CREATE_DOCUMENT( ).
* PARSER = IXML->CREATE_PARSER( STREAM_FACTORY = STREAMFACTORY
* ISTREAM = ISTREAM
* DOCUMENT = DOCUMENT ).
* PARSER->SET_NORMALIZING( ).
* PARSER->SET_VALIDATING( MODE = IF_IXML_PARSER=>CO_NO_VALIDATION ).
* PARSER->PARSE( ).
*
*
*
*DATA: CNT TYPE I.
* DATA: COLLECTION TYPE REF TO IF_IXML_NODE_COLLECTION,
* COLLECTION1 TYPE REF TO IF_IXML_NODE_COLLECTION,
* NODE TYPE REF TO IF_IXML_NODE,
* ELEMENT TYPE REF TO IF_IXML_ELEMENT,
* INDEX TYPE I,
* INDEX1 TYPE I.
*
*
* COLLECTION = DOCUMENT->GET_ELEMENTS_BY_TAG_NAME( NAME = 'str' ).
* COLLECTION1 = DOCUMENT->GET_ELEMENTS_BY_TAG_NAME( NAME = 'object' ).
*data: text TYPE REF TO IF_IXML_NAMED_NODE_MAP.
* INDEX1 = COLLECTION->GET_LENGTH( )..
* WHILE INDEX < COLLECTION->GET_LENGTH( ).
*
* NODE = COLLECTION1->GET_ITEM( INDEX ).
* ELEMENT ?= NODE->QUERY_INTERFACE( IXML_IID_ELEMENT ).
* INDEX = INDEX + 1.
*
* APPEND INITIAL LINE TO BLOGS ASSIGNING <BLOG>.
**{ INSERT GAPK901906 2
* NODE = ELEMENT->FIND_FROM_NAME( NAME = 'str' ).
* IF NODE IS NOT INITIAL.
* <BLOG>-EID = NODE->GET_VALUE( ).
* <BLOG>-ENTRY = NODE->GET_NAME( ).
* text = NODE->GET_ATTRIBUTES( ).
** <BLOG>-EID = NODE->GET_PARENT( ).
* ENDIF.
*
**} INSERT
*
* NODE = ELEMENT->FIND_FROM_NAME( NAME = 'UserID' ).
* IF NODE IS NOT INITIAL.
* <BLOG>-USERID = NODE->GET_VALUE( ).
* ENDIF.
*
*
* NODE = ELEMENT->FIND_FROM_NAME( NAME = 'EventDateTime' ).
* IF NODE IS NOT INITIAL.
* <BLOG>-PUNCH1 = NODE->GET_VALUE( ).
*ENDIF.
*NODE = ELEMENT->FIND_FROM_NAME( NAME = 'EntryExitType' ).
* IF NODE IS NOT INITIAL.
* <BLOG>-ENTRY = NODE->GET_VALUE( ).
*ENDIF.
*
*NODE = ELEMENT->FIND_FROM_NAME( NAME = 'MasterControllerID' ).
* IF NODE IS NOT INITIAL.
* <BLOG>-ID = NODE->GET_VALUE( ).
*ENDIF.
*
*NODE = ELEMENT->FIND_FROM_NAME( NAME = 'DoorControllerID' ).
* IF NODE IS NOT INITIAL.
* <BLOG>-DID = NODE->GET_VALUE( ).
*ENDIF.
*
*
*ENDWHILE.
BREAK-POINT.

Vous aimerez peut-être aussi