Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

response_entity_body of HTTP_GET:(response_entity_body Text table to Internal Table Conversion)

Former Member
0 Kudos

Hi All,

The format of OUTPUT i got is i think HTML.

I am using HTTP_GET for consuming the webservice(BZSt: USt-IdNr. Bestätigung). I am getting the output in the response_entity_body of the function HTTP_GET.

response_entity_body is a type table of text with headerline. But it is in XML format.

Can someone please suggest me how to convert this table which has XML format to ABAP internal table.

Here is my code of HTTP_GET and also attaching the output:


REPORT ZZ_N_TEST3.

DATA p_url(264) TYPE c.
DATA: p_ustid TYPE stceg ,
     pu_ustid
TYPE stceg ,
     l_name
TYPE c,
     ort
TYPE c,
     pstlz
TYPE c,
     stras
TYPE c,
     user
(30) type C,
     pwd
(30) type C.
DATA: proxy_ip like THTTP-PROXY,
      g_status
(3) type c,
      g_status_text
(128) type c,
      response
type table of text with header line,
      response_headers
type table of text with header line,
      P_FILE    
LIKE RLGRAP-FILENAME.
     

p_ustid
= 'DEXXXXXXXX'.

pu_ustid
= 'NLXXXXXXXXXX'.

CONCATENATE 'http://evatr.bff-online.de/evatrRPC?UstId_1=' p_ustid '&UstId_2=' pu_ustid
               
'&Druck=nein' INTO p_url.

REFRESH response.

 
CALL FUNCTION 'HTTP_GET'
   
EXPORTING
      absolute_uri                     
= p_url
*   REQUEST_ENTITY_BODY_LENGTH        =
     rfc_destination                  
= 'SAPHTTP'
     proxy                            
= proxy_ip
   BLANKSTOCRLF                     
= 'Y'
     timeout                          
= 30
  
IMPORTING
     status_code                      
= g_status
     status_text                      
= g_status_text
   RESPONSE_ENTITY_BODY_LENGTH      
= rlength
   
TABLES
*   REQUEST_ENTITY_BODY               =
     response_entity_body             
= response
      response_headers                 
= response_headers
*   REQUEST_HEADERS                   =
  
EXCEPTIONS
     connect_failed                   
= 1
     timeout                          
= 2
     internal_error                   
= 3
     tcpip_error                      
= 4
     data_error                       
= 5
     system_failure                   
= 6
     communication_failure            
= 7
    
OTHERS                            = 8.


loop at response.
 
write:/ response.
endloop.

11 REPLIES 11

custodio_deoliveira
Active Contributor
0 Kudos

Hi Narsi,

If can convert the XML into a internal table using CALL TRANSFORMATION.

Regards,

Custodio

0 Kudos

Hi Custodio,

Its not in the XML format and i think not even HTML.

Please have a look at attached file Output.TXT,  Please suggest me how to get the required output from the OUTPUT.txt.

Thanks & regards,

NarsiReddy.

0 Kudos

Why do you think it is not in XML format? Well sure its missing the XML header row, but other than that it is an poorly created XML structure for which you can use a transformation to convert.

0 Kudos

Hi Dorminik Krämer,

WHich transformation i need to use?

its the fixed format of output. BZSt: USt-IdNr. Bestätigung              

0 Kudos

I'd be amazed if there would already by an existing transformation for this format.

You will need to create your own in STRANS.

0 Kudos

Hi Dominik Krämer,

Can you please provide some example how to create transformation for this type of output.

Thanks & regards,

NarsiReddy.

0 Kudos

Acutally there is a more simple solution: Put your data into an string and call methods 'SCMS_STRING_TO_XSTRING' and 'SMUM_XML_PARSE'. Not as pretty though as you still need to put this data then into the structure you need.

DATA: lv_string TYPE string VALUE '<params><param><value><array><data><value><string>UstId_1</string></value><value><string></string></value></data></array></value></param></params>'.
DATA: lv_xstring TYPE xstring.
DATA: xml_table LIKE  smum_xmltb OCCURS 0,
      return    LIKE  bapiret2 OCCURS 0.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
  EXPORTING
    text           = lv_string
*   MIMETYPE       = ' '
*   ENCODING       = ENCODING
IMPORTING
   buffer         = lv_xstring
* EXCEPTIONS
*   FAILED         = 1
*   OTHERS         = 2
          .

CALL FUNCTION 'SMUM_XML_PARSE'
  EXPORTING
    xml_input = lv_xstring
  TABLES
    xml_table = xml_table
    return    = return.

BREAK-POINT.

0 Kudos

Hi @Dominik_Krämer ,

I got something good now, while debugging in XML_TABLE i can see values and everything perfectly.

Can you please say how to take these values from XML_TABLE and assign to variables.

example:

USTID_1 = DEXXXXXXXX.

ErrorCode = 200.

USTID_2 = NLXXXXXXXXX. and so on.

Thanks & regards,

NarsiReddy.

0 Kudos

According to the documentation (BZSt: USt-IdNr. Best&amp;auml;tigung), always two string entries belong togther. So simply loop at the XML_TABLE where the Type = V and then you always got the field & content:

Fieldname = sy-tabix

Content = sy-tabix + 1.

Regards,

Dominik

0 Kudos

Hi Dominik,

I have written code as below but getting wrong Value.

data itab TYPE smum_xmltb.

DATA UstId_1 TYPE string.

loop at xml_table TRANSPORTING NO FIELDS WHERE type = 'V'.

  READ TABLE xml_table INDEX sy-tabix INTO itab.

  IF itab-CVALUE = 'UstId_1'.

    READ TABLE xml_table INDEX sy-tabix + 1 INTO itab.

    UstId_1 = itab-CVALUE.

  ENDIF.

  ENDLOOP.

  WRITE:/ 'VAt num is:', UstId_1.

Please suggest me where i went wrong.

Thanks & regards,

NarsiReddy.

0 Kudos

Do you get a wrong value or empty value?
In case you egt an empty value use + 2 as there is an empty line in between.