今天做一个需求,需要在自己的程序中调用SM30,本想着直接SUBMIT,或者是CALL TRANSFORMATION,但此SM30对应的程序是程序池,测试了一下,不知应该如何调用,而使用SUBMIT时,得把表维护创建成事务码,并且用户还得申请此事务码的权限,项目上管理事务太严,申请事务码太麻烦,所以此方法也不太好,最后找到一个调用VIEW_MAINTENANCE_CALL,使用此函数可以相当于调用SM30,功能应该比直接SUBMIT还多,
并且重要的是跳过了SM30事务码的权限检查。
在LT_VIMSELLIST中可以加入表维护筛选条件。使用中如下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
DATA: L_VIEW_NAME LIKE DD02V-TABNAME. DATA: LS_VIMSELLIST LIKE VIMSELLIST, LT_VIMSELLIST LIKE TABLE OF VIMSELLIST. IF P_CHK41 = 'X'. L_VIEW_NAME = 'ZSDT0226_CONF'. ELSEIF P_CHK42 = 'X'. L_VIEW_NAME = 'ZSDT0226_CONF1'. ELSEIF P_CHK43 = 'X'. L_VIEW_NAME = 'ZSDT0226_CONF2'. ENDIF. * GS_VIMSELLIST-VIEWFIELD = 'MATNR'. * GS_VIMSELLIST-OPERATOR = 'EQ'. * GS_VIMSELLIST-VALUE = GS_ZMM_MAT_DESC-MATNR. * GS_VIMSELLIST-AND_OR = 'OR'. * APPEND LS_VIMSELLIST TO LT_VIMSELLIST. * CALL FUNCTION 'VIEW_MAINTENANCE_CALL' EXPORTING ACTION = 'U' VIEW_NAME = L_VIEW_NAME TABLES DBA_SELLIST = LT_VIMSELLIST 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. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. |
同理使用函数VIEWCLUSTER_MAINTENANCE_CALL,可调用SM34的功能,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
FORM FRM_CONFIG_SET. DATA: L_VIEWCLUSTER_NAME LIKE VCLDIR-VCLNAME. L_VIEWCLUSTER_NAME = 'ZFI_REPORT_627'. CALL FUNCTION 'VIEWCLUSTER_MAINTENANCE_CALL' EXPORTING VIEWCLUSTER_NAME = L_VIEWCLUSTER_NAME MAINTENANCE_ACTION = 'U' * TABLES * DBA_SELLIST = LT_VIMSELLIST EXCEPTIONS CLIENT_REFERENCE = 1 FOREIGN_LOCK = 2 VIEWCLUSTER_NOT_FOUND = 3 VIEWCLUSTER_IS_INCONSISTENT = 4 MISSING_GENERATED_FUNCTION = 5 NO_UPD_AUTH = 6 NO_SHOW_AUTH = 7 OBJECT_NOT_FOUND = 8 NO_TVDIR_ENTRY = 9 NO_CLIENTINDEP_AUTH = 10 INVALID_ACTION = 11 SAVING_CORRECTION_FAILED = 12 SYSTEM_FAILURE = 13 UNKNOWN_FIELD_IN_DBA_SELLIST = 14 MISSING_CORR_NUMBER = 15 OTHERS = 16. ENDFORM. "FRM_CONFIG_SET |
完整的代码,可参看标准程序:WFMCVSTART
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
*&---------------------------------------------------------------------* *& Report WFMCVSTART * *& * *&---------------------------------------------------------------------* *& * *& * *&---------------------------------------------------------------------* REPORT WFMCVSTART . constants: c_show(1) type c value 'S', c_update(1) type c value 'U', c_true(1) type c value 'X', c_false(1) type c value ' '. data: l_action like c_true, lt_sellist like vimsellist occurs 5 with header line. parameters: p_vclust like tvdir-tabname, p_view like tvdir-tabname. selection-screen skip. parameters: p_show radiobutton group GR1 default 'X', p_update radiobutton group GR1. selection-screen skip. parameters: p_par1 like RSSTCD-para_field, p_val1 like rsstcd-para_value, p_par2 like RSSTCD-para_field, p_val2 like rsstcd-para_value, p_par3 like RSSTCD-para_field, p_val3 like rsstcd-para_value, p_par4 like RSSTCD-para_field, p_val4 like rsstcd-para_value, p_par5 like RSSTCD-para_field, p_val5 like rsstcd-para_value. * build selection list if p_par1 ne space. LT_SELLIST-VIEWFIELD = p_par1. lt_sellist-operator = 'EQ'. lt_sellist-value = p_val1. append lt_sellist. endif. if p_par2 ne space. LT_SELLIST-VIEWFIELD = p_par2. lt_sellist-operator = 'EQ'. lt_sellist-value = p_val2. append lt_sellist. endif. if p_par3 ne space. LT_SELLIST-VIEWFIELD = p_par3. lt_sellist-operator = 'EQ'. lt_sellist-value = p_val3. append lt_sellist. endif. if p_par4 ne space. LT_SELLIST-VIEWFIELD = p_par4. lt_sellist-operator = 'EQ'. lt_sellist-value = p_val4. append lt_sellist. endif. if p_par5 ne space. LT_SELLIST-VIEWFIELD = p_par5. lt_sellist-operator = 'EQ'. lt_sellist-value = p_val5. append lt_sellist. endif. * determine action if p_show eq c_true. l_action = c_show. else. l_action = c_update. endif. * viewcluster if p_vclust ne space. CALL FUNCTION 'VIEWCLUSTER_MAINTENANCE_CALL' EXPORTING VIEWCLUSTER_NAME = p_vclust MAINTENANCE_ACTION = l_action TABLES DBA_SELLIST = lt_sellist EXCEPTIONS CLIENT_REFERENCE = 1 FOREIGN_LOCK = 2 VIEWCLUSTER_NOT_FOUND = 3 VIEWCLUSTER_IS_INCONSISTENT = 4 MISSING_GENERATED_FUNCTION = 5 NO_UPD_AUTH = 6 NO_SHOW_AUTH = 7 OBJECT_NOT_FOUND = 8 NO_TVDIR_ENTRY = 9 NO_CLIENTINDEP_AUTH = 10 INVALID_ACTION = 11 SAVING_CORRECTION_FAILED = 12 SYSTEM_FAILURE = 13 UNKNOWN_FIELD_IN_DBA_SELLIST = 14 MISSING_CORR_NUMBER = 15 OTHERS = 16. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. else. * view CALL FUNCTION 'VIEW_MAINTENANCE_CALL' EXPORTING ACTION = l_action VIEW_NAME = p_view TABLES DBA_SELLIST = lt_sellist 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 OTHERS = 14. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. endif. |
1.RANGES值
如果SM30,SM34调用时查询 条件是RANGES值 ,或者是选择屏幕SELECT-OPTIONS的参数值 时,可以使用函数 转有查询 条件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
DATA: G_FIELDNAME TYPE VIMSELLIST-VIEWFIELD. SELECT-OPTIONS: S_WERKS FOR ZRTCO005A-WERKS, S_MATNR FOR ZRTCO005A-MATNR . G_FIELDNAME = 'WERKS'. CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST' EXPORTING FIELDNAME = G_FIELDNAME APPEND_CONJUNCTION = 'AND' TABLES SELLIST = GT_SELLIST RANGETAB = S_WERKS. G_FIELDNAME = 'MATNR'. CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST' EXPORTING FIELDNAME = G_FIELDNAME APPEND_CONJUNCTION = 'AND' TABLES SELLIST = GT_SELLIST RANGETAB = S_MATNR. |
2.带查询条件下的SM34登陆
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
*&********************************************************************* *& PROGRAM NAME : ZTEST1 *& Module Name : *& Apply Author : *& Author : *& Started on : 2019-06-01 *& Transaction : ZTEST1 *& Program type : Report *& Program ID : ZTEST1 *& Program Description : 功能描述。。。。。。 *&*&******************************************************************* *& REVISION LOG * *& * *& LOG# DATE AUTHOR DESCRIPTION * *& ---- ---- ------ ----------- * *& 0001 2019-06-01 XXX Initial Creation *&********************************************************************* REPORT ZTEST1. TABLES: T001. DATA: LS_VIMSELLIST LIKE VIMSELLIST, LT_VIMSELLIST LIKE TABLE OF VIMSELLIST, LT_VCL_SEL_LIST TYPE VCLTY_SELLIST_TABLE, LS_VCL_SEL_LIST TYPE LINE OF VCLTY_SELLIST_TABLE. DATA: LS_SEL_LIST LIKE LINE OF LS_VCL_SEL_LIST-SELLIST. DATA: L_FIELDNAME TYPE VIMSELLIST-VIEWFIELD. DATA: L_VIEWCLUSTER_NAME LIKE VCLDIR-VCLNAME. SELECT-OPTIONS: S_BUKRS FOR T001-BUKRS. LS_VCL_SEL_LIST-OBJECT = 'ZTRV9040_2'. L_FIELDNAME = 'BUKRS'. CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST' EXPORTING FIELDNAME = L_FIELDNAME APPEND_CONJUNCTION = 'AND' TABLES SELLIST = LT_VIMSELLIST RANGETAB = S_BUKRS. LS_VCL_SEL_LIST-SELLIST = LT_VIMSELLIST. APPEND LS_VCL_SEL_LIST TO LT_VCL_SEL_LIST. L_VIEWCLUSTER_NAME = 'ZTRVC_CONFIG'. CALL FUNCTION 'VIEWCLUSTER_MAINTENANCE_CALL' EXPORTING VIEWCLUSTER_NAME = L_VIEWCLUSTER_NAME MAINTENANCE_ACTION = 'U' TABLES * DBA_SELLIST = LT_VIMSELLIST DBA_SELLIST_CLUSTER = LT_VCL_SEL_LIST EXCEPTIONS CLIENT_REFERENCE = 1 FOREIGN_LOCK = 2 VIEWCLUSTER_NOT_FOUND = 3 VIEWCLUSTER_IS_INCONSISTENT = 4 MISSING_GENERATED_FUNCTION = 5 NO_UPD_AUTH = 6 NO_SHOW_AUTH = 7 OBJECT_NOT_FOUND = 8 NO_TVDIR_ENTRY = 9 NO_CLIENTINDEP_AUTH = 10 INVALID_ACTION = 11 SAVING_CORRECTION_FAILED = 12 SYSTEM_FAILURE = 13 UNKNOWN_FIELD_IN_DBA_SELLIST = 14 MISSING_CORR_NUMBER = 15 OTHERS = 16. |
3.表维护常用事件
另一个常用事务是21,用于在改变字段值回车后触发(ZCHANGED_FINISH),可用来更新一些隐藏字段,字段文本等信息
可以在before_save事件中,将新增的数据存到一个全局变量的gt_cust_table内表中。
1 2 3 4 5 6 |
FORM before_save. LOOP AT total. IF <action> = neuer_eintrag OR <action> = aendern. APPEND CORRESPONDING #( <vim_total_struc> ) TO gt_cust_table. ENDIF. ENDLOOP. |
after_save事件中,基于这些数据做进一步的处理。
1 2 3 |
FORM after_save. modify z_cust_table from gt_cust_table. ENDFORM. |
全局变量是定义在维护视图对应的Funtion Group的TOP文件中
1 2 3 4 5 6 7 |
FUNCTION-POOL ztest_cfm MESSAGE-ID sv. DATA gt_cust_table TYPE ztest_t_table. * INCLUDE LFINS_CFIN_CGLCTLD... " Local class definition INCLUDE lsvimdat . "general data decl. INCLUDE lfins_cfin_cglctlt00 . "view rel. data dcl. |
before_delete事件中,做一些业务校验逻辑,以判断是否可以删除数据等等
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
FORM before_delete. DATA lv_delete_row TYPE abap_bool. LOOP AT extract. IF <xact> <> neuer_eintrag AND <xmark> = markiert. <xmark> = nicht_markiert. MODIFY extract. lv_delete_row = abap_true. ENDIF. ENDLOOP. IF lv_delete_row = abap_true. MESSAGE 'you cannot delete entries' TYPE 'E'. ENDIF. ENDFORM. |
另一个常用事务是21,用于在改变字段值回车后触发(ZCHANGED_FINISH),可用来更新一些隐藏字段,字段文本等信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
FORM ZCHANGED_FINISH. DATA: L_FIELDNAMET TYPE AS4TEXT. FIELD-SYMBOLS: <F> TYPE ZTRV3023_25. BREAK YANGSEN. IF X_HEADER-MAINTVIEW = 'ZTRV3023_25'. ASSIGN <TABLE1> TO <F>. IF <F>-TABNAME IS NOT INITIAL AND <F>-FIELDNAME IS NOT INITIAL. SELECT SINGLE DDTEXT INTO L_FIELDNAMET FROM DD03VT WHERE TABNAME = <F>-TABNAME AND FIELDNAME = <F>-FIELDNAME AND DDLANGUAGE = '1'. <F>-FIELDNAMET = L_FIELDNAMET. ENDIF. ENDIF. UNASSIGN <F>. ENDFORM. |