SAP ABAP 顾问(开发工程师)能力模型_Terry谈企业数字化的博客-CSDN博客文章浏览阅读458次。目标:基于对SAP abap 顾问能力模型的梳理,给一年左右经验的abaper 快速成长为三年经验提供超级燃料!https://blog.csdn.net/java_zhong1990/article/details/132469977
1 应用场景,查询物料主数据维护情况,为物料维护及时性提供参考。
2 实现效果
*&---------------------------------------------------------------------*
*& Report ZMM029
*&---------------------------------------------------------------------*
*& 事务代码:ZMM029 *
*& 程序名称:ZMM029 物料主数据视图清单 *
*& 请 求 号: *
*& 程序目的: *
*& 创 建 人:TerryZhong *
*& 设计时间: *
*& 程序类型: ABAP/4 程序 ,数据转换 *
*& 输入文件: *
*& 输出文件: *
*& 描 述: *
*&---------------------------------------------------------------------*
*---------------------------------------------------------------------------------------------------------------------*
*** Modification LOG *
*---------------------------------------------------------------------------------------------------------------------*
*Date | Userid | Reason | Request No | Description of Change *
*
*---------------------------------------------------------------------------------------------------------------------*
REPORT zmm029.
INCLUDE zmm029_top.
INCLUDE zmm029_sel.
INCLUDE zmm029_frm.
INCLUDE zmm029_pbo.
INCLUDE zmm029_pai.
INITIALIZATION.
AT SELECTION-SCREEN.
START-OF-SELECTION.
PERFORM get_data.
PERFORM set_catalog.
PERFORM display_alv.
*&---------------------------------------------------------------------*
*& Form display_alv
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
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.
*&---------------------------------------------------------------------*
*& 包含 ZFICO042_TOP
*&---------------------------------------------------------------------*
TYPES: BEGIN OF gy_data,
matnr TYPE mara-matnr, "物料描述
mtart TYPE mara-mtart, "物料类型
meins TYPE mara-meins, "单位
werks TYPE marc-werks, "工厂
base_view TYPE c, "基本数据
pur_view TYPE c, "采购视图
mrp_view TYPE c, "MRP视图
workplan_view TYPE c, "工作计划
sales_view TYPE c, "销售视图
vkorg TYPE mvke-vkorg, "销售组织
fico_view TYPE c, "财务视图
vprsv TYPE mbew-vprsv , "价格控制
mlast TYPE mbew-mlast, "物料价格确定: 控制
werks_view TYPE c, "工厂存储视图
ekgrp TYPE marc-ekgrp,
dismm TYPE marc-dismm,
dispo TYPE marc-dispo,
sfcpf TYPE marc-sfcpf,
fevor TYPE marc-fevor,
END OF gy_data.
DATA gt_data TYPE TABLE OF gy_data.
DATA gs_data TYPE gy_data.
DATA: gt_fieldcat_lvc TYPE lvc_t_fcat, "ALV:定义一个先显示字段的表
gs_fieldcat_lvc LIKE LINE OF gt_fieldcat_lvc. "ALV
TABLES:rbkp,rseg,acdoca,mara,marc,mbew.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: so_matnr FOR mara-matnr .
SELECT-OPTIONS: so_werks FOR marc-werks .
PARAMETERS: p_vprsv LIKE mbew-vprsv .
PARAMETERS: p_mlast LIKE mbew-mlast .
SELECTION-SCREEN END OF BLOCK b1.
*&---------------------------------------------------------------------*
*& 包含 ZZFICO43_FRM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM get_data .
SELECT
mara~matnr, "物料描述
mara~mtart, "物料类型
mara~meins, "单位
marc~werks,
marc~ekgrp,
marc~dismm,
marc~dispo,
marc~sfcpf,
marc~fevor,
mvke~vkorg, "销售组织
mbew~vprsv, "价格控制
mbew~mlast "物料价格确定: 控制
INTO CORRESPONDING FIELDS OF TABLE @gt_data
FROM mara
LEFT JOIN marc ON marc~matnr = mara~matnr
LEFT JOIN mvke ON mvke~matnr = mara~matnr AND mvke~dwerk = marc~werks
LEFT JOIN mbew ON mbew~matnr = mara~matnr AND mbew~bwkey = marc~werks
WHERE
mara~matnr IN @so_matnr
AND marc~werks IN @so_werks
.
IF gt_data IS NOT INITIAL.
SELECT *
INTO TABLE @DATA(lt_msta)
FROM msta FOR ALL ENTRIES IN @gt_data WHERE msta~matnr = @gt_data-matnr AND msta~werks = @gt_data-werks.
SORT lt_msta BY matnr werks statm lgort DESCENDING.
ENDIF.
LOOP AT gt_data ASSIGNING FIELD-SYMBOL(<fs1>).
IF <fs1>-matnr IS NOT INITIAL.
<fs1>-base_view = 'X'.
ENDIF.
IF <fs1>-matnr IS NOT INITIAL AND <fs1>-ekgrp IS NOT INITIAL.
<fs1>-pur_view = 'X'.
ENDIF.
IF <fs1>-matnr IS NOT INITIAL AND <fs1>-dismm = 'PD' AND <fs1>-dispo IS NOT INITIAL .
<fs1>-mrp_view = 'X'.
ENDIF.
IF <fs1>-sfcpf = '000001' AND <fs1>-fevor = '001' .
<fs1>-workplan_view = 'X'.
ENDIF.
IF <fs1>-vkorg IS NOT INITIAL .
<fs1>-sales_view = 'X'.
ENDIF.
IF <fs1>-vprsv IS NOT INITIAL.
<fs1>-fico_view = 'X'.
ENDIF.
READ TABLE lt_msta INTO DATA(ls_msta) WITH KEY matnr = <fs1>-matnr werks = <fs1>-werks statm = 'L' .
IF sy-subrc = 0.
IF ls_msta-lgort IS NOT INITIAL .
<fs1>-werks_view = 'X'.
ENDIF..
ENDIF.
ENDLOOP.
SORT gt_data BY matnr werks vkorg.
DELETE ADJACENT DUPLICATES FROM gt_data COMPARING matnr werks vkorg.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form set_catalog
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
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:
'物料编号' 'MATNR' 'X' '' '' '18' 'MARA' 'MATNR' '',
'物料类型' 'MTART' 'X' '' '' '' '' '' '',
'单位' 'MEINS' 'X' '' '' '' '' '' '',
'工厂' 'WERKS' 'X' '' '' '' '' '' '',
'基本数据' 'BASE_VIEW' 'X' 'X' '' '' '' '' '',
'采购视图' 'PUR_VIEW' 'X' 'X' '' '' '' '' '',
'MRP视图' 'MRP_VIEW' 'X' 'X' '' '' '' '' '',
'工作计划' 'WORKPLAN_VIEW' 'X' 'X' '' '' '' '' '',
'销售视图' 'SALES_VIEW' 'X' 'X' '' '' '' '' '',
'销售组织' 'VKORG' 'X' '' '' '' '' '' '',
'财务视图' 'FICO_VIEW' 'X' 'X' '' '' '' '' '',
'价格控制' 'VPRSV' 'X' '' '' '' '' '' '',
'物料价格确定: 控制' 'MLAST' 'X' '' '' '' '' '' '',
'工厂存储视图' 'WERKS_VIEW' 'X' 'X' '' '' '' '' ''
.
ENDFORM.
*&---------------------------------------------------------------------*
*& 包含 ZFICO042_PBO
*&---------------------------------------------------------------------*
FORM pf_status USING lt_extab TYPE slis_t_extab.
REFRESH:lt_extab[]. CLEAR:lt_extab.
SET TITLEBAR 'ZSTATUS_TITLE'.
"说明:需要显示的按钮进行注释
* APPEND 'ZSAVE' TO lt_extab.
SET PF-STATUS 'ZSTATUS_001' EXCLUDING lt_extab.
ENDFORM.
*&---------------------------------------------------------------------*
*& 包含 ZFICO042_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'.
WHEN OTHERS.
ENDCASE.
ENDFORM.
3 碰到的问题已经解决情况
4 方案设计
4.1 输出逻辑
画面选项文本 | 参考字段技术名 | 选择类型 | 默认值 | 必输项? | 备注 | |||
单 值 | 区 间 | 复选 方框 | 单选 圆点 | |||||
物料编码 | MARA-MATNR | √ | 可模糊搜索 | |||||
工厂 | √ | |||||||
价格控制 | MBEW-VPRSV | √ | ||||||
物料价格确定: 控制 | MBEW-MLAST | √ |
4.2 输出逻辑
表名 | 表名描述 | 字段名 | 字段描述 | 说明 |
MARA | 常规物料数据 | |||
MARA | 常规物料数据 | MTART | 物料类型 | |
MARA | 常规物料数据 | MEINS | 单位 | |
工厂 | ||||
基本数据 | 当物料编码存在MARA-MATNR 则此字段则勾选或者显示是 | |||
采购视图 | 当物料编码存在MARC-MATNR,且MARC-EKGRP≠空 则对应工厂此字段则勾选或者显示是 | |||
MRP视图 | 当物料编码存在MARC-MATNR,且MARC-DISMM=PD和MARC-DISPO≠空 则对应工厂此字段则勾选或者显示是 | |||
工作计划 | MARC-SFCPF=000001和MARC-FEVOR=001 则对应工厂此字段则勾选或者显示是 | |||
销售视图 | 当物料编码存在MVKE-MATNR 则对应工厂此字段则勾选或者显示是 | |||
MVKE | 物料销售数据 | VKORG | 销售组织 | MVKE-VKORG |
会计视图 | 当物料编码存在MBEW-MATNR 则对应工厂此字段则勾选或者显示是 | |||
MBEW | 物料评估 | VPRSV | 价格控制 | |
MBEW | 物料评估 | MLAST | 物料价格确定: 控制 | |
工厂存储视图 | 当物料编码存在MSTA-MATNR,且MSTA-WERKS=工厂 + MSTA-STATM=L + MSTA-LGORT≠空 则对应工厂此字段则勾选或者显示是 | |||