Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

F1 & F4 in alv

Former Member
0 Kudos
1,290

How to use F1 & F4 help in alv

1 ACCEPTED SOLUTION

Former Member
0 Kudos
226

hi anid i have one sample code for implimentation of f1 and f4 help it must clear ur all concept....

Global data definitions for ALV.......................................

DATA : alvgrid TYPE REF TO cl_gui_alv_grid,

custom_container TYPE REF TO cl_gui_custom_container,

fieldcatalog TYPE lvc_t_fcat.

table to contain fields that require f4...............................

DATA : lt_f4 TYPE lvc_t_f4 WITH HEADER LINE.

ok_code declaration...................................................

DATA : ok_code TYPE sy-ucomm.

Tables declaration....................................................

TABLES : zaemp.

Types declaration.....................................................

TYPES : BEGIN OF ty_emp,

code LIKE zaemp-code,

designation LIKE zaemp-designation,

END OF ty_emp.

Internal table declaration............................................

DATA : i_emp TYPE TABLE OF ty_emp.

Workarea declaration..................................................

DATA : wa_emp TYPE ty_emp.

Selection screen parameters...........................................

SELECT-OPTIONS : s_code FOR zaemp-code.

----


  • CLASS lcl_event_handler DEFINITION

----


  • ........ *

----


CLASS lcl_event_handler DEFINITION.

PUBLIC SECTION.

METHODS :

handle_on_f1 FOR EVENT onf1 OF cl_gui_alv_grid

IMPORTING e_fieldname es_row_no er_event_data,

handle_on_f4 for event onf4 of cl_gui_alv_grid

importing e_fieldname es_row_no er_event_data

.

ENDCLASS.

----


  • CLASS lcl_event_handler IMPLEMENTATION

----


  • ........ *

----


CLASS lcl_event_handler IMPLEMENTATION.

METHOD handle_on_f1.

custom f1 help for code field.......................................

IF e_fieldname = 'code'.

CALL SCREEN 3001.

ENDIF.

to prevent processing of standard f1 help............................

er_event_data->m_event_handled = 'X'.

ENDMETHOD.

Method handle_on_f4.

standard f4 help will be invoked......................................

endmethod.

ENDCLASS.

start of selection....................................................

START-OF-SELECTION.

SELECT code designation FROM zaemp

INTO CORRESPONDING FIELDS OF TABLE i_emp

WHERE code IN s_code.

CALL SCREEN 3000.

&----


*& Module STATUS_3000 OUTPUT

&----


  • text

----


MODULE status_3000 OUTPUT.

SET PF-STATUS 'ZTOOL'.

SET TITLEBAR 'ZTITLE'.

IF alvgrid IS INITIAL.

CREATE OBJECT custom_container

EXPORTING

container_name = 'ZCONTAINER'.

CREATE OBJECT alvgrid

EXPORTING

i_parent = custom_container.

PERFORM prepare_f4.

CALL METHOD alvgrid->register_f4_for_fields

EXPORTING

it_f4 = lt_f4[]

.

creating instance for event handler..................................

DATA : event_handler TYPE REF TO lcl_event_handler.

CREATE OBJECT event_handler.

SET HANDLER event_handler->handle_on_f1 FOR alvgrid.

SET HANDLER event_handler->handle_on_f4 FOR alvgrid.

preparing field catalog..............................................

PERFORM prepare_fieldcatalog CHANGING fieldcatalog.

CALL METHOD alvgrid->set_table_for_first_display

  • EXPORTING

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME =

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

  • IS_LAYOUT =

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

CHANGING

it_outtab = i_emp

it_fieldcatalog = fieldcatalog

  • IT_SORT =

  • IT_FILTER =

  • EXCEPTIONS

  • INVALID_PARAMETER_COMBINATION = 1

  • PROGRAM_ERROR = 2

  • TOO_MANY_LINES = 3

  • others = 4

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDIF.

ENDMODULE. " STATUS_3000 OUTPUT

preparing field catalog...............................................

FORM prepare_fieldcatalog CHANGING i_fieldcatalog TYPE lvc_t_fcat.

DATA : ls_fcat TYPE lvc_s_fcat.

