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: 

Attach F4 to an editable field in ALV Gird

Former Member
0 Kudos
488

Hi all,

I have an (OO)ALV grid editable. I have 2 fields MATNR and MAKTX. Requirement is, to attach an F4 to MATNR and as soon as i populate the MATNR field (through F4), the MAKTX field should get automaticaly populated with corresponding value. Kindly help.

Thanks in advance

Abhilash

3 REPLIES 3

Former Member
0 Kudos
140

chk these standard reports

BCALV_EDIT_08                  Integrate Non-Standard F4 Help
BCALV_F4                       Possible entries
BCALV_GRID_EDIT_DELTA          Example Report for F4 Help of the ALV Grid
BCALV_GRID_F4_HELP_APPLICATION
BCALV_GRID_F4_HELPM01
BCALV_TEST_GRID_EDIT           F4 Help
BCALV_TEST_GRID_F4_HELP        Example Report for F4 Help of the ALV Grid

Former Member
0 Kudos
140

In the field catalog if u assign the

REF_FIELD = 'MATNR'

REF_TABLE = 'MARA'.

F4 will come automatically.

Use the handle_data_change event for changing the values in MAKTX.

After calling the first table for display (CALL METHOD o_alvgrid->set_table_for_first_display)

Set the handler for handling the event handle_data_changed.

SET HANDLER o_event_receiver->handle_data_changed FOR o_alvgrid.

*-- ALV Grid data declaration

----


  • CLASS v_lcl_event_receiver DEFINITION

----


CLASS lcl_event_receiver DEFINITION.

methods:

handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed.

ENDCLASS. "o_lcl_event_receiver DEFINITION

----


  • CLASS LCL_EVENT_RECEIVER IMPLEMENTATION

----


CLASS lcl_event_receiver IMPLEMENTATION.

    • "handle_data_changed

METHOD handle_data_changed.

PERFORM handle_data_changed USING er_data_changed.

ENDMETHOD. "handle_data_changed

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

&----


*& Form f2200_handle_data_changed

&----


  • Handle Data Changed in the ALV grid

----


FORM handle_data_changed USING ir_data_changed

TYPE REF TO

cl_alv_changed_data_protocol.

DATA : ls_mod_cell TYPE lvc_s_modi,

  • lv_value TYPE lvc_value,

lws_date TYPE scal-date.

DATA: lws_contrlife LIKE zspa_es_contlife-zzcontrlife,

lwa_contrlife TYPE zspa_es_contlife,

lws_mod_eff_code TYPE zspa_es_mod_code-zzmod_eff_code,

lwa_mod_eff_code TYPE zspa_es_mod_code.

SORT ir_data_changed->mt_mod_cells BY row_id .

LOOP AT ir_data_changed->mt_mod_cells

INTO ls_mod_cell

WHERE fieldname = text-025 "ZZCONTRLIFE

OR fieldname = text-026 "ZZMOD_EFF_CODE

OR fieldname = text-027 "DATE

OR fieldname = text-028. "CLIENT_AGGR.

READ TABLE i_final INTO wa_final

INDEX ls_mod_cell-row_id.

IF sy-subrc = 0.

IF ls_mod_cell-fieldname = text-025. "ZZCONTRLIFE

lws_contrlife = ls_mod_cell-value.

SELECT SINGLE * FROM zspa_es_contlife

INTO lwa_contrlife WHERE zzcontrlife = lws_contrlife.

IF sy-subrc NE 0.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-025

i_value = ''.

MESSAGE s001(zesspa) WITH text-035.

EXIT.

ELSE.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-025

i_value = lws_contrlife.

wa_final-zzcontrlife = lws_contrlife.

MODIFY i_final FROM wa_final INDEX ls_mod_cell-row_id.

ENDIF.

ENDIF.

IF ls_mod_cell-fieldname = text-026. "ZZMOD_EFF_CODE

lws_mod_eff_code = ls_mod_cell-value.

SELECT SINGLE * FROM zspa_es_mod_code

INTO lwa_mod_eff_code

WHERE zzmod_eff_code = lws_mod_eff_code.

IF sy-subrc NE 0.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-026

i_value = ''.

MESSAGE s001(zesspa) WITH text-036.

EXIT.

ELSE.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-026

i_value = lws_mod_eff_code.

wa_final-zzmod_eff_code = lws_mod_eff_code.

IF wa_final-zzmod_eff_code = 1 OR

wa_final-zzmod_eff_code = 2.

wa_final-date = ''.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-027

i_value = ''.

ENDIF.

MODIFY i_final FROM wa_final INDEX ls_mod_cell-row_id.

**-- No Edit control for Date when mode eff code = '1', '2'.

PERFORM no_edit_for_date TABLES i_final.

*This perform Refresh's the ALV list and Set's the Focus to

*Current Cell and keep the Scroll bar in the same place.

PERFORM alv_refresh.

ENDIF.

ENDIF.

IF ls_mod_cell-fieldname = text-027. "DATE

CONCATENATE ls_mod_cell-value+6(4)

ls_mod_cell-value+3(2)

ls_mod_cell-value+0(2) INTO lws_date.

IF lws_date NE ''.

IF lws_date > sy-datum.

wa_final-date = lws_date.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-027

i_value = lws_date.

MODIFY i_final FROM wa_final INDEX ls_mod_cell-row_id.

ELSE.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-027

i_value = ''.

MESSAGE s001(zesspa) WITH text-037.

EXIT.

ENDIF.

ENDIF.

ENDIF.

IF ls_mod_cell-fieldname = text-028. "CLIENT_AGGR

TRANSLATE ls_mod_cell-value TO UPPER CASE. "#EC SYNTCHAR

*"#EC TRANSLANG

IF ls_mod_cell-value EQ c_s OR ls_mod_cell-value EQ c_n.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-028

i_value = ls_mod_cell-value.

wa_final-client_aggr = ls_mod_cell-value.

MODIFY i_final FROM wa_final INDEX ls_mod_cell-row_id.

ELSE.

CALL METHOD ir_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cell-row_id

i_fieldname = text-028

i_value = ''.

MESSAGE s001(zesspa) WITH text-039.

EXIT.

ENDIF.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. " handle_data_changed

Regards,

Prakash.

former_member188685
Active Contributor
0 Kudos
140

Hi,

In this case You will have only F4 help for MATNR , and after you select the MATNR from F4 Help you need to Get the MAKTX from MAKT table and show. all these can be done in DATA_CHANGED event since it is editable Grid.

for getting MATNR f4 help use REF_FIELD and REF_TABNAME in fieldcat.

Regards

vijay