Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Alex_Hauck
Product and Topic Expert
Product and Topic Expert
8,416

Introduction


It is often still the case that companies rely on manual order processing across multiple systems (Email, CRM, ERP) that are not fully integrated. SAP Invoice Management can help companies transition from manual sales order processing to an automated sales order management in SAP. To further increase the degree of end-to-end automation, SAP Intelligent RPA can be added to the mix. In this post, we show how to use SAP Intelligent RPA in combination with SAP Invoice Management and SAP Information Capture by OpenText for an end-to-end automation of an example use case.

Update 27.07.2020 - Announcement of Webinar:

A dedicated Webinar, scheduled for August 3rd will provide additional information about the described scenario below. This gives you also the opportunity to ask questions. Follow this link to register for this Webinar.

Scenario


“The sales managers of Innovate Corp. track important opportunities in Excel. If an order is received, it has to be processed within SAP, the opportunity in CRM needs to be updated and in addition to that, the sales team needs to be notified if it’s of significant value. Due to the high volume of orders received, especially at quarter end, the back-office team spends much time with this repetitive manual task and sometimes even delays timely fulfilment.”

Analysis


Looking at the scenario, we can identify the following subtasks a member of the team needs to perform:

Check the email inbox and find emails that need to be processed.

  1. Check the email inbox and find emails that need to be processed.

  2. Route the corresponding purchase orders to SAP, check it and create the corresponding sales order.

  3. Update CRM and the Excel file using the data from the purchase order (e.g. total amount).

  4. Get the email addresses of colleagues in charge of the opportunity, and notify them on the won opportunity.


The sales order processing requires complex exception routing and collaboration. It is completely covered by the invoice management solution in combination with SAP Information Capture. SAP Intelligent RPA bots can cover the rest:

One bot extracts the attachments and routes them to SAP Invoice Management, while another bot can perform the remaining two tasks. Thus, a first SAP Intelligent RPA bot scans the inbox for unread emails containing certain keywords, extracts the attachments (orders) from these emails and hands them over to the invoice management solution. This routes the order to SAP Information Capture, which intelligently extracts header and line items including the reference to the opportunity/quotation.

SAP Invoice Management then enriches missing information (like business partner IDs, incoterms, payment terms), checks everything according to pre-defined rules, creates the sales order if everything is OK and finally notifies a second SAP Intelligent RPA bot about the sales order details including total amount and reference to opportunity/quotation. This bot uses the data to update the Excel file, gets the email addresses of colleagues in charge of the opportunity (e.g. from an SAP Cloud for Customer system) and sends them a notification via email.

There are very efficient ways foreseen to integrate the two solutions:

  1. For the integration of subtasks 1 and 2 from above, we use a REST call in SAP Intelligent RPA. Thus, the first SAP Intelligent RPA bot will extract the attached document(s) and send them for processing to SAP Invoice Management where it’s first archived, then sent to OCR (information capture) and processed.

  2. For the integration of subtasks 3 and 4 from above, we use an API Trigger (more information on this can be found in this blog post or in this one). With the help of a small extension, SAP Invoice Management (IM) by OpenText can execute an API Trigger and provide the extracted data as input to the second SAP Intelligent RPA bot.


The general workflow looks as follows:


The next part of this blog post explains the configurations required to implement the above workflow with SAP Intelligent RPA and SAP Invoice Management.

Configuration


Sending the document to SAP Invoice Management Inbound


The first SAP Intelligent RPA bot can use an "ajax" call in Desktop Studio. The following contains an example where the corresponding placeholders (username, password, url, value) have to be replaced with the respective values:
var auth = ctx.base64.encode('username' + ':' + 'password');
ctx.ajax.call({
url: 'url of the SAP IM system',
method: e.ajax.method.post,
formData: [{
name: 'document',
file: 'location of the attachment file'}, {
name: 'register_document_request',
value: 'the xml request to process the document (see below)',
type: e.ajax.content.html
}],
contentType: e.ajax.content.form,
headers: {
'Authorization': 'Basic ' + auth
},
success: function(res, status, xhr) {
ctx.log("Success!");
return;
},
error: function(res, status, xhr) {
ctx.log("Error :" + res);
}
});

The structure of an XML request to process a document looks like the following (values to be adjusted accordingly):
<?xml version="1.0" encoding="utf-8"?>
<register_document_request>
<scan_date>20-06-01</scan_date>
<scan_time>14:00:00</scan_time>
<scan_user>USER</scan_user>
<ar_object>ZOTBC/2SO5</ar_object>
<doc_type>PDF</doc_type>
<arc_doc_id></arc_doc_id>
<archiv_id></archiv_id>
<version>0000000001</version>
</register_document_request>

Setting up the receiving side in SAP Invoice Management


The processing logic is tied to the ArchiveDocType (indicated in element “<ar_object>”) used in the registration step above. The document type determines the information capture profile (which fields need to be extracted), the data enrichment and subsequent processing (list of business rules, business objects and posting logic). In this example we can simply create the profile “PS02_BCF_ORDER” based on the predefined “sales order” scenario.

