SAP ABAP SM30 自定义检查

SAP ABAP SM30 自定义检查

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 LISTE_AFTER_LOOP.
    MODULE LISTE_AFTER_LOOP_ADD."增加按钮删除时检查

&---------------------------------------------------------------------
*& 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 TO LS_ZXXXX.

    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.

  • 原标准MODULE LISTE_AFTER_LOOP
    ** Table-control !!!
    PERFORM FRM_LISTE_AFTER_LOOP.
    ENDMODULE. " LISTE_AFTER_LOOP_ADD INPUT

----------------------------------------------------------------------
***INCLUDE LZFGSD4002F01 .
----------------------------------------------------------------------
&---------------------------------------------------------------------
*& Form FRM_CHECK_DELE
&---------------------------------------------------------------------

  • –> p1 text
  • <-- p2 text
    ----------------------------------------------------------------------
    FORM FRM_CHECK_DELE .

FIELD-SYMBOLS:
TYPE ANY.
LOOP AT extract.
CHECK EQ markiert.
ASSIGN COMPONENT ‘PZZT’ OF STRUCTURE TO .
IF IS NOT INITIAL.
GV_FLG = ‘X’.
MESSAGE S001(00) WITH ‘选择数据已批准,不允许删除’ DISPLAY LIKE ‘E’.
RETURN.
ENDIF.
ENDLOOP.
ENDFORM. " FRM_CHECK_DELE
&---------------------------------------------------------------------
*& Form FRM_LISTE_AFTER_LOOP
&---------------------------------------------------------------------

  • –> p1 text
  • <-- p2 text
    ----------------------------------------------------------------------
    FORM FRM_LISTE_AFTER_LOOP .
    IF VIM_TABCTRL_ACTIVE NE SPACE.
    IF NEXTLINE NE -TOP_LINE.
    NEXTLINE = -TOP_LINE.
    ENDIF.
    ENDIF.
    ** Table-control !!!
    IF DESTPAGE NE 0.
    NEXTLINE = DESTPAGE. CLEAR DESTPAGE.
    ENDIF.
  • IF TEMPORAL_DELIMITATION_HAPPENED NE SPACE.
    IF VIM_SPECIAL_MODE NE VIM_UPGRADE AND
    VIM_SPECIAL_MODE NE VIM_DELIMIT AND
    TEMPORAL_DELIMITATION_HAPPENED NE SPACE.
    PERFORM AFTER_TEMPORAL_DELIMITATION.
    CLEAR: TEMPORAL_DELIMITATION_HAPPENED, VIM_OLD_VIEWKEY.
    TRANSLATE VIM_NO_MAINKEY_EXISTS USING VIM_NO_MKEY_NOT_PROCSD_PATT.
    ENDIF.
    IF FUNCTION IN MARK_FUNCTIONS AND MARK_EXTRACT EQ 0.
    MESSAGE S026(SV). "Bitte vorher Einträge markieren
    LEAVE SCREEN.
    ENDIF.
    PERFORM UPDATE_STATUS.
    IF VIM_SINGLE_ENTRY_FUNCTION EQ ‘INS’ AND
    VIM_SINGLE_ENTRY_INS_KEY_INPUT NE SPACE AND
    STATUS-ACTION EQ HINZUFUEGEN.
    PERFORM VIM_SINGLE_ENTRY_FILL_SELLIST.
    ENDIF.
    CLEAR: VIM_NEXT_SCREEN, VIM_LEAVE_SCREEN.
    CASE FUNCTION.
    WHEN ‘ADDR’.
    PERFORM LISTE_ADDRESS_MAINTAIN.
    WHEN ‘AEND’.
    PERFORM ANZG_TO_AEND.
    WHEN ‘ALCO’.
    PERFORM SELEKTIERE USING TRANSPORTIEREN.
    WHEN ‘ALMK’.
    PERFORM SELEKTIERE USING MARKIERT.
    WHEN ‘ALNC’.
    PERFORM SELEKTIERE USING SPACE.
    WHEN ‘ALOE’.
    PERFORM SELEKTIERE USING GELOESCHT.
    WHEN ‘ALNW’.
    PERFORM SELEKTIERE USING NEUER_EINTRAG.
    WHEN ‘ANZG’.
    PERFORM AEND_TO_ANZG.
    VIM_NEXT_SCREEN = 0. VIM_LEAVE_SCREEN = ‘X’.
    WHEN ‘ATAB’.
    VIM_NEXT_SCREEN = 0. VIM_LEAVE_SCREEN = ‘X’.
    WHEN ‘BACK’.
    IF STATUS-MODE EQ LIST_BILD AND STATUS-DATA EQ GESAMTDATEN OR
    VIM_SINGLE_ENTRY_FUNCTION NE SPACE.
    VIM_NEXT_SCREEN = 0. VIM_LEAVE_SCREEN = ‘X’.
    ELSE.
    PERFORM LISTE_BACK.
    ENDIF.
    WHEN ‘BCCH’. "change fix bc-set fields
    PERFORM VIM_CHNG_FIX_FLDS.
    WHEN ‘BCSH’. " show fix bc-set fields
    PERFORM VIM_BC_SHOW_FIX_FLDS.
    WHEN ‘BCON’.
    PERFORM SELEKTIERE USING BCSET_ONLY. "show only data from bcset
    WHEN ‘CMPO’.
    PERFORM UPGRADE USING ‘O’.
    WHEN ‘CMPR’.
    PERFORM UPGRADE USING ‘R’.
    WHEN ‘COMP’.
    PERFORM UPGRADE USING SPACE.
    WHEN ‘DELE’.
    PERFORM LOESCHEN.
    IF REPLACE_MODE NE SPACE.
    -MK_TO = MARK_TOTAL.
    -MK_XT = MARK_EXTRACT.
    VIM_NEXT_SCREEN = 0. VIM_LEAVE_SCREEN = ‘X’.
    ENDIF.
    WHEN ‘DELM’.
    PERFORM DELIMITATION.
    WHEN ‘DETM’. "UFdetail
    PERFORM DETAIL_MARKIERTE.
    WHEN ‘DETA’.
    PERFORM DETAILBILD.
    WHEN ‘ENDE’.
    VIM_NEXT_SCREEN = 0. VIM_LEAVE_SCREEN = ‘X’.
    WHEN ‘EXPA’.
  • 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
    PERFORM SHOW_FUNCTION_DOCU.
  • WHEN ‘GPRF’. "UF Profile
  • choose profile
  •  CLEAR: -prof_found, vim_pr_records.
    
  •  PERFORM get_profiles USING -prof_found.
    
    WHEN ‘KOPE’.
    COUNTER = 0.
    VIM_GUID_COPY = ‘X’.
    PERFORM KOPIERE.
    WHEN ‘KOPF’.
    SET SCREEN 0. LEAVE SCREEN.
    WHEN ‘LANG’. "SW Texttransl
    PERFORM VIM_SET_LANGUAGES.
    WHEN ‘MKAL’.
    PERFORM MARKIERE_ALLE USING MARKIERT.
    WHEN ‘MKBL’.
    PERFORM MARKIERE_BLOCK.
    WHEN ‘MKEZ’.
    PERFORM LISTE_MARKIERE.
    WHEN ‘MKLO’.
    PERFORM MARKIERE_ALLE USING NICHT_MARKIERT.
    WHEN ‘NEWL’.
    PERFORM HINZUFUEGEN.
    WHEN ‘NEXT’.
    PERFORM NAECHSTER.
    WHEN ‘ORDR’.
    PERFORM ORDER_ADMINISTRATION.
    WHEN ‘ORGI’.
    PERFORM ORIGINAL_HOLEN.
    WHEN ‘POSI’.
    PERFORM POPUP_POSITIONIEREN.
    WHEN ‘PREV’.
    PERFORM VORIGER.
    WHEN ‘PRMO’.
  • 4.6A: obsolete, left for individual status only
    PERFORM LIST_ALV.
    WHEN ‘PROT’.
    PERFORM LOGS_ANALYSE.
    WHEN ‘PRST’.
    PERFORM LIST_ALV.
    WHEN 'P+ '.
    PERFORM BLAETTERN.
    WHEN 'P- '.
    PERFORM BLAETTERN.
    WHEN 'P++ '.
    PERFORM BLAETTERN.
    WHEN 'P-- '.
    PERFORM BLAETTERN.
    WHEN ‘REPL’.
    PERFORM REPLACE.
    WHEN ‘SAVE’.
    IF STATUS-ACTION EQ HINZUFUEGEN.
  •   SORT EXTRACT BY .  "not nec. anymore
      -FIRSTLINE = FIRSTLINE = -CUR_LINE = L = 1.
    ENDIF.
    VIM_NEXT_SCREEN = 0. VIM_LEAVE_SCREEN = 'X'.
    
    WHEN ‘SCRF’.
    PERFORM VIM_SAPSCRIPT_FORM_MAINT.
    WHEN ‘SEAR’.
    PERFORM SUCHEN.
    WHEN ‘SELU’.
    PERFORM SELEKTIERE USING AENDERN.
  • WHEN ‘SPRF’. "UF Profile
  • show chosen profile
  •  PERFORM get_profiles USING -prof_found.
    
    WHEN ‘TEXT’. "SW Texttransl
    PERFORM VIM_MULTI_LANGU_TEXT_MAINT.
    WHEN ‘TREX’.
    MOVE GELOESCHT TO CORR_ACTION.
    PERFORM UPDATE_CORR.
    IF REPLACE_MODE NE SPACE.
    -MK_TO = MARK_TOTAL.
    -MK_XT = MARK_EXTRACT.
    VIM_NEXT_SCREEN = 0. VIM_LEAVE_SCREEN = ‘X’.
    ENDIF.
    WHEN ‘TRIN’.
    MOVE HINZUFUEGEN TO CORR_ACTION.
    PERFORM UPDATE_CORR.
    IF REPLACE_MODE NE SPACE.
    -MK_TO = MARK_TOTAL.
    -MK_XT = MARK_EXTRACT.
    VIM_NEXT_SCREEN = 0. VIM_LEAVE_SCREEN = ‘X’.
    ENDIF.
    WHEN ‘TRSP’.
    IF X_HEADER-CURSETTING NE SPACE AND
    X_HEADER-FLAG EQ VIM_TRANSPORT_DENIED.
    X_HEADER-FLAG = X_HEADER-CURSETTING.
    TRANSLATE X_HEADER-FLAG USING ‘X YX’.
    MODIFY X_HEADER INDEX 1. "#EC *
    ENDIF.
    VIM_NEXT_SCREEN = 0. VIM_LEAVE_SCREEN = ‘X’.
    WHEN ‘UNDO’.
  • PERFORM 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
  • activate chosen profile
  •  PERFORM activate_profile CHANGING -prof_found.
    MESSAGE S175(SV).
    
    WHEN ’ '.
    IF VIM_SINGLE_ENTRY_FUNCTION EQ ‘INS’ AND
    STATUS-ACTION EQ HINZUFUEGEN.
    PERFORM LISTE_BACK.
    ENDIF.
    IF REPLACE_MODE NE SPACE.
    VIM_NEXT_SCREEN = 0. VIM_LEAVE_SCREEN = ‘X’.
    ENDIF.
    WHEN OTHERS.
    IF VIM_CALLED_BY_CLUSTER NE SPACE.
    CALL FUNCTION ‘VIEWCLUSTER_NEXT_ACTION’
    IMPORTING
    LEAVE_SCREEN = VIM_LEAVE_SCREEN
    CHANGING
    FCODE = FUNCTION.
    IF VIM_LEAVE_SCREEN NE SPACE.
    VIM_NEXT_SCREEN = 0.
    ENDIF.
    ENDIF.
    ENDCASE.
    IF VIM_LEAVE_SCREEN NE SPACE.
    CLEAR: VIM_LEAVE_SCREEN, VIM_ACT_DYNP_VIEW.
    SET SCREEN VIM_NEXT_SCREEN. LEAVE SCREEN.
    ENDIF.

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
    DBA_SELLIST = LT_SEL "因设定SEL,新建数据时也会限定
    EXCL_CUA_FUNCT = LT_FUN
    EXCEPTIONS
    CLIENT_REFERENCE = 1
    FOREIGN_LOCK = 2
    INVALID_ACTION = 3
    NO_CLIENTINDEPENDENT_AUTH = 4
    NO_DATABASE_FUNCTION = 5
    NO_EDITOR_FUNCTION = 6
    NO_SHOW_AUTH = 7
    NO_TVDIR_ENTRY = 8
    NO_UPD_AUTH = 9
    ONLY_SHOW_ALLOWED = 10
    SYSTEM_FAILURE = 11
    UNKNOWN_FIELD_IN_DBA_SELLIST = 12
    VIEW_NOT_FOUND = 13
    MAINTENANCE_PROHIBITED = 14
    OTHERS = 15.
    IF SY-SUBRC <> 0.
  • Implement suitable error handling here
    ENDIF.

你可能感兴趣的:(sap,abap)