Extend Form Template using SAP S/4 HANA Cloud In-App Extensibility
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
Prerequisite:
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.
Description: INT_HTTP
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.
Scenario: YY1_INT_HTTP
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.
Hi Arun,
Very informative on extensibility. Quick question on the logic extension, because this is cloud and customers wouldn't have access to ABAP stack, how do u think customers should approach to identify what class APIs to use. In your example, how did you arrive at using cl_ble_http_client.
I thought there should have been a cloud plus simplification approach to invoking APIs and mapping the API call results to the extended elements wherever required.
Regards,
Sitakant
Hello Sitakant,
Well the number of utility classes pre delivered by SAP are quite limited for ABAP for Key users in Cloud. The only way currently to get the classes and methods is by using Keyboard Shortcut (Ctrl + Space).
Also currently there is no specific Utility Method which can invoke an API and map the results to a desired resultset.
In the future release we have a functionality planned call "Reuse Functions" which will help you to write utility classes and reuse it in multiple places. So you would ideally write such a logic in your utility class and call it from Custom Logics or Custom Business Objects.
Regards
Arun.
Love that and appreciate the effort on screen shots 🙂
Regards,
Sitakant.
Hi Arun,
Thanks for your Blog, I could get this work without any issue.
Arun, I have a question, To access the ODATA service how do we provide the user credentials of the communication user in the BADI? Can you elaborate on the authentication part and how should we code this in the BADI.
Regards
Guru
Hello Guru,
The authentication used in this case is Basic Authentication. That's why we use Communication User here with ID and password. You do not have to write any specific code in the BAdI for authentication. This is taken care in your Communication Arrangement. See Step 4, points 3,4 and 5. Here you can see that the Outbound Communication user is HTTP_USER which has the same credentials as Inbound Communication User for scenario SAP_COM_0309.
Regards
Arun.
Hi Arun,
Thanks for your Time and explanation 🙂
I have implemented above solution in the Starter System and it worked perfectly fine for some data from Business Partner ODATA service. I implemented exactly the same thing in Test System, when I test in the Web BADI editor it fails with exception "HTTP Client - Communication error", not sure what's the issue, Can you please advise what could be the issue? However when I test it on the Rest client in Chrome I am able to access the service without any issue.
With Kind Regards
Guru
Hi Guru,
Were you able to resolve it, we are also facing same issue.
Regards,
Vinay
Hi Arun,
We are facing issue while adding Custom Logic.
We have same kind of requirement but for Billing Document Item.
We have followed all your steps and copied the custom logic code and made some changes in the code as per our requirement but while testing it throws error saying "HTTP client - communication error" at line - DATA(response) = lo_client->send( request ).
Can you please help.
Kind Regards,
Vinay
Hi Vinay,
I still have this issue in Q system, did you manage to solve it?
With Regards
Guru
Hi Guru,
Can you raise an SAP incident/ticket for that issue?
Regards
Arun.
Hello Arun, I’m stucked in the search of the precise Business Context.
My scenario is totally the opposite from yours. I have the form (FIN_FO_CORR_OPI_LIST), and I need to add the field ‘AccountingDocumentHeaderText’ from the api: API_OPLACCTGDOCITEMCUBE_SRV.
I tried to add custom fields in different Business Contexts, but I’m not able to see which is the one related to my form with the aim of activate it with ‘Enable the usage’.
Any hints on how to look for it?
Kind Regards,
Dan
Hello Daniel,
Please check if your service is extensible in the first place. I am not very sure that the Open Item List form service is extensible.
Regards
Arun
Hello Arun,
Thanks for the nice Blog.
Can you please check the below link and help me
https://answers.sap.com/questions/638772/how-to-add-custom-logic-for-custom-field-in-s4-han.html
Hello Arun,
is it possible to create new Form Templates (using Adobe Livecycle Designer for example) for custom business object in S/4HANA Cloud?
Could you please redirect me on the right information source?
Thanks
Regards
Francesco
Hi Francesco,
As of today this cannot be done. Your form templates would require a Data Source behind it. The data sources are pre-defined in S4 Cloud.
Regards
Arun.
Thank you very much Arun.
This helped a lot.
Regards
Francesco
Hi Arun,
I need HSN/SAC in the purchase order form where I can see it in Purchase Order but not in the form
Hi Arun
thanks for sharing the information via blog, its helpful a lot.
Here I have to customize the standard form template for the business scenario create correspondence app in hana cloud, for that we are unable to find the business context for developing the custom logic through Badi implementation. Could you please suggest which business scenario we have to use?
Regards
Sathya eathakota
Hello Sathya,
Did you get the business context for "Create correspondence " form?
we have the similar requirement , do the needful if you have got some solution on this
Raju Mammula