关于sap:在SAP-C4C里使用Restful服务消费SAP-S4HANA的标准功能

20次阅读

共计 5944 个字符,预计需要花费 15 分钟才能阅读完成。

My series of Cloud Application Studio Blogs

  • How to detect EditMode in an Embedded Component
  • Step by step to enable your custom BO with attachment upload functionality
  • Step by step to create an Adobe Print form in Cloud application Studio
  • How to render PDF which displays picture from the image attachment of your custom BO
  • How to get current logged on business user’s employee information and assigned organization unit via ABSL
  • How to implement dynamic access control based on custom BO using OWL
  • How to make Code List Restriction work when control field and restricted field are not on the same BO
  • How to implement custom number range using custom business object
  • Two approaches to create Code List in Cloud Studio
  • Create Dynamic Code List via Custom Business Object Association
  • Step by step to develop Thing Type based navigation and BO Object based navigation
  • Put Extension field into embedded component and make it visible in Standard UI
  • One possible cause that embedded component fails to display in UI
  • Step by step to create HTML Mashup and make it visible in UI
  • Step by step to enable Text Collection for your custom BO
  • Automatically send an Email notification to line manager via Workflow in Account application
  • Step by step to create Object Value Selector in Cloud Application Studio
  • Two approaches to fill an UI field with dedicated logic implemented in Cloud Application Studio
  • How to execute BO action on multiple selected BO instances in AdvancedListPane
  • How to add custom validation logic on mobile phone field in Contact TI
  • An example about how I analyze why some OBN button does not work
  • Step by step to create OBN button which navigates from standard UI to custom UI
  • Service Request ticket split – how to bring the selected service request item to new custom UI
  • Step by step to create two drop down list with dependency
  • Expose Custom BO logic implemented by ABSL via Custom OData service
  • Step by step to create web service in Cloud Application studio and bind it to a custom action in standard BO
  • Use Restful Service to consume S4 functionality in SAP Cloud for Customer

I have a requirement recently to trigger the creation of the corresponding S/4HANA outbound delivery document in SAP Cloud for Customer.

The basic idea is to replicate Sales order created in SAP C4C into S/4HANA, trigger the production and delivery process. Once the production is finished in S/4HANA, it is required to trigger the outbound delivery creation in C4C Sales Order UI.

(1) The easiest part is to implement the outbound delivery creation in S/4HANA using function module BAPI_OUTB_DELIVERY_CREATE_SLS.

REPORT zcreate_dn.

DATA:lv_ship_point        TYPE          bapidlvcreateheader-ship_point VALUE '0001',
     lv_due_date          TYPE datum VALUE '20181205',
     lv_delivery          TYPE          bapishpdelivnumb-deliv_numb,
     lt_so_items          LIKE TABLE OF bapidlvreftosalesorder,
     ls_so_items          LIKE LINE OF lt_so_items,
     lt_return            TYPE TABLE OF bapiret2,
     ls_read              TYPE order_view,
     lt_item              TYPE TABLE OF bapisdit,
     lt_order_headers_out TYPE TABLE OF bapisdhd,
     lt_header            TYPE TABLE OF sales_key,
     lt_bapisdtehd        TYPE TABLE OF bapisdtehd,
     lt_bapitextli        TYPE TABLE OF bapitextli,
     lt_bapiret2          LIKE bapiret2   OCCURS 0 WITH HEADER LINE.

APPEND INITIAL LINE TO lt_header ASSIGNING FIELD-SYMBOL(<header>).

ls_read-item = 'X'.

<header>-vbeln = '0000000376'.

CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
  EXPORTING
    i_bapi_view     = ls_read
  TABLES
    sales_documents = lt_header
    order_items_out = lt_item.

LOOP AT lt_item ASSIGNING FIELD-SYMBOL(<item>).
  APPEND INITIAL LINE TO lt_so_items ASSIGNING FIELD-SYMBOL(<fill>).

  <fill>-ref_doc = <item>-doc_number.
  <fill>-ref_item = <item>-itm_number.
  <fill>-dlv_qty = <item>-req_qty.
  <fill>-sales_unit = 'EA'.
ENDLOOP.

CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS'
  EXPORTING
    ship_point        = lv_ship_point
    due_date          = lv_due_date
  IMPORTING
    delivery          = lv_delivery
  TABLES
    sales_order_items = lt_so_items
    return            = lt_return.

LOOP AT lt_return ASSIGNING FIELD-SYMBOL(<return>).
  WRITE:/ | Type: {<return>-type}: {<return>-message} | COLOR COL_NEGATIVE.
ENDLOOP.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    wait   = 'X'
  IMPORTING
    return = lt_bapiret2.

LOOP AT lt_bapiret2 ASSIGNING <return>.
  WRITE:/ 'Message:', <return>-message COLOR COL_POSITIVE.
ENDLOOP.

The idea is first to read Sales Order line item detail via function module BAPISDORDER_GETDETAILEDLIST, then BAPI_OUTB_DELIVERY_CREATE_SLS did the job.

Replace your actual Sales Order ID with the hard coded value in line 21.

Create a new SICF service node and wrap the above ABAP code into the method HANDLE_REQUEST of the service node’s handler class.

For more detail about ABAP SICF handler class, please refer to my blogs:

[ABAP ICF handler and Java Servlet
Export WebClient UI table to PDF](https://blogs.sap.com/2017/05…

(2) Create a new action triggerOutboundDelivery in Business Object CustomerQuote which is the data model of Sales Order TI page in C4C.

It’s time now to consume the S/4HANA SICF service created in previous step as a restful service in this custom BO action implementation.

Some necessary model must be created as prerequisite before we start to implement service consumption in ABSL code.
Create a new External Web Service Integration named“JerryExternal”:

Paste the service url created in previous step into service maintenance window here and choose“REST”as web service type:

A new communication scenario is also generated meanwhile:


Right click Communication Scenario and choose“Manage Communication Arrangement”to finish the left Communication Arrangement maintenance task.

The configuration UI will be launched by a new browser window.

Select the Communication Scenario created in SAP Cloud application studio and create a new Communication arrangement based on it:

Maintain the credentials of communication user and activate this arrangement.

Now we can start to program in Sales order’s action triggerOutboundDelivery using ABSL.
The restful service consumption is fired by ABSL utility method WebServiceUtilities.ExecuteRESTService. We can figure out its signature via code auto completion:

Here below is my complete implementation for BO action:

import ABSL;

var HttpMethod = "GET";
var HttpResource = "";                            // not required
var ContentType = "";                             // not required
var Body = "";                                    // not required
var HeaderParameter : collectionof NameAndValue;  // not required

var URLParameter    : collectionof NameAndValue;

var URLParameterEntry : NameAndValue;

URLParameterEntry.Name  = "SoID";
URLParameterEntry.Value = this.ID.content;

URLParameter.Add(URLParameterEntry);

WebServiceUtilities.ExecuteRESTService("JerryExternalService", "JerryExternal", HttpMethod, HttpResource,
URLParameter, HeaderParameter,ContentType, Body);

Activate the method implementation and now we can test:
Choose Sales Order 9000000325 and press“Trigger Delivery”button,

the S/4HANA SICF service implementation is called as expected, with Sales Order ID from C4C successfully passed.

要获取更多 Jerry 的原创文章,请关注公众号 ” 汪子熙 ”:

正文完
 0