当前位置:   article > 正文

SAP_ABAP_MM_安全库存_设计方案+实现代码(MARD_MBEW )_ALV_行列控制动态编辑

SAP_ABAP_MM_安全库存_设计方案+实现代码(MARD_MBEW )_ALV_行列控制动态编辑

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 代码实现
  1. *&---------------------------------------------------------------------*
  2. *& Report ZMM028
  3. *&---------------------------------------------------------------------*
  4. *&
  5. *&---------------------------------------------------------------------*
  6. REPORT zmm031.
  7. INCLUDE zmm031_top.
  8. INCLUDE zmm031_sel.
  9. INCLUDE zmm031_frm.
  10. INCLUDE zmm031_pbo.
  11. INCLUDE zmm031_pai.
  12. SELECTION-SCREEN FUNCTION KEY: 1 .
  13. INITIALIZATION.
  14. PERFORM init.
  15. AT SELECTION-SCREEN OUTPUT.
  16. AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_file.
  17. PERFORM get_excel.
  18. AT SELECTION-SCREEN.
  19. CASE sscrfields-ucomm .
  20. WHEN 'FC01'.
  21. PERFORM download_template USING '批导模版.xlsx' 'ZMM031'.
  22. WHEN OTHERS.
  23. ENDCASE.
  24. START-OF-SELECTION.
  25. IF p_inp = 'X'.
  26. * SELECT * INTO TABLE @DATA(ls_ztmm031) FROM ztmm031 WHERE ztmm031~c1 = @sy-uname.
  27. * IF sy-subrc = 0.
  28. * ELSE.
  29. * MESSAGE '没有权限,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.
  30. * LEAVE TO LIST-PROCESSING.
  31. * EXIT.
  32. *
  33. * ENDIF.
  34. PERFORM get_data_for_excel.
  35. PERFORM check_data_for_excel.
  36. PERFORM set_catalog.
  37. PERFORM display_alv.
  38. ELSEIF p_sel = 'X'.
  39. PERFORM get_data_for_ztmm030.
  40. PERFORM set_catalog1.
  41. PERFORM display_alv_ztmm030.
  42. ELSE.
  43. PERFORM get_data_for_mard.
  44. PERFORM set_catalog2.
  45. PERFORM display_alv2.
  46. ENDIF.
  47. *&---------------------------------------------------------------------*
  48. *& Form get_data_for_mard
  49. *&---------------------------------------------------------------------*
  50. *& text
  51. *&---------------------------------------------------------------------*
  52. *& --> p1 text
  53. *& <-- p2 text
  54. *&---------------------------------------------------------------------*
  55. FORM get_data_for_mard .
  56. DATA:lv_lfgja TYPE mard-lfgja.
  57. DATA:lv_lfmon TYPE mard-lfmon.
  58. lv_lfgja = sy-datum+0(4).
  59. lv_lfmon = sy-datum+4(2).
  60. * lv_lfgja = '2022'.
  61. * lv_lfmon = '05'.
  62. SELECT
  63. mard~lfgja,
  64. mard~lfmon,
  65. mard~werks,
  66. mard~lgort,
  67. mard~matnr,
  68. mard~labst,
  69. t001l~lgobe,
  70. mara~zwlcms,
  71. mara~meins,
  72. mbew~verpr,
  73. mbew~peinh,
  74. ztmm030~l1,
  75. ztmm030~l2,
  76. ztmm030~createby,
  77. ztmm030~createdate,
  78. ztmm030~createtime
  79. INTO CORRESPONDING FIELDS OF TABLE @gt_data2
  80. FROM mard
  81. LEFT JOIN ztmm030 ON ztmm030~werks = mard~werks AND ztmm030~lgort = mard~lgort AND ztmm030~matnr = mard~matnr
  82. INNER JOIN t001l ON t001l~werks = mard~werks AND mard~lgort = t001l~lgort
  83. INNER JOIN mara ON mara~matnr = mard~matnr
  84. INNER JOIN mbew ON mbew~matnr = mard~matnr AND mbew~bwkey = mard~werks AND mbew~vprsv = 'V'
  85. WHERE mard~lfgja = @lv_lfgja AND mard~lfmon = @lv_lfmon
  86. AND mard~werks IN @so_werks
  87. AND mard~lgort IN @so_lgort
  88. AND mard~matnr IN @so_matnr
  89. AND mard~labst <> '0'
  90. .
  91. "verpr
  92. LOOP AT gt_data2 ASSIGNING FIELD-SYMBOL(<fs1>).
  93. <fs1>-je = <fs1>-verpr / <fs1>-peinh * <fs1>-labst.
  94. IF <fs1>-l1 IS NOT INITIAL AND <fs1>-l2 IS NOT INITIAL.
  95. IF <fs1>-labst < <fs1>-l1 .
  96. <fs1>-text = '库存过低'.
  97. ELSEIF <fs1>-labst > <fs1>-l2.
  98. <fs1>-text = '超上限'.
  99. ELSE.
  100. <fs1>-text = '库存正常'.
  101. ENDIF.
  102. ENDIF.
  103. * <fs1>-labst2 = <fs1>-labst.
  104. <fs1>-l1_ = <fs1>-l1.
  105. <fs1>-l2_ = <fs1>-l2.
  106. IF <fs1>-l1 IS INITIAL AND <fs1>-l2 IS INITIAL.
  107. <fs1>-f1 = 'X'.
  108. ELSE.
  109. SELECT * INTO TABLE @DATA(ls_ztmm031) FROM ztmm031 WHERE ztmm031~c1 = @sy-uname.
  110. IF sy-subrc = 0.
  111. <fs1>-f1 = 'X'.
  112. ELSE.
  113. "<fs>-message = '无权限修改'.<fs>-status = 'E'. CONTINUE.
  114. ENDIF.
  115. ENDIF.
  116. ENDLOOP.
  117. DATA:gwa_edit TYPE lvc_s_styl,
  118. git_edit TYPE lvc_t_styl.
  119. LOOP AT gt_data2 INTO gs_data2.
  120. IF gs_data2-f1 = 'X'.
  121. CLEAR: gwa_edit.
  122. gwa_edit-fieldname = 'L1'.
  123. gwa_edit-style = cl_gui_alv_grid=>mc_style_enabled."设置为可编辑
  124. APPEND gwa_edit TO gs_data2-celtab .
  125. CLEAR: gwa_edit.
  126. gwa_edit-fieldname = 'L2'.
  127. gwa_edit-style = cl_gui_alv_grid=>mc_style_enabled."设置为可编辑
  128. APPEND gwa_edit TO gs_data2-celtab .
  129. ELSE.
  130. CLEAR: gwa_edit.
  131. gwa_edit-fieldname = 'L1'.
  132. gwa_edit-style = cl_gui_alv_grid=>mc_style_disabled."设置为不可编辑
  133. APPEND gwa_edit TO gs_data2-celtab .
  134. CLEAR: gwa_edit.
  135. gwa_edit-fieldname = 'L2'.
  136. gwa_edit-style = cl_gui_alv_grid=>mc_style_disabled."设置为不可编辑
  137. APPEND gwa_edit TO gs_data2-celtab .
  138. ENDIF.
  139. MODIFY gt_data2 FROM gs_data2 .
  140. ENDLOOP.
  141. ENDFORM.
  1. *&---------------------------------------------------------------------*
  2. *& 包含 ZMM028_FRM
  3. *&---------------------------------------------------------------------*
  4. FORM get_excel.
  5. DATA : l_filetab TYPE filetable,
  6. l_waftab LIKE LINE OF l_filetab,
  7. l_rc TYPE i.
  8. CALL METHOD cl_gui_frontend_services=>file_open_dialog
  9. EXPORTING
  10. window_title = '打开文件'
  11. initial_directory = 'C:/'
  12. CHANGING
  13. file_table = l_filetab
  14. rc = l_rc
  15. EXCEPTIONS
  16. file_open_dialog_failed = 1
  17. cntl_error = 2
  18. error_no_gui = 3
  19. not_supported_by_gui = 4
  20. OTHERS = 5.
  21. IF sy-subrc <> 0.
  22. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  23. WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  24. EXIT.
  25. ELSE.
  26. READ TABLE l_filetab INTO l_waftab INDEX 1.
  27. pa_file = l_waftab-filename.
  28. CLEAR: l_filetab,l_waftab.
  29. ENDIF.
  30. ENDFORM.
  31. FORM init.
  32. DATA: ls_dyntxt TYPE smp_dyntxt .
  33. ls_dyntxt-icon_id = icon_export.
  34. ls_dyntxt-quickinfo = '模板下载'.
  35. ls_dyntxt-icon_text = '模板下载'.
  36. sscrfields-functxt_01 = ls_dyntxt.
  37. ENDFORM.
  38. FORM init_output.
  39. ENDFORM.
  40. FORM get_data_for_excel.
  41. TYPES: BEGIN OF ly_excel_data,
  42. werks TYPE ztmm030-werks, "工厂
  43. lgort TYPE ztmm030-lgort, "存储地点
  44. matnr TYPE ztmm030-matnr, "物料编号
  45. l1 TYPE ztmm030-l1, "库存下限(未来)
  46. l2 TYPE ztmm030-l2, "库存上限(未来)
  47. * createby TYPE ztmm030-createby, "最近更新人
  48. * createdate TYPE ztmm030-createdate, "最近更新日期
  49. * createtime TYPE ztmm030-createtime, "最近更新时间
  50. END OF ly_excel_data.
  51. DATA: lt_excel TYPE TABLE OF alsmex_tabline WITH HEADER LINE,
  52. ls_excel_data TYPE ly_excel_data,
  53. l_index LIKE sy-tabix.
  54. DATA: lv_lines TYPE i.
  55. FIELD-SYMBOLS: <fs>.
  56. IF pa_file IS NOT INITIAL.
  57. CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
  58. EXPORTING
  59. filename = pa_file
  60. i_begin_col = '1'
  61. i_begin_row = '2'
  62. i_end_col = '10'
  63. i_end_row = '50000'
  64. TABLES
  65. intern = lt_excel
  66. EXCEPTIONS
  67. inconsistent_parameters = 1
  68. upload_ole = 2
  69. OTHERS = 3.
  70. IF sy-subrc = 0.
  71. *&& 将EXCEL格式中的数据导入到内表TAB_LOAD中
  72. LOOP AT lt_excel.
  73. ASSIGN COMPONENT lt_excel-col OF STRUCTURE ls_excel_data TO <fs>.
  74. <fs> = lt_excel-value.
  75. AT END OF row.
  76. MOVE-CORRESPONDING ls_excel_data TO gs_data."跟Excel的列一一对应的内表
  77. APPEND gs_data TO gt_data.
  78. CLEAR: ls_excel_data,gs_data.
  79. ENDAT.
  80. ENDLOOP.
  81. lv_lines = lines( gt_data ).
  82. IF lv_lines > 8000.
  83. MESSAGE '本次导入数据超过5000,请拆分数据文件!' TYPE 'S'DISPLAY LIKE 'E'.
  84. STOP.
  85. ENDIF.
  86. ENDIF.
  87. ELSE.
  88. MESSAGE '请输入文件路径!' TYPE 'S'DISPLAY LIKE 'E'.
  89. STOP.
  90. ENDIF.
  91. ENDFORM.
  92. FORM check_data_for_excel.
  93. LOOP AT gt_data ASSIGNING FIELD-SYMBOL(<fs>).
  94. CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
  95. EXPORTING
  96. input = <fs>-matnr
  97. IMPORTING
  98. output = <fs>-matnr
  99. * EXCEPTIONS
  100. * LENGTH_ERROR = 1
  101. * OTHERS = 2
  102. .
  103. IF sy-subrc <> 0.
  104. ENDIF.
  105. SELECT SINGLE matnr INTO @DATA(ls1) FROM mara WHERE mara~matnr = @<fs>-matnr.
  106. IF sy-subrc = 0.
  107. ELSE.
  108. <fs>-message = '物料号不存在'.
  109. <fs>-status = 'E'.
  110. CONTINUE.
  111. ENDIF.
  112. SELECT SINGLE t001l~werks INTO @DATA(ls2) FROM t001l WHERE t001l~werks = @<fs>-werks.
  113. IF sy-subrc = 0.
  114. ELSE.
  115. <fs>-message = '工厂不存在'.<fs>-status = 'E'.
  116. CONTINUE.
  117. ENDIF.
  118. SELECT SINGLE t001l~werks INTO @DATA(ls3) FROM t001l WHERE t001l~lgort = @<fs>-lgort.
  119. IF sy-subrc = 0.
  120. ELSE.
  121. <fs>-message = '库位不存在'.<fs>-status = 'E'.
  122. CONTINUE.
  123. ENDIF.
  124. SELECT SINGLE * INTO @DATA(ls_ztmm030)
  125. FROM ztmm030 WHERE ztmm030~werks = @<fs>-werks AND ztmm030~lgort = @<fs>-lgort AND ztmm030~matnr = @<fs>-matnr.
  126. IF sy-subrc = 0.
  127. <fs>-l1_old = ls_ztmm030-l1.
  128. <fs>-l2_old = ls_ztmm030-l2.
  129. <fs>-createby = ls_ztmm030-createby.
  130. <fs>-createdate = ls_ztmm030-createdate.
  131. <fs>-createtime = ls_ztmm030-createtime.
  132. SELECT * INTO TABLE @DATA(ls_ztmm031) FROM ztmm031 WHERE ztmm031~c1 = @sy-uname.
  133. IF sy-subrc = 0.
  134. ELSE.
  135. <fs>-message = '无权限修改'.<fs>-status = 'E'. CONTINUE.
  136. ENDIF.
  137. ELSE.
  138. <fs>-createby = sy-uname.
  139. <fs>-createdate = sy-datum.
  140. <fs>-createtime = sy-uzeit.
  141. ENDIF.
  142. ENDLOOP.
  143. ENDFORM.
  144. FORM download_template USING pu_filename pu_objid.
  145. *& 下载模版
  146. DATA: ls_objdata LIKE wwwdatatab.
  147. DATA: lv_filename TYPE string,
  148. lv_fullpath TYPE string VALUE 'C:\',
  149. lv_path TYPE string VALUE 'C:\'.
  150. DATA: lv_errtxt TYPE string.
  151. DATA: lv_destination LIKE rlgrap-filename.
  152. DATA: lv_rc LIKE sy-subrc.
  153. DATA: lv_fileup LIKE rlgrap-filename.
  154. lv_filename = pu_filename .
  155. *& 调用保存对话框
  156. CALL METHOD cl_gui_frontend_services=>file_save_dialog
  157. EXPORTING
  158. default_extension = 'xlsx'
  159. default_file_name = lv_filename
  160. initial_directory = 'C:\'
  161. CHANGING
  162. filename = lv_filename
  163. path = lv_path
  164. fullpath = lv_fullpath
  165. EXCEPTIONS
  166. cntl_error = 1
  167. error_no_gui = 2
  168. not_supported_by_gui = 3
  169. OTHERS = 4.
  170. IF sy-subrc NE 0.
  171. MESSAGE '不能打开EXCEL' TYPE 'E'.
  172. ENDIF.
  173. CHECK lv_fullpath IS NOT INITIAL .
  174. lv_fileup = lv_fullpath.
  175. ls_objdata-relid = 'MI' .
  176. ls_objdata-objid = pu_objid .
  177. lv_destination = lv_fullpath .
  178. CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
  179. EXPORTING
  180. key = ls_objdata
  181. destination = lv_destination
  182. IMPORTING
  183. rc = lv_rc.
  184. IF lv_rc NE 0.
  185. CONCATENATE '模板文件:' ls_objdata-objid '下载失败' INTO lv_errtxt.
  186. MESSAGE lv_errtxt TYPE 'E'.
  187. ELSE.
  188. MESSAGE '模版下载成功' TYPE 'S'.
  189. ENDIF.
  190. ENDFORM. " DOWNLOAD_TEMPLATE
  191. FORM set_catalog.
  192. DATA:lv_position TYPE i VALUE 1.
  193. CLEAR: lv_position.
  194. lv_position = lv_position + 1.
  195. * 预定义一个输出模式
  196. DEFINE df_fieldcat.
  197. CLEAR gs_fieldcat_lvc.
  198. gs_fieldcat_lvc-col_pos = lv_position."ALV 控制: 输出列
  199. gs_fieldcat_lvc-scrtext_m = &1."中字段标签
  200. gs_fieldcat_lvc-fieldname = &2."ALV 控制: 内部表字段的字段名称
  201. gs_fieldcat_lvc-no_zero = &3."ALV 控制: 为输出隐藏零
  202. gs_fieldcat_lvc-checkbox = &4."ALV 控制: 作为复选框输出
  203. gs_fieldcat_lvc-edit = &5."设置可编辑模式
  204. gs_fieldcat_lvc-outputlen = &6."输出长度
  205. gs_fieldcat_lvc-ref_table = &7.
  206. gs_fieldcat_lvc-ref_field = &8.
  207. gs_fieldcat_lvc-datatype = &9.
  208. APPEND gs_fieldcat_lvc TO gt_fieldcat_lvc.
  209. ADD 1 TO lv_position.
  210. END-OF-DEFINITION.
  211. df_fieldcat:
  212. '状态' 'STATUS' 'X' '' '' '' '' '' '',
  213. '消息' 'MESSAGE' 'X' '' '' '' '' '' '',
  214. '工厂' 'WERKS' 'X' '' '' '' '' '' '',
  215. '存储地点' 'LGORT' 'X' '' '' '' '' '' '',
  216. '物料编号' 'MATNR' 'X' '' '' '' '' '' '',
  217. '库存下限(当前)' 'L1_OLD' 'X' '' '' '' '' '' '',
  218. '库存上限(当前)' 'L2_OLD' 'X' '' '' '' '' '' '',
  219. '最近更新人' 'CREATEBY' 'X' '' '' '' '' '' '',
  220. '最近更新日期' 'CREATEDATE' 'X' '' '' '' '' '' '',
  221. '最近更新时间' 'CREATETIME' 'X' '' '' '' '' '' '',
  222. '库存下限(未来)' 'L1' 'X' '' '' '' '' '' '',
  223. '库存上限(未来)' 'L2' 'X' '' '' '' '' '' ''
  224. .
  225. ENDFORM.
  226. FORM set_catalog1.
  227. DATA:lv_position TYPE i VALUE 1.
  228. CLEAR: lv_position.
  229. lv_position = lv_position + 1.
  230. * 预定义一个输出模式
  231. DEFINE df_fieldcat.
  232. CLEAR gs_fieldcat_lvc.
  233. gs_fieldcat_lvc-col_pos = lv_position."ALV 控制: 输出列
  234. gs_fieldcat_lvc-scrtext_m = &1."中字段标签
  235. gs_fieldcat_lvc-fieldname = &2."ALV 控制: 内部表字段的字段名称
  236. gs_fieldcat_lvc-no_zero = &3."ALV 控制: 为输出隐藏零
  237. gs_fieldcat_lvc-checkbox = &4."ALV 控制: 作为复选框输出
  238. gs_fieldcat_lvc-edit = &5."设置可编辑模式
  239. gs_fieldcat_lvc-outputlen = &6."输出长度
  240. gs_fieldcat_lvc-ref_table = &7.
  241. gs_fieldcat_lvc-ref_field = &8.
  242. gs_fieldcat_lvc-datatype = &9.
  243. APPEND gs_fieldcat_lvc TO gt_fieldcat_lvc.
  244. ADD 1 TO lv_position.
  245. END-OF-DEFINITION.
  246. df_fieldcat:
  247. '工厂' 'WERKS' 'X' '' '' '' '' '' '',
  248. '存储地点' 'LGORT' 'X' '' '' '' '' '' '',
  249. '物料编号' 'MATNR' 'X' '' '' '' '' '' '',
  250. '库存下限' 'L1' 'X' '' '' '' '' '' '',
  251. '库存上限' 'L2' 'X' '' '' '' '' '' '',
  252. '最近更新人' 'CREATEBY' 'X' '' '' '' '' '' '',
  253. '最近更新日期' 'CREATEDATE' 'X' '' '' '' '' '' '',
  254. '最近更新时间' 'CREATETIME' 'X' '' '' '' '' '' ''
  255. .
  256. ENDFORM.
  257. FORM set_catalog2.
  258. DATA:lv_position TYPE i VALUE 1.
  259. CLEAR: lv_position.
  260. lv_position = lv_position + 1.
  261. * 预定义一个输出模式
  262. DEFINE df_fieldcat.
  263. CLEAR gs_fieldcat_lvc.
  264. gs_fieldcat_lvc-col_pos = lv_position."ALV 控制: 输出列
  265. gs_fieldcat_lvc-scrtext_m = &1."中字段标签
  266. gs_fieldcat_lvc-fieldname = &2."ALV 控制: 内部表字段的字段名称
  267. gs_fieldcat_lvc-no_zero = &3."ALV 控制: 为输出隐藏零
  268. gs_fieldcat_lvc-checkbox = &4."ALV 控制: 作为复选框输出
  269. gs_fieldcat_lvc-edit = &5."设置可编辑模式
  270. gs_fieldcat_lvc-outputlen = &6."输出长度
  271. gs_fieldcat_lvc-ref_table = &7.
  272. gs_fieldcat_lvc-ref_field = &8.
  273. gs_fieldcat_lvc-datatype = &9.
  274. APPEND gs_fieldcat_lvc TO gt_fieldcat_lvc.
  275. ADD 1 TO lv_position.
  276. END-OF-DEFINITION.
  277. df_fieldcat:
  278. '年度' 'LFGJA' 'X' '' '' '' '' '' '',
  279. '月份' 'LFMON' 'X' '' '' '' '' '' '',
  280. '工厂' 'WERKS' 'X' '' '' '' '' '' '',
  281. '库存地点' 'LGORT' 'X' '' '' '' '' '' '',
  282. '仓储地点描述' 'LGOBE' 'X' '' '' '' '' '' '',
  283. '物料' 'MATNR' 'X' '' '' '' '' '' '',
  284. '物料描述' 'ZWLCMS' 'X' '' '' '' '' '' '',
  285. '单位' 'MEINS' 'X' '' '' '' '' '' '',
  286. '库存数量' 'LABST' 'X' '' '' '' '' '' '',
  287. '库存下限' 'L1' 'X' '' 'X' '' '' '' '',
  288. '库存上限' 'L2' 'X' '' 'X' '' '' '' '',
  289. '金额' 'JE' 'X' '' '' '' '' '' '',
  290. '库存状态' 'TEXT' 'X' '' '' '' '' '' '',
  291. '最近更新人' 'CREATEBY' 'X' '' '' '' '' '' '',
  292. '最近更新日期' 'CREATEDATE' 'X' '' '' '' '' '' '',
  293. '最近更新时间' 'CREATETIME' 'X' '' '' '' '' '' ''
  294. .
  295. ENDFORM.
  296. FORM display_alv_ztmm030.
  297. DATA: ls_layout TYPE lvc_s_layo.
  298. IF gt_data IS NOT INITIAL.
  299. ls_layout-zebra = 'X'.
  300. ls_layout-cwidth_opt = 'X'.
  301. * 调用ALV function
  302. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  303. EXPORTING
  304. i_callback_program = sy-repid "这里是调用这个ALV的程序名
  305. i_callback_pf_status_set = 'PF_STATUS' "设置ALV状态栏的函数
  306. i_callback_user_command = 'USER_COMMAND' "获取用户事件的函数
  307. is_layout_lvc = ls_layout "显示的布局
  308. it_fieldcat_lvc = gt_fieldcat_lvc "设置显示的字段以及字段的功能
  309. i_save = 'A'
  310. TABLES
  311. t_outtab = gt_data
  312. EXCEPTIONS
  313. program_error = 1.
  314. IF sy-subrc <> 0.
  315. MESSAGE '报表生成异常,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.
  316. ENDIF.
  317. ELSE.
  318. * 这个消息用来显示我们是不是获取到了数据,自己用的时候把这个硬代码换成你需要的TEXT-XXX.
  319. MESSAGE '没有获取到数据,请重新检索!' TYPE 'S' DISPLAY LIKE 'E'.
  320. LEAVE TO LIST-PROCESSING.
  321. EXIT.
  322. ENDIF.
  323. ENDFORM.
  324. FORM display_alv.
  325. DATA: ls_layout TYPE lvc_s_layo.
  326. IF gt_data IS NOT INITIAL.
  327. ls_layout-zebra = 'X'.
  328. ls_layout-cwidth_opt = 'X'.
  329. * 调用ALV function
  330. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  331. EXPORTING
  332. i_callback_program = sy-repid "这里是调用这个ALV的程序名
  333. i_callback_pf_status_set = 'PF_STATUS' "设置ALV状态栏的函数
  334. i_callback_user_command = 'USER_COMMAND' "获取用户事件的函数
  335. is_layout_lvc = ls_layout "显示的布局
  336. it_fieldcat_lvc = gt_fieldcat_lvc "设置显示的字段以及字段的功能
  337. i_save = 'A'
  338. TABLES
  339. t_outtab = gt_data
  340. EXCEPTIONS
  341. program_error = 1.
  342. IF sy-subrc <> 0.
  343. MESSAGE '报表生成异常,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.
  344. ENDIF.
  345. ELSE.
  346. * 这个消息用来显示我们是不是获取到了数据,自己用的时候把这个硬代码换成你需要的TEXT-XXX.
  347. MESSAGE '没有获取到数据,请重新检索!' TYPE 'S' DISPLAY LIKE 'E'.
  348. LEAVE TO LIST-PROCESSING.
  349. EXIT.
  350. ENDIF.
  351. ENDFORM.
  352. FORM display_alv2.
  353. DATA: ls_layout TYPE lvc_s_layo.
  354. IF gt_data2 IS NOT INITIAL.
  355. ls_layout-zebra = 'X'.
  356. ls_layout-cwidth_opt = 'X'.
  357. ls_layout-stylefname = 'CELTAB'.
  358. * 调用ALV function
  359. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  360. EXPORTING
  361. i_callback_program = sy-repid "这里是调用这个ALV的程序名
  362. i_callback_pf_status_set = 'PF_STATUS' "设置ALV状态栏的函数
  363. i_callback_user_command = 'USER_COMMAND' "获取用户事件的函数
  364. is_layout_lvc = ls_layout "显示的布局
  365. it_fieldcat_lvc = gt_fieldcat_lvc "设置显示的字段以及字段的功能
  366. i_save = 'A'
  367. TABLES
  368. t_outtab = gt_data2
  369. EXCEPTIONS
  370. program_error = 1.
  371. IF sy-subrc <> 0.
  372. MESSAGE '报表生成异常,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.
  373. ENDIF.
  374. ELSE.
  375. * 这个消息用来显示我们是不是获取到了数据,自己用的时候把这个硬代码换成你需要的TEXT-XXX.
  376. MESSAGE '没有获取到数据,请重新检索!' TYPE 'S' DISPLAY LIKE 'E'.
  377. LEAVE TO LIST-PROCESSING.
  378. EXIT.
  379. ENDIF.
  380. ENDFORM.
  381. *&---------------------------------------------------------------------*
  382. *& Form get_data_for_ztmm030
  383. *&---------------------------------------------------------------------*
  384. *& text
  385. *&---------------------------------------------------------------------*
  386. *& --> p1 text
  387. *& <-- p2 text
  388. *&---------------------------------------------------------------------*
  389. FORM get_data_for_ztmm030 .
  390. SELECT * INTO CORRESPONDING FIELDS OF TABLE @gt_data FROM ztmm030
  391. WHERE ztmm030~matnr IN @so_matnr
  392. AND ztmm030~werks IN @so_werks
  393. AND ztmm030~lgort IN @so_lgort
  394. .
  395. ENDFORM.
  1. *&---------------------------------------------------------------------*
  2. *& 包含 ZMM028_PAI
  3. *&---------------------------------------------------------------------*
  4. *&---------------------------------------------------------------------*
  5. *& 包含 ZFI068_PAI
  6. *&---------------------------------------------------------------------*
  7. FORM user_command USING i_ucomm TYPE sy-ucomm
  8. i_wa_selfield TYPE slis_selfield.
  9. DATA:gwa_edit TYPE lvc_s_styl,
  10. git_edit TYPE lvc_t_styl.
  11. DATA lv_length TYPE num10.
  12. DATA lr_grid TYPE REF TO cl_gui_alv_grid.
  13. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
  14. IMPORTING
  15. e_grid = lr_grid.
  16. CALL METHOD lr_grid->check_changed_data.
  17. CALL METHOD lr_grid->refresh_table_display.
  18. i_wa_selfield-refresh = 'X'.
  19. CASE i_ucomm.
  20. WHEN 'ZSAVE'.
  21. DATA(lt_check) = gt_data.
  22. DELETE lt_check WHERE status <> 'E'.
  23. IF lines( lt_check ) <> 0.
  24. MESSAGE '检查未通过' TYPE 'E'.
  25. ENDIF.
  26. * "权限检查
  27. * DATA:lv_auth TYPE char.
  28. * lv_auth = ''.
  29. * SELECT * INTO TABLE @DATA(ls_ztmm031) FROM ztmm031 WHERE ztmm031~c1 = @sy-uname.
  30. * IF sy-subrc = 0.
  31. * lv_auth = 'X'.
  32. * ELSE.
  33. ** MESSAGE '没有权限,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.
  34. ** LEAVE TO LIST-PROCESSING.
  35. ** EXIT.
  36. * ENDIF.
  37. *
  38. * IF lv_auth = 'X'.
  39. DATA:lt_ TYPE TABLE OF ztmm030.
  40. MOVE-CORRESPONDING gt_data TO lt_.
  41. MODIFY ztmm030 FROM TABLE lt_.
  42. MESSAGE '保存成功' TYPE 'S'.
  43. * ENDIF.
  44. WHEN 'ZSAVE1'.
  45. DATA:lt_ztmm030 TYPE TABLE OF ztmm030.
  46. DATA:ls_ztmm030 TYPE ztmm030.
  47. LOOP AT gt_data2 INTO gs_data2.
  48. IF gs_data2-l1 = gs_data2-l1_ AND gs_data2-l2 = gs_data2-l2_.
  49. ELSE.
  50. MOVE-CORRESPONDING gs_data2 TO ls_ztmm030.
  51. ls_ztmm030-createby = sy-uname.
  52. ls_ztmm030-createdate = sy-datum.
  53. ls_ztmm030-createtime = sy-uzeit.
  54. APPEND ls_ztmm030 TO lt_ztmm030.
  55. ENDIF.
  56. ENDLOOP.
  57. IF lt_ztmm030 IS NOT INITIAL.
  58. MODIFY ztmm030 FROM TABLE lt_ztmm030.
  59. MESSAGE '保存成功' TYPE 'S'.
  60. ENDIF.
  61. WHEN 'ZSAVE2'.
  62. WHEN 'ZSAL'.
  63. WHEN 'ZALL'.
  64. WHEN OTHERS.
  65. ENDCASE.
  66. ENDFORM.
  1. *&---------------------------------------------------------------------*
  2. *& 包含 ZMM028_PBO
  3. *&---------------------------------------------------------------------*
  4. FORM pf_status USING lt_extab TYPE slis_t_extab.
  5. REFRESH:lt_extab[]. CLEAR:lt_extab.
  6. IF p_inp = 'X'.
  7. SET TITLEBAR 'ZSTATUS_TITLE'.
  8. "说明:需要显示的按钮进行注释
  9. * APPEND 'ZSAVE' TO lt_extab.
  10. APPEND 'ZSAVE1' TO lt_extab.
  11. SET PF-STATUS 'ZSTATUS_001' EXCLUDING lt_extab.
  12. ELSEIF p_sel = 'X'.
  13. SET TITLEBAR 'ZSTATUS_TITLE'.
  14. "说明:需要显示的按钮进行注释
  15. APPEND 'ZSAVE' TO lt_extab.
  16. APPEND 'ZSAVE1' TO lt_extab.
  17. SET PF-STATUS 'ZSTATUS_001' EXCLUDING lt_extab.
  18. ELSE.
  19. SET TITLEBAR 'ZSTATUS_TITLE'.
  20. "说明:需要显示的按钮进行注释
  21. APPEND 'ZSAVE' TO lt_extab.
  22. SET PF-STATUS 'ZSTATUS_001' EXCLUDING lt_extab.
  23. ENDIF.
  24. ENDFORM.
  1. *&---------------------------------------------------------------------*
  2. *& 包含 ZMM028_SEL
  3. *&---------------------------------------------------------------------*
  4. TABLES:lips,ztmm030,mard.
  5. SELECTION-SCREEN:BEGIN OF BLOCK b0 WITH FRAME TITLE TEXT-001.
  6. PARAMETERS:p_inp RADIOBUTTON GROUP g1 USER-COMMAND u1 DEFAULT 'X'.
  7. PARAMETERS:p_sel RADIOBUTTON GROUP g1 .
  8. PARAMETERS:p_sel2 RADIOBUTTON GROUP g1 .
  9. PARAMETERS: pa_file TYPE rlgrap-filename ."文件夹上传
  10. SELECTION-SCREEN SKIP 1.
  11. *
  12. * SELECT-OPTIONS: so_lfgja FOR mard-lfgja.
  13. * SELECT-OPTIONS: so_lfmon FOR mard-lfmon.
  14. SELECT-OPTIONS: so_werks FOR ztmm030-werks.
  15. SELECT-OPTIONS: so_lgort FOR ztmm030-lgort.
  16. SELECT-OPTIONS: so_matnr FOR ztmm030-matnr.
  17. SELECTION-SCREEN:END OF BLOCK b0.
  1. *&---------------------------------------------------------------------*
  2. *& 包含 ZMM028_TOP
  3. *&---------------------------------------------------------------------*
  4. *&---------------------------------------------------------------------*
  5. *& 包含 ZFI068_TOP
  6. *&---------------------------------------------------------------------*
  7. TABLES: sscrfields,vbak,bsis.
  8. TYPE-POOLS: esp1,slis ,icon.
  9. TYPES: BEGIN OF gy_data,
  10. * checked TYPE char1, "勾选框
  11. * status_inc TYPE char10, "状态灯
  12. status TYPE char2, "状态
  13. message TYPE char255, "消息文本
  14. zindex TYPE i, "序号
  15. werks TYPE ztmm030-werks, "工厂
  16. lgort TYPE ztmm030-lgort, "存储地点
  17. matnr TYPE ztmm030-matnr, "物料编号
  18. l1_old TYPE ztmm030-l1, "库存下限(当前)
  19. l2_old TYPE ztmm030-l2, "库存上限(当前)
  20. createby TYPE ztmm030-createby, "最后更新人
  21. createdate TYPE ztmm030-createdate, "最后更新日期
  22. createtime TYPE ztmm030-createtime, "最后更新时间
  23. l1 TYPE ztmm030-l1, "库存下限(未来)
  24. l2 TYPE ztmm030-l2, "库存上限(未来)
  25. END OF gy_data.
  26. DATA: gs_data TYPE gy_data,
  27. gt_data TYPE TABLE OF gy_data.
  28. FIELD-SYMBOLS: <fs_data> TYPE gy_data.
  29. TYPES: BEGIN OF gy_data2,
  30. lfgja TYPE mard-lfgja, "年度
  31. lfmon TYPE mard-lfmon, "月份
  32. werks TYPE mard-werks, "工厂
  33. lgort TYPE mard-lgort, "库存地点
  34. lgobe TYPE t001l-lgobe, "仓储地点描述
  35. matnr TYPE mard-matnr, "物料
  36. zwlcms TYPE mara-zwlcms, "物料描述
  37. meins TYPE mara-meins, "单位
  38. labst TYPE mard-labst, "库存数量
  39. l1 TYPE ztmm030-l1, "库存下限
  40. l2 TYPE ztmm030-l2, "库存上限
  41. "je TYPE mbew-verpr, "金额
  42. je TYPE acdoca-tsl, "金额
  43. text TYPE char10, "库存状态
  44. verpr TYPE mbew-verpr,
  45. peinh TYPE mbew-peinh,
  46. * sobkz TYPE mspr-sobkz, "特殊库存
  47. * pspnr TYPE mspr-pspnr, "特殊库存编号
  48. * prlab TYPE mspr-prlab, "库存数量
  49. createby TYPE ztmm030-createby, "最后更新人
  50. createdate TYPE ztmm030-createdate, "最后更新日期
  51. createtime TYPE ztmm030-createtime, "最后更新时间
  52. f1 TYPE char1,
  53. l1_ TYPE ztmm030-l1, "库存下限
  54. l2_ TYPE ztmm030-l2, "库存上限
  55. celtab TYPE lvc_t_styl, "控制字段可编辑的参数
  56. END OF gy_data2.
  57. DATA: gs_data2 TYPE gy_data2,
  58. gt_data2 TYPE TABLE OF gy_data2.
  59. FIELD-SYMBOLS: <fs_data2> TYPE gy_data2.
  60. DATA: gt_fieldcat_lvc TYPE lvc_t_fcat, "ALV:定义一个先显示字段的表
  61. 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

用户输入

库存下限

  1. 用户可批导
  2. 用户编辑修改  只能编辑修改一次   可参考ZMM018变更计划交期字段 

用户输入

库存上限

  1. 用户可批导
  2. 用户编辑修改  只能编辑修改一次   可参考ZMM018变更计划交期字段 

库存金额

MBEW-MATNR =MARD-MATNR

MBEW-BWKEY=MARD-WERKS

取到MBEW-VERPR ÷MBEW-PEINH的单价

再用单价*所对应的库存数量

文本显示

库存状态

状态有四种(超上限、库存过低、库存正常、空)

当前库存数量与库存上下限对比,无上下限对比则为空

高于上限值=“超上限”

介于上下限值中间=“库存正常”

低于下限值=“库存过低”

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/609804
推荐阅读
相关标签
  

闽ICP备14008679号