This looks like the following:


Furthermore, the sales order scenario is linked to the incoming document type:


In addition to this, we need to add a small step at process end to notify SAP Intelligent RPA about the success.

Sending the extracted data to SAP Intelligent RPA via API Trigger


To execute an API Trigger, first a JWT token needs to be obtained using service key credentials. To learn how to get those credentials for SAP Intelligent RPA, please refer to the following post.

For calling the API trigger to update the Excel file after a creation of the sales order, you need to enhance the sales order process configuration. This means as a final step in this process a new background step (“Z_IRPA”) must be added:


The action "Z_IRPA_SERVICE_B" of this process step needs to be defined in the process profile:


It is implemented by the action class "Z_PS02_CL_ACT_IRPA" which implements the interface "/OTX/PF04_IF_ACTION". We recommended to derive this class from the standard implementation "/OTX/PF04_CL_ACTION". In order to trigger the IRPA bot, you redefine the method "/OTX/PF04_IF_ACTION~ACTION_LOGIC_BGR" of this class.

The bot is triggered with a http request using an instance of "if_http_client". To create this instance, use "cl_http_client=>create_by_url" leveraging the URL of the system where the API trigger is implemented.

The request method needs to issue a POST operation. As header parameters the parameter “~request_uri” with value “/apitrigger/<version>/triggers/<bot id>/run” and parameter “irpa-trigger-token” with the token as value need to be added.

The information about the sales order is added to the body of the request as a JSON, as indicated by the header parameter “content-type”.

The sales order header information is available in the method with parameter "PCS_PLH" (header information) and "PCT_PLI" (items). This bot only requires the header information. To convert it to JSON the standard method "/ui2/cl_json=>serialize" has been used. The formatting to binary format can be done using the function module “SCMS_STRING_TO_XSTRING”.

A simplified sample coding looks as the follows. Please be aware that exception and authentication handling needs to be added:
DATA: l_data_so           TYPE xstring,
l_json_data TYPE string,
ls_plh TYPE /otx/ps02_t_plh,
ls_so_irpa TYPE zbc_ps02_s_sales_order_irpa,
lh_if_client TYPE REF TO if_http_client,
lh_entity_request TYPE REF TO if_http_entity,
l_content TYPE string,
l_value TYPE string.

* Set header fields
cl_http_client=>create_by_url( EXPORTING url = <API server URL>
IMPORTING client = lh_if_client ).

lh_if_client->request->set_method( method = if_http_request=>co_request_method_post ).
lh_if_client->request->set_header_field( name = '~request_uri' value = '/apitrigger/<version>/triggers/<bot id>/run' ).
lh_if_client->request->set_header_field( name = 'content-type' value = 'application/hal+json' ).
lh_if_client->request->set_header_field( name = 'irpa-trigger-token' value = ‘<token>' ).
lh_entity_request = lh_if_client->request.
* Set sales order data
ls_plh = pcs_plh.
l_json_data = /ui2/cl_json=>serialize( data = ls_so_irpa
pretty_name = /ui2/cl_json=>pretty_mode-camel_case ).

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING text = l_json_data
IMPORTING buffer = l_data_so
EXCEPTIONS failed = 1
OTHERS = 2.

lh_entity_request->set_data( EXPORTING data = l_data_so ).

* Send request
lh_if_client->send( ).
* Set step status (should be set depending on request result)
pe_success = /otx/pf20_if_basis_api_const=>c_true.

The structure "ZBC_PS02_S_SALES_ORDER_IRPA" contains the payload data exchanged with SAP Intelligent RPA:


The resulting JSON snippet looks like the following:
{“xblnr”:”RiverPark-51362”,”netwr”:57088.35,”waerk”:”USD”}

Updating an Excel File


SAP Intelligent RPA offers various activities that allow bots to manipulate Excel files as shown in the figure below.



Sending Emails


The Outlook Library of SAP Intelligent RPA offers various activities that allow bots to send emails, make appointments or send meeting requests.


For additional information regarding the Excel and Outlook libraries and how to use them, check out further technical articles regarding these topics in SAP Intelligent.

Conclusion


The goal of the post is to illustrate the ease of integration of the mentioned solutions based on simple APIs. This allows a transparent usage of business context across multiple systems by combining SAP Invoice Management with SAP Intelligent RPA bots in an end-to-end fashion. The configuration is straightforward and is reusing existing tools. Based on the template above, any use case requiring a digitization of documents can be implemented. This way, we can extend our automation capabilities to address further tedious and repetitive processes.

Contacts


Stephan König, SAP (Commercial Questions)

Peter Engel, SAP (Functional Questions)

Alexander Hauck, SAP (Technical Questions)

Dr. Pavel Efros, SAP

Matthias Niessen, OpenText (Functional/Technical Questions)

Vladimir Shakhov, OpenText (Commercial Questions)

Learn More


For more information on SAP Intelligent RPA,
5 Comments