Web Service SAP ABAP Web Dynpro

The Application Server ABAP can be a Web Service provider and a Web Service required. The basic architecture of the Web Service Framework of AS ABAP.

Basic web service framework architecture

The Web Service provider creates the WS and its definition. After this,it can publish the WSDL document to a Universal Description Discovery and Integration (UDDI) service directory, or it can create a direct exchange of WSDL document with the WS client.The Web Service Description Language(WSDL)is a special form of XML that contains all the information required by a client to connect with the Web Service provider and all the required information to programmatically work with the respective service (e.g.number of parameters passed to the service,structure of the returned result,type of the used parameters).

We can store the released Web Services in an UDDI registry. There are many organizations that offer web services we can use for free.Such free Web Services we can find. The web address of the public UDDI service directory for SAP we can find.

With the ABAP Workbench,we have many options to create a Web Service (inside-out type).We can use, for example, a BAPI, a Function Module,a Function Group or an Interface message.

In our case,we want to provide the same search option for our YPERSON database table.A Function Module implementation will be used as a Web Service endpoint.After Function Module implementation,we create the Web Service definition with only a few mouse clicks,we test it and we consume it in the Web Dynpro ABAP,as a model for our WD component.In our case,we don’t focus on the WS security,but we only create a small example required to exemplify how we can consume a Web Service in the Web Dynpro ABAP.

Creating the Web Service

First,we copy the Function Module used to search for a candidate and we slightly modify it(Listing ).To be possible to further transform it into a RFC-enabled Module,in the Attributes tab of the Function Module,we have to activate the option Remote-Enabled Module.

As we have mentioned before, no exception classes can be used in the RFCenabled FunctionModule.This is the reason why,for the purpose of this example, we have chosen to create a non class exception:NO_ID.To manage the exceptions that may occur,we can use the BAPIRET2 structure similar to the latter example.

Listing Implementation of YFM_SEARCH_PERSON

Then,we transform our RFC into a Web Service.We have many possibilities to do this,as follows:

  • Right click on the FM name and,from the contextual menu,we choose Create --> Web Service.
  • From Function Builder (Transaction SE37), we choose from the menu Utilities --> More Utilities --> Create Web Services.

The Wizard steps are:

Object Type– we can choose the object type; in our case,the Web Service is a service provider.

Object type wizard step

  • Service Provider - we create a service provider for an existing ABAP Object (Inside Out).

Service provider wizard step

  • Object type - here,we enter a name and a short description for our Web Service,and we can choose the type of the Endpoint use.

Object type wizard step

  • Choose Endpoint - here,we can enter the name of the Function Module that we want to use as endpoint for our Web Service.

Choosing the endpoint wizard step

  • Configure Service - here,we choose an Authorization profile.As we have mentioned above,for the purpose of this example we choose the profile PRF_DT_IF_SEC_NO.

Configuring the service wizard step

Enter Package/Request - here, we have to enter the name of the package Y_WEBDYNPRO and the Transport Request.

Completeit’s the last step in the wizard,where we are informed that the Web Service with the desired name will be generated after pressing the “Complete” button.

The generated service definition

Web Service Configuration

To perform the necessary configuration tasks,we use the SOA Manager,accessible through the SOAMANAGER transaction.By using “Single Service Administration”,we can search for our created WS and configure it(Fig).We can find this option in the tab: “Application and Scenario Communication”.

Searching for our web service

By pressing the“Apply Selection” button,we can see the Details of our Service Definition.Using the“Configurations”tab,we can create a Service and a Service- Endpoint for our Service Definition YWEB_SERVICE.

Details of service definition configurations

Each Service Definition may have more than one Service and,for each Service, we can create more than one Endpoint.Each Service-Endpoint can configure a service in a different way.

Testing the Web Service

After configuring our endpoint, we save it and go into the “Overview”tab.

Details of service definition overview

From here,we choose the link “Open WSDL document for selected binding”and we copy the URL address from the window that appears. By selecting the link “Open Web Service navigator for selected binding”,the Web Service test page opens and we can test our new created Web Service after pressing the “Test” button.

Web service navigator

In case an error occurs,we have to configure the J2EE server access information (the host name and a port number),because the Web Service test page (Web Service Navigator) runs on Java stack. To do this,we can use the same SOAMANAGER transaction --> the tab Technical Configuration --> the option System Global Settings.

Testing our web service request/response

Consuming the Web Service in Web Dynpro

To be able to consume the created Web Service into the Web Dynpro application, we have to firstly create a Proxy.To create it, we can use the same Wizard as for the Web Service creation.

