文章目录
- 需求场景
- 一、实现的效果
- 二、实现步骤
- 1.创建自建表
- 2.增强代码
- 三、重磅福利
需求场景
计划员释放订单时,如果下层组件在不合格库存中有库存时,应先确认不合格库存地库存是否可用,已避免重复生产和库存积压.
因此,提出此需求:
在生产订单下达(释放)时,要提示下层组件在不合格库存地的库存数量.
一、实现的效果
先上图,如下图所示,点击释放按钮后,会弹出窗口,显示组件在不合格库存地点中的库存.
二、实现步骤
1.创建自建表
因特定库存地通常不只一个,而且会经常变动,所以做个自建表,存储需要检查的库存地点.
自建表ZTPPDS_026结构如下:
2.增强代码
增强点:WORKORDER_UPDATE(事务代码:SE18),在AT_RELEASE方法中进行增强.
代码如下(示例):
*--------------------------------------------------------------------S↓*
"S4 LJ 下达时检查订单组件在ZTPPDS_026 不合格库存地点中是否有库存 21.02.2024 15:15:25
TYPES:BEGIN OF ty_alv,
matnr TYPE mara-matnr,
lgort TYPE mard-lgort,
lgobe TYPE t001l-lgobe,
labst TYPE mard-labst,
meins TYPE mara-meins,
maktx TYPE makt-maktx,
END OF ty_alv.
DATA:gt_data TYPE TABLE OF ty_alv,
gs_data TYPE ty_alv,
gt_alv TYPE TABLE OF ty_alv,
gs_alv TYPE ty_alv.
DATA : stb TYPE TABLE OF stpox.
"将自建表中的库存地点放入RANGER中便于使用
SELECT 'I' AS sign,'EQ' AS option, lgort AS low,lgort AS hight INTO TABLE @DATA(s_lgort) FROM ztppds_026.
SELECT lgort,lgobe INTO TABLE @DATA(dt_txt) FROM t001l.
SELECT matnr,maktx INTO TABLE @DATA(dt_makt) FROM makt WHERE spras = @sy-langu.
SORT dt_makt BY matnr.
"展开BOM,获取下层组件物料
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
capid = 'PP01' "BOM 应用程序
datuv = sy-datum "有效起始日
mtnrv = ds_matkl-matnr "成品号或半成品号
stlan = '1' "BOM 用途,1 代表生产
stlal = is_header_dialog-stlal "可选BOM
mktls = 'X'
mehrs = '' "是否多层展开,'X' 代表多层
rndkz = '1' "Round off: ' '=always, '1'=never, '2'=only levels > 1 是否取整
werks = is_header_dialog-werks "工厂
* IMPORTING
* topmat = selpool "开始BOM 展开的物料显示
* dstst = dstst_flg "BOM 帮助字段
TABLES
stb = stb
* matcat = matcat "下面含有组件的物料存放在该内表对应 STB-TTIDX 在类别表内的索引﹐标志直属哪个物料下的 BOM
EXCEPTIONS
alt_not_found = 1
call_invalid = 2
material_not_found = 3
missing_authorization = 4
no_bom_found = 5
no_plant_data = 6
no_suitable_bom_found = 7
OTHERS = 8.
CLEAR:gt_alv.
LOOP AT stb INTO DATA(ds_stb).
SELECT SINGLE matnr,meins INTO @DATA(ds_mara) FROM mara WHERE matnr = @ds_stb-idnrk.
"分别取普通库存,批次库存,销售订单库存(这里也可以考虑用bapi取库存)
SELECT lgort,labst INTO CORRESPONDING FIELDS OF TABLE @gt_data
FROM mard WHERE labst > 0 AND lgort IN @s_lgort AND matnr = @ds_stb-idnrk.
SELECT lgort,SUM( clabs ) AS labst APPENDING CORRESPONDING FIELDS OF TABLE @gt_data
FROM mchb WHERE clabs > 0 AND lgort IN @s_lgort AND matnr = @ds_stb-idnrk GROUP BY lgort.
SELECT lgort,SUM( kalab ) AS labst APPENDING CORRESPONDING FIELDS OF TABLE @gt_data
FROM mska WHERE kalab > 0 AND lgort IN @s_lgort AND matnr = @ds_stb-idnrk GROUP BY lgort.
SORT gt_data BY lgort.
"整理数据到ALV显示结构中
LOOP AT gt_data INTO gs_data.
AT END OF lgort.
SUM.
gs_alv = gs_data.
READ TABLE dt_txt INTO DATA(ds_txt) WITH KEY lgort = gs_alv-lgort.
gs_alv-lgobe = ds_txt-lgobe.
gs_alv-matnr = ds_mara-matnr.
gs_alv-meins = ds_mara-meins.
READ TABLE dt_makt INTO DATA(ds_makt) WITH KEY matnr = gs_alv-matnr.
gs_alv-maktx = ds_makt-maktx.
APPEND gs_alv TO gt_alv.
CLEAR:gs_data,gs_alv,ds_makt,ds_txt.
ENDAT.
ENDLOOP.
CLEAR:ds_mara,gt_data.
ENDLOOP.
"进行ALV显示
IF gt_alv IS NOT INITIAL.
DATA go_alv TYPE REF TO cl_salv_table.
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = go_alv
CHANGING
t_table = gt_alv ).
CATCH cx_salv_msg.
ENDTRY.
DATA: lr_functions TYPE REF TO cl_salv_functions_list.
lr_functions = go_alv->get_functions( ).
lr_functions->set_all( 'X' ).
* lr_functions->set_popup_cancel( 'X' ).
IF go_alv IS BOUND.
go_alv->set_screen_popup(
start_column = 25
end_column = 150
start_line = 1
end_line = 20 ).
go_alv->display( ).
ENDIF.
ENDIF.
*--------------------------------------------------------------------E↑*
三、重磅福利
重磅粉丝福利,点击参与抽现金红包!