This document could be used as guide for beginners to learn and use ABAP web service.

How to create web service provider in ABAP system

The following steps demonstrates how to expose a function module as a web service provider in SAP CRM system.

1. create a new function module to return product description by given input product ID.

Signature and source code of function module:

FUNCTION ZGET_PROD_DESCRIPTION.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IV_PROD_ID) TYPE  COMM_PRODUCT-PRODUCT_ID
*"  EXPORTING
*"     VALUE(RV_TEXT) TYPE  STRING
*"----------------------------------------------------------------------
SELECT SINGLE A~short_text INTO rv_text FROM COMM_PRSHTEXT  AS A
  INNER JOIN comm_product AS B ON B~product_id = iv_prod_id AND B~product_guid = A~product_guid.
ENDFUNCTION.

Make sure the FM is marked as “Remote enabled”.

/wp-content/uploads/2014/05/clipboard1_456138.png

2. start the web service creation wizard:

/wp-content/uploads/2014/05/clipboard2_456139.png

Just follow the wizard to finish creation. Choose the appropriate authentication approach according to your use case.

/wp-content/uploads/2014/05/clipboard3_456147.png

3. Once creation is finished, you would find your service definition as below:

/wp-content/uploads/2014/05/clipboard4_456149.png

click tab WSDL, write down your WSDL link:

/wp-content/uploads/2014/05/clipboard5_456150.png

4. use tcode SOAMANAGER, click Web Service Configuration

/wp-content/uploads/2014/05/clipboard6_456151.png

you can find your service definition created just now:

/wp-content/uploads/2014/05/clipboard7_456155.png

click the hyperlink and create a new service:

/wp-content/uploads/2014/05/clipboard8_456156.png

For security reasons choose radio box “SSL”.

/wp-content/uploads/2014/05/clipboard9_456157.png

click Finish button:

/wp-content/uploads/2014/05/clipboard10_456158.png

Now your web service is ready for consumption. click this icon:

/wp-content/uploads/2014/05/clipboard11_456159.png

write down this link for later usage.

/wp-content/uploads/2014/05/clipboard12_456160.png

How to consume web service in ABAP system

1. tcode SE80, create a new service consumer:

/wp-content/uploads/2014/05/clipboard14_456162.png

2. Choose external WSDL:

/wp-content/uploads/2014/05/clipboard15_456163.png

choose the url got from last step of chapter “How to create web service provider in ABAP system”:

/wp-content/uploads/2014/05/clipboard16_456164.png

activate your consumer proxy and write down the ABAP class name.

/wp-content/uploads/2014/05/clipboard17_456165.png

3. go back to SOAMANAGER, find the consumer proxy created in step2:

/wp-content/uploads/2014/05/clipboard18_456166.png

create a new logical port:

/wp-content/uploads/2014/05/clipboard19_456167.png

/wp-content/uploads/2014/05/clipboard20_456168.png

4. Make sure you specify URL got from the last step of web service creation chapter. If you just use the URL got from SE80 in tab “WSDL”, you will meet with below error.

/wp-content/uploads/2014/05/clipboard21_456170.png

5. consume the web service in ABAP report:

you can find the data type for input and output parameters in SE80:

/wp-content/uploads/2014/05/clipboard22_456172.png

data: lr_proxy TYPE REF TO CO_ZPRODUCTDESCRIPTION4,
input TYPE ZGET_PROD_DESCRIPTION,
output TYPE ZGET_PROD_DESCRIPTION_RESPONSE.
input-iv_prod_id = 'ARNO_TEST004'.
CREATE OBJECT lr_proxy
     EXPORTING
            LOGICAL_PORT_NAME = 'ZLP_JERRY1'.
CALL METHOD lr_proxy->ZGET_PROD_DESCRIPTION
     EXPORTING
            input = input
     IMPORTING
            output = output.

Now we execute the report and get the web service execution result as expected:

/wp-content/uploads/2014/05/clipboard23_456174.png

The product description in UI:

/wp-content/uploads/2014/05/clipboard24_456175.png

How to trace the web service execution

Use tcode SRT_UTIL, add a new configuration for your user which triggers the web service call:

/wp-content/uploads/2014/05/clipboard26_456181.png

Set the Functional Trace to “High”. You could also enable Performance and Payload trace if necessary.

Click Save Configuration button to persist the change.

/wp-content/uploads/2014/05/clipboard27_456182.png

Execute the report which triggers the web service call. After it finishes, click tab “Functional Trace” and click refresh button, you should see several records for execution trace.

/wp-content/uploads/2014/05/clipboard28_456183.png

Double click and select the row with type “Response”, where you could find the product description value returned by service provider.

/wp-content/uploads/2014/05/clipboard29_456184.png

To report this post you need to login first.

13 Comments

