F4 values

Question: Hi all,
How to get F4 values for a particular field?
My req . is like I need to pull the variants for a program and those variants I want to display it in my program . when the user presses the variant button , all those Variant list need to be displayed .
How can i achieve this?

Thnx.

Answer:
The simplest way is to find an existing program which has F4 lookup working as you want it and do it the same way. Ideally there is a search help or value table used and you can simply reference it. If the lookup is coded, you copy the code.

In this case, transaction SE38 has a lookup for variant, and if you look at the PAI logic for the screen, it calls function module RS_VARIANT_CATALOG.
In your code, add an event AT SELECTION-SCREEN ON VALUE-REQUEST FOR FIELD p_variant, and then call the function module.

Answer:
Table VARID stores the program name (REPORT) and corresponding vartiants(VARIANT).

You can add this table as a search help in the data element of your required field you need F4 help for:

Alternatively you can add the following code to your program:

REPORT <your_program> .

TYPES: BEGIN OF ty_itab,
report TYPE vari_reprt, "report name
variant TYPE variant, "variant name
END OF ty_itab.

DATA: t_itab TYPE STANDARD TABLE OF ty_itab WITH HEADER LINE INITIAL SIZE 0.

DATA: BEGIN OF fields OCCURS 10,
tabname TYPE tabname, "table name
fieldname TYPE fieldname, "field name
selectflag TYPE selectflag, "flag
END OF fields.

DATA : BEGIN OF itab OCCURS 5 ,
ctext(50) , "F4 values
END OF itab .

PARAMETER: p_vart TYPE variant. "variant


************************************************
*INITIALIZATION
************************************************
INITIALIZATION.
* add field names to populate F4 field list.
PERFORM sub_populate_fields.

* get values from table for variant.
PERFORM sub_get_variant.

************************************************
*AT SELECTION SCREEN
************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vart.

* get values for F4 help from internal table
PERFORM sub_get_F4_values.



************************************************
*SUBROUTINES
************************************************

************************************************
* FORM sub_populate_fields.
* populate fields table for F4 values
************************************************
FORM sub_populate_fields.

CLEAR fields .
REFRESH fields .

fields-tabname = 'VARID'.
fields-fieldname = 'VARIANT'.
fields-selectflag = 'X'.
APPEND fields.

CLEAR fields .

ENDFORM. "sub_populate_fields.

************************************************
* FORM sub_get_variant.
* get values from table for variant.
************************************************

FORM sub_get_variant.
* you can pass the program name you want in the select statement
* the structure of t_itab has both program name
* and variant names - u can use structure as required.

CLEAR itab .
REFRESH itab .


SELECT report variant
FROM varid
INTO TABLE t_itab
WHERE report = 'your_program'. "change report value as required
IF sy-subrc <> 0.
EXIT.
ELSE.
LOOP AT t_itab.

itab-ctext = t_itab-variant.
APPEND itab .
CLEAR itab.
ENDLOOP.
ENDIF.

ENDFORM. "sub_get_variant.


************************************************
* FORM sub_get_F4_values.
* get values into selection field for F4 help.
************************************************

FORM sub_get_F4_values.
* you can add your own title in the 'titel' field.
* fields: internal table with the field names
* valuetab: table with values to be displayed on F4 help.


CALL FUNCTION 'HELP_VALUES_GET_WITH_TABLE'
EXPORTING
cucol = 10
curow = 10
titel = 'SELECT VARIANT FROM THE LIST'
IMPORTING
select_value = p_vart
TABLES
fields = fields
valuetab = itab.


ENDFORM. "sub_get_F4_values.
Copyright ?2007 - 2008 www.jt77.com