ls_fcat-fieldname = 'code'.

ls_fcat-ref_table = 'zaemp'.

ls_fcat-coltext = 'EMPLOYEE ID'.

APPEND ls_fcat TO i_fieldcatalog.

CLEAR ls_fcat.

ls_fcat-fieldname = 'designation'.

ls_fcat-ref_table = 'zaemp'.

ls_fcat-coltext = 'EMPLOYEE NAME'.

APPEND ls_fcat TO i_fieldcatalog.

ENDFORM.

&----


*& Module USER_COMMAND_3000 INPUT

&----


  • text

----


MODULE user_command_3000 INPUT.

CASE ok_code.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_3000 INPUT

&----


*& Module USER_COMMAND_3001 INPUT

&----


  • text

----


MODULE user_command_3001 INPUT.

CASE ok_code.

WHEN 'SAVE'.

LEAVE TO SCREEN 0.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE. " USER_COMMAND_3001 INPUT

&----


*& Module STATUS_3001 OUTPUT

&----


  • text

----


MODULE status_3001 OUTPUT.

  • SET PF-STATUS 'GUI'.

  • SET TITLEBAR 'TITLE'.

*

ENDMODULE. " STATUS_3001 OUTPUT

preparing fields to be registered for f4 help.........................

FORM prepare_f4.

lt_f4-fieldname = 'designation'.

lt_f4-register = 'X'.

lt_f4-getbefore = 'X'.

lt_f4-chngeafter = 'X'.

APPEND lt_f4.

ENDFORM.

3 REPLIES 3

Former Member
0 Kudos
226

hi anid ,,,,,

Linking F1 Help to Fields

To link your own F1 help to a field, you should simply utilize the event “onf1”. At this point, The event has following

parameters at its interface:

E_FIELDNAME of type LVC_FNAME

ES_ROW_NO of type LVC_S_ROID

ER_EVENT_DATA reference to type CL_ALV_EVENT_DATA

Linking F4 Help to Fields

implement and register the event “onf4” at proper places in your code. For F4 help, you must register the fields

whose F4 request will trigger the “onf4” event. For this you must prepare a table of type “LVC_T_F4” and

register this table using the method “register_f4_for_fields”. While preparing table you must

include a line for each field which will trigger F4 event. For each field in the structure;

Pass the fieldname to ‘FIELDNAME’

Set ‘REGISTER’ to make the field registered,

Set ‘GETBEFORE’ to provide field content transport before F4 in editable mode

Set ‘CHNGEAFTER’ to make the data changed after F4 in editable mode.

athavanraja
Active Contributor
0 Kudos
226

check the standard demo programs

BCALV_F4

BCALV_GRID_F4_HELP_APPLICATION

BCALV_GRID_F4_HELPM01

BCALV_TEST_GRID_F4_HELP

Regards

Raja

Former Member
0 Kudos
227

hi anid i have one sample code for implimentation of f1 and f4 help it must clear ur all concept....

Global data definitions for ALV.......................................

DATA : alvgrid TYPE REF TO cl_gui_alv_grid,

custom_container TYPE REF TO cl_gui_custom_container,

fieldcatalog TYPE lvc_t_fcat.

table to contain fields that require f4...............................

DATA : lt_f4 TYPE lvc_t_f4 WITH HEADER LINE.

ok_code declaration...................................................

DATA : ok_code TYPE sy-ucomm.

Tables declaration....................................................

TABLES : zaemp.

Types declaration.....................................................

TYPES : BEGIN OF ty_emp,

code LIKE zaemp-code,

designation LIKE zaemp-designation,

END OF ty_emp.

Internal table declaration............................................

DATA : i_emp TYPE TABLE OF ty_emp.

Workarea declaration..................................................

DATA : wa_emp TYPE ty_emp.

Selection screen parameters...........................................

SELECT-OPTIONS : s_code FOR zaemp-code.

----


  • CLASS lcl_event_handler DEFINITION

----


  • ........ *

----


CLASS lcl_event_handler DEFINITION.

PUBLIC SECTION.

METHODS :

handle_on_f1 FOR EVENT onf1 OF cl_gui_alv_grid

IMPORTING e_fieldname es_row_no er_event_data,

