In this blog, we will see how a standard form template can be extended for Custom Fields. We will also see how an HTTP Call can be made from Custom Logic. The HTTP call will be made to read data from a whitelisted API which reads the Characteristic Value of a Product.
In this business scenario, the Standard Form Template of Purchase Order needs to be extended with the value of the Characteristic Value assigned to a material. In this example, we assume that this requirement is needed only for Class Type ‘001’ and this can have only one characteristic value.
To achieve this, we do the following steps as depicted below.
Step 1: Create a Custom Field
- Login to SAP S/4 HANA Cloud with user having role SAP_BR_ADMINISTRATOR.
- Create a Custom Field using the app Custom Fields and Logic under the catalog Extensibility.
- Enable the following usages and Save and Publish.
- UIs and Reports: Manage Purchase Order
- Form Templates: Form Template Purchase Order
Step 2: Add this Custom Field in a Form Template
Form Templates are modified using Adobe LiveCycle Designer. The software can be downloaded from the app Install Additional Software under the catalog Additional Software.
Once the software is installed, do the following steps.
- Continue with the user having role SAP_BR_ADMINISTRATOR. Choose the app Maintain Form Templates under the catalog Output Management.
- Download the SAP pre-delivered form template MM_PUR_PURCHASE_ORDER. The file gets downloaded as a zip file. Extract the files to a folder.
- Open the file xdp using Adobe LiveCycle Designer. Add a Column “Characteristic” between the columns Description and Quantity. The field should be binded to custom field YY1_CHARCVALUE_PDI.
- This Custom Form Template needs to be uploaded. Use the app Maintain Form Templates under the catalog Output Management to do this.
Step 3: Enable the usage of Custom Form Template using Output Determination
- Login to SAP S/4 HANA Cloud with user having role SAP_BR_BPC_EXPERT.
- Choose the app Manage Your Solution under the catalog Implementation Cockpit.
- Choose Configure Your Solution and Search with keywords Form Template.
- Navigate to the details of Output Control. Under the Configuration Steps, choose Configure under Assign Form Templates.
- Create a new assignment for Purchase Order.
- Login with user having role SAP_BR_ADMINISTRATOR.
- Choose the app Output Parameter Determination under the catalog Output Control.
- Choose the following parameters and Click Edit.
- Show Rule For: Purchase Order
- Determination Step: Form Template
- Change the value of Form Template to YY1_MOD_PURCHASE_ORDER_01.
Step 4: Create Communication Arrangements to enable HTTP Call
- Login with the user having role SAP_BR_ADMINISTRATOR.
- Create a Communication User using the app Maintain Communication Users under the catalog Communication Management. In this example we create a user named HTTP_USER.
- Create a Communication System using the app Communication Systems under the catalog Communication Management with following details.
System ID: INT_HTTP
System Name: INT_HTTP
- Enter the following details for the Communication System and click Save.
Host Name: myXXXXXX-api.s4hana.ondemand.com (Replace XXXXXX with your tenant URL)
HTTPS Port: 443
User for Inbound Communication: HTTP_USER
User for Outbound Communication: HTTP_USER
- Create a Custom Communication Scenario using the app Custom Communication Scenarios under the catalog Extensibility.
- Create a new Communication Scenario with the following details.
Communication Scenario ID: YY1_INT_HTTP
Description: Internal HTTP
- Create an Outbound Service with the following details.
Outbound Service ID: YY1_INT_HTTP_REST
URL Path: /sap/opu/odata/sap
- Create Communication Arrangement using the app Communication Arrangements under the catalog Communication Management.
- Click New, enter the following details and click Create.
Arrangement Name: YY1_INT_HTTP
- In the details page, enter the details shown below and click Save.
- Repeat Step 5 for Communication Scenario SAP_COM_0309. The Inbound User will be HTTP_USER.
Step 5: Custom Logic to make HTTP Call and Pre-Populate the Custom Field
In this section, we make an HTTP call to a whitelisted API in order to read characteristic value of the Product and populate the custom field created in Step 1.
- Login with user having role SAP_BR_ADMINISTRATOR.
- Choose the app Custom Fields and Logic under the catalog Extensibility.
- Choose the tab Custom Logic. Click +, enter the following details and click Create.
- Click on Create Draft and paste the following lines of code.
CHECK cl_ble_http_client=>is_service_available( communication_scenario = 'YY1_INT_HTTP' outbound_service = 'YY1_INT_HTTP_REST' ) = abap_true. DATA(lo_client) = cl_ble_http_client=>create( communication_scenario = 'YY1_INT_HTTP' outbound_service = 'YY1_INT_HTTP_REST' ). DATA(request) = cl_ble_http_request=>create( ). DATA lv_q1 TYPE string VALUE '/API_CLFN_PRODUCT_SRV/A_ProductCharcValue?$filter=Product eq '. DATA lv_q2 TYPE string VALUE ' and ClassType eq ''001'''. DATA lv_material TYPE string. CONCATENATE lv_q1 '''' purchaseorderitem-material '''' lv_q2 INTO lv_material. request->set_method( 'GET' )->set_resource_extension( lv_material ). TRY . DATA(response) = lo_client->send( request ). DATA(lv_string) = response->get_body( ). SPLIT lv_string at 'CharcValue>' INTO lv_q1 lv_q2. SPLIT lv_q2 at '<' INTO purchaseorderitemchange-yy1_charcvalue_pdi lv_q1. CATCH cx_ble_http_exception INTO DATA(lx). ENDTRY.
- Click Save Draft and Publish.
This code can be replaced by SELECT statements to whitelisted CDS views which can read the characteristic value of a Material once it is available. The whitelisted CDS view is planned for 1805 release.
Test the Scenario
- Login with user having role SAP_BR_PURCHASER.
- Choose the app Manage Purchase Orders under the catalog Purchase Order Processing.
- Create a new Purchase Order. In the PO line items include materials which have classification maintained as well as which do not have maintained.
- View the preview file in Output Management tab. The Custom Field Characteristic can be seen in the output.