SAP订单上Shipping抬头和行项目字段的持久化实现原理-阿里云开发者社区

开发者社区> 开发者小助手-bz4> 正文

SAP订单上Shipping抬头和行项目字段的持久化实现原理

简介: SAP订单上Shipping抬头和行项目字段的持久化实现原理
+关注继续查看

It is known that we can maintain shipping data for order header and order item separately.

For example, suppose when I have maintained the following data, what happens when save button is clicked?


image.pngimage.pngFirst all links to this service order is retrieved by function module CRM_GET_ALL_LINKS which works based on database table CRMD_LINK.

image.pngThe link data has the following format:image.pngThe persistence of shipping data is done in function module CRM_SHIPPING_SAVE_OB:

image.pngThe header guid together with all link data is put into the generic function module CRM_ORDER_UPDATE_TABLES_DETERM, which will calculate current change mode ( insert, update or delete ) by comparing object buffer with database buffer.


image.pngimage.pngIn this example, the determined change are two update operations as expected.image.pngNow let’s write a standalone report to perform the change on both header and item shipping data and try to interpret these two changes by our own code.


REPORT crms4_change_shipping.

PARAMETERS: inh     TYPE crmd_shipping-incoterms2 OBLIGATORY DEFAULT 'header',

           ini     LIKE inh OBLIGATORY DEFAULT 'item',

           srvo_id TYPE crmd_orderadm_h-object_id OBLIGATORY DEFAULT '8000000111'.

DATA: lv_srvo_guid      TYPE crmd_orderadm_h-guid,

     lt_changed_fields TYPE crmt_input_field_tab,

     ls_changed_fields LIKE LINE OF lt_changed_fields,

     lt_orderadm_i     TYPE TABLE OF crmd_orderadm_i,

     lt_shipping       TYPE crmt_shipping_comt,

     ls_shipping       LIKE LINE OF lt_shipping.

