Simple Code To Consume Web Service Using SAP ABAP
Simple Code To Consume Web Service Using SAP ABAP
ABAP
REPORT zpw_webservice.
*&---------------------------------------------------------------------*
*& Selection Screen
*&---------------------------------------------------------------------*
PARAMETERS : p_cnt TYPE t005t-landx .
*&---------------------------------------------------------------------*
*& Types and Data
*&---------------------------------------------------------------------*
DATA: http_client TYPE REF TO if_http_client ,
http_url TYPE string ,
p_content TYPE string .
*&---------------------------------------------------------------------*
*& Start of Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION .
p_content = http_client->response->get_cdata( ).
REPLACE ALL OCCURRENCES OF '<' IN p_content WITH '<' .
REPLACE ALL OCCURRENCES OF '>' IN p_content WITH '>' .
*&---------------------------------------------------------------------*
*& Processing string
*&---------------------------------------------------------------------*
DATA : moff TYPE syst-tabix ,
moff1 TYPE syst-tabix ,
len TYPE syst-tabix .
DO .
FIND '<City>' IN SECTION OFFSET moff OF p_content IGNORING CASE MATCH OFFSET
moff .
IF sy-subrc = 0 .
moff = moff + 6 .
FIND '</City>' IN SECTION OFFSET moff OF p_content IGNORING CASE MATCH
OFFSET moff1 .
len = moff1 - moff .
WRITE : / p_content+moff(len) .
ELSE.
EXIT.
ENDIF.
ENDDO .
In this code processing of XML string is done using FIND statement. SAP has introduced command CALL
TRANSFORMATION since Basis release 6.10 for XML processing. This command CALL TRANSFORMATION
process the whole XML string based on defined transformation and return it in variable/internal table.
Transformations can be defined using transaction SE80. Ok I am leaving this topic for next blog ;)