handle_on_f4 for event onf4 of cl_gui_alv_grid

importing e_fieldname es_row_no er_event_data

.

ENDCLASS.

----


  • CLASS lcl_event_handler IMPLEMENTATION

----


  • ........ *

----


CLASS lcl_event_handler IMPLEMENTATION.

METHOD handle_on_f1.

custom f1 help for code field.......................................

IF e_fieldname = 'code'.

CALL SCREEN 3001.

ENDIF.

to prevent processing of standard f1 help............................

er_event_data->m_event_handled = 'X'.

ENDMETHOD.

Method handle_on_f4.

standard f4 help will be invoked......................................

endmethod.

ENDCLASS.

start of selection....................................................

START-OF-SELECTION.

SELECT code designation FROM zaemp

INTO CORRESPONDING FIELDS OF TABLE i_emp

WHERE code IN s_code.

CALL SCREEN 3000.

&----


*& Module STATUS_3000 OUTPUT

&----


  • text

----


MODULE status_3000 OUTPUT.

SET PF-STATUS 'ZTOOL'.

SET TITLEBAR 'ZTITLE'.

IF alvgrid IS INITIAL.

CREATE OBJECT custom_container

EXPORTING

container_name = 'ZCONTAINER'.

CREATE OBJECT alvgrid

EXPORTING

i_parent = custom_container.

PERFORM prepare_f4.

CALL METHOD alvgrid->register_f4_for_fields

EXPORTING

it_f4 = lt_f4[]

.

creating instance for event handler..................................

DATA : event_handler TYPE REF TO lcl_event_handler.

CREATE OBJECT event_handler.

SET HANDLER event_handler->handle_on_f1 FOR alvgrid.

SET HANDLER event_handler->handle_on_f4 FOR alvgrid.

preparing field catalog..............................................

PERFORM prepare_fieldcatalog CHANGING fieldcatalog.

CALL METHOD alvgrid->set_table_for_first_display

  • EXPORTING

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME =

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

  • IS_LAYOUT =

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

CHANGING

it_outtab = i_emp

it_fieldcatalog = fieldcatalog

  • IT_SORT =

  • IT_FILTER =

  • EXCEPTIONS

  • INVALID_PARAMETER_COMBINATION = 1

  • PROGRAM_ERROR = 2

  • TOO_MANY_LINES = 3

  • others = 4

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDIF.

ENDMODULE. " STATUS_3000 OUTPUT

preparing field catalog...............................................

FORM prepare_fieldcatalog CHANGING i_fieldcatalog TYPE lvc_t_fcat.

DATA : ls_fcat TYPE lvc_s_fcat.

ls_fcat-fieldname = 'code'.

ls_fcat-ref_table = 'zaemp'.

ls_fcat-coltext = 'EMPLOYEE ID'.

APPEND ls_fcat TO i_fieldcatalog.

CLEAR ls_fcat.

ls_fcat-fieldname = 'designation'.

ls_fcat-ref_table = 'zaemp'.

ls_fcat-coltext = 'EMPLOYEE NAME'.

APPEND ls_fcat TO i_fieldcatalog.

ENDFORM.

&----


*& Module USER_COMMAND_3000 INPUT

&----


  • text

----


MODULE user_command_3000 INPUT.

CASE ok_code.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_3000 INPUT

&----


*& Module USER_COMMAND_3001 INPUT

&----


  • text

----


MODULE user_command_3001 INPUT.

CASE ok_code.

WHEN 'SAVE'.

LEAVE TO SCREEN 0.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE. " USER_COMMAND_3001 INPUT

&----


*& Module STATUS_3001 OUTPUT

&----


  • text

----


MODULE status_3001 OUTPUT.

  • SET PF-STATUS 'GUI'.

  • SET TITLEBAR 'TITLE'.

*

ENDMODULE. " STATUS_3001 OUTPUT

preparing fields to be registered for f4 help.........................

FORM prepare_f4.

lt_f4-fieldname = 'designation'.

lt_f4-register = 'X'.

lt_f4-getbefore = 'X'.

lt_f4-chngeafter = 'X'.

APPEND lt_f4.

ENDFORM.