SM30自定义表数据维护
SAP的自定义表可以生成表维护视图后,通过SM30进行维护。生成标准的表维护有时候不满足用户需求;我们可以手动调整生成的屏幕。 常见的调整有根据字段获取描述,,更改屏幕属性,增加记录修改字段,增加内容检查。
因业务需求,处理了一个自定义增加批准状态字段的设定,批准状态标记后,SM30维护这边不能进行修改和删除,同时因为有日期字段,为限定日期字段的重叠,增加了自定义检查;通过调用函数来跳转到SM30维护画面,所以进行了选择条件传值。
主要是在PAI和PBO中手动增加MODULE.
如果只是需要显示时获取字段描述,例如物料描述,可在屏幕上增加全局变量GV_MAKTX,然后在PAO中LISTE_SHOW_LISTE后面增加MODELE get_maktx.
如果需获取其他表的值且该值需保存在自定义表中或者类似存储当前用户,日期时间的更改记录时,则需在PAI的MODULE LISTE_UPDATE_LISTE.前增加自己的取值MODULE,否则获取值会不能存入自定义表,同时程序激活时需要整个函数组激活,否则也会出现默认值设定无效现象。
表维护视图建好后,如果需要维护事务码可以通过SE93新建事务码封装SM30,也可以建程序调用函数VIEW_MAINTENANCE_CALL
表维护视图MODULE
PBO
LOOP AT EXTRACT WITH CONTROL
TCTRL_ZXXXX CURSOR NEXTLINE.
MODULE LISTE_SHOW_LISTE.
MODULE GET_MAKTX."获取物料描述
MODULE CHANG_EDIT."动态修改屏幕属性
ENDLOOP.
MODULE CLEAR_HEAD.
调用VIEW_MAINTENANCE_CALL时如果设定SEL,新建数据时也会保留限定
所以有时需要清空选择标记字段
&---------------------------------------------------------------------
*& Module CLEAR_HEAD OUTPUT
&---------------------------------------------------------------------
MODULE CLEAR_HEAD OUTPUT.
CLEAR X_HEADER-SELECTION.
ENDMODULE. " CLEAR_HEAD OUTPUT
获取物料描述
SELECT SINGLE MAKTX
FROM MAKT
INTO GV_MAKTX
WHERE MATNR = ZXXX-MATNR
AND SPRAS = SY-LANGU.
动态更改行的输入属性,不允许输入
IF ZXXXX-PZZT IS NOT INITIAL .
LOOP AT SCREEN.
IF SCREEN-NAME = ‘ZXXXX-PRICE’
OR SCREEN-NAME = ‘ZXXXX-WAERS’
.
SCREEN-INPUT = ‘0’.
MODIFY SCREEN.
ENDLOOP.
ENDIF.
PAI
PROCESS AFTER INPUT.
MODULE LISTE_EXIT_COMMAND AT EXIT-COMMAND.
MODULE LISTE_BEFORE_LOOP.
LOOP AT EXTRACT.
MODULE LISTE_INIT_WORKAREA.
CHAIN.
FIELD ZXXXX-WERKS .
FIELD ZXXXX-LGORT .
FIELD ZXXXX-UMLGO .
FIELD ZXXXX-LIFNR .
FIELD ZXXXX-MATNR .
FIELD ZXXXX-KSCHL .
FIELD ZXXXX-DATAB .
FIELD ZXXXX-DATBI .
FIELD ZXXXX-YMATNR .
FIELD ZXXXX-YMAKTX .
FIELD ZXXXX-PRICE .
FIELD ZXXXX-PZZT .
FIELD ZXXXX-BZ1 .
MODULE SET_UPDATE_FLAG ON CHAIN-REQUEST.
ENDCHAIN.
FIELD VIM_MARKED MODULE LISTE_MARK_CHECKBOX.
CHAIN. "自定义检查
FIELD ZXXXX-WERKS .
FIELD ZXXXX-LGORT .
FIELD ZXXXX-UMLGO .
FIELD ZXXXX-LIFNR .
FIELD ZXXXX-MATNR .
FIELD ZXXXX-KSCHL .
FIELD ZXXXX-DATAB .
MODULE CHECK_DATBI."自定义检查及值获取
ENDCHAIN.
CHAIN.
FIELD ZXXXX-WERKS .
FIELD ZXXXX-LGORT .
FIELD ZXXXX-UMLGO .
FIELD ZXXXX-LIFNR .
FIELD ZXXXX-MATNR .
FIELD ZXXXX-KSCHL .
FIELD ZXXXX-DATAB .
MODULE LISTE_UPDATE_LISTE.
ENDCHAIN.
ENDLOOP.
&---------------------------------------------------------------------
*& Module CHECK_DATBI INPUT
&---------------------------------------------------------------------
MODULE CHECK_DATBI INPUT.
IF ZXXXX-DATBI < ZXXXX-DATAB.
MESSAGE E897(SD) WITH ‘输入的结束时间应大于开始时间’ .
ENDIF.
DATA:LS_ZXXXX TYPE ZXXXX.
lt_extract[] = EXTRACT[].
获取物料单位
SELECT SINGLE MEINS FROM MARA
INTO ZXXXX-KMEIN
WHERE MATNR = ZXXXX-MATNR.
LOOP AT EXTRACT.
MOVE
IF LS_ZXXXX-WERKS = ZXXXX-WERKS AND
LS_ZXXXX-MATNR = ZXXXX-MATNR AND
LS_ZXXXX-LGORT = ZXXXX-LGORT AND
LS_ZXXXX-UMLGO = ZXXXX-UMLGO AND
LS_ZXXXX-LIFNR = ZXXXX-LIFNR AND
LS_ZXXXX-KSCHL = ZXXXX-KSCHL AND
LS_ZXXXX-DATAB <> ZXXXX-DATAB.
IF NOT ( ZXXXX-DATBI < LS_ZXXXX-DATAB
"开始日期大于前一条结束日期
OR ZXXXX-DATAB > LS_ZXXXX-DATBI
"结束日期小于前一条开始日期
).
MESSAGE E897(SD) WITH '输入的时间与时间范围重复'
LS_ZXXXX-DATAB '--' LS_ZXXXX-DATBI .
ENDIF.
ENDIF.
ENDLOOP.
ENDMODULE. " CHECK_DATBI INPUT
&---------------------------------------------------------------------
*& Module LISTE_AFTER_LOOP_ADD INPUT
&---------------------------------------------------------------------
MODULE LISTE_AFTER_LOOP_ADD.
CLEAR GV_FLG.
*-- 检查删除
CASE FUNCTION.
WHEN ‘DELE’.
*-- 检查数据
PERFORM FRM_CHECK_DELE.
WHEN OTHERS.
ENDCASE.
IF GV_FLG IS NOT INITIAL.
RETURN.
ENDIF.
----------------------------------------------------------------------
***INCLUDE LZFGSD4002F01 .
----------------------------------------------------------------------
&---------------------------------------------------------------------
*& Form FRM_CHECK_DELE
&---------------------------------------------------------------------
FIELD-SYMBOLS:
LOOP AT extract.
CHECK EQ markiert.
ASSIGN COMPONENT ‘PZZT’ OF STRUCTURE
IF
GV_FLG = ‘X’.
MESSAGE S001(00) WITH ‘选择数据已批准,不允许删除’ DISPLAY LIKE ‘E’.
RETURN.
ENDIF.
ENDLOOP.
ENDFORM. " FRM_CHECK_DELE
&---------------------------------------------------------------------
*& Form FRM_LISTE_AFTER_LOOP
&---------------------------------------------------------------------
PERFORM TIME_DEPENDENT_DISPLAY_MODIF.
IF X_HEADER-DELMDTFLAG EQ SPACE.
MESSAGE S001(SV). EXIT.
ENDIF.
PERFORM (VIM_TIME_DEP_DPL_MODIF_FORM) IN PROGRAM. "#EC *
WHEN ‘FDOC’. "HW Functiondocu CLEAR: -prof_found, vim_pr_records.
PERFORM get_profiles USING -prof_found.
WHEN ‘KOPE’. SORT EXTRACT BY . "not nec. anymore
-FIRSTLINE = FIRSTLINE = -CUR_LINE = L = 1.
ENDIF.
VIM_NEXT_SCREEN = 0. VIM_LEAVE_SCREEN = 'X'.
WHEN ‘SCRF’. PERFORM get_profiles USING -prof_found.
WHEN ‘TEXT’. "SW TexttranslPERFORM LISTE_ZURUECKHOLEN.
PERFORM ZURUECKHOLEN.
IF REPLACE_MODE NE SPACE.
-MK_TO = MARK_TOTAL.
-MK_XT = MARK_EXTRACT.
VIM_NEXT_SCREEN = 0. VIM_LEAVE_SCREEN = 'X'.
ENDIF.
WHEN ‘UPRF’. "UF Profile PERFORM activate_profile CHANGING -prof_found.
MESSAGE S175(SV).
WHEN ’ '.ENDFORM. " FRM_LISTE_AFTER_LOOP
程序调用函数
DATA:
LT_SEL TYPE TABLE OF VIMSELLIST,
LS_SEL TYPE VIMSELLIST.
设定数据限定条件 单一值
LS_SEL-VIEWFIELD = ‘VKORG’.
LS_SEL-OPERATOR = ‘EQ’.
LS_SEL-VALUE = P_WERKS.
LS_SEL-AND_OR = ‘AND’.
APPEND LS_SEL TO LT_SEL.
设定数据限定条件 范围
CALL FUNCTION ‘VIEW_RANGETAB_TO_SELLIST’
EXPORTING
FIELDNAME = ‘LGORT’
APPEND_CONJUNCTION = ‘AND’
TABLES
SELLIST = LT_SEL
RANGETAB = S_LGORT.
CALL FUNCTION ‘VIEW_RANGETAB_TO_SELLIST’
EXPORTING
FIELDNAME = ‘LIFNR’
APPEND_CONJUNCTION = ‘AND’
TABLES
SELLIST = LT_SEL
RANGETAB = S_LIFNR.
IF S_DATAB-LOW IS NOT INITIAL AND S_DATAB-HIGH IS INITIAL.
.
LS_SEL-VIEWFIELD = ‘DATAB’.
LS_SEL-OPERATOR = ‘LE’.
LS_SEL-VALUE = S_DATAB-LOW.
LS_SEL-AND_OR = ‘AND’.
APPEND LS_SEL TO LT_SEL.
LS_SEL-VIEWFIELD = 'DATBI'.
LS_SEL-OPERATOR = 'GE'.
LS_SEL-VALUE = S_DATAB-LOW.
LS_SEL-AND_OR = 'AND'.
APPEND LS_SEL TO LT_SEL.
ENDIF.
IF S_DATAB-LOW IS NOT INITIAL AND S_DATAB-HIGH IS NOT INITIAL.
.
LS_SEL-VIEWFIELD = ‘DATAB’.
LS_SEL-OPERATOR = ‘LE’.
LS_SEL-VALUE = S_DATAB-HIGH.
LS_SEL-AND_OR = ‘AND’.
APPEND LS_SEL TO LT_SEL.
LS_SEL-VIEWFIELD = 'DATBI'.
LS_SEL-OPERATOR = 'GE'.
LS_SEL-VALUE = S_DATAB-LOW.
LS_SEL-AND_OR = 'AND'.
APPEND LS_SEL TO LT_SEL.
ENDIF.
DATA:
LV_VIEW TYPE DD02V-TABNAME.
LV_VIEW = 'ZXXX'.
DATA:LT_FUN TYPE TABLE OF VIMEXCLFUN,
LS_FUN TYPE VIMEXCLFUN.
LS_FUN-FUNCTION = ‘KOPE’."复制按钮
APPEND LS_FUN TO LT_FUN. "隐藏按钮
LS_FUN-FUNCTION = ‘NEWL’."新建
APPEND LS_FUN TO LT_FUN.
CALL FUNCTION ‘VIEW_MAINTENANCE_CALL’
EXPORTING
ACTION = ‘U’
CORR_NUMBER = ' '
GENERATE_MAINT_TOOL_IF_MISSING = ' '
SHOW_SELECTION_POPUP = 'X'
VIEW_NAME = LV_VIEW
NO_WARNING_FOR_CLIENTINDEP = ' '
RFC_DESTINATION_FOR_UPGRADE = ' '
CLIENT_FOR_UPGRADE = ' '
VARIANT_FOR_SELECTION = ''
COMPLEX_SELCONDS_USED = 'X'
CHECK_DDIC_MAINFLAG = ' '
SUPPRESS_WA_POPUP = ' '
TABLES