You must be Logged on to comment or reply to a post.

  1. Piet Demeester

    Thank you Jerry for this document.

    A minor remark:

    I suppose that in the section ‘How to consume web service in ABAP system’.

    At step 3. ‘create a new logical point’, should be ‘create a new logical port’.

    (0) 
  2. Piet Demeester

    Hi Jerry,

    When I create the logical port,

    I find that I have to enter the User Name and Password in the tab ‘Comsumer Security’.

    If I use that logical port in ABAP code, and  I do not specify the user name and password, I get a popup asking for user name and password, when I call an operation on the proxy.

    I do not want the authentication to be done with a fix user and password,

    but without authentication.

    Is that possible?

    Thanks,

    Piet

    (0) 
    1. Jerry Wang Post author

      Hello Piet,

      If you don’t like to use authentication with username & password, you can use two other authentication settings, although I haven’t tried myself. And so far I didn’t know whether there is a way to consume web service generated via SOAMANAGER without authentication.

      /wp-content/uploads/2014/09/clipboard1_533681.png

      Although I have a rough research on SAP logon procedure, currently I still don’t know how to consume it without authentication. Any reasons for this requirement( not good from my point of view regarding security guideline )?

      Best regards,

      Jerry

      (0) 
      1. Karthi M R

        Hi Jerry / Piet

        It is possible to access the web service even without authentication. You have to make the changes in SOAMANAGER accordingly. If the service is consumed in a secure environment, then there could be no need of authentication as well.

        Regards,

        Karthi M R.

        (0) 
        1. Jerry Wang Post author

          Hello Karthi,

          Thanks a lot for your information 🙂 Would you please kindly share the screenshot of necessary changes in SOAMANAGER to achieve this?

          Best regards,

          Jerry

          (0) 
          1. Karthi M R

            Hi Jerry,

            I hope there are four levels of authentication to be selected while creating the web service.

            The authentication is set to Basic when Low Security is selected. If “No Security” is selected, the authentication level will be set to None.

            Also, you can manually edit and activate the service from the available configurations in the Configurations tab.

            IMG_SOA.png

            Regards,

            Karthi M R.

            (0) 
            1. Piet Demeester

              Hello Karthi,

              I think you are showing the configuration of the service here.

              In my question, I was referring to the configuration of the consumer proxy.

              Even if I set the authentication of the service to ‘None’,

              I have to choose between one of the 3 authentication settings that Jerry mentioned

              (user ID/Password, SAP Authentication Assertion Ticket, X.509 SSL Client Certificate),

              when I add a logical port for the consumer proxy.

              Consumer Proxy.png

              Best Regards,

              Piet

              (0) 
      2. Piet Demeester

        Hi Jerry,

        Thanks for your reply.

        I did not express myself correctly. I am not a security specialist, so please bear with me.

        I am not looking for a solution without authentication,

        but for a solution without authentication with a separate userid and password (basic authentication). In our company, the policy is that everyone, including IT staff, authenticates to the SAP portal using Shibboleth, and when authenticated accesses using SSO to the SAP environmnent. We are not supposed to use basic authentication with a password and userid in production.

        My goal is to use a webservice that is not created via the web service tool (WST),

        and use it in a document template. So, in short, I want to combine the ideas of both your

        blogs http://scn.sap.com/docs/DOC-55153 and http://scn.sap.com/docs/DOC-55507.

        If I would create a web service using the WST, and I use it in a document template, during this process, I do not have to specify a separate userid and password. Hence, I suppose that the system knows that the user is already authenticated at the moment that he uses the document template and thus allows to call the web service.

        I was wondering if the same authentication principle cannot be used when using a web service which is not created using the WST.

        [Update (7 Sept ’14)]

        Hi, I was able to achieve my goal by choosing the authentication settings to ‘SAP Authentication Assertion Ticket’.

        During one test (which I am not able to consistently reproduce), I was able to enter far more parameters in the Security tab (no longer labeled ‘Consumer Security’ tab, but ‘Security’):

        7-09-2014 23-45-48.png

        If I choose Authentication Method SAP Logon Ticket then, it also works.

        If anyone knows how to get access to those additional security parameters consistently, I am interested to know how.

        Best Regards,

        Piet

        (0) 
  3. Rohit Agarwal

    Hi Jerry

    I have a question regarding consuming a web service –

    If the server location of the web service changes do we have to follow all the steps all over again that is create new PROXY CLASS, Create Logical Port and then call that in report?

    What if the third party application also have a landscape just like SAP  for ex – DEV, QA, PRD –  the IP of the web service is different on each system.

    The user(who is not a technical person) wants something very simple where they just want to put the web service’s new link and system should function as it was with old link.

    Will really appreciate if you can help with this.

    Thanks

    Rohit

    (0) 
  4. Rainer Schlott

      Hi Jerry,

    why does
    the document template designer looks so different? The CALL BADI-Buttonis
    missing, also the radio buttons and the URL button . Our system parameters are
    BBPCRM release 713, SP 8.

    /wp-content/uploads/2015/05/documentdesignertemp_712075.gif

    Rainer

    (0) 
  5. Wei Li

    Hi Jerry,
    Thanks a lot for the nice document. I have the same approach like Piet: use external web service for document template.
    We have CRM 7.14 with SP04. So the SOAMANAGER looks a little different.
    I created the FM and web service with profile “Authentication with Certificates and Transport Guarantee”. (same as your step 2). Configuration of binding and creation of service consumer were successful.
    By configuration of logical port system shows that the Authentication Level ist “Strong”. So I couldn’t select UserID/Password. I selected “Single Sign On using SAP Assertion Ticket”. The Logical Port was created successfully.

    But by testing of the service consumer in SE80 I got exception.

    And the trace in SRT_UTIL:

    Can you please provide some advice?

    Thanks a lot.
    Wei

    (0) 

Leave a Reply