In this case, the Wizard steps are:
Object type Service Consumer.

Wizard object type step

Select Source offers the possibility to select the source of the WSDL document.

Wizard selected source step

Select Source here,we enter our Web Service’s URL.We can use copy and paste to take this URL from the SOAMANAGER transaction.

Wizard selected source step

Enter Package/Request we have to enter the package name, the prefix and the Workbench Request.Because,in the same time with the generation of the proxy class,there are also generated other development objects (e.g.Dictionary objects,classes and interfaces),it is recommended to generate these objects in a separate package (in our case, the Y_PROXY package).

Wizard enter package/request step

Complete after the last step,theWizard generates the consumer proxy.

The consumer proxy

Generated development objects

Before pressing the RUN button to test our Consumer Proxy, we have to create a logical port by using the SOAMANAGER transaction or the old LPCONFIG transaction.

In the SOAMANAGER transaction,in the same window where we searched for the Web Service,we can search now for a consumer proxy with the external name: “yweb_service”.

Searching for a consumer proxy

By pressing the “Apply Selection” button, we open the field where we can create the Proxy Definition.Into the “Configurations” tab,we can create the Logical Port.In the next step,we have to create the Web Dynpro component to use the created Client Proxy.We create a Web Dynpro component named Y_WS_CONSUMER with a view named V_VIEW and a default window.

By using the Service Call(similar to the “BAPI” example),we can integrate our Client Proxy into our WD application. In this case,we have to use the “Web Service Proxy” option as service type.Then,we have to enter the proxy class name,the public method and the logical port.

Because in the latter example we showed how to use this Wizard, now we are going to show,through this example,how to use the proxy without the Wizard’s help.In case we have more complex structures, it happens that Wizard generates only one attribute instead of a node with attributes.In this case,we have to make manually the adequate modifications.

The V_VIEW view context and the layout are presented.The ID_PERSON attribute is of the YPERSON-ID_PERSON type and shall be used to maintain the ID of the searched competitor. The Person child node has the YPERSON dictionary structure,so here we are going to find the data about the searched competitor: his first name,last name,telephone,age and his country id.In the View Layout,we have inserted the UI elements: Group, InputField,Label and Table.

View context und view layout

When the user presses the Search button,the Framework triggers the event handler method onactionsearch.

The onactionsearch event handler method

METHOD onactionsearch . DATA: lr_node TYPE REF TO if_wd_context_node, lr_subnode TYPE REF TO if_wd_context_node, ls_subnode TYPE wd_this->element_person, lv_id_person TYPE yperson-id_person. DATA: obj1 TYPE REF TO ysco_yweb_service, obj2 TYPE REF TO cx_ai_system_fault, ls_input TYPE ysyfm_search_person, ls_output TYPE ysyfm_search_personresponse. lr_node = wd_context->get_child_node('SEARCH_PERSON'). lr_subnode = lr_node->get_child_node('PERSON'). lr_node->get_attribute( EXPORTING name = 'ID_PERSON' IMPORTING value = lv_id_person). TRY. CREATE OBJECT obj1. CATCH cx_ai_system_fault INTO obj2. ENDTRY. ls_input-id_candidate = lv_id_person. TRY. CALL METHOD obj1->yfm_search_person EXPORTING input = ls_input IMPORTING output = ls_output. CATCH cx_ai_system_fault INTO obj2. CATCH cx_ai_application_fault . ENDTRY. IF ls_output IS INITIAL. DATA lr_api_controller TYPE REF TO if_wd_controller. DATA lr_message_manager TYPE REF TO if_wd_message_manager. lr_api_controller ?= wd_this->wd_get_api( ). lr_message_manager = lr_api_controller->get_message_manager( ). lr_message_manager->report_exception(message_object = obj2). ELSE. ls_subnode-firstname = ls_output-firstname. ls_subnode-lastname = ls_output-lastname. ls_subnode-telephone = ls_output-telephone. ls_subnode-age = ls_output-age. ls_subnode-id_country = ls_output-id_country. lr_subnode->set_static_attributes(ls_subnode). ENDIF. ENDMETHOD. n we use proxy objects in methods or programs we can use drag and drop to ease the code generation.

Drag and drop for code generation

As we can see,we have declared a reference variable for proxy (obj1 TYPE REF TO ysco_yweb_service) and two local structures to set the input parameter (ls_input TYPE ysyfm_search_person) and to get the response (ls_output TYPE ysyfm_search_personresponse).

After creating the proxy,we call it and pass the response values in the corresponding child node “PERSON”.At runtime,we have.


Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAP ABAP Web Dynpro Topics