SAP dialog 自定义搜索帮助 案例+源码
同之前的blog一样,新建一个9000的屏幕,元素清单配好ok_code即可
前置准备
准备一个屏幕,具体步骤和之前一样,这边也按步骤做一下
状态栏
因为这个只是用于搜索帮助的演示,所以不需要应用应用程序工具栏,只需要设置功能键方便返回测试即可
标题
9000程序
PROCESS BEFORE OUTPUT.
MODULE status_9000.
*
PROCESS AFTER INPUT.
MODULE user_command_9000.
MODULE user_exit_9000 AT EXIT-COMMAND.
PBO
MODULE status_9000 OUTPUT.
SET PF-STATUS 'SRANDARD_9000'.
SET TITLEBAR 'TITLE_9000'.
ENDMODULE.
PAI
MODULE user_command_9000 INPUT.
save_ok = ok_code.
CLEAR:ok_code.
CASE save_ok.
WHEN '$BACK'.
LEAVE TO SCREEN 0.
WHEN '$ROLL'.
LEAVE TO SCREEN 0.
WHEN OTHERS.
ENDCASE.
ENDMODULE.
MODULE user_exit_9000 INPUT.
LEAVE PROGRAM.
ENDMODULE.
单个选择搜索帮助
布局构建
9000程序
PROCESS BEFORE OUTPUT.
MODULE status_9000.
*
PROCESS AFTER INPUT.
MODULE user_command_9000.
MODULE user_exit_9000 AT EXIT-COMMAND.
PROCESS ON VALUE-REQUEST.
FIELD gv_matnr MODULE get_matnr.
POV
编写POV程序
MODULE get_matnr INPUT.
"获取搜索搜索帮助
select
from makt
FIELDS
makt~matnr,
makt~maktx
INTO CORRESPONDING FIELDS OF TABLE @gt_makt.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'MATNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'GV_MATNR'
value_org = 'S'
TABLES
value_tab = gt_makt
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
ENDMODULE.
展示如下
子屏幕范围选择搜索帮助
构建屏幕
构建子屏幕
在主程序中添加子屏幕
SELECTION-SCREEN BEGIN OF SCREEN 9001 AS SUBSCREEN.
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME.
SELECT-OPTIONS:
s_matnr FOR mara-matnr.
SELECTION-SCREEN: END OF BLOCK blk1.
SELECTION-SCREEN END OF SCREEN 9001.
9000程序
PROCESS BEFORE OUTPUT.
CALL SUBSCREEN: subscreen INCLUDING sy-repid dynn_9001.
MODULE status_9000.
*
PROCESS AFTER INPUT.
CALL SUBSCREEN: subscreen.
MODULE user_command_9000.
MODULE user_exit_9000 AT EXIT-COMMAND.
添加搜索帮助代码
在子屏幕下方添加如下代码
"搜索帮助
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_matnr-low.
PERFORM frm_create_help.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_matnr-high.
PERFORM frm_create_help.
例程frm_create_help
FORM frm_create_help .
"获取搜索搜索帮助
SELECT
FROM makt
FIELDS
makt~matnr,
makt~maktx
INTO CORRESPONDING FIELDS OF TABLE @gt_makt.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'MATNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'S_MATNR-LOW'
value_org = 'S'
TABLES
value_tab = gt_makt
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
ENDFORM.
结果展示
表控件搜索帮助并回填
表空间的搜索帮助会有点不一样,因为需要刷新表数据来进行呈现,否则是不会展现出来的
屏幕构建
建议使用带向导的表控件
9000屏幕
主要看最后一行,其他多余的代码都是通过向导表控件生成的
PROCESS BEFORE OUTPUT.
*&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL 'MAKT_TABLE'
MODULE makt_table_change_tc_attr.
*&SPWIZARD: MODULE MAKT_TABLE_CHANGE_COL_ATTR.
LOOP AT gt_table_makt
INTO gs_table_makt
WITH CONTROL makt_table
CURSOR makt_table-current_line.
*&SPWIZARD: MODULE MAKT_TABLE_CHANGE_FIELD_ATTR
ENDLOOP.
CALL SUBSCREEN: subscreen INCLUDING sy-repid dynn_9001.
MODULE status_9000.
*
PROCESS AFTER INPUT.
*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'MAKT_TABLE'
LOOP AT gt_table_makt.
CHAIN.
FIELD gs_table_makt-matnr.
FIELD gs_table_makt-maktx.
MODULE makt_table_modify ON CHAIN-REQUEST.
ENDCHAIN.
ENDLOOP.
*&SPWIZARD: MODULE MAKT_TABLE_CHANGE_TC_ATTR.
*&SPWIZARD: MODULE MAKT_TABLE_CHANGE_COL_ATTR.
CALL SUBSCREEN: subscreen.
MODULE user_command_9000.
MODULE user_exit_9000 AT EXIT-COMMAND.
PROCESS ON VALUE-REQUEST.
FIELD gv_matnr MODULE get_matnr.
FIELD gs_table_makt-matnr MODULE get_table_matnr.
get_table_matnr
MODULE get_table_matnr INPUT.
"获取搜索搜索帮助
SELECT
FROM makt
FIELDS
makt~matnr,
makt~maktx
INTO CORRESPONDING FIELDS OF TABLE @gt_table_makt.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'MATNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'GS_TABLE_MAKT-MATNR'
value_org = 'S'
TABLES
value_tab = gt_table_makt
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
ENDMODULE.
展现
数据回填
如果不只是想要物料号回填上来,还要自动把物料描述带出来要怎么做呢
更新get_table_matnr
获取选择行 以及在搜索帮助的函数中新增两个导入参数,并在最后对表格进行刷新展现
DATA: lt_return TYPE STANDARD TABLE OF ddshretval,
ls_return TYPE ddshretval.
DATA: lv_row LIKE sy-tabix.
"获取屏幕行
CLEAR lv_row.
CALL FUNCTION 'DYNP_GET_STEPL'
IMPORTING
povstepl = lv_row.
"获取搜索搜索帮助
SELECT
FROM makt
FIELDS
makt~matnr,
makt~maktx
INTO CORRESPONDING FIELDS OF TABLE @gt_table_makt.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'MATNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'GS_TABLE_MAKT-MATNR'
value_org = 'S'
callback_program = sy-repid
callback_form = 'FRM_RETURN_INFO'
TABLES
value_tab = gt_table_makt
return_tab = lt_return
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc EQ 0.
LOOP AT lt_return INTO ls_return.
CASE ls_return-fieldname.
WHEN 'F0002'.
gs_table_makt-maktx = ls_return-fieldval.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
ENDIF.
"POV 不经过 PBO PAI 所以需要手动进行数据更新
PERFORM frm_refresh_table USING lv_row.
例程:FRM_RETURN_INFO
将自定义搜索帮助的数据 回填到上一个函数中的lt_return
FORM frm_return_info TABLES record_tab STRUCTURE seahlpres
CHANGING shlp TYPE shlp_descr_t
callcontrol LIKE ddshf4ctrl.
DATA: interface LIKE LINE OF shlp-interface.
READ TABLE shlp-interface INTO interface INDEX 1.
CLEAR interface.
interface-shlpfield = 'F0002'. "这里的编号就是搜索帮助上的顺序
interface-valfield = 'GS_TABLE_MAKT-MAKTX'.
APPEND interface TO shlp-interface.
ENDFORM.
例程:frm_refresh_table
FORM frm_refresh_table USING lv_row LIKE sy-tabix.
DATA: lt_systems TYPE STANDARD TABLE OF dynpread,
ls_systems TYPE dynpread.
CLEAR:lt_systems.
CLEAR ls_systems.
ls_systems-fieldname = 'GS_TABLE_MAKT-MATNR'.
ls_systems-stepl = lv_row.
ls_systems-fieldvalue = gs_table_makt-matnr.
APPEND ls_systems TO lt_systems.
CLEAR ls_systems.
ls_systems-fieldname = 'GS_TABLE_MAKT-MAKTX'.
ls_systems-stepl = lv_row.
ls_systems-fieldvalue = gs_table_makt-maktx.
APPEND ls_systems TO lt_systems.
CALL FUNCTION 'DYNP_VALUES_UPDATE'
EXPORTING
dyname = sy-repid
dynumb = sy-dynnr
TABLES
dynpfields = lt_systems
EXCEPTIONS
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
undefind_error = 7
OTHERS = 8.
ENDFORM.
展现
完成上述操作后,点击搜索帮助就会发现 除了物料号,物料描述也带出来了
源码
以上的三种搜索帮助在一起,使用的时候记得区分,注意:部分源码时使用dialog的时候自动生成的
主程序
*&---------------------------------------------------------------------*
*& Report Y_PNJ_DEMO16
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT y_pnj_demo16.
INCLUDE y_pnj_demo16_top.
INCLUDE y_pnj_demo16_pbo.
INCLUDE y_pnj_demo16_pai.
INCLUDE y_pnj_demo16_pov.
INCLUDE y_pnj_demo16_per.
TABLES: mara.
"定义 9001的选择屏幕
SELECTION-SCREEN BEGIN OF SCREEN 9001 AS SUBSCREEN.
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME.
SELECT-OPTIONS:
s_matnr FOR mara-matnr.
SELECTION-SCREEN: END OF BLOCK blk1.
SELECTION-SCREEN END OF SCREEN 9001.
"搜索帮助
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_matnr-low.
PERFORM frm_create_help.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_matnr-high.
PERFORM frm_create_help.
*&---------------------------------------------------------------------*
*&INITIALIZATION/选择屏幕前初始化(选择屏幕展示之前执行)
*&---------------------------------------------------------------------*
INITIALIZATION .
*&---------------------------------------------------------------------*
*& AT SELECTION-SCREEN OUTPUT/选择屏幕控制(第二屏输出)
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT .
*&---------------------------------------------------------------------*
*& AT SELECTION-SCREEN/选择屏幕执行(参数输入检查)
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN .
*&---------------------------------------------------------------------*
*& START-OF-SELECTION/开始选择屏幕(点击执行按钮之后执行的语块)
*&---------------------------------------------------------------------*
START-OF-SELECTION .
CALL SCREEN 9000.
*&---------------------------------------------------------------------*
*& END-OF-SELECTION/结束选择屏幕(程序结束处理,输出等)
*&---------------------------------------------------------------------*
END-OF-SELECTION .
包含文件Y_PNJ_DEMO16_PAI
*&---------------------------------------------------------------------*
*& 包含 Y_PNJ_DEMO16_PAI
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
save_ok = ok_code.
CLEAR:ok_code.
CASE save_ok.
WHEN '$BACK'.
LEAVE TO SCREEN 0.
WHEN '$ROLL'.
LEAVE TO SCREEN 0.
WHEN OTHERS.
ENDCASE.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_EXIT_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_exit_9000 INPUT.
LEAVE PROGRAM.
ENDMODULE.
*&SPWIZARD: INPUT MODULE FOR TC 'MAKT_TABLE'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: MODIFY TABLE
MODULE MAKT_TABLE_MODIFY INPUT.
MODIFY GT_TABLE_MAKT
FROM GS_TABLE_MAKT
INDEX MAKT_TABLE-CURRENT_LINE.
ENDMODULE.
包含文件Y_PNJ_DEMO16_PBO
*&---------------------------------------------------------------------*
*& 包含 Y_PNJ_DEMO16_PBO
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS 'STANDARD_9000'.
SET TITLEBAR 'TITLE_9000'.
ENDMODULE.
*&SPWIZARD: OUTPUT MODULE FOR TC 'MAKT_TABLE'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: UPDATE LINES FOR EQUIVALENT SCROLLBAR
MODULE MAKT_TABLE_CHANGE_TC_ATTR OUTPUT.
DESCRIBE TABLE GT_TABLE_MAKT LINES MAKT_TABLE-lines.
ENDMODULE.
包含文件Y_PNJ_DEMO16_PER
*&---------------------------------------------------------------------*
*& 包含 Y_PNJ_DEMO16_PER
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form frm_create_help
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_create_help .
"获取搜索搜索帮助
SELECT
FROM makt
FIELDS
makt~matnr,
makt~maktx
INTO CORRESPONDING FIELDS OF TABLE @gt_makt.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'MATNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'S_MATNR-LOW'
value_org = 'S'
TABLES
value_tab = gt_makt
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_RETURN_INFO
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_return_info TABLES record_tab STRUCTURE seahlpres
CHANGING shlp TYPE shlp_descr_t
callcontrol LIKE ddshf4ctrl.
DATA: interface LIKE LINE OF shlp-interface.
READ TABLE shlp-interface INTO interface INDEX 1.
CLEAR interface.
interface-shlpfield = 'F0002'.
interface-valfield = 'GS_TABLE_MAKT-MAKTX'.
APPEND interface TO shlp-interface.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_refresh_table
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> LV_ROW
*&---------------------------------------------------------------------*
FORM frm_refresh_table USING lv_row LIKE sy-tabix.
DATA: lt_systems TYPE STANDARD TABLE OF dynpread,
ls_systems TYPE dynpread.
CLEAR:lt_systems.
CLEAR ls_systems.
ls_systems-fieldname = 'GS_TABLE_MAKT-MATNR'.
ls_systems-stepl = lv_row.
ls_systems-fieldvalue = gs_table_makt-matnr.
APPEND ls_systems TO lt_systems.
CLEAR ls_systems.
ls_systems-fieldname = 'GS_TABLE_MAKT-MAKTX'.
ls_systems-stepl = lv_row.
ls_systems-fieldvalue = gs_table_makt-maktx.
APPEND ls_systems TO lt_systems.
CALL FUNCTION 'DYNP_VALUES_UPDATE'
EXPORTING
dyname = sy-repid
dynumb = sy-dynnr
TABLES
dynpfields = lt_systems
EXCEPTIONS
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
undefind_error = 7
OTHERS = 8.
ENDFORM.
包含文件Y_PNJ_DEMO16_POV
*&---------------------------------------------------------------------*
*& 包含 Y_PNJ_DEMO16_POV
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module GET_MATNR INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE get_matnr INPUT.
"获取搜索搜索帮助
SELECT
FROM makt
FIELDS
makt~matnr,
makt~maktx
INTO CORRESPONDING FIELDS OF TABLE @gt_makt.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'MATNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'GV_MATNR'
value_org = 'S'
TABLES
value_tab = gt_makt
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module GET_TABLE_MATNR INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE get_table_matnr INPUT.
DATA: lt_return TYPE STANDARD TABLE OF ddshretval,
ls_return TYPE ddshretval.
DATA: lv_row LIKE sy-tabix.
"获取屏幕行
CLEAR lv_row.
CALL FUNCTION 'DYNP_GET_STEPL'
IMPORTING
povstepl = lv_row.
"获取搜索搜索帮助
SELECT
FROM makt
FIELDS
makt~matnr,
makt~maktx
INTO CORRESPONDING FIELDS OF TABLE @gt_table_makt.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'MATNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'GS_TABLE_MAKT-MATNR'
value_org = 'S'
callback_program = sy-repid
callback_form = 'FRM_RETURN_INFO'
TABLES
value_tab = gt_table_makt
return_tab = lt_return
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc EQ 0.
LOOP AT lt_return INTO ls_return.
CASE ls_return-fieldname.
when 'F0001'.
gs_table_makt-matnr = ls_return-fieldval.
WHEN 'F0002'.
gs_table_makt-maktx = ls_return-fieldval.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
ENDIF.
*
"POV 不经过 PBO PAI 所以需要手动进行数据更新
PERFORM frm_refresh_table USING lv_row.
ENDMODULE.
包含文件Y_PNJ_DEMO16_TOP
*&---------------------------------------------------------------------*
*& 包含 Y_PNJ_DEMO16_TOP
*&---------------------------------------------------------------------*
*&---Variable
DATA: ok_code TYPE sy-ucomm, " 用于接收屏幕操作
save_ok TYPE sy-ucomm. " 接入屏幕操作 并清空ok_code
DATA: gv_matnr TYPE mara-matnr.
TYPES: BEGIN OF ty_makt,
matnr TYPE makt-matnr,
maktx TYPE makt-maktx,
END OF ty_makt.
DATA: gt_makt TYPE STANDARD TABLE OF ty_makt,
gs_makt TYPE ty_makt.
DATA: gt_table_makt TYPE STANDARD TABLE OF ty_makt,
gs_table_makt TYPE ty_makt.
DATA: dynn_9001(4) VALUE '9001'.
*&SPWIZARD: DECLARATION OF TABLECONTROL 'MAKT_TABLE' ITSELF
CONTROLS: MAKT_TABLE TYPE TABLEVIEW USING SCREEN 9000.