Consumir un Web Service JSON

Saludos @Roland,

En sap hay dos formas de consumir web services:

  • La primera es creando un objeto dentro de SAP (ABAP Proxy) que lo que hace es que mapea el web service a un objeto utilizable desde ABAP. Este nunca lo pude poner a funcionar. Nota: Esto se hace por la SE80

h_tp://scn.sap.com/community/abap/blog/2013/07/29/consuming-webservices-directly-from-abap

  • La segunda es consumiendo el web service a la roca desde ABAP. Te pondré un código de muestra:

FORM get_ws_data.

  DATA: http_client TYPE REF TO if_http_client .

  DATA: w_string TYPE string ,
  w_result TYPE string ,
  r_str TYPE string .

  DATA: result_tab TYPE TABLE OF string WITH HEADER LINE.

  CLEAR w_string .
  w_string = 'URL DEL WEB SERVICE'.

  CALL METHOD cl_http_client=>create_by_url
    EXPORTING
      url                = w_string
    IMPORTING
      client             = http_client
    EXCEPTIONS
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      OTHERS             = 4.


* Se establece el método GET o POST
  CALL METHOD http_client->request->set_header_field
    EXPORTING
      name  = '~request_method'
      value = 'POST'.

* Parámetro que recibe el web service
  CALL METHOD http_client->request->set_form_field
    EXPORTING
      name  = 'nombre del parámetro'
      value = valor.

  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 w_result .

* Resultado del web service  
  w_result = http_client->response->get_cdata( ).
ENDFORM.                    "get_ws_data
7 Me gusta