Dynamic F4 Help based on the Value of other Field.
TYPES: BEGIN OF ty_lgort,
werks TYPE t001l-werks,
lgort TYPE t001l-lgort,
lgobe TYPE t001l-lgobe,
END OF ty_lgort.
DATA: gt_return TYPE TABLE OF ddshretval,
gw_return TYPE ddshretval.
DATA: gwa_dynpfields TYPE dynpread,
gt_dynpfields TYPE TABLE OF dynpread.
DATA: gt_lgort TYPE TABLE OF ty_lgort,
gw_lgort TYPE ty_lgort.
DATA: gv_werks TYPE marc-werks.
*&---------------------------------------------------------------------*
*& Selection screen for Display button
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1,
PARAMETERS: p_plant TYPE werks_d, "PLANT
p_strloc TYPE t001l-lgort. "STORAGE LOCATION
SELECTION-SCREEN END OF BLOCK B1.
*--------------------------------------------------------------*
*Selection-Screen on Value-Request
*--------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_strloc.
REFRESH gt_dynpfields.
gwa_dynpfields-fieldname = 'P_PLANT'.
APPEND gwa_dynpfields TO gt_dynpfields.
*Get plant value on the selection screen
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = sy-repid
dynumb = sy-dynnr
TABLES
dynpfields = gt_dynpfields
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 gt_dynpfields INTO gwa_dynpfields
WITH KEY fieldname = 'P_PLANT'.
IF sy-subrc = 0.
gv_werks = gwa_dynpfields-fieldvalue.
ENDIF.
SELECT werks
lgort
lgobe
FROM t001l
INTO TABLE gt_lgort
WHERE werks = gv_werks.
IF sy-subrc EQ 0.
ENDIF.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'LGORT'
value_org = 'S'
TABLES
value_tab = gt_lgort
return_tab = gt_return
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
READ TABLE gt_return INTO gw_return INDEX 1.
IF sy-subrc = 0.
p_strloc = gw_return-fieldval.
ENDIF.