SAP ABAP 顾问(开发工程师)能力模型-CSDN博客文章浏览阅读959次。目标:基于对SAP abap 顾问能力模型的梳理,给一年左右经验的abaper 快速成长为三年经验提供超级燃料!https://blog.csdn.net/java_zhong1990/article/details/132469977
目标:从工厂、库存地点、物料层面,设置库存的范围,在范围内的库存表示正常,在范围外的库存表示异常.
需要考虑的是如何定义正常的库存范围,
一、背景说明
1.1 实现效果
1.2 业务说明
设计步骤:
1 计划员,批量维护物料的安全库存
2 计划主管,可以更改安全库存范围
3 输出安全库存报表
1.3 代码实现
*&---------------------------------------------------------------------*
*& Report ZMM028
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zmm031.
INCLUDE zmm031_top.
INCLUDE zmm031_sel.
INCLUDE zmm031_frm.
INCLUDE zmm031_pbo.
INCLUDE zmm031_pai.
SELECTION-SCREEN FUNCTION KEY: 1 .
INITIALIZATION.
PERFORM init.
AT SELECTION-SCREEN OUTPUT.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_file.
PERFORM get_excel.
AT SELECTION-SCREEN.
CASE sscrfields-ucomm .
WHEN 'FC01'.
PERFORM download_template USING '批导模版.xlsx' 'ZMM031'.
WHEN OTHERS.
ENDCASE.
START-OF-SELECTION.
IF p_inp = 'X'.
* SELECT * INTO TABLE @DATA(ls_ztmm031) FROM ztmm031 WHERE ztmm031~c1 = @sy-uname.
* IF sy-subrc = 0.
* ELSE.
* MESSAGE '没有权限,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.
* LEAVE TO LIST-PROCESSING.
* EXIT.
*
* ENDIF.
PERFORM get_data_for_excel.
PERFORM check_data_for_excel.
PERFORM set_catalog.
PERFORM display_alv.
ELSEIF p_sel = 'X'.
PERFORM get_data_for_ztmm030.
PERFORM set_catalog1.
PERFORM display_alv_ztmm030.
ELSE.
PERFORM get_data_for_mard.
PERFORM set_catalog2.
PERFORM display_alv2.
ENDIF.
*&---------------------------------------------------------------------*
*& Form get_data_for_mard
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM get_data_for_mard .
DATA:lv_lfgja TYPE mard-lfgja.
DATA:lv_lfmon TYPE mard-lfmon.
lv_lfgja = sy-datum+0(4).
lv_lfmon = sy-datum+4(2).
* lv_lfgja = '2022'.
* lv_lfmon = '05'.
SELECT
mard~lfgja,
mard~lfmon,
mard~werks,
mard~lgort,
mard~matnr,
mard~labst,
t001l~lgobe,
mara~zwlcms,
mara~meins,
mbew~verpr,
mbew~peinh,
ztmm030~l1,
ztmm030~l2,
ztmm030~createby,
ztmm030~createdate,
ztmm030~createtime
INTO CORRESPONDING FIELDS OF TABLE @gt_data2
FROM mard
LEFT JOIN ztmm030 ON ztmm030~werks = mard~werks AND ztmm030~lgort = mard~lgort AND ztmm030~matnr = mard~matnr
INNER JOIN t001l ON t001l~werks = mard~werks AND mard~lgort = t001l~lgort
INNER JOIN mara ON mara~matnr = mard~matnr
INNER JOIN mbew ON mbew~matnr = mard~matnr AND mbew~bwkey = mard~werks AND mbew~vprsv = 'V'
WHERE mard~lfgja = @lv_lfgja AND mard~lfmon = @lv_lfmon
AND mard~werks IN @so_werks
AND mard~lgort IN @so_lgort
AND mard~matnr IN @so_matnr
AND mard~labst <> '0'
.
"verpr
LOOP AT gt_data2 ASSIGNING FIELD-SYMBOL(<fs1>).
<fs1>-je = <fs1>-verpr / <fs1>-peinh * <fs1>-labst.
IF <fs1>-l1 IS NOT INITIAL AND <fs1>-l2 IS NOT INITIAL.
IF <fs1>-labst < <fs1>-l1 .
<fs1>-text = '库存过低'.
ELSEIF <fs1>-labst > <fs1>-l2.
<fs1>-text = '超上限'.
ELSE.
<fs1>-text = '库存正常'.
ENDIF.
ENDIF.
* <fs1>-labst2 = <fs1>-labst.
<fs1>-l1_ = <fs1>-l1.
<fs1>-l2_ = <fs1>-l2.
IF <fs1>-l1 IS INITIAL AND <fs1>-l2 IS INITIAL.
<fs1>-f1 = 'X'.
ELSE.
SELECT * INTO TABLE @DATA(ls_ztmm031) FROM ztmm031 WHERE ztmm031~c1 = @sy-uname.
IF sy-subrc = 0.
<fs1>-f1 = 'X'.
ELSE.
"<fs>-message = '无权限修改'.<fs>-status = 'E'. CONTINUE.
ENDIF.
ENDIF.
ENDLOOP.
DATA:gwa_edit TYPE lvc_s_styl,
git_edit TYPE lvc_t_styl.
LOOP AT gt_data2 INTO gs_data2.
IF gs_data2-f1 = 'X'.
CLEAR: gwa_edit.
gwa_edit-fieldname = 'L1'.
gwa_edit-style = cl_gui_alv_grid=>mc_style_enabled."设置为可编辑
APPEND gwa_edit TO gs_data2-celtab .
CLEAR: gwa_edit.
gwa_edit-fieldname = 'L2'.
gwa_edit-style = cl_gui_alv_grid=>mc_style_enabled."设置为可编辑
APPEND gwa_edit TO gs_data2-celtab .
ELSE.
CLEAR: gwa_edit.
gwa_edit-fieldname = 'L1'.
gwa_edit-style = cl_gui_alv_grid=>mc_style_disabled."设置为不可编辑
APPEND gwa_edit TO gs_data2-celtab .
CLEAR: gwa_edit.
gwa_edit-fieldname = 'L2'.
gwa_edit-style = cl_gui_alv_grid=>mc_style_disabled."设置为不可编辑
APPEND gwa_edit TO gs_data2-celtab .
ENDIF.
MODIFY gt_data2 FROM gs_data2 .
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& 包含 ZMM028_FRM
*&---------------------------------------------------------------------*
FORM get_excel.
DATA : l_filetab TYPE filetable,
l_waftab LIKE LINE OF l_filetab,
l_rc TYPE i.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = '打开文件'
initial_directory = 'C:/'
CHANGING
file_table = l_filetab
rc = l_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ELSE.
READ TABLE l_filetab INTO l_waftab INDEX 1.
pa_file = l_waftab-filename.
CLEAR: l_filetab,l_waftab.
ENDIF.
ENDFORM.
FORM init.
DATA: ls_dyntxt TYPE smp_dyntxt .
ls_dyntxt-icon_id = icon_export.
ls_dyntxt-quickinfo = '模板下载'.
ls_dyntxt-icon_text = '模板下载'.
sscrfields-functxt_01 = ls_dyntxt.
ENDFORM.
FORM init_output.
ENDFORM.
FORM get_data_for_excel.
TYPES: BEGIN OF ly_excel_data,
werks TYPE ztmm030-werks, "工厂
lgort TYPE ztmm030-lgort, "存储地点
matnr TYPE ztmm030-matnr, "物料编号
l1 TYPE ztmm030-l1, "库存下限(未来)
l2 TYPE ztmm030-l2, "库存上限(未来)
* createby TYPE ztmm030-createby, "最近更新人
* createdate TYPE ztmm030-createdate, "最近更新日期
* createtime TYPE ztmm030-createtime, "最近更新时间
END OF ly_excel_data.
DATA: lt_excel TYPE TABLE OF alsmex_tabline WITH HEADER LINE,
ls_excel_data TYPE ly_excel_data,
l_index LIKE sy-tabix.
DATA: lv_lines TYPE i.
FIELD-SYMBOLS: <fs>.
IF pa_file IS NOT INITIAL.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = pa_file
i_begin_col = '1'
i_begin_row = '2'
i_end_col = '10'
i_end_row = '50000'
TABLES
intern = lt_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc = 0.
*&& 将EXCEL格式中的数据导入到内表TAB_LOAD中
LOOP AT lt_excel.
ASSIGN COMPONENT lt_excel-col OF STRUCTURE ls_excel_data TO <fs>.
<fs> = lt_excel-value.
AT END OF row.
MOVE-CORRESPONDING ls_excel_data TO gs_data."跟Excel的列一一对应的内表
APPEND gs_data TO gt_data.
CLEAR: ls_excel_data,gs_data.
ENDAT.
ENDLOOP.
lv_lines = lines( gt_data ).
IF lv_lines > 8000.
MESSAGE '本次导入数据超过5000,请拆分数据文件!' TYPE 'S'DISPLAY LIKE 'E'.
STOP.
ENDIF.
ENDIF.
ELSE.
MESSAGE '请输入文件路径!' TYPE 'S'DISPLAY LIKE 'E'.
STOP.
ENDIF.
ENDFORM.
FORM check_data_for_excel.
LOOP AT gt_data ASSIGNING FIELD-SYMBOL(<fs>).
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = <fs>-matnr
IMPORTING
output = <fs>-matnr
* EXCEPTIONS
* LENGTH_ERROR = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
ENDIF.
SELECT SINGLE matnr INTO @DATA(ls1) FROM mara WHERE mara~matnr = @<fs>-matnr.
IF sy-subrc = 0.
ELSE.
<fs>-message = '物料号不存在'.
<fs>-status = 'E'.
CONTINUE.
ENDIF.
SELECT SINGLE t001l~werks INTO @DATA(ls2) FROM t001l WHERE t001l~werks = @<fs>-werks.
IF sy-subrc = 0.
ELSE.
<fs>-message = '工厂不存在'.<fs>-status = 'E'.
CONTINUE.
ENDIF.
SELECT SINGLE t001l~werks INTO @DATA(ls3) FROM t001l WHERE t001l~lgort = @<fs>-lgort.
IF sy-subrc = 0.
ELSE.
<fs>-message = '库位不存在'.<fs>-status = 'E'.
CONTINUE.
ENDIF.
SELECT SINGLE * INTO @DATA(ls_ztmm030)
FROM ztmm030 WHERE ztmm030~werks = @<fs>-werks AND ztmm030~lgort = @<fs>-lgort AND ztmm030~matnr = @<fs>-matnr.
IF sy-subrc = 0.
<fs>-l1_old = ls_ztmm030-l1.
<fs>-l2_old = ls_ztmm030-l2.
<fs>-createby = ls_ztmm030-createby.
<fs>-createdate = ls_ztmm030-createdate.
<fs>-createtime = ls_ztmm030-createtime.
SELECT * INTO TABLE @DATA(ls_ztmm031) FROM ztmm031 WHERE ztmm031~c1 = @sy-uname.
IF sy-subrc = 0.
ELSE.
<fs>-message = '无权限修改'.<fs>-status = 'E'. CONTINUE.
ENDIF.
ELSE.
<fs>-createby = sy-uname.
<fs>-createdate = sy-datum.
<fs>-createtime = sy-uzeit.
ENDIF.
ENDLOOP.
ENDFORM.
FORM download_template USING pu_filename pu_objid.
*& 下载模版
DATA: ls_objdata LIKE wwwdatatab.
DATA: lv_filename TYPE string,
lv_fullpath TYPE string VALUE 'C:\',
lv_path TYPE string VALUE 'C:\'.
DATA: lv_errtxt TYPE string.
DATA: lv_destination LIKE rlgrap-filename.
DATA: lv_rc LIKE sy-subrc.
DATA: lv_fileup LIKE rlgrap-filename.
lv_filename = pu_filename .
*& 调用保存对话框
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
default_extension = 'xlsx'
default_file_name = lv_filename
initial_directory = 'C:\'
CHANGING
filename = lv_filename
path = lv_path
fullpath = lv_fullpath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE '不能打开EXCEL' TYPE 'E'.
ENDIF.
CHECK lv_fullpath IS NOT INITIAL .
lv_fileup = lv_fullpath.
ls_objdata-relid = 'MI' .
ls_objdata-objid = pu_objid .
lv_destination = lv_fullpath .
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
key = ls_objdata
destination = lv_destination
IMPORTING
rc = lv_rc.
IF lv_rc NE 0.
CONCATENATE '模板文件:' ls_objdata-objid '下载失败' INTO lv_errtxt.
MESSAGE lv_errtxt TYPE 'E'.
ELSE.
MESSAGE '模版下载成功' TYPE 'S'.
ENDIF.
ENDFORM. " DOWNLOAD_TEMPLATE
FORM set_catalog.
DATA:lv_position TYPE i VALUE 1.
CLEAR: lv_position.
lv_position = lv_position + 1.
* 预定义一个输出模式
DEFINE df_fieldcat.
CLEAR gs_fieldcat_lvc.
gs_fieldcat_lvc-col_pos = lv_position."ALV 控制: 输出列
gs_fieldcat_lvc-scrtext_m = &1."中字段标签
gs_fieldcat_lvc-fieldname = &2."ALV 控制: 内部表字段的字段名称
gs_fieldcat_lvc-no_zero = &3."ALV 控制: 为输出隐藏零
gs_fieldcat_lvc-checkbox = &4."ALV 控制: 作为复选框输出
gs_fieldcat_lvc-edit = &5."设置可编辑模式
gs_fieldcat_lvc-outputlen = &6."输出长度
gs_fieldcat_lvc-ref_table = &7.
gs_fieldcat_lvc-ref_field = &8.
gs_fieldcat_lvc-datatype = &9.
APPEND gs_fieldcat_lvc TO gt_fieldcat_lvc.
ADD 1 TO lv_position.
END-OF-DEFINITION.
df_fieldcat:
'状态' 'STATUS' 'X' '' '' '' '' '' '',
'消息' 'MESSAGE' 'X' '' '' '' '' '' '',
'工厂' 'WERKS' 'X' '' '' '' '' '' '',
'存储地点' 'LGORT' 'X' '' '' '' '' '' '',
'物料编号' 'MATNR' 'X' '' '' '' '' '' '',
'库存下限(当前)' 'L1_OLD' 'X' '' '' '' '' '' '',
'库存上限(当前)' 'L2_OLD' 'X' '' '' '' '' '' '',
'最近更新人' 'CREATEBY' 'X' '' '' '' '' '' '',
'最近更新日期' 'CREATEDATE' 'X' '' '' '' '' '' '',
'最近更新时间' 'CREATETIME' 'X' '' '' '' '' '' '',
'库存下限(未来)' 'L1' 'X' '' '' '' '' '' '',
'库存上限(未来)' 'L2' 'X' '' '' '' '' '' ''
.
ENDFORM.
FORM set_catalog1.
DATA:lv_position TYPE i VALUE 1.
CLEAR: lv_position.
lv_position = lv_position + 1.
* 预定义一个输出模式
DEFINE df_fieldcat.
CLEAR gs_fieldcat_lvc.
gs_fieldcat_lvc-col_pos = lv_position."ALV 控制: 输出列
gs_fieldcat_lvc-scrtext_m = &1."中字段标签
gs_fieldcat_lvc-fieldname = &2."ALV 控制: 内部表字段的字段名称
gs_fieldcat_lvc-no_zero = &3."ALV 控制: 为输出隐藏零
gs_fieldcat_lvc-checkbox = &4."ALV 控制: 作为复选框输出
gs_fieldcat_lvc-edit = &5."设置可编辑模式
gs_fieldcat_lvc-outputlen = &6."输出长度
gs_fieldcat_lvc-ref_table = &7.
gs_fieldcat_lvc-ref_field = &8.
gs_fieldcat_lvc-datatype = &9.
APPEND gs_fieldcat_lvc TO gt_fieldcat_lvc.
ADD 1 TO lv_position.
END-OF-DEFINITION.
df_fieldcat:
'工厂' 'WERKS' 'X' '' '' '' '' '' '',
'存储地点' 'LGORT' 'X' '' '' '' '' '' '',
'物料编号' 'MATNR' 'X' '' '' '' '' '' '',
'库存下限' 'L1' 'X' '' '' '' '' '' '',
'库存上限' 'L2' 'X' '' '' '' '' '' '',
'最近更新人' 'CREATEBY' 'X' '' '' '' '' '' '',
'最近更新日期' 'CREATEDATE' 'X' '' '' '' '' '' '',
'最近更新时间' 'CREATETIME' 'X' '' '' '' '' '' ''
.
ENDFORM.
FORM set_catalog2.
DATA:lv_position TYPE i VALUE 1.
CLEAR: lv_position.
lv_position = lv_position + 1.
* 预定义一个输出模式
DEFINE df_fieldcat.
CLEAR gs_fieldcat_lvc.
gs_fieldcat_lvc-col_pos = lv_position."ALV 控制: 输出列
gs_fieldcat_lvc-scrtext_m = &1."中字段标签
gs_fieldcat_lvc-fieldname = &2."ALV 控制: 内部表字段的字段名称
gs_fieldcat_lvc-no_zero = &3."ALV 控制: 为输出隐藏零
gs_fieldcat_lvc-checkbox = &4."ALV 控制: 作为复选框输出
gs_fieldcat_lvc-edit = &5."设置可编辑模式
gs_fieldcat_lvc-outputlen = &6."输出长度
gs_fieldcat_lvc-ref_table = &7.
gs_fieldcat_lvc-ref_field = &8.
gs_fieldcat_lvc-datatype = &9.
APPEND gs_fieldcat_lvc TO gt_fieldcat_lvc.
ADD 1 TO lv_position.
END-OF-DEFINITION.
df_fieldcat:
'年度' 'LFGJA' 'X' '' '' '' '' '' '',
'月份' 'LFMON' 'X' '' '' '' '' '' '',
'工厂' 'WERKS' 'X' '' '' '' '' '' '',
'库存地点' 'LGORT' 'X' '' '' '' '' '' '',
'仓储地点描述' 'LGOBE' 'X' '' '' '' '' '' '',
'物料' 'MATNR' 'X' '' '' '' '' '' '',
'物料描述' 'ZWLCMS' 'X' '' '' '' '' '' '',
'单位' 'MEINS' 'X' '' '' '' '' '' '',
'库存数量' 'LABST' 'X' '' '' '' '' '' '',
'库存下限' 'L1' 'X' '' 'X' '' '' '' '',
'库存上限' 'L2' 'X' '' 'X' '' '' '' '',
'金额' 'JE' 'X' '' '' '' '' '' '',
'库存状态' 'TEXT' 'X' '' '' '' '' '' '',
'最近更新人' 'CREATEBY' 'X' '' '' '' '' '' '',
'最近更新日期' 'CREATEDATE' 'X' '' '' '' '' '' '',
'最近更新时间' 'CREATETIME' 'X' '' '' '' '' '' ''
.
ENDFORM.
FORM display_alv_ztmm030.
DATA: ls_layout TYPE lvc_s_layo.
IF gt_data IS NOT INITIAL.
ls_layout-zebra = 'X'.
ls_layout-cwidth_opt = 'X'.
* 调用ALV function
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid "这里是调用这个ALV的程序名
i_callback_pf_status_set = 'PF_STATUS' "设置ALV状态栏的函数
i_callback_user_command = 'USER_COMMAND' "获取用户事件的函数
is_layout_lvc = ls_layout "显示的布局
it_fieldcat_lvc = gt_fieldcat_lvc "设置显示的字段以及字段的功能
i_save = 'A'
TABLES
t_outtab = gt_data
EXCEPTIONS
program_error = 1.
IF sy-subrc <> 0.
MESSAGE '报表生成异常,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
ELSE.
* 这个消息用来显示我们是不是获取到了数据,自己用的时候把这个硬代码换成你需要的TEXT-XXX.
MESSAGE '没有获取到数据,请重新检索!' TYPE 'S' DISPLAY LIKE 'E'.
LEAVE TO LIST-PROCESSING.
EXIT.
ENDIF.
ENDFORM.
FORM display_alv.
DATA: ls_layout TYPE lvc_s_layo.
IF gt_data IS NOT INITIAL.
ls_layout-zebra = 'X'.
ls_layout-cwidth_opt = 'X'.
* 调用ALV function
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid "这里是调用这个ALV的程序名
i_callback_pf_status_set = 'PF_STATUS' "设置ALV状态栏的函数
i_callback_user_command = 'USER_COMMAND' "获取用户事件的函数
is_layout_lvc = ls_layout "显示的布局
it_fieldcat_lvc = gt_fieldcat_lvc "设置显示的字段以及字段的功能
i_save = 'A'
TABLES
t_outtab = gt_data
EXCEPTIONS
program_error = 1.
IF sy-subrc <> 0.
MESSAGE '报表生成异常,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
ELSE.
* 这个消息用来显示我们是不是获取到了数据,自己用的时候把这个硬代码换成你需要的TEXT-XXX.
MESSAGE '没有获取到数据,请重新检索!' TYPE 'S' DISPLAY LIKE 'E'.
LEAVE TO LIST-PROCESSING.
EXIT.
ENDIF.
ENDFORM.
FORM display_alv2.
DATA: ls_layout TYPE lvc_s_layo.
IF gt_data2 IS NOT INITIAL.
ls_layout-zebra = 'X'.
ls_layout-cwidth_opt = 'X'.
ls_layout-stylefname = 'CELTAB'.
* 调用ALV function
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid "这里是调用这个ALV的程序名
i_callback_pf_status_set = 'PF_STATUS' "设置ALV状态栏的函数
i_callback_user_command = 'USER_COMMAND' "获取用户事件的函数
is_layout_lvc = ls_layout "显示的布局
it_fieldcat_lvc = gt_fieldcat_lvc "设置显示的字段以及字段的功能
i_save = 'A'
TABLES
t_outtab = gt_data2
EXCEPTIONS
program_error = 1.
IF sy-subrc <> 0.
MESSAGE '报表生成异常,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
ELSE.
* 这个消息用来显示我们是不是获取到了数据,自己用的时候把这个硬代码换成你需要的TEXT-XXX.
MESSAGE '没有获取到数据,请重新检索!' TYPE 'S' DISPLAY LIKE 'E'.
LEAVE TO LIST-PROCESSING.
EXIT.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form get_data_for_ztmm030
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM get_data_for_ztmm030 .
SELECT * INTO CORRESPONDING FIELDS OF TABLE @gt_data FROM ztmm030
WHERE ztmm030~matnr IN @so_matnr
AND ztmm030~werks IN @so_werks
AND ztmm030~lgort IN @so_lgort
.
ENDFORM.
*&---------------------------------------------------------------------*
*& 包含 ZMM028_PAI
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& 包含 ZFI068_PAI
*&---------------------------------------------------------------------*
FORM user_command USING i_ucomm TYPE sy-ucomm
i_wa_selfield TYPE slis_selfield.
DATA:gwa_edit TYPE lvc_s_styl,
git_edit TYPE lvc_t_styl.
DATA lv_length TYPE num10.
DATA lr_grid TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = lr_grid.
CALL METHOD lr_grid->check_changed_data.
CALL METHOD lr_grid->refresh_table_display.
i_wa_selfield-refresh = 'X'.
CASE i_ucomm.
WHEN 'ZSAVE'.
DATA(lt_check) = gt_data.
DELETE lt_check WHERE status <> 'E'.
IF lines( lt_check ) <> 0.
MESSAGE '检查未通过' TYPE 'E'.
ENDIF.
* "权限检查
* DATA:lv_auth TYPE char.
* lv_auth = ''.
* SELECT * INTO TABLE @DATA(ls_ztmm031) FROM ztmm031 WHERE ztmm031~c1 = @sy-uname.
* IF sy-subrc = 0.
* lv_auth = 'X'.
* ELSE.
** MESSAGE '没有权限,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.
** LEAVE TO LIST-PROCESSING.
** EXIT.
* ENDIF.
*
* IF lv_auth = 'X'.
DATA:lt_ TYPE TABLE OF ztmm030.
MOVE-CORRESPONDING gt_data TO lt_.
MODIFY ztmm030 FROM TABLE lt_.
MESSAGE '保存成功' TYPE 'S'.
* ENDIF.
WHEN 'ZSAVE1'.
DATA:lt_ztmm030 TYPE TABLE OF ztmm030.
DATA:ls_ztmm030 TYPE ztmm030.
LOOP AT gt_data2 INTO gs_data2.
IF gs_data2-l1 = gs_data2-l1_ AND gs_data2-l2 = gs_data2-l2_.
ELSE.
MOVE-CORRESPONDING gs_data2 TO ls_ztmm030.
ls_ztmm030-createby = sy-uname.
ls_ztmm030-createdate = sy-datum.
ls_ztmm030-createtime = sy-uzeit.
APPEND ls_ztmm030 TO lt_ztmm030.
ENDIF.
ENDLOOP.
IF lt_ztmm030 IS NOT INITIAL.
MODIFY ztmm030 FROM TABLE lt_ztmm030.
MESSAGE '保存成功' TYPE 'S'.
ENDIF.
WHEN 'ZSAVE2'.
WHEN 'ZSAL'.
WHEN 'ZALL'.
WHEN OTHERS.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& 包含 ZMM028_PBO
*&---------------------------------------------------------------------*
FORM pf_status USING lt_extab TYPE slis_t_extab.
REFRESH:lt_extab[]. CLEAR:lt_extab.
IF p_inp = 'X'.
SET TITLEBAR 'ZSTATUS_TITLE'.
"说明:需要显示的按钮进行注释
* APPEND 'ZSAVE' TO lt_extab.
APPEND 'ZSAVE1' TO lt_extab.
SET PF-STATUS 'ZSTATUS_001' EXCLUDING lt_extab.
ELSEIF p_sel = 'X'.
SET TITLEBAR 'ZSTATUS_TITLE'.
"说明:需要显示的按钮进行注释
APPEND 'ZSAVE' TO lt_extab.
APPEND 'ZSAVE1' TO lt_extab.
SET PF-STATUS 'ZSTATUS_001' EXCLUDING lt_extab.
ELSE.
SET TITLEBAR 'ZSTATUS_TITLE'.
"说明:需要显示的按钮进行注释
APPEND 'ZSAVE' TO lt_extab.
SET PF-STATUS 'ZSTATUS_001' EXCLUDING lt_extab.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& 包含 ZMM028_SEL
*&---------------------------------------------------------------------*
TABLES:lips,ztmm030,mard.
SELECTION-SCREEN:BEGIN OF BLOCK b0 WITH FRAME TITLE TEXT-001.
PARAMETERS:p_inp RADIOBUTTON GROUP g1 USER-COMMAND u1 DEFAULT 'X'.
PARAMETERS:p_sel RADIOBUTTON GROUP g1 .
PARAMETERS:p_sel2 RADIOBUTTON GROUP g1 .
PARAMETERS: pa_file TYPE rlgrap-filename ."文件夹上传
SELECTION-SCREEN SKIP 1.
*
* SELECT-OPTIONS: so_lfgja FOR mard-lfgja.
* SELECT-OPTIONS: so_lfmon FOR mard-lfmon.
SELECT-OPTIONS: so_werks FOR ztmm030-werks.
SELECT-OPTIONS: so_lgort FOR ztmm030-lgort.
SELECT-OPTIONS: so_matnr FOR ztmm030-matnr.
SELECTION-SCREEN:END OF BLOCK b0.
*&---------------------------------------------------------------------*
*& 包含 ZMM028_TOP
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& 包含 ZFI068_TOP
*&---------------------------------------------------------------------*
TABLES: sscrfields,vbak,bsis.
TYPE-POOLS: esp1,slis ,icon.
TYPES: BEGIN OF gy_data,
* checked TYPE char1, "勾选框
* status_inc TYPE char10, "状态灯
status TYPE char2, "状态
message TYPE char255, "消息文本
zindex TYPE i, "序号
werks TYPE ztmm030-werks, "工厂
lgort TYPE ztmm030-lgort, "存储地点
matnr TYPE ztmm030-matnr, "物料编号
l1_old TYPE ztmm030-l1, "库存下限(当前)
l2_old TYPE ztmm030-l2, "库存上限(当前)
createby TYPE ztmm030-createby, "最后更新人
createdate TYPE ztmm030-createdate, "最后更新日期
createtime TYPE ztmm030-createtime, "最后更新时间
l1 TYPE ztmm030-l1, "库存下限(未来)
l2 TYPE ztmm030-l2, "库存上限(未来)
END OF gy_data.
DATA: gs_data TYPE gy_data,
gt_data TYPE TABLE OF gy_data.
FIELD-SYMBOLS: <fs_data> TYPE gy_data.
TYPES: BEGIN OF gy_data2,
lfgja TYPE mard-lfgja, "年度
lfmon TYPE mard-lfmon, "月份
werks TYPE mard-werks, "工厂
lgort TYPE mard-lgort, "库存地点
lgobe TYPE t001l-lgobe, "仓储地点描述
matnr TYPE mard-matnr, "物料
zwlcms TYPE mara-zwlcms, "物料描述
meins TYPE mara-meins, "单位
labst TYPE mard-labst, "库存数量
l1 TYPE ztmm030-l1, "库存下限
l2 TYPE ztmm030-l2, "库存上限
"je TYPE mbew-verpr, "金额
je TYPE acdoca-tsl, "金额
text TYPE char10, "库存状态
verpr TYPE mbew-verpr,
peinh TYPE mbew-peinh,
* sobkz TYPE mspr-sobkz, "特殊库存
* pspnr TYPE mspr-pspnr, "特殊库存编号
* prlab TYPE mspr-prlab, "库存数量
createby TYPE ztmm030-createby, "最后更新人
createdate TYPE ztmm030-createdate, "最后更新日期
createtime TYPE ztmm030-createtime, "最后更新时间
f1 TYPE char1,
l1_ TYPE ztmm030-l1, "库存下限
l2_ TYPE ztmm030-l2, "库存上限
celtab TYPE lvc_t_styl, "控制字段可编辑的参数
END OF gy_data2.
DATA: gs_data2 TYPE gy_data2,
gt_data2 TYPE TABLE OF gy_data2.
FIELD-SYMBOLS: <fs_data2> TYPE gy_data2.
DATA: gt_fieldcat_lvc TYPE lvc_t_fcat, "ALV:定义一个先显示字段的表
gs_fieldcat_lvc LIKE LINE OF gt_fieldcat_lvc. "ALV
二、设计逻辑
表名**-**字段名
字段描述
说明
MARD-LFGJA
MARD-LFMON
备注:
1.以当前年月为查询条件
MARD-LFGJA = 当前年
MARD-LFMON = 当前月份
2.通用库存MARD,库存数量不为0的数据
3.只查询V价物料
MBEW-MATNR =MSPR/MARD-MATNR
MBEW-BWKEY=MSPR/MARD-WERKS
MBEW-VPRSV=V的数据
MARD-WERKS
工厂
MARD-LGORT
仓库
T001L-LGOBE
仓储地点描述
MARD-WERKS=T001L-WERKS
MARD-LGORT=T001L-LGORT
取T001L-LGOBE
MARD-MATNR
物料编码
MARA-ZWLCMS
物料长描述
MARD-MATNR=MARA-MATNR
取MARA-ZWLCMS
MSPR-SOBKZ
特殊库存
MSPR-PSPNR
特殊库存编号
MARA-MEINS
单位
MSPR-PRLAB
MARD-LABST
库存数量
MSPR-PRLAB≠0
MARD-LABST≠0
用户输入
库存下限
- 用户可批导
- 用户编辑修改 只能编辑修改一次 可参考ZMM018变更计划交期字段
用户输入
库存上限
- 用户可批导
- 用户编辑修改 只能编辑修改一次 可参考ZMM018变更计划交期字段
库存金额
MBEW-MATNR =MARD-MATNR
MBEW-BWKEY=MARD-WERKS
取到MBEW-VERPR ÷MBEW-PEINH的单价
再用单价*所对应的库存数量
文本显示
库存状态
状态有四种(超上限、库存过低、库存正常、空)
当前库存数量与库存上下限对比,无上下限对比则为空
高于上限值=“超上限”
介于上下限值中间=“库存正常”
低于下限值=“库存过低”
版权归原作者 Terry谈企业数字化 所有, 如有侵权,请联系我们删除。