创建销售订单时如何给增强字段赋值[BAPI_SALESORDER_CREATEFROMDAT2]

在使用bapi BAPI_SALESORDER_CREATEFROMDAT2创建销售订单时,可以通过extensionin参数给自定义的参数赋值。

创建销售订单时如何给增强字段赋值[BAPI_SALESORDER_CREATEFROMDAT2]_第1张图片

具体的使用方法可以通过点击Function module documentaion来查看,如下:

 

创建销售订单时如何给增强字段赋值[BAPI_SALESORDER_CREATEFROMDAT2]_第2张图片

下面举例说明:

在销售订单的行项目上的additional data a tab页上有5个自定义的增强字段,如下:

创建销售订单时如何给增强字段赋值[BAPI_SALESORDER_CREATEFROMDAT2]_第3张图片

对应表vbap中是如下几个字段,这些字段是通过append的方式加到vbap上的

创建销售订单时如何给增强字段赋值[BAPI_SALESORDER_CREATEFROMDAT2]_第4张图片

同样,这些自定义字段也要加到structure VBAPKOZ,BAPE_VBAP和 BAPE_VBAPX中,

创建销售订单时如何给增强字段赋值[BAPI_SALESORDER_CREATEFROMDAT2]_第5张图片

创建销售订单时如何给增强字段赋值[BAPI_SALESORDER_CREATEFROMDAT2]_第6张图片

创建销售订单时如何给增强字段赋值[BAPI_SALESORDER_CREATEFROMDAT2]_第7张图片

总结一下:

如果增强字段在销售订单抬头(vbak)上,则要将增强字段一并append到如下四个表/结构中:

  1.  VBAKKOZ
  2.  VBAKKOZX
  3.  BAPE_VBAK
  4.  BAPE_VBAKX

在行项目(vbap)上:

  1. VBAPKOZ
  2. VBAPKOZX
  3. BAPE_VBAP
  4. BAPE_VBAPX

在运货计划行(VBEP)上:

  1. VBEPKOZ
  2. BEPKOZX
  3. BAPE_VBEP
  4. BAPE_VBEPX

下面介绍如何向bapi中extensionin参数赋值数据,具体代码如下:

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

DATA: lwa_bape_vbap   TYPE bape_vbap.  "BAPI Interface for Customer Enhancements to Table VBAP

DATA: lwa_bape_vbapx  TYPE bape_vbapx. "BAPI Checkbox for Customer Enhancments to Table VBAP

DATA: lwa_extensionin TYPE bapiparex.  "Customer Enhancement for VBAK, VBAP, VBEP

 

      "Fill item level self-defined fields

*     extension BAPE_VBAP

      CLEAR: lwa_bape_vbap,

             lwa_bape_vbapx.

*     订单号可以不填,只填行项目号就可以,然后给自定义字段赋值

      lwa_bape_vbap-posnr   =  lwa_order_items_in-itm_number.

      lwa_bape_vbap-yymv_mvgr1 = lwa_items-yymv_mvgr1.

      lwa_bape_vbap-yymv_mvgr2 = lwa_items-yymv_mvgr2.

      lwa_bape_vbap-yymv_mvgr3 = lwa_items-yymv_mvgr3.

      lwa_bape_vbap-yymv_mvgr4 = lwa_items-yymv_mvgr4.

      lwa_bape_vbap-yymv_mvgr5 = lwa_items-yymv_mvgr5.

      lwa_bape_vbapx-yymv_mvgr1 = 'X'.

      lwa_bape_vbapx-yymv_mvgr2 = 'X'.

      lwa_bape_vbapx-yymv_mvgr3 = 'X'.

      lwa_bape_vbapx-yymv_mvgr4 = 'X'.

      lwa_bape_vbapx-yymv_mvgr5 = 'X'.

      lwa_bape_vbapx-posnr  =  lwa_order_items_in-itm_number.

      MOVE 'BAPE_VBAP' TO lwa_extensionin-structure.

      CALL METHOD cl_abap_container_utilities=>fill_container_c

        EXPORTING

          im_value     = lwa_bape_vbap

        IMPORTING

          ex_container = lwa_extensionin-valuepart1.

      APPEND lwa_extensionin TO  m_it_extensionin.

      CLEAR lwa_extensionin.

 

      MOVE 'BAPE_VBAPX' TO lwa_extensionin-structure.

      MOVE lwa_bape_vbapx TO lwa_extensionin-valuepart1.

      APPEND lwa_extensionin TO m_it_extensionin.

最后调用bapi BAPI_SALESORDER_CREATEFROMDAT2时将上面代码中填充好的m_it_extensionin内表传入就可以了。

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'

      EXPORTING

        order_header_in     = m_order_header_in

        logic_switch        = lwa_logic_switch

        testrun             = i_test_run

      IMPORTING

        salesdocument       = m_order_number

      TABLES

        return              = lit_return

        order_items_in      = m_it_order_items_in

        order_partners      = m_it_order_partners

        order_schedules_in  = m_it_order_schedules_in

        order_conditions_in = m_it_order_conditions_in

        order_cfgs_ref      = m_it_order_cfgs_ref

        order_cfgs_inst     = m_it_order_cfgs_inst

        order_cfgs_value    = m_it_order_cfgs_value

        order_cfgs_refinst  = m_it_order_cfgs_refinst

        order_text          = m_it_order_text

        extensionin         = m_it_extensionin "<====自定义字段

        partneraddresses    = m_it_partneraddresses.

以上。

你可能感兴趣的:(SD,增强)