This post describes how F4 help can be displayed for selection criteria defined by SELECT-OPTIONS on selection screen of ABAP report programs.
F4 help can be added to selection criteria:
◉ automatically: if there is input help associated to the data type of the selection criteria, F4 help will be displayed automatically in the selection screen
◉ programatically: if no input help exists for the data type of the selection criteria, F4 help can be provided by program code
Based on input help associated with data type. Data type of the selection criteria can be derived from:
Data element
Table/Structure field
Input help with fixed values
To define input help with fixed values for Data element, create/select Domain with Fixed Values Value Range, and define that Domain as Elementary Type for Data element.
Example:
Define Domain with Value Range Fixed Values
Let’s create a Data element with Fixed Values Domain. The process works with existing data elements like AUFTYP, but as an example we will create our own data element.
1. Domain: In SE11 create a Domain, (e.g.: ZDOMA_FIX) in the Definition tab give a Data type to it (e.g.: CHAR) and for Value Range define the desired Fixed Values (e.g.: A, B). Save and Activate.
F4 help can be added to selection criteria:
◉ automatically: if there is input help associated to the data type of the selection criteria, F4 help will be displayed automatically in the selection screen
◉ programatically: if no input help exists for the data type of the selection criteria, F4 help can be provided by program code
Automatic F4 help
Based on input help associated with data type. Data type of the selection criteria can be derived from:
Data element
Table/Structure field
Data element
Input help with fixed values
To define input help with fixed values for Data element, create/select Domain with Fixed Values Value Range, and define that Domain as Elementary Type for Data element.
Example:
Define Domain with Value Range Fixed Values
Let’s create a Data element with Fixed Values Domain. The process works with existing data elements like AUFTYP, but as an example we will create our own data element.
1. Domain: In SE11 create a Domain, (e.g.: ZDOMA_FIX) in the Definition tab give a Data type to it (e.g.: CHAR) and for Value Range define the desired Fixed Values (e.g.: A, B). Save and Activate.
2. Data element: In SE11 create a Data element (e.g.: ZDTEL_FIX), as Data Type give Elementary Type > Domain and the previously created Domain (ZDOMA_FIX). Fill out necessary inputs like Field Label, Save and Activate.
The system will consider our Data element / Data type as “Input help with fixed values“.
Sample program
Let’s create a sample program, that uses our Domain as data type for selection criteria, and test it:
1. Program: In SE80 select Program and input the desired name of your program (e.g.: Z_F4_FOR_SELECT_OPTIONS) Create it and enter code, save and activate
REPORT Z_F4_FOR_SELECT_OPTIONS.
DATA:
ls_fixedv TYPE zdtel_fix
.
SELECT-OPTIONS:
s_fixedv FOR ls_fixedv
.
2. Test: Run your program, and press F4 in input field. Verify that input help appears with the values entered in your domain.
Table/Structure field
Table/Structure components can have Origin of Input Help:
◉ Input help implemented with check table
◉ Explicit search help interface to field
◉ Input help based on data type
◉ Input help with fixed values
Input help implemented with check table
If Component is a foreign key, the referenced table will be used as a check table.
Example:
Foreign key creation:
◉ Let’s create a structure and define a component with data type that is key in a table. I will use AUFNR which is key in AUFK.
◉ In Input Help/Check tab let’s create a foreign key from our component by pressing the key icon above the table. Create foreign key window appears, accept proposal creation, and hit copy in the popoup window. Save and activate
◉ Verify that Origin of the Input Help is Input help implemented with check table, and Check table is the referenced table from foreign key
Explicit search help interface to field
We can define expilit search help as input help for our component.
Example
Search help
1. Create Component. (e.g.: AUFART) Go to Input Help/Check, select component, click Search Help, enter serach help name (e.g.: AUART) and in popup select Copy.
2. Verify that Origin is Explicit search help interface to field and Srch Help is the entered search help (AUART)
Input help based on data type
There are data types input help associated with them by default.
Example
DATS
1. Create component with type DATS, go to Input Help/Check and verify that Origin is Input help based on data type. Save and activate.
Input help with fixed values
When Data Type with Domain Value Range Fixed Values used.
Example
Domain – Fixed Values
1. Let’s use our previously create Data Element as Component type, go to Input Help/Check and verify that Origin is Input help with fixed values
Example
Sample program
1. Create program with SELECT-OPTIONS for all of our structures’ components
REPORT Z_F4_FOR_SELECT_OPTIONS.
DATA:
ls_test TYPE zstest
.
SELECT-OPTIONS:
s_chktab FOR ls_test-check_tab,
s_explic FOR ls_test-explicit,
s_dattyp FOR ls_test-datatyp,
s_fixed FOR ls_test-fixed
.
2. Verify F4 helps
Adding F4 help programatically
When no input help can be determined for the data type of the selection criteria, or there is no such context, for example data element used as type of selection criteria, no automatic F4 help can be displayed in selection screen.
F4 help can be added to selection criteria if there is no automatic F4 help by defining AT SELECTION-SCREEN ON VALUE-REQUEST FOR event for it.
Values for F4 help can be provided in the event. To display F4 help values in popup window, we use function module:
◉ F4IF_FIELD_VALUE_REQUEST if suitable SEARCHHELP already exists in system (SE11>Search help)
◉ SEARCHHELP param will be the search help that exists in system, to find existing Search help for Data Element use Where-Used list (Ctrl+Shift+F3) and select Search help
◉ TABNAME, FIELDNAME can be any string, not used when providing SEARCHHELP param but mandatory
◉ F4IF_INT_TABLE_VALUE_REQUEST if select options can be provided in an itab table
◉ VALUE_TAB param contains the possible values
◉ RETFIELD param should be the field name from VALUE_TAB
Example
Code snippet:
*&---------------------------------------------------------------------*
*& Report Z_F4_FOR_SELECT_OPTIONS
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_F4_FOR_SELECT_OPTIONS.
DATA:
lv_aufnr TYPE aufnr,
lv_aufart TYPE aufart
.
SELECT-OPTIONS:
s_aufnr FOR lv_aufnr,
s_aufart FOR lv_aufart
.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_aufnr-low.
PERFORM aufnr_f4 CHANGING s_aufnr-low.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_aufnr-high.
PERFORM aufnr_f4 CHANGING s_aufnr-high.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_aufart-low.
PERFORM aufart_f4 CHANGING s_aufart-low.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_aufart-high.
PERFORM aufart_f4 CHANGING s_aufart-high.
FORM aufnr_f4
CHANGING
cv_aufnr TYPE aufnr.
DATA:
lv_value TYPE help_info-fldvalue,
lt_return TYPE STANDARD TABLE OF ddshretval
.
CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
exporting
TABNAME = '<any>' " Table/structure name from Dictionary
FIELDNAME = '<any>' " Field name from Dictionary
SEARCHHELP = 'ORDE' " Search help as screen field attribute
VALUE = lv_value " Field contents for F4 call
tables
RETURN_TAB = lt_return " Return the selected value
exceptions
FIELD_NOT_FOUND = 1 " Field does not exist in the Dictionary
NO_HELP_FOR_FIELD = 2 " No F4 help is defined for the field
INCONSISTENT_HELP = 3 " F4 help for the field is inconsistent
NO_VALUES_FOUND = 4 " No values found
OTHERS = 5
.
IF sy-subrc NE 0.
RETURN.
ENDIF.
READ TABLE lt_return INTO DATA(ls_ret) INDEX 1.
cv_aufnr = ls_ret-fieldval.
ENDFORM.
FORM aufart_f4
CHANGING
cv_aufart TYPE aufart.
DATA:
lt_values TYPE STANDARD TABLE OF t003o,
lt_return TYPE STANDARD TABLE OF ddshretval
.
SELECT * "#EC CI_NOWHERE
FROM t003o
INTO TABLE lt_values.
IF sy-subrc NE 0.
RETURN.
ENDIF.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
exporting
RETFIELD = 'AUART' " Name of field in VALUE_TAB
VALUE_ORG = 'S' " Value return: C: cell by cell, S: structured
tables
VALUE_TAB = lt_values " Table of values: entries cell by cell
RETURN_TAB = lt_return " Return the selected value
exceptions
PARAMETER_ERROR = 1 " Incorrect parameter
NO_VALUES_FOUND = 2 " No values found
OTHERS = 3
.
IF sy-subrc NE 0.
RETURN.
ENDIF.
read table lt_return INTO DATA(ls_return) INDEX 1.
cv_aufart = ls_return-fieldval.
ENDFORM.
No comments:
Post a Comment