如何在SAP C4C里使用ABSL消费第三方Restful API
【摘要】 首先我们得有一个可以正常工作的Restful API:然后在Cloud for Customer的Cloud Application Studio里创建Restful API的模型,把第一步可以正常工作的Restful API url填进模型里去:然后在ABSL里使用如下代码进行消费:import ABSL;if( this.OutboundDeliveryID.IsInitial() ==...
首先我们得有一个可以正常工作的Restful API:
然后在Cloud for Customer的Cloud Application Studio里创建Restful API的模型,把第一步可以正常工作的Restful API url填进模型里去:
然后在ABSL里使用如下代码进行消费:
import ABSL;
if( this.OutboundDeliveryID.IsInitial() == false){
raise already_delivered.Create("E");
return;
}
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);
var response = WebServiceUtilities.ExecuteRESTService("JerryExternalService", "JerryExternal", HttpMethod, HttpResource,
URLParameter, HeaderParameter,ContentType, Body);
this.OutboundDeliveryID = response.Content;
raise delivery_message.Create("S", this.OutboundDeliveryID);
这个自动触发的过程是怎么实现的?
使用下面的代码创建一个销售订单:
DATA: ls_header TYPE bapisdhd1,
ls_headerx TYPE bapisdhd1x,
lt_bapiret2 LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
po_order_number TYPE bapivbeln-vbeln,
lt_partners TYPE TABLE OF bapiparnr,
lt_order_items_in TYPE TABLE OF bapisditm,
lt_order_item_x TYPE TABLE OF bapisditmx,
ls_order_item_x LIKE LINE OF lt_order_item_x,
ls_order_items_in LIKE LINE OF lt_order_items_in,
lt_schdlin TYPE TABLE OF bapischdl,
ls_schdlin LIKE LINE OF lt_schdlin,
lt_schdlinx TYPE TABLE OF bapischdlx,
ls_schdlinx LIKE LINE OF lt_schdlinx,
ls_partners LIKE LINE OF lt_partners,
lt_order_text TYPE TABLE OF bapisdtext,
ls_order_text TYPE bapisdtext.
ls_header-serv_date = '20200101'.
ls_header-doc_type = 'TA'.
ls_header-purch_no_c = 'a'.
ls_headerx-purch_no_c = 'X'.
*ls_header-sales_org = '0001'.
*ls_header-distr_chan = '01'.
*ls_header-division = '01'.
ls_header-comp_cde_b = '0001'.
ls_headerx-comp_cde_b = 'X'.
ls_headerx-doc_type = 'X'.
ls_headerx-updateflag = 'I'.
ls_partners-partn_role = 'WE'. "ship to party
ls_partners-partn_numb = '0000000001'.
APPEND ls_partners TO lt_partners.
ls_partners-partn_role = 'AG'. " sold to party
ls_partners-partn_numb = '0000000001'.
APPEND ls_partners TO lt_partners.
ls_order_items_in-item_categ = 'TAN'.
ls_order_items_in-material = 'REDUCER_A'.
ls_order_items_in-target_qty = 999.
ls_order_items_in-itm_number = 10.
ls_order_item_x-item_categ = 'X'.
ls_order_item_x-material = 'X'.
ls_order_item_x-target_qty = 'X'.
ls_order_item_x-itm_number = 'X'.
ls_order_item_x-updateflag = 'I'.
APPEND ls_order_item_x TO lt_order_item_x.
APPEND ls_order_items_in TO lt_order_items_in.
ls_schdlin-itm_number = 10.
ls_schdlin-req_qty = 3.
ls_schdlinx-itm_number = 'X'.
ls_schdlinx-itm_number = 'X'.
ls_schdlinx-updateflag = 'X'.
APPEND ls_schdlin TO lt_schdlin.
APPEND ls_schdlinx TO lt_schdlinx.
"ls_order_text-doc_number = SALESDOCUMENT.
ls_order_text-itm_number = '000010'.
ls_order_text-text_id = '0006'.
"ls_order_text-langu = 'E'.
ls_order_text-langu_iso = 'ZH'.
ls_order_text-format_col = '*'.
ls_order_text-text_line = 'Test 2 DSFSDFDSFDS'.
ls_order_text-function = '006'.
APPEND ls_order_text TO lt_order_text.
CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
EXPORTING
sales_header_in = ls_header
sales_header_inx = ls_headerx
int_number_assignment = 'X'
IMPORTING
salesdocument_ex = po_order_number
TABLES
return = lt_bapiret2
sales_items_in = lt_order_items_in
sales_items_inx = lt_order_item_x
sales_schedules_in = lt_schdlin
sales_schedules_inx = lt_schdlinx
sales_partners = lt_partners
sales_text = lt_order_text.
LOOP AT lt_bapiret2 ASSIGNING FIELD-SYMBOL(<return>) WHERE type = 'E'.
WRITE:/ 'Error:', <return>-message COLOR COL_NEGATIVE.
RETURN.
ENDLOOP.
IF po_order_number IS INITIAL.
WRITE:/ 'PO number initial'.
RETURN.
ENDIF.
CLEAR: lt_bapiret2.
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.
用事务码SAT分析,发现总共创建消耗的时间为3.98秒,
其中1.84秒花费在EIGENFERTIGUNG_BEARBEITEN这个subroutine上。
用一下Google Translate:
发现EIGENFERTIGUNG的含义就和生产有关:own production
BEARBEITEN的意思是TO eidt:
看这个函数CO_61_ORDER_EDIT:
这个函数的描述信息指向了它是用来做生产用的:
这个函数所在的包也透露了它的作用,是负责生产相关实现的:
观察一下传入这个函数的各参数值:
推荐
![](https://res.hc-cdn.com/ecology/9.3.130/v2_resources\images\global\blog-dialog.png)
华为开发者空间发布
让每位开发者拥有一台云主机
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)