cancel
Showing results for 
Search instead for 
Did you mean: 

Call Webservice from inside an ABAP program

ayan_chaudhuri
Participant
0 Kudos

Hi Experts,

I have a file which contains 100 rows of Service Order data.In each row, I have service order no. and post code.

Now I have to call a webservice ( WSDL and URL will be provided by 3rd Party)for each of these service order records passing order no. and post code to the web service and store the response in a z-table.

Can I achieve this by creating an ABAP program ?I will schedule the program as a background batch job.

Next ,  I need to create a second ABAP program which will take the value stored in z-table and update the service order. This program will also be scheduled as a background batch job and run after the completion of first program.

Therefore, my question is how to call webservice from inside  ABAP program?

Any step by step document will be of great help.

Thanks

Ayan

Accepted Solutions (1)

Accepted Solutions (1)

former_member201285
Active Participant

You can call a webservice by using class CL_HTTP_CLIENT

Regards,

Ulrich

ayan_chaudhuri
Participant
0 Kudos

Hi Ulrich,

Can you please elaborate a little bit?

A bit more pointers will be helpful.

Thanks

Ayan

guilherme_frisoni
Contributor
0 Kudos

Hi Ayan,

a very simple example:

Regards,

Frisoni

former_member201285
Active Participant
0 Kudos

Hi Ayan, I've just found my sample program which I created some years ago (converting measures with www.webservicex.net):


REPORT z_re_call_webservice.

PARAMETERS: p_source(50) TYPE c DEFAULT 'Meters' LOWER CASE,

            p_dest(50) TYPE c DEFAULT 'Yards' LOWER CASE,

            p_value(50) TYPE c DEFAULT '50',

            p_uname(50)  TYPE c          " Username Proxy

            p_pw(50) TYPE c LOWER CASE.  " Password Proxy

DATA: gv_uname_proxy TYPE string,

      gv_pw_proxy TYPE string,

      gv_subrc TYPE sy-subrc,

      gv_errortext TYPE string.

DATA: http_client TYPE REF TO if_http_client .

DATA: w_string TYPE string ,  " Input

      w_result TYPE string ,  " Output

      r_str    TYPE string .

DATA: result_tab TYPE TABLE OF string.

DATA : html_content TYPE w3htmltabtype,

      generated_url TYPE char1024,

      html_line TYPE w3html.

START-OF-SELECTION.

* Passing parameters with HTTP GET (Is SOAP also possible???)

  CONCATENATE

    'http://www.webservicex.net/length.asmx'

    '/ChangeLengthUnit?LengthValue=' p_value

    '&fromLengthUnit=' p_source

    '&toLengthUnit=' p_dest

  INTO w_string.

* Create HTTP-Client-Objekt

  CALL METHOD cl_http_client=>create_by_url

    EXPORTING

      proxy_host        = '00.000.0.000'

      proxy_service    = '8080'

      url              = w_string

    IMPORTING

      client            = http_client

    EXCEPTIONS

      argument_not_found = 1

      plugin_not_active = 2

      internal_error    = 3

      OTHERS            = 4.

  IF sy-subrc <> 0.

    MESSAGE 'Error creating client' TYPE 'E'.

  ENDIF.

* Proxy login

  gv_uname_proxy = p_uname.

  gv_pw_proxy = p_pw.

  CALL METHOD http_client->authenticate

    EXPORTING

      proxy_authentication = 'X'

      username            = gv_uname_proxy

      password            = gv_pw_proxy.

* Send

  CALL METHOD http_client->send

    EXCEPTIONS

      http_communication_failure = 1

      http_invalid_state        = 2.

  IF sy-subrc <> 0.

    CALL METHOD http_client->get_last_error(

      IMPORTING

        code  = gv_subrc

        MESSAGE = gv_errortext ).

    WRITE: / 'communication_error( send )',

          / 'code: ', gv_subrc, 'message: ', gv_errortext.

    EXIT.

  ENDIF.

* Receive Result

  CALL METHOD http_client->receive

    EXCEPTIONS

      http_communication_failure = 1

      http_invalid_state        = 2

      http_processing_failed    = 3.

  IF sy-subrc <> 0.

    CALL METHOD http_client->get_last_error(

      IMPORTING

        code  = gv_subrc

        MESSAGE = gv_errortext ).

    WRITE: / 'communication_error( receive )',

          / 'code: ', gv_subrc, 'message: ', gv_errortext.

    EXIT.

  ENDIF.

  CLEAR w_result .

* Result to string

  w_result = http_client->response->get_cdata( ).

* Disconnect

  CALL METHOD http_client->close

    EXCEPTIONS

      http_invalid_state = 1

      OTHERS            = 2.

Answers (2)

Answers (2)

Hvshal4u
Active Participant

Hi Ayan ,

You can follow these steps:

1. Open the package in SE80

2. Right Click on package & Create Enterprise service.

3. Select the radio button 'Service Consumer' & continue

4. Select the radio button External WSDL where you will specify the url of the external web service i.e. WSDL url given by third party.

5.Save in package & it will create a class along with the ddic structure.

6. Now Activate the code.

7. go to tcode 'SOAMANAGER' & specify the logical port.

8. in SE37 create new program for consuming the external webservice.

Note : Steps may vary according to your version.

Thanks & Regards -

Vishal

matt
Active Contributor
0 Kudos

Moved to SOA.

The process is well documented. When I had this requirement I managed to quite easily figure out what I needed to do by doing the appropriate searches in SCN.

The absolutely most straightforward way is what has said. Anything is unnecessarily complicated.