<span style="font-family:Times New Roman;font-size:14px;"></span>
This BOK will help in understanding how to create custom F4 help for any field in the selection screen on the basis of data from the selection screen.
Creating customF4 help in the selection screen:
In the selection screen, we may need to display the custom F4 help for a particular field like the data in the F4 help should be filtered on the basis of any other field from the selection screen or we may want to display an extra field in the F4 help. Then two function modules are used DYNP_VALUES_READ and F4IF_INT_TABLE_VALUE_REQUEST.
Scenario - Suppose we have Material number(MATNR) and Plant(WERKS) as mandatory fields and on the basis of that we want to display the F4 help for production version with Material, Plant, version id, Production version description in the F4 help.
Selection screen
STEP 1 : Call the functionmodules on ‘AT SELECTION SCREEN’ Event.
Create a perform atselection screen event on value request event. The perform will be called onthe value request for that parameter. Each time the F4 is called for thatparameter it will call that perform.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR po_verid.
* Perform f4 help on verid
PERFORM verid_search.
This is a perform which contains code for the F4 help the code is explained in the below steps.
STEP 2 : Add the fields to be fetched from the screen to dynpread table.
Create an internal table of type dynpread and add the fields to be fetched from the screen to internal table.
lwa_dynpread-fieldname =‘PO_WERKS’.
APPEND lwa_dynpread TO li_dynpread.
lwa_dynpread-fieldname =‘PO_MATNR’.
APPEND lwa_dynpread TO li_dynpread.
STEP 3 : Fetch the values from the screen
DYNP_VALUES_READ-This function module reads the screen field values before PAI field event. It reads the values even if the user command is not triggered. In this case this function module will read values of PLANT and Material Number even if PAI is not triggered that is even if the user hasn’t pressed an enter key, it can still read the values from the screen.
Call the function module ‘DYNP_VALUES_READ’ and pass the values to be fetched and read the returned values from the internal table.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = sy-repid
dynumb = sy-dynnr
TABLES
dynpfields = li_dynpread
EXCEPTIONS
invalid_abapworkarea =1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer =4
invalid_request = 5
no_fielddescription = 6
invalid_parameter = 7
undefind_error = 8
double_conversion = 9
stepl_not_found = 10
OTHERS = 11.
The values fetched from the screen has been populated in theli_dynpread
READ TABLE li_dynpread INTO lwa_dynpread WITH KEY
fieldname = ‘PO_WERKS’.
IF sy-subrc EQ 0.
l_werks = lwa_dynpread-fieldvalue.
CALL FUNCTION'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = l_werks
IMPORTING
output = po_werks.
TRANSLATE po_werks TOUPPER CASE.
STEP 4 : Select the data from thedatabase table
Select the data from the database table on the basis of theselection screen fields.
SELECT matnr werks verid text1 bstmi bstma adatu bdatu
FROM mkal INTO TABLE li_tab
WHERE matnr EQpo_matnr
AND werks EQ po_werks.
STEP 5 : Display the data in theF4 help
F4IF_INT_TABLE_VALUE_REQUEST-This module implements the standard help at Process On Value request while passing the values to be displayed in a table. The entire dialogue behaves as for a standard F4 help. This module also supports input help control.If the screen information DYNPPROG, DYNPNR, DYNPROFIELD and possibly STEPL are also defined, the selected value is automatically returned in the screen field.
Call the function module F4IF_INT_TABLE_VALUE_REQUESTto display the F4 help and pass the data.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'VERID'
dynpprog = sy-repid
dynpnr = '1000'
dynprofield = 'PO_VERID'
window_title = text-t01
value_org = 'S'
TABLES
value_tab = li_tab
return_tab = li_ret
EXCEPTIONS
parameter_error = 1
no_values_found =2
OTHERS = 3.
Text-t01 contains the title of the F4 help window
Li_tab contains the data.
Li_ret contains the return field.
For Mulitple selection Field – when the data is to be screen is having multiple values then high and low fields are passed to the dynpread table and high and low values are fetched from the sceen.
lwa_dynpread-fieldname =‘SO_WERKS-LOW’.
APPEND lwa_dynpread TOli_dynpread.
lwa_dynpread-fieldname =‘SO_WERKS-HIGH’.
APPEND lwa_dynpread TOli_dynpread.
For F4 help on the multiple value field are applied on both high and low values
Output F4 help dialog
PARAMETERS: po_matnr LIKE mkal-matnr OBLIGATORY ,
po_werks LIKE mkal-werks OBLIGATORY,
po_verid LIKE mkal-verid,
po_text1 like mkal-text1,
po_BDATU like mkal-BDATU.
<strong>STEP 1 : Call the function modules on ‘AT SELECTION SCREEN’ Event.</strong>
AT SELECTION-SCREEN ON VALUE-REQUEST FOR po_verid.
* Perform f4 help on verid
PERFORM verid_search.
*&---------------------------------------------------------------------*
*& Form verid_search
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM verid_search .
DATA: BEGIN OF ty_mkal,
matnr TYPE mkal-matnr,
werks TYPE mkal-werks,
verid TYPE mkal-verid,
text1 TYPE mkal-text1,
BDATU type mkal-BDATU,
END OF ty_mkal.
DATA: lwa_dynpread TYPE dynpread,
li_dynpread TYPE TABLE OF dynpread,
li_tab LIKE TABLE OF ty_mkal,
li_ret LIKE TABLE OF ddshretval,
l_matnr TYPE mkal-matnr,
l_werks TYPE mkal-werks.
<strong>STEP 2 : Add the fields to be fetched from the screen to dynpread table.</strong>
lwa_dynpread-fieldname = 'PO_MATNR'.
APPEND lwa_dynpread TO li_dynpread.
lwa_dynpread-fieldname = 'PO_WERKS'.
APPEND lwa_dynpread TO li_dynpread.
<strong>STEP 3 : Fetch the values from the screen
</strong> CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = sy-repid
dynumb = sy-dynnr
TABLES
dynpfields = li_dynpread
EXCEPTIONS
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
invalid_parameter = 7
undefind_error = 8
double_conversion = 9
stepl_not_found = 10
OTHERS = 11.
READ TABLE li_dynpread INTO lwa_dynpread
WITH KEY fieldname = 'PO_MATNR'.
IF sy-subrc EQ 0.
l_matnr = lwa_dynpread-fieldvalue.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = l_matnr
IMPORTING
output = po_matnr.
TRANSLATE po_matnr TO UPPER CASE.
ENDIF.
READ TABLE li_dynpread INTO lwa_dynpread
WITH KEY fieldname = 'PO_WERKS'.
IF sy-subrc EQ 0.
l_werks = lwa_dynpread-fieldvalue.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = l_werks
IMPORTING
output = po_werks.
TRANSLATE po_werks TO UPPER CASE.
ENDIF.
<strong>STEP 4 : Select the data from the database table</strong>
SELECT matnr werks verid text1 BDATU
FROM mkal INTO TABLE li_tab
WHERE matnr EQ po_matnr
AND werks EQ po_werks.
<strong>STEP 5 : Display the data in the F4 help</strong>
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'VERID'
dynpprog = sy-repid
dynpnr = '1000'
dynprofield = 'PO_VERID'
window_title = text-t01
value_org = 'S'
TABLES
value_tab = li_tab
return_tab = li_ret
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
ENDFORM. " verid_search