Friday, November 23, 2007

sap abap program for Value Request For Parameter

* If you have two parameters, you want to display values(f4) in parameter 2
* depending on the values entered in parameter 1.

REPORT Z_SRI_HELP_VALUE_FOR_TABLES .

tables tcurt.
DATA DYFIELDS LIKE DYNPREAD OCCURS 1 WITH HEADER LINE.
PARAMETERS: P_WAERS LIKE TCURT-WAERS, "Currency
P_LTEXT LIKE TCURT-LTEXT, "Long Text
P_KTEXT LIKE TCURT-KTEXT. "Short Text
*-----------------------------------------------------------------------
*--- Example of updating value of another field on the screen ----------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_WAERS.
CLEAR: DYFIELDS[], DYFIELDS.
*--- select currency
CALL FUNCTION 'HELP_VALUES_GET'
EXPORTING
fieldname = 'WAERS'
tabname = 'TCURT'
IMPORTING
SELECT_VALUE = P_WAERS.
*--- get long text for the selected currency
SELECT SINGLE LTEXT FROM TCURT
INTO DYFIELDS-FIELDVALUE
WHERE SPRAS = SY-LANGU
AND WAERS = P_WAERS.
IF SY-SUBRC <> 0.
CLEAR DYFIELDS-FIELDVALUE.
ENDIF.
*--- update another field
DYFIELDS-FIELDNAME = 'P_LTEXT'.
APPEND DYFIELDS.
CALL FUNCTION 'DYNP_VALUES_UPDATE'
EXPORTING
DYNAME = SY-CPROG
DYNUMB = SY-DYNNR
tables
dynpfields = DYFIELDS .
*-----------------------------------------------------------------------
*--- Example of reading value of another field -------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_KTEXT.
*--- read another field
CLEAR: DYFIELDS[], DYFIELDS.
DYFIELDS-FIELDNAME = 'P_WAERS'.
APPEND DYFIELDS.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
DYNAME = SY-CPROG
DYNUMB = SY-DYNNR
TABLES
DYNPFIELDS = DYFIELDS .
READ TABLE DYFIELDS INDEX 1.
*--- get short text and update current field
SELECT SINGLE KTEXT FROM TCURT
INTO P_KTEXT
WHERE SPRAS EQ SY-LANGU
AND WAERS EQ DYFIELDS-FIELDVALUE.
*-----------------------------------------------------------------------

How to add F4 functionality to a paramter variable? Say P_name ie Parameters: P_name like dbtab-fieldname
in At selection-screen on value-request for p_name. How should I add the values john, abraham, linga etc so that these values appear when f4 is pressed on the field in the selection screen?

PARAMETERS: p_name(10).
DATA: BEGIN OF value_tab OCCURS 0,
name(10),
END OF value_tab.
DATA :field_tab LIKE dfies OCCURS 0 WITH HEADER LINE.
DATA : return_tab LIKE ddshretval OCCURS 0 WITH HEADER LINE. DATA : x TYPE string.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_name.

REFRESH value_tab[].
REFRESH field_tab[].
REFRESH return_tab[].
field_tab-fieldname = 'ERNAM'.
field_tab-tabname = 'VBAK'.
APPEND field_tab.
value_tab-name = 'John'.
APPEND value_tab.
value_tab-name = 'Abraham'.
APPEND value_tab.
value_tab-name = 'Lingam'.
APPEND value_tab.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = field_tab-fieldname
TABLES
value_tab = value_tab
field_tab = field_tab
return_tab = return_tab
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc = 0.
p_name = return_tab-fieldval.
ENDIF.

No comments:

Blog Archive