文章概览
- 一、思路
- 二、过程
- 2.1前台的主要过程:
- 2.2 BAPI的实现过程:
之前写过几篇生产领料的思路包括代码,有兴趣的可以翻翻之前我发的文章。最近遇到既有项目专用物资、按单专用物资、通用物资合并领料的业务模式,所以领料的库存的类型涉及特殊库存:Q库存,E库存,并且三种库存会是在一张领料单中出现。如果方案偏向于标准功能来实现,而不是自定义表的话,直接用UB订单是可以直接解决的,但问题是这个是一个工厂代码不同库位的物料移动,才有UB订单的方式涉及到接口的时候连续产生的单据有点多了。所以想的通过标准的311预留实现。最终效果:一个预留中既有WBS预留也有销售订单预留也有通用库存预留
这篇文章其实也是一种标准预留实现领料功能的进一步探索吧,自己瞎琢磨写了点增强代码算是搞定了业务段的功能吧,毕竟更改了标准的逻辑,也不知道会不会影响到财务的数据。
一、思路
标准的MB21创建预留是没有特殊库存这个输入项的,而且标准的功能,在创建311预留时是无法输入销售订单号和WBS号。但是通过以下几个条件判断,311的特殊预留是可以实现的:
1.221是可以输入项目号的,而且输入的位置在预留的抬头信息中,组件产生预留的特殊库存标识是根据抬头WBS+物料的独立集中字段生成的。
2.预留的行项目数据表:RESB中有销售订单和WBS号的信息
3.生产订单的预留中式可以有特殊库存和通用库存预留同时存在的
所以要实现目标如下:
311的预留创建屏幕把销售订单号和WBS号配置搞出来,并且不是必输
311预留过账时根据行项目的特殊库存标识和科目分配信息根据预留自动带出
二、过程
2.1前台的主要过程:
OMJJ设置移动类型的屏幕字段,将销售订单和WBS设置未可选项。并且设置自定义的子屏幕块,使得销售订单和WBS的子屏幕优先级最高。效果:
创建界面:
预留抬头显示界面:
预留行项目明细:
MIGO过账界面发现有个问题,就是抬头的销售订单或者WBS会覆盖所有行项目。所以需要通过在更新预留的标准程序中做==隐式增强==,在系统会用RKPF抬头的值替换RESB的销售订单等值前,用行项目数据先覆盖抬头的数据信息。这个增强的方式和地点就有点多了,大家慎重自己拿主意,也要注意控制生效的条件,为了测试期间不影响其他人,专门加了自己账号的限制。
为了最终实现一个预留单中多种特殊库存的效果,这里就不过多增强标准功能,曲线救国采用BAPI来实现。
2.2 BAPI的实现过程:
采用通过BAPI实现的主要过程,这里需要增强一下BAPI的功能,因为标准的创建预留BAPI行项目没办法传入销售订单和WBS号的。
预留的BAPI的增强点:MB_RES_BAPI_CREATE1
DATA:lt_item_resb TYPE TABLE OF zresb_item,
lw_item_resb TYPE zresb_item.
"CS_RKPF
"获取增强字段
REFRESH lt_item_resb.
LOOP AT it_extension_in INTO DATA(lw_extension_in).
IF lw_extension_in-structure = 'ZRESB_ITEM'.
lw_item_resb = lw_extension_in-valuepart1.
APPEND lw_item_resb TO lt_item_resb.
CLEAR lw_item_resb.
ENDIF.
ENDLOOP.
"通过扩展字段值更改标准字段
LOOP AT resb ASSIGNING FIELD-SYMBOL(<fs_resb>).
lw_item_resb-rspos = sy-tabix.
READ TABLE lt_item_resb INTO lw_item_resb WITH KEY rspos = lw_item_resb-rspos.
<fs_resb>-kdauf = lw_item_resb-kdauf.
<fs_resb>-kdpos = lw_item_resb-kdpos.
<fs_resb>-pspel = lw_item_resb-pspel.
<fs_resb>-sobkz = lw_item_resb-sobkz.
IF lw_item_resb-sobkz IS NOT INITIAL.
<fs_resb>-KZBWS = 'M'."特定库存的评估-带参照销售凭证/项目的单独评估
ENDIF.
IF lw_item_resb-sobkz = 'E'.
<fs_resb>-KNTTP = 'M'.
ELSEIF lw_item_resb-sobkz = 'Q'.
<fs_resb>-KNTTP = 'Q'.
ENDIF.
CLEAR lw_item_resb.
ENDLOOP.
预留BAPI:BAPI_RESERVATION_CREATE1
DATA:reservationheader TYPE bapi2093_res_head,
reservationitems TYPE TABLE OF bapi2093_res_item WITH HEADER LINE,
profitabilitysegment TYPE TABLE OF bapi_profitability_segment WITH HEADER LINE,
return TYPE TABLE OF bapiret2 WITH HEADER LINE,
reservation TYPE bapi2093_res_key-reserv_no,
extensionin TYPE TABLE OF bapiparex WITH HEADER LINE.
DATA:lw_item_resb TYPE zresb_item.
"抬头数据
reservationheader-res_date = sy-datum."需求日期
reservationheader-move_type = '311'.
reservationheader-orderid = '000001001408'.
reservationheader-move_plant = '6102'."接收工厂
reservationheader-move_stloc = '4001'."接收库位
"行项目数据
"第一行
reservationitems-material = 'A803YX1000035H'.
reservationitems-plant = '6102'."发出工厂
reservationitems-entry_qnt = '1'.
reservationitems-movement = 'X'.
reservationitems-item_text = '备注'.
APPEND reservationitems.
CLEAR reservationitems.
"第二行
reservationitems-material = 'A803YX1000035H'.
reservationitems-plant = '6102'."工厂
reservationitems-entry_qnt = '1'.
reservationitems-movement = 'X'.
reservationitems-item_text = '备注'.
APPEND reservationitems.
CLEAR reservationitems.
"第三行
reservationitems-material = 'A803YX1000035H'.
reservationitems-plant = '6102'."工厂
reservationitems-entry_qnt = '1'.
reservationitems-movement = 'X'.
reservationitems-item_text = '备注'.
APPEND reservationitems.
CLEAR reservationitems.
"第4行
reservationitems-material = 'A803YX1000035H'.
reservationitems-plant = '6102'."发出工厂
reservationitems-entry_qnt = '1'.
reservationitems-movement = 'X'.
reservationitems-item_text = '备注'.
APPEND reservationitems.
CLEAR reservationitems.
"增强数据
LOOP AT reservationitems.
DATA(lv_count) = sy-tabix.
extensionin-structure = 'ZRESB_ITEM'.
lw_item_resb-rspos = lv_count.
IF lv_count = 1."销售订单库存
lw_item_resb-kdauf = '0000004244'.
lw_item_resb-kdpos = '000020'.
lw_item_resb-sobkz = 'E'.
ELSEIF lv_count = 2."通用库存
ELSEIF lv_count = 3."项目库存
lw_item_resb-pspel = '00000581'.
lw_item_resb-sobkz = 'Q'.
ELSEIF lv_count = 4."项目库存
lw_item_resb-kdauf = '0000004244'.
lw_item_resb-kdpos = '000010'.
lw_item_resb-sobkz = 'E'.
ENDIF.
extensionin-valuepart1 = lw_item_resb.
APPEND extensionin.
CLEAR: reservationitems,extensionin,lw_item_resb.
ENDLOOP.
CLEAR reservation.
CALL FUNCTION 'BAPI_RESERVATION_CREATE1'
EXPORTING
reservationheader = reservationheader
* TESTRUN =
* ATPCHECK =
* CALCHECK =
* RESERVATION_EXTERNAL =
IMPORTING
reservation = reservation
TABLES
reservationitems = reservationitems
profitabilitysegment = profitabilitysegment
return = return
extensionin = extensionin.
IF reservation IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
MESSAGE reservation TYPE 'I'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
BREAK-POINT.
ENDIF.
做到这一步,预留和前台创建效果一样,
虽然搞定了吧,但是MB23显示的时候,销售订单显示不出来,所以要是效果再好点,还得增强显示前的block屏幕的取数逻辑。。。。。