Customer-exit是SAP ABAP的第二代增强技术, 它主要能实现三个方面的增强:
1. Function-exit(功能增强)
2. Menu-exit(菜单增强)
3. Screen-exit(屏幕增强)
Find Customer-exit
通常找增强点有三种方法, 建议用程序来找, 简单, 快捷, 准确
方法1: 搜关键字法(缺点:有时不能把所有点找到)
Step 1: 以TCODE: SE38为例, 对应的程序是SAPLS38E, 先进去程序的代码界面, 点系统工具栏的FIND按扭
Step 2: 查找关键字CALL CUSTOMER-FUNCTION
Step 3: 按确定后就能看到对应的结果了
方法2: 利用TCODE: CMOD来找
Step 1: CMOD-> Utilities-> SAP enhancements, 我们可以通过Package或Component name来找, 还可以选择要找的增强类型. (这里我用Component name来找, EXIT_PROGRAMNAME*, 我选所有的增强类型, 如果用Package来找可以找到同一个Package下的其他程序的增强点)
Step 2: 按F8后查看结果
方法3: 通过一个网上流传很广的程序去找, 下面是程序的代码
TABLES:tstc,tadir,modsapt,modact,trdir,tfdir,enlfdir,sxs_attrt,tstct. DATA : jtab LIKE tadir OCCURS 0 WITH HEADER LINE. DATA : field1(30). DATA : v_devclass LIKE tadir-devclass. PARAMETERS : p_tcode LIKE tstc-tcode, p_pgmna LIKE tstc-pgmna . DATA wa_tadir TYPE tadir. START-OF-SELECTION. IF NOT p_tcode IS INITIAL. SELECT SINGLE * FROM tstc WHERE tcode EQ p_tcode. ELSEIF NOT p_pgmna IS INITIAL. tstc-pgmna = p_pgmna. ENDIF. IF sy-subrc EQ 0. SELECT SINGLE * FROM tadir WHERE pgmid = 'R3TR' AND object = 'PROG' AND obj_name = tstc-pgmna. MOVE : tadir-devclass TO v_devclass. IF sy-subrc NE 0. SELECT SINGLE * FROM trdir WHERE name = tstc-pgmna. IF trdir-subc EQ 'F'. SELECT SINGLE * FROM tfdir WHERE pname = tstc-pgmna. SELECT SINGLE * FROM enlfdir WHERE funcname = tfdir-funcname. SELECT SINGLE * FROM tadir WHERE pgmid = 'R3TR' AND object = 'FUGR' AND obj_name EQ enlfdir-area. MOVE : tadir-devclass TO v_devclass. ENDIF. ENDIF. SELECT * FROM tadir INTO TABLE jtab WHERE pgmid = 'R3TR' AND object IN ('SMOD', 'SXSD') AND devclass = v_devclass. SELECT SINGLE * FROM tstct WHERE sprsl EQ sy-langu AND tcode EQ p_tcode. FORMAT COLOR COL_POSITIVE INTENSIFIED OFF. WRITE:/(19) 'Transaction Code - ', 20(20) p_tcode, 45(50) tstct-ttext. SKIP. IF NOT jtab[] IS INITIAL. WRITE:/(105) sy-uline. FORMAT COLOR COL_HEADING INTENSIFIED ON. SORT jtab BY object. DATA : wf_txt(60) TYPE c, wf_smod TYPE i , wf_badi TYPE i , wf_object2(30) TYPE c. CLEAR : wf_smod, wf_badi , wf_object2. LOOP AT jtab INTO wa_tadir. AT FIRST. FORMAT COLOR COL_HEADING INTENSIFIED ON. WRITE:/1 sy-vline, 2 'Enhancement/ Business Add-in', 41 sy-vline , 42 'Description', 105 sy-vline. WRITE:/(105) sy-uline. ENDAT. CLEAR wf_txt. AT NEW object. IF wa_tadir-object = 'SMOD'. wf_object2 = 'Enhancement' . ELSEIF wa_tadir-object = 'SXSD'. wf_object2 = ' Business Add-in'. ENDIF. FORMAT COLOR COL_GROUP INTENSIFIED ON. WRITE:/1 sy-vline, 2 wf_object2, 105 sy-vline. ENDAT. CASE wa_tadir-object. WHEN 'SMOD'. wf_smod = wf_smod + 1. SELECT SINGLE modtext INTO wf_txt FROM modsapt WHERE sprsl = sy-langu AND name = wa_tadir-obj_name. FORMAT COLOR COL_NORMAL INTENSIFIED OFF. WHEN 'SXSD'. " For BADis wf_badi = wf_badi + 1 . SELECT SINGLE text INTO wf_txt FROM sxs_attrt WHERE sprsl = sy-langu AND exit_name = wa_tadir-obj_name. FORMAT COLOR COL_NORMAL INTENSIFIED ON. ENDCASE. WRITE:/1 sy-vline, 2 wa_tadir-obj_name HOTSPOT ON, 41 sy-vline , 42 wf_txt, 105 sy-vline. AT END OF object. WRITE : /(105) sy-uline. ENDAT. ENDLOOP. WRITE:/(105) sy-uline. SKIP. FORMAT COLOR COL_TOTAL INTENSIFIED ON. WRITE:/ 'No.of Exits:' , wf_smod. WRITE:/ 'No.of BADis:' , wf_badi. ELSE. FORMAT COLOR COL_NEGATIVE INTENSIFIED ON. WRITE:/(105) 'No userexits or BADis exist'. ENDIF. ELSE. FORMAT COLOR COL_NEGATIVE INTENSIFIED ON. WRITE:/(105) 'Transaction does not exist'. ENDIF. AT LINE-SELECTION. DATA : wf_object TYPE tadir-object. CLEAR wf_object. GET CURSOR FIELD field1. CHECK field1(8) EQ 'WA_TADIR'. READ TABLE jtab WITH KEY obj_name = sy-lisel+1(20). MOVE jtab-object TO wf_object. CASE wf_object. WHEN 'SMOD'. SET PARAMETER ID 'MON' FIELD sy-lisel+1(10). CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN. WHEN 'SXSD'. SET PARAMETER ID 'EXN' FIELD sy-lisel+1(20). CALL TRANSACTION 'SE18' AND SKIP FIRST SCREEN. ENDCASE.
Step 2: 按F8查看结果
Customer-exit的实现
1. Function-exit的实现
Step 1: CMOD-> Create project
Step 2: Enhancement assignments
Step3: 保存, 激活
Step 4: Write enhancement code
Step 5: 测试结果
2. Menu-exit的实现
Step 1: CMOD-> Create project
Step 2: Enhancement assignments
Step 3: 保存, 激活
Step 4: Add the menu test
Step 5: Write the enhancement code and activate it
Step 6: 测试结果
3. Screen-exit的实现
现在我对IW22增加一个子屏幕
STEP 1: 找触发点
程序SAPLIQS0里面screen太多了, 有些screen少的程序可以直接看flow logic来查看customer subscreen area
来判断屏幕的逻辑, 同时可以根据语句call customer-subscreen来判断, 当然debug也可以.
这里还是直接用搜索的方法来找出口吧
首先找到程序的Package:
通过程序RPR_ABAP_SOURCE_SCAN去查找语句call customer-subscreen
这里找出了5个exit, 我这里只截了其中一个的图
注意PBO事件里call的前面有个MODULE USER0002_OUTPUT_O90
PAI事件里call的后面有个MODULE USER0002_INPUT_I90
在PBO那个module里面打个断点, 5个exit都打
然后运行TCODE IW22输入notification number后按回车
可以看到, 程序在user0001断下来了.
进入subroutine user_exit_008_f90就可以看到exit EXIT_SAPMIWO0_008了.
按两下F6, 我们可以看到customer subscreen的程序和屏幕号
Step 2: CMOD建Project, assign exit QQMA0001, 激活.
Step 3: 到表QMEL的include structure CI_QMEL那里增加两个field
Step 4: 到目标screen去建需要的field
Step 5: 定义全局变量(SAPLXQQM->LXQQMTOP->ZXQQMTOP)
Step 6: 到ZXQQMU07去写两句代码
Step 7: 到ZXQQMU08去写两句代码, 顺便写上按钮触发事件(不知道为什么写在9100的PAI没有反应)
Step 8: 测试一下, 当我按下button时, 出现Zero test后, 又出现了另一条Error message Requested function Z8ZE is not available here.
我Debug这条message的位置附近发现程序有一个select 表T158F的过程.
下面是ABAP stack
Step 9: Google一下这个表, 发现这里有一个screen control的概念, 到TCODE VFBS里对表T158F和表T158增加一条新纪录(PM模块好几个TCODE的FCODE增强都需要这一步, FCODE最好是以Z8或Z9开头的四位字符, 这个namespace可以在report RDDKOR54查得到)
(这里有个链接有比较详细的解释: http://scn.sap.com/message/374999 )
表T158F:
表T158:
到此为止, 增强做完了
Step10: 效果图
P.S. 1: Clear SY-UCOMM的问题
留意到我step 7的那段代码
IF sy-ucomm = 'Z8ZE'. MESSAGE 'Zero test' TYPE 'I'. ENDIF.
其实这样写并不是很恰当, 我之前留意到更多前辈是这样写的
DATA: lv_ucomm TYPE sy_ucomm. clear lv_ucomm. lv_ucomm = sy-ucomm. CLEAR sy-ucomm. IF lv_ucomm = 'Z8ZE'. MESSAGE 'Zero test' TYPE 'I'. ENDIF.
之前一直不知道这样写有什么作用, 现在知道了, 就我这个例子而言, 当我按了Test那个按钮后, 就会弹出'Zero test'的message, 但当我放大或缩小当前session的窗口后, message又再一次弹出来, 这是证明了像放大或缩小窗口这种操作并不会重置function code, function code还是之前操作那个, 该走的逻辑还是会走...
过了几天后, Palm童鞋发现这个message在放大缩小窗口时还是会弹出来, 我debug了program, 发现在customer subscreen的逻辑走完后, 回到上一层的subsreen, sy-ucomm居然还是'Z8ZE', 这是什么问题还搞不清楚.
我想试一下在这一层清掉sy-ucomm, 看能否解决重复弹message的问题
首先修改一下customer-exit的代码
然后在7212这个Screen这一层加上隐式增强代码
看看ABAP stack
最后问题顺利解决
P.S. 2: IW22的screen配置
IW22的屏幕增强还和SPRO的配置有关, 配置路径SPRO->Plant Maintenance and Customer Service->Maintenance and Service Processing->Maintenance and Service Notifications->Notification Creation->Notification Types->Set screen Templates for notification type.
在这里我对M1类型增加了一个tab Zero test, 之前的增强是在tab Notification 1里面做的
这里可以把期中一个subscreen area配成Customer subscreen, 如果没有配的话之前的增强就不会成立, 即使加断点也不会跑那一段程序