共计 10824 个字符,预计需要花费 28 分钟才能阅读完成。
咱们晓得 ABAP 零碎里有一个有用的工具,事物码 SE10,输出用户名称,能够查看该用户在本零碎上创立的传输申请 (Transport Request) 列表:
点击 Display 按钮,能看到用户名 WANGJER 上面的所有传输申请:
每个传输申请能够开展,查看外面具体蕴含的 ABAP 对象。很多 ABAP 对象,比方上图蓝色高亮的 ABAP 类办法,双击之后,能够用 ABAP 编辑器关上这些办法,查看其实现源代码。
本教程咱们曾经用了几个步骤的篇幅,介绍了 ABAP ALV 的开发步骤:
- 44. 27 行代码开发一个最简略的 SAP ALV 报表
- 45. 48 行代码给 ABAP ALV 报表的数据行削减色彩成果
- 46. 77 行代码实现 ABAP ALV 中的双击事件处理
- 47. SAP ABAP ALV 档次程序表如何应用双表头 (Multiple Headers) 进行数据输入
- 48. 如何在 SAP ABAP ALV 报表里以交通灯的形式显示某一列的值
- 49. 在弹出对话框窗口里显示 SAP ABAP ALV 列表
本文咱们来应用以前所学习的常识,入手开发一个相似 SE10 的工具。这个工具也是笔者理论工作中开发的一个工具,这里分享给各位 ABAP 学习者。
这个工具容许用户输出指定的用户名,执行之后,在 ALV 列表里列出该用户在该零碎创立的所有传输申请,并主动把传输申请里蕴含的 ABAP 对象 (包含 ABAP 类,ABAP DDIC 对象等等) 也显示进去,如下图所示:
单击上图的 ALV 行我的项目,同样能主动跳转到 ABAP 编辑器里,关上这些 ABAP 对象,成果如下图所示:
上面咱们介绍这个工具的具体设计思路,开发步骤和全副源代码。
这个工具的骨干程序很精简,代码如下,蕴含 4 个 ABAP include 程序。每个 ABAP include 程序负责实现一项特定的业务逻辑。通过将业务逻辑拆分到不同的 ABAP include 程序,使咱们工具实现的代码构造和逻辑更清晰,可读性更好。
骨干程序和 4 个 ABAP include 程序的 smc,代表 Social Media Cockpit,这是笔者过后参加的 CRM 我的项目的缩写。
zsmc_data
咱们在 SE38 里创立的 ABAP 程序,默认类型都是能够运行的报表,即 executable program
,如果要创立 include program
,从下拉列表里抉择对应的类型即可。
这个 include 的工作是定义所有须要在这个工具里应用到的 ABAP 变量:
ZSMC_TR
这个 include 的工作是从数据库表 e070
里读取出指定用户在以后 ABAP 零碎里创立的所有传输申请的 id,存储到 ABAP 内表 lt_trlist
里。
比方在笔者应用的 AG3 零碎上,我总共创立了 595 个传输申请:
e070
数据库表只保护了用户名和传输申请 id 之间的关系,如果咱们想晓得每个传输申请里蕴含了哪些 ABAP 开发对象,须要采取其余方法来查找。
ZSMC_PREPARE_DATA
这个 ABAP include 负责将 ZSMC_TR include 里编写的逻辑,即从 e070
数据库表里取出的 ABAP 传输申请 id 进行解析,取出每一个传输申请蕴含的 ABAP 对象。
解析操作通过 Function Module 实现,解析后果如下图所示:
上图函数的 Tables 参数 et_e071
,存储的就是传输申请里蕴含的不同类型的 ABAP 对象。这些 ABAP 对象的类型,通过字段 PGMID
和 OBJECT
进行辨别。
- R3TR.CLAS, 代表存储在传输申请里的是 ABAP 类名称
- LIMU.METH, 代表存储在传输申请里的是 ABAP 类的办法实现
ZSMC_ALV
负责 ABAP ALV 的数据显示和点击事件处理。
如图所示,咱们应用 Function Module REUSE_ALV_GRID_DISPLAY
来输入 ALV 报表。
这个函数有一个输出参数 i_callback_user_command
, 能够指定一个用户自定义的 subroutine,用于解决 ALV 的点击事件。
如下图所示,当咱们单击 ALV 报表某些能够点击的列时,咱们通过代码 123 行指定的 subroutine,ALV_USER_COMMAND
会主动被触发,在这个 subroutine 里咱们调用本人编写的另一个 subroutine display_object
,来实现主动关上对应的 ABAP 编辑器以查看的性能。
比方咱们单击下图红色的行我的项目 CL_ABAP_GIT_ISSUE_IMAGE_TOOL
,
从调试器里的函数上下文调用栈能看出,咱们编写的 subroutine ALV_USER_COMMAND
被调用,输出参数 ct_selfield
蕴含了被点击的行我的项目的索引 12,所以咱们能够从 ALV 报表的数据源,lt_dev_object 内表里,通过 READ TABLE INDEX XXX
的 ABAP 语句将该行我的项目的明细读取进去:
行我的项目 ABAP 对象的类型,通过输出参数 ct_selfield
的字段 fieldname
来辨别。如果字段名称为 TRKORR
, 阐明这个行我的项目是一个传输申请,此时调用第 150 行的工具函数 TR_PRESENT_REQUEST
来显示这个传输申请。
否则,阐明该行我的项目是一个一般的 ABAP 对象,此时调用能解决绝大多数 ABAP 对象显示性能的 RS_TOOL_ACCESS
来实现 ABAP 对象的显示操作。
ALV 报表里具体哪些列反对单击事件处理呢?只须要将传入函数 REUSE_ALV_GRID_DISPLAY
的输出参数 it_fieldcat
里蕴含的每一列对应的 hotspot
字段设置为 X
即可。
如下图所示,代码的语义就是,咱们冀望 OBJ_NAME
和 TRKORR
这两列,即对象名称和传输申请号可能反对单击操作。
这两个反对单击操作的列如下图所示,用户很容易辨别,因为其值下有一条下划线,显示成超链接的成果。
本例残缺的源代码如下:
主程序:
REPORT ZSMC_OBJECT_LIST.
PARAMETERS: user type usr02-bname DEFAULT sy-uname OBLIGATORY.
INCLUDE zsmc_data.
INCLUDE zsmc_tr.
INCLUDE zsmc_prepare_data.
INCLUDE zsmc_alv.
INITIALIZATION.
PERFORM init.
START-OF-SELECTION.
PERFORM fill_trlist.
PERFORM fill_data.
PERFORM alv_display.
ZSMC_DATA:
*&---------------------------------------------------------------------*
*& Include ZSMC_DATA
*&---------------------------------------------------------------------*
TYPES: begin of ty_dev_object,
obj_name TYPE string,
pgm_id TYPE char4,
object TYPE char4,
trkorr TYPE char20,
as4user TYPE char12,
as4date TYPE d,
as4time TYPE t,
as4text TYPE char60,
package TYPE tadir-devclass,
tech_name TYPE tadir-obj_name,
color TYPE lvc_t_scol,
END OF ty_dev_object.
TYPES: tt_dev_object TYPE STANDARD TABLE OF ty_dev_object WITH KEY obj_name pgm_id object trkorr.
DATA: lt_trkorr TYPE TABLE OF scwbtrkorr,
ls_trkorr LIKE LINE OF lt_trkorr,
lt_trlist TYPE string_table,
lt_e070 TYPE STANDARD TABLE OF SCWB_E070,
lt_e070t TYPE STANDARD TABLE OF SCWB_E07T,
lt_e070c TYPE STANDARD TABLE OF SCWB_E070C,
lt_e071 TYPE STANDARD TABLE OF SCWB_E071,
lt_e071k TYPE STANDARD TABLE OF SCWB_E071K,
lt_e070a TYPE STANDARD TABLE OF SCWB_E070A,
lt_dev_object TYPE tt_dev_object,
ls_dev_object TYPE ty_dev_object.
DATA: lv_col TYPE lvc_s_scol,
lt_coltab TYPE lvc_t_scol,
ls_color TYPE lvc_s_colo,
lt_ic TYPE string_table.
FIELD-SYMBOLS: <e071> LIKE LINE OF lt_e071,
<e070> LIKE LINE OF lt_e070,
<e070t> LIKE LINE OF lt_e070t.
ZSMC_TR:
*&---------------------------------------------------------------------*
*& Include ZSMC_TR
*&---------------------------------------------------------------------*
FORM fill_trlist.
PERFORM log USING 10 'Fetching Transport request from DB...'.
PERFORM add_tr USING user.
ENDFORM.
FORM add_tr USING name TYPE char12.
DATA: lt_e070 TYPE STANDARD TABLE OF e070.
FIELD-SYMBOLS:<line> TYPE e070.
SELECT trkorr as4user INTO CORRESPONDING FIELDS OF TABLE lt_e070 FROM e070 WHERE as4user = name.
LOOP AT lt_e070 ASSIGNING <line>.
APPEND <line>-trkorr TO lt_trlist.
ENDLOOP.
ENDFORM.
FORM log USING per TYPE i text TYPE string.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = per
text = text.
ENDFORM.
ZSMC_PREPARE_DATA:
*&---------------------------------------------------------------------*
*& Include ZSMC_PREPARE_DATA
*&---------------------------------------------------------------------*
FORM fill_data.
DATA: lv_tr TYPE string.
LOOP AT lt_trlist INTO lv_tr.
ls_trkorr-trkorr = lv_tr.
ls_trkorr-srcsyst = space.
APPEND ls_trkorr TO lt_trkorr.
ls_trkorr-srcsyst = lv_tr(3).
APPEND ls_trkorr TO lt_trkorr.
ENDLOOP.
CALL FUNCTION 'SCWB_GET_COMPL_REQUESTS_REM_40'
EXPORTING
iv_merge_object_lists = ' '
TABLES
it_request_numbers = lt_trkorr
et_e070 = lt_e070
et_e07t = lt_e070t
et_e070c = lt_e070c
et_e071 = lt_e071
et_e070a = lt_e070a
EXCEPTIONS
error_message = 0. "suppres
SORT lt_e070 BY trkorr.
SORT lt_e070t BY trkorr.
PERFORM log USING 50 'Analyzing object information from Transport request...'.
LOOP AT lt_e071 ASSIGNING <e071> WHERE object <> 'CORR' AND object <> 'AVAS' AND object <> 'PDWS' AND object <> 'DLCS' AND object <> 'CDAT'
AND object <> 'TDAT' AND object <> 'SMIM' AND object <> 'RELE' AND object <> 'MERG' AND object <> 'CLSD' AND object <> 'CPRO'
AND object <> 'CPUB' AND object <> 'CPRI' AND object <> 'DOCU' AND object <> 'SICF' AND object <> 'MESS' AND object <> 'PIFA'
AND object <> 'SHI6' AND object <> 'SHI3' AND object <> 'TABU' AND object <> 'VDAT'.
ls_dev_object-trkorr = <e071>-trkorr.
ls_dev_object-pgm_id = <e071>-pgmid.
ls_dev_object-object = <e071>-object.
ls_dev_object-obj_name = <e071>-obj_name.
READ TABLE lt_e070t ASSIGNING <e070t> WITH KEY trkorr = <e071>-trkorr BINARY SEARCH.
IF sy-subrc = 0.
ls_dev_object-as4text = <e070t>-as4text.
IF <e070t>-as4text CS 'Generated test transport'.
CONTINUE.
ENDIF.
ENDIF.
READ TABLE lt_e070 ASSIGNING <e070> WITH KEY trkorr = <e071>-trkorr BINARY SEARCH.
IF sy-subrc = 0.
ls_dev_object-as4user = <e070>-as4user.
ls_dev_object-as4date = <e070>-as4date.
ls_dev_object-as4time = <e070>-as4time.
ENDIF.
READ TABLE lt_e070t ASSIGNING <e070t> WITH KEY trkorr = <e071>-trkorr BINARY SEARCH.
IF sy-subrc = 0.
ls_dev_object-as4text = <e070t>-as4text.
ENDIF.
IF <e071>-object <> 'METH'.
ls_dev_object-tech_name = <e071>-obj_name.
ELSE.
PERFORM get_tech_name CHANGING ls_dev_object.
ENDIF.
APPEND ls_dev_object TO lt_dev_object.
ENDLOOP.
SORT lt_dev_object BY obj_name.
DELETE ADJACENT DUPLICATES FROM lt_dev_object COMPARING obj_name as4user as4text.
ENDFORM.
FORM get_tech_name CHANGING ls_dev_object TYPE ty_dev_object.
DATA: lt_temp TYPE string_table.
SPLIT ls_dev_object-obj_name AT space INTO TABLE lt_temp.
READ TABLE lt_temp INTO ls_dev_object-tech_name INDEX 1.
ENDFORM.
FORM init.
APPEND 'CRM_IC_APPL_INBOX' TO lt_ic.
APPEND 'CRM_IC_CMP_INBOX' TO lt_ic.
APPEND 'CRM_IC_CMP_BTX' TO lt_ic.
ls_color-col = '6'.
ls_color-int = '0'.
ls_color-inv = '0'.
lv_col-fname = 'OBJECT'.
lv_col-color = ls_color.
APPEND lv_col TO lt_coltab.
lv_col-fname = 'TRKORR'.
APPEND lv_col TO lt_coltab.
lv_col-fname = 'AS4USER'.
APPEND lv_col TO lt_coltab.
lv_col-fname = 'AS4DATE'.
APPEND lv_col TO lt_coltab.
lv_col-fname = 'AS4TIME'.
APPEND lv_col TO lt_coltab.
lv_col-fname = 'AS4TEXT'.
APPEND lv_col TO lt_coltab.
ENDFORM.
ZSMC_ALV:
*&---------------------------------------------------------------------*
*& Include ZSMC_ALV
*&---------------------------------------------------------------------*
DATA ls_layout TYPE slis_layout_alv.
DATA lt_sort TYPE slis_t_sortinfo_alv.
DATA gt_fieldcat TYPE SLIS_T_FIELDCAT_ALV.
DATA lt_event TYPE SLIS_T_EVENT.
data ls_event type slis_alv_event.
FORM alv_build_fieldcat CHANGING ct_fieldcat TYPE slis_t_fieldcat_alv.
DATA lv_col_pos TYPE i.
DATA ls_fieldcat TYPE slis_fieldcat_alv.
CLEAR ct_fieldcat.
lv_col_pos = 1.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = lv_col_pos.
ls_fieldcat-fieldname = 'OBJ_NAME'.
ls_fieldcat-key = 'X'.
ls_fieldcat-hotspot = 'X'.
APPEND ls_fieldcat TO ct_fieldcat.
ADD 1 TO lv_col_pos.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = lv_col_pos.
ls_fieldcat-fieldname = 'OBJECT'.
ls_fieldcat-rollname = 'CHAR4'.
ls_fieldcat-reptext_ddic = 'Object TYPE'.
APPEND ls_fieldcat TO ct_fieldcat.
ADD 1 TO lv_col_pos.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = lv_col_pos.
ls_fieldcat-fieldname = 'TRKORR'.
ls_fieldcat-rollname = 'CHAR20'.
ls_fieldcat-hotspot = 'X'.
ls_fieldcat-reptext_ddic = 'TR number'.
APPEND ls_fieldcat TO ct_fieldcat.
ADD 1 TO lv_col_pos.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = lv_col_pos.
ls_fieldcat-fieldname = 'AS4USER'.
ls_fieldcat-rollname = 'CHAR12'.
ls_fieldcat-reptext_ddic = 'Developer'.
APPEND ls_fieldcat TO ct_fieldcat.
ADD 1 TO lv_col_pos.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = lv_col_pos.
ls_fieldcat-reptext_ddic = 'Date'.
ls_fieldcat-fieldname = 'AS4DATE'.
APPEND ls_fieldcat TO ct_fieldcat.
ADD 1 TO lv_col_pos.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = lv_col_pos.
ls_fieldcat-fieldname = 'AS4TIME'.
ls_fieldcat-reptext_ddic = 'Time'.
APPEND ls_fieldcat TO ct_fieldcat.
ADD 1 TO lv_col_pos.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = lv_col_pos.
ls_fieldcat-fieldname = 'AS4TEXT'.
ls_fieldcat-reptext_ddic = 'Description'.
APPEND ls_fieldcat TO ct_fieldcat.
ADD 1 TO lv_col_pos.
ENDFORM. "alv_build_fieldcat
FORM alv_build_layout USING es_layout TYPE slis_layout_alv.
es_layout-colwidth_optimize = 'X'.
es_layout-zebra = 'X'.
es_layout-coltab_fieldname = 'COLOR'.
ENDFORM. "alv_build_layout
*&---------------------------------------------------------------------*
*& Form alv_build_sorting
*&---------------------------------------------------------------------*
FORM alv_build_sorting USING et_sort TYPE slis_t_sortinfo_alv.
DATA ls_sort LIKE LINE OF et_sort.
CLEAR ls_sort.
ls_sort-fieldname = 'OBJ_NAME'.
ls_sort-up = 'X'.
APPEND ls_sort TO et_sort.
ENDFORM.
FORM html_top_of_page USING document TYPE REF TO cl_dd_document.
DATA: text TYPE sdydo_text_element.
text = '用户传输申请查看小工具'.
CALL METHOD document->add_text
EXPORTING
text = text
sap_style = 'HEADING'.
ENDFORM. "HTML_TOP_OF_PAGE
FORM alv_display.
PERFORM alv_build_fieldcat CHANGING gt_fieldcat.
PERFORM alv_build_layout USING ls_layout.
PERFORM alv_build_sorting USING lt_sort.
ls_event-name = 'DATA_CHANGED'.
ls_event-form = 'DATA_CHANGED'.
append ls_event to lt_event.
PERFORM log USING 80 'Determining Package information...'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'ALV_SET_STATUS'
i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
i_callback_user_command = 'ALV_USER_COMMAND'
is_layout = ls_layout
it_fieldcat = gt_fieldcat
it_sort = lt_sort
it_events = lt_event
i_grid_title = 'Transport Request Object List'
TABLES
t_outtab = lt_dev_object
EXCEPTIONS
program_error = 1
OTHERS = 2.
ASSERT sy-subrc = 0.
ENDFORM.
FORM ALV_USER_COMMAND USING iv_ucomm LIKE sy-ucomm
ct_selfield TYPE slis_selfield."#EC CALLED .
PERFORM display_object USING ct_selfield.
ENDFORM.
FORM display_object USING ct_selfield TYPE slis_selfield.
FIELD-SYMBOLS: <line> TYPE ty_dev_object.
READ TABLE lt_dev_object ASSIGNING <line> INDEX ct_selfield-tabindex.
CHECK sy-subrc = 0.
IF ct_selfield-fieldname = 'TRKORR'.
SET PARAMETER ID 'KOR' FIELD <line>-trkorr.
CALL FUNCTION 'TR_PRESENT_REQUEST'
EXPORTING
iv_trkorr = <line>-trkorr
iv_highlight = 'X'.
ELSE.
CALL FUNCTION 'RS_TOOL_ACCESS'
EXPORTING
operation = 'SHOW'
object_name = <line>-obj_name
object_type = <line>-object
EXCEPTIONS
OTHERS = 1.
ENDIF.
ENDFORM.
FORM ALV_SET_STATUS USING it_exclude TYPE table.
SET PF-STATUS 'ZALV'.
ENDFORM.