Hello Experts,
Wishing you a very Happy new year!
Hope you have already been through the
first part of this blog post series.
In this series, we will do an end to end integration from the S/4 Hana system to SAP Conversational AI Chatbot and then access the chatbot from the MS Teams.
we will access the Purchase Order, Purchase Requisition and Sales Order header details using the Chatbot via the Teams Application. For a detailed overview do check the first part.
For now let's quickly dive in to the technical details.
Agenda for the blog post:
- Activate standard OData service for PO and PR OData service.
- Create a basic CDS view to be exposed as SO OData Service.
- Cloud connector configuration
Prerequisites:
- Access to S/4 Hana system (preferably S/4 Hana 1709 and above)
- Purchase Order – Standard OData service MM_PUR_PO_MAINT_V2_SRV should be activated
- Purchase Requisition - Standard OData service MM_PUR_PR_PROFNL_MAINTAIN_SRV should be activated
- S/4 Hana system with the OData Service as mentioned above.
- Access the Community edition of SAP CAI Chatbot
- Local setup of eclipse with ADT plugin installed.
- Basic understanding ABAP project and CDS view creation in the Eclipse.
Ensure the below URLs are working fine for your system,
Caution : - Make sure you replace your system HOST, PORT, PURCHASEORDERNUMBER and PURCHASEREQUISITIONNUMBER in the provided URL Link.
Purchase Order URL: https://HOST:PORT/sap/opu/odata/sap/MM_PUR_PO_MAINT_V2_SRV/C_PurchaseOrderTP(PurchaseOrder='PURCHASEORDERNUMBER',DraftUUID=guid'00000000-0000-0000-0000-000000000000',IsActiveEntity=true)
Purchase Requisition URL: https://HOST:PORT/sap/opu/odata/sap/MM_PUR_PR_PROFNL_MAINTAIN_SRV/C_PurchaseReqnHeader(PurchaseRequisition='PURCHASEREQUISITIONNUMBER',DraftUUID=guid'00000000-0000-0000-0000-000000000000',IsActiveEntity=true)
Sales Order: For Sales Order Header details, let's create custom OData service on VBAK table, we will perform the below steps:
Create a new Data Definition in the eclipse and name it zsapbot01. Copy the below code to the newly created file.
@AbapCatalog.sqlViewName: 'ZSAPBOT001'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Sales Order Details and Post'
@Metadata.allowExtensions: true
@ObjectModel.modelCategory: #BUSINESS_OBJECT
@ObjectModel.compositionRoot: true
@ObjectModel.transactionalProcessingEnabled: true
//@ObjectModel.writeDraftPersistence: 'zvbak'
//@ObjectModel.draftEnabled: true
@ObjectModel.writeActivePersistence: 'vbak'
@ObjectModel.createEnabled: true
@ObjectModel.updateEnabled: true
@ObjectModel.deleteEnabled: true
@OData.publish: true
//@ObjectModel.writeActivePersistence: 'zsapbot01'
define view zsapbot01 as select from vbak as so
association [1..1] to vbkd as _businessData on $projection.vbeln = _businessData.vbeln and _businessData.posnr = '000000' {
//zcovid_country
key so.vbeln,
so.erdat,
so.ernam,
so.audat,
so.vbtyp,
so.auart,
so.netwr,
so.waerk,
so.vkorg,
so.vtweg,
so.spart,
so.vkgrp,
so.vkbur,
so.vdatu,
so.gsber,
so.cmwae,
_businessData.bstkd,
_businessData
}
For annotation file, create a new Metadata Extension file and name it as zsapbot01. Copy the below code to the newly created file.
@Metadata.layer: #PARTNER
annotate view zsapbot01
with
{
//ZCOVID_STATE_WISE
@UI:{ selectionField: [{ position: 10 }],
lineItem: [ { position: 10 } ],
identification: [ { position: 10 } ],
identification: [ { label: 'VBELN' } ]
}
vbeln;
@UI:{ lineItem: [ { position: 20 } ],
identification: [ { position: 20 } ],
identification: [ { label: 'CONFIRMED' } ]
}
erdat;
@UI:{ lineItem: [ { position: 40 } ],
identification: [ { position: 40 } ],
identification: [ { label: 'RECOVERED' } ]
}
ernam;
@UI:{ lineItem: [ { position: 50 } ],
identification: [ { position: 50 } ],
identification: [ { label: 'DECEASED' } ]
}
audat;
@UI:{ lineItem: [ { position: 30 } ],
identification: [ { position: 30 } ],
identification: [ { label: 'CASE TODAY' } ]
}
vbtyp;
@UI:{ lineItem: [ { position: 60 } ],
identification: [ { position: 60 } ],
identification: [ { label: 'DECEASED' } ]
}
auart;
}
Once done activate both the views. After activation, check if the OData service “ZSAPBOT01_CDS” is activated in the SICF tcode. If yes, we need to register the CDS based OData service “ZSAPBOT01_CDS” in /iwfnd/maint_service . Once done we need to test the Sales Order OData service using the below url.
Caution:- Open the below url in browser (replace HOST, PORT and SALESORDERNUMBER with the values of host, port and a valid Sales Order Number).
https://HOST:PORT/sap/opu/odata/sap/ZSAPBOT01_CDS/zsapbot01('SALESORDERNUMBER')
Once we have activated the OData service, we need the Cloud connector to ensure our Cloud foundry trial account has access to this service.
Let us configure the cloud connector:
Prerequisites for the same are as follows:
Let us start with the SAP Cloud connector setup:
- Login to SAP Cloud connector > Open SAP Cloud Connector using the URL > Enter the user name and password and click Login
- Click the button “Add Subaccount”
- Add subaccount window/page is displayed and to fill this page we need to go the SAP BTP trial account
- Open the SAP BTP Trial account and > click on the Enter Your Trial Account and then > click on the trial subaccount as depicted in the image below
- For the details to be entered in the Add subaccount page/popup window, please find the screenshot below > Region and Subaccount to be entered as per the mapping > Display Name: enter “caibot” > Login E-mail and Password: Enter the SAP BTP trial account Email and password > Location ID: Enter “sapcai” > Click Save
- The Subaccount has been added and is visible in the subaccount dashboard. Now we have successfully established trust between the SAP cloud connector and the SAP BTP trial account. In the next steps we will add the systems to be exposed using the SAP Cloud connector. (ensure your SAP Cloud connector always remains inside your company domain)
- Select the subaccount “caibot” in the displayed field
- Click on “Cloud To On-Premise” in the left side panel as highlighted below
- Go to access control tab as in the above image and add a system in the “Mapping Virtual To Internal System” by clicking the + button
- Select the backend type and the protocol as http or https as per the onPrem configurations.
- Provide the internal host and port number. Check TCode SMICM for the same or connect with the Basis team for this.
- Provide the virtual host and the port. Though we can provide any value for virtual host and port but in order to reduce complexity lets keep the value of virtual host same as internal host and virtual port same as the internal port. The virtual host and port will be used in the Destinations ( to be created in the next blog) using which the OData can be consumed in the node JS application.
- Click Finish to create a mapping successfully and you can see the same in the Mapping (Mapping virtual to internal system) table. Now the backend SAP system has been successfully added.
- Repeat steps 8 -13 for any other system to be added.
- Though the system has been added the status is not coming green yet. For the same, select a line item from the Mapping Virtual to Internal System (Mapping) table and click the + button on the Resources table just below the Mapping table
- Add Resource window will popup, enter the details as displayed in the image below and click the save button.
- Once done check the status of connection via the highlighted button in the actions column, if successful the status will come as green
Conclusion:
Solution Diagram
We are now at the end of this blog post. During the course of this blog post we have successfully identified and activated OData service for PO and PR. For SO we have create a custom CDS view to exposed as an OData Service. registered the same in /iwfnd/maint_service. Since the service is available inside the company domain only, we have configured the SAP Cloud Connector (SCC) to expose the service to the SAP BTP trial account.
In the next blog post we will create destinations using which we can consume the OData service in SAP BTP applications. For the same we need to create Connectivity and Destination instance. Once done we will create a node JS application to consume the OData service and expose it as a public API.
Feedback :
Thanks for taking your time to go through this article, we hope you liked the content. We would appreciate, if you can spare few minutes to leave us feedback on your experience.
See you in the next part of this blog post
🙂 🙂