START-OF-SELECTION.

 SELECT SINGLE * INTO @DATA(ls_header) FROM crmd_orderadm_h WHERE object_id = @srvo_id.

 IF sy-subrc <> 0.

   WRITE:/ 'Service order not found for id:', srvo_id.

   RETURN.

 ENDIF.

 lv_srvo_guid = ls_header-guid.

 SELECT SINGLE guid INTO @DATA(lv_item_guid) FROM crmd_orderadm_i

    WHERE header = @lv_srvo_guid.

 IF sy-subrc <> 0.

   WRITE:/ 'No item found for service order:', srvo_id.

   RETURN.

 ENDIF.

 SELECT * INTO TABLE @DATA(lt_link) FROM crmd_link WHERE

  ( guid_hi = @lv_srvo_guid OR guid_hi = @lv_item_guid ) AND

   objtype_set = '12'.

 SELECT * INTO TABLE @DATA(lt_shipping_db) FROM crmd_shipping

    FOR ALL ENTRIES IN @lt_link WHERE guid = @lt_link-guid_set.

 IF lines( lt_shipping_db ) <> 2.

   WRITE:/ 'corrupted shipping data'.

   RETURN.

 ENDIF.

 READ TABLE lt_link ASSIGNING FIELD-SYMBOL(<head_link>) WITH KEY

    objtype_hi = '05'.

 IF sy-subrc <> 0.

   WRITE:/ 'header data does not exist'.

   RETURN.

 ENDIF.

 READ TABLE lt_shipping_db ASSIGNING FIELD-SYMBOL(<head>) WITH KEY

   guid = <head_link>-guid_set.

 <head>-incoterms2 = inh.

 MOVE-CORRESPONDING <head> TO ls_shipping.

 ls_shipping-ref_guid = lv_srvo_guid.

 ls_shipping-ref_kind = 'A'.

 INSERT ls_shipping INTO TABLE lt_shipping.

 ls_changed_fields-ref_guid = <head_link>-guid_hi.

 ls_changed_fields-ref_kind = 'A'.

 ls_changed_fields-objectname = 'SHIPPING'.

 APPEND 'INCOTERMS2' TO ls_changed_fields-field_names.

 APPEND ls_changed_fields TO lt_changed_fields.

 READ TABLE lt_link ASSIGNING FIELD-SYMBOL(<item_link>) WITH KEY

    objtype_hi = '06'.

 IF sy-subrc <> 0.

   WRITE:/ 'item data does not exist'.

   RETURN.

 ENDIF.

 READ TABLE lt_shipping_db ASSIGNING FIELD-SYMBOL(<item>) WITH KEY

   guid = <item_link>-guid_set.

 <item>-incoterms2 = ini.

 MOVE-CORRESPONDING <item> TO ls_shipping.

 ls_shipping-ref_guid = lv_item_guid.

 ls_shipping-ref_kind = 'B'.

 INSERT ls_shipping INTO TABLE lt_shipping.

 CLEAR: ls_changed_fields.

 ls_changed_fields-ref_guid = <item_link>-guid_hi.

 ls_changed_fields-objectname = 'SHIPPING'.

 ls_changed_fields-ref_kind = 'B'.

 APPEND 'INCOTERMS2' TO ls_changed_fields-field_names.

 INSERT ls_changed_fields INTO TABLE lt_changed_fields.

 CALL FUNCTION 'CRM_ORDER_MAINTAIN'

   EXPORTING

     it_shipping       = lt_shipping

   CHANGING

     ct_input_fields   = lt_changed_fields

   EXCEPTIONS

     error_occurred    = 1

     document_locked   = 2

     no_change_allowed = 3

     no_authority      = 4.

 IF sy-subrc <> 0.

   WRITE: / 'error during quantity change'.

   RETURN.

 ENDIF.Execute the report, specify new incoterms for header and item:image.pngAnd use the following code to capture the change:DATA: lt_update TYPE crmt_shipping_du_tab,

       lt_insert TYPE crmt_shipping_du_tab,

       lt_delete TYPE crmt_shipping_du_tab,

       lt_guid   TYPE crmt_object_guid_tab.

 DO 2 TIMES.

   CLEAR: lt_guid.

   IF sy-index = 1.

     APPEND <head>-guid TO lt_guid.

   ELSE.

     APPEND <item>-guid TO lt_guid.

   ENDIF.

   CALL FUNCTION 'CRM_ORDER_UPDATE_TABLES_DETERM'

     EXPORTING

       iv_object_name       = 'SHIPPING'

       iv_field_name_key    = 'GUID'

       it_guids_to_process  = lt_guid

       iv_header_to_save    = lv_srvo_guid

     IMPORTING

       et_records_to_insert = lt_insert

       et_records_to_update = lt_update

       et_records_to_delete = lt_delete.

   READ TABLE lt_update ASSIGNING FIELD-SYMBOL(<update>) INDEX 1.

   IF <update> IS ASSIGNED.

     CASE sy-index.

       WHEN 1.

         WRITE:/ |changes on header, new incoterms: { <update>-incoterms2 }| COLOR COL_GROUP.

       WHEN 2.

         WRITE:/ |changes on item, new incoterms: { <update>-incoterms2 }| COLOR COL_KEY.

     ENDCASE.

   ENDIF.

 ENDDO.And you will see the output, the change is detected correctly as expected.image.png

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
阿里云服务器怎么设置密码?怎么停机?怎么重启服务器?
如果在创建实例时没有设置密码,或者密码丢失,您可以在控制台上重新设置实例的登录密码。本文仅描述如何在 ECS 管理控制台上修改实例登录密码。
8641 0
SAP CRM订单抬头级别的组织架构数据是如何自动拷贝到行项目的
SAP CRM订单抬头级别的组织架构数据是如何自动拷贝到行项目的
19 0
SAP Spartacus 基于行项目的订单取消功能(order cancel)实现
SAP Spartacus 基于行项目的订单取消功能(order cancel)实现
4 0
C语言OJ项目参考(2279) 字符串分段(串)
2279: 字符串分段(串) Description 输入一个字符串,将其分段输出,分段符为除字母和数字之外的符号。 Input 输入一个字符串 Output 输出分段后的字符串 Sample Input** ad/adfa,,123d?#a1 Sample Output ad adfa 123d a1 参考解答: #include &lt;stdi
1031 0
SAP订单上Shipping抬头和行项目字段的持久化实现原理
SAP订单上Shipping抬头和行项目字段的持久化实现原理
15 0
阿里云服务器端口号设置
阿里云服务器初级使用者可能面临的问题之一. 使用tomcat或者其他服务器软件设置端口号后,比如 一些不是默认的, mysql的 3306, mssql的1433,有时候打不开网页, 原因是没有在ecs安全组去设置这个端口号. 解决: 点击ecs下网络和安全下的安全组 在弹出的安全组中,如果没有就新建安全组,然后点击配置规则 最后如上图点击添加...或快速创建.   have fun!  将编程看作是一门艺术,而不单单是个技术。
10467 0
SAP CRM Service Order(服务订单)的状态字段设计原理介绍
SAP CRM Service Order(服务订单)的状态字段设计原理介绍
12 0
SAP CRM销售订单UI上的字段对应的数据库表存储字段:requested start date和end date
SAP CRM销售订单UI上的字段对应的数据库表存储字段:requested start date和end date
13 0
使用CDS view直接从数据库表里取出服务订单的行项目
How to get Service Order item detail by directly query from Database table
13 0
2315
文章
0
问答
来源圈子
更多
+ 订阅
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载