0% found this document useful (0 votes)
184 views5 pages

How To Easy Create A Search Help in ALV OOPS Editable Field - SAP Blogs

The document provides a step-by-step guide on how to create a custom Search Help for an editable field in an ALV OOPS environment in SAP. It details the necessary code snippets and event handling required to implement the F4 help functionality for a specific field called BWTAR. The process includes setting field attributes, registering the field for F4, and defining the event handler to manage the F4 event and display the search help popup.

Uploaded by

ANDRE DWI CAHYA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
184 views5 pages

How To Easy Create A Search Help in ALV OOPS Editable Field - SAP Blogs

The document provides a step-by-step guide on how to create a custom Search Help for an editable field in an ALV OOPS environment in SAP. It details the necessary code snippets and event handling required to implement the F4 help functionality for a specific field called BWTAR. The process includes setting field attributes, registering the field for F4, and defining the event handler to manage the F4 event and display the search help popup.

Uploaded by

ANDRE DWI CAHYA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

25/08/23, 09.

44 How to Easy… Create a Search Help in ALV OOPS editable field | SAP Blogs

Community Topics Groups Answers Blogs Events Programs Resources What's New Explore SAP

Ask a Question Write a Blog Post Login

Guilherme Frisoni
April 2, 2013 | 4 minute read

How to Easy… Create a Search Help in ALV OOPS editable field


 7  15  28,948

When we use an editable ALV, some fields must have a custom Search Help. Let’s describe the simple way to add a custom Search Help to a specific field of
an ALV using OOPS.

Assuming we have a field called BWTAR in our alv table GT_OUT.

At fieldcat, we need to set this field editable and with F4:

CLEAR ls_fcat.

ls_fcat-fieldname = ‘BWTAR’.

ls_fcat-ref_field = ‘BWTAR’.

ls_fcat-ref_table = ‘MBEW’.

ls_fcat-edit = ‘X’.

ls_fcat-f4availabl = ‘X’.

APPEND ls_fcat TO gt_fcat.

After create ALV Object GO_ALV, we need to register BWTAR field for F4 and set ONF4 event handler.

DATA: lt_f4 TYPE lvc_t_f4 WITH HEADER LINE.

CLEAR lt_f4.

lt_f4-fieldname = ‘BWTAR’.

lt_f4-register = ‘X’.

INSERT table lt_f4.

” Register F4 for BWTAR

CALL METHOD go_alv->register_f4_for_fields

EXPORTING

it_f4 = lt_f4[].

” Set Handler

SET HANDLER lo_handler->handle_on_f4 FOR go_alv.

In our local event handler class, we need to define the ONF4 event and code it.

CLASS lcl_event_handler DEFINITION FINAL.

PUBLIC SECTION.

METHODS:

handle_on_f4

FOR EVENT onf4 OF cl_gui_alv_grid

IMPORTING e_fieldname

es_row_no

https://blogs.sap.com/2013/04/02/how-to-easy-create-a-search-help-in-alv-oops-editable-field/ 1/5
25/08/23, 09.44 How to Easy… Create a Search Help in ALV OOPS editable field | SAP Blogs
er_event_data.

ENDCLASS.

CLASS lcl_event_handler IMPLEMENTATION.

*–Handle On F4

METHOD handle_on_f4.

PERFORM handle_on_f4

USING e_fieldname

es_row_no

er_event_data.

ENDMETHOD.

ENDCLASS.

At last, let’s code handle_on_f4 perform:

FORM handle_on_f4

USING e_fieldname TYPE lvc_fname

es_row_no TYPE lvc_s_roid

er_event_data TYPE REF TO cl_alv_event_data.

” Types

TYPES: BEGIN OF ys_bwtar,

bwtar TYPE mbew-bwtar,

END OF ys_bwtar.

” Local Vars

DATA: lt_bwtar TYPE TABLE OF ys_bwtar,

ls_bwtar TYPE ys_bwtar,

lt_map TYPE TABLE OF dselc,

ls_map TYPE dselc,

lt_return TYPE TABLE OF ddshretval,

ls_return TYPE ddshretval,

ls_stable TYPE lvc_s_stbl.

” Field-symbols

FIELD-SYMBOLS: <l_out> TYPE ys_out. ” ALV table line

” Check which field raise f4 event

CASE e_fieldname.

WHEN ‘BWTAR’.

” Read current line

READ TABLE gt_out ASSIGNING <l_out>

INDEX es_row_no-row_id.

” Load F4 Data

SELECT bwtar

FROM mbew

INTO TABLE lt_bwtar

WHERE matnr = <l_out>-matnr AND

bwkey = <l_out>-werks.

https://blogs.sap.com/2013/04/02/how-to-easy-create-a-search-help-in-alv-oops-editable-field/ 2/5
25/08/23, 09.44 How to Easy… Create a Search Help in ALV OOPS editable field | SAP Blogs

” Set return field

CLEAR ls_map.

ls_map-fldname = ‘F0001’.

ls_map-dyfldname = ‘BWTAR’.

APPEND ls_map TO lt_map.

” Call Search Help Popup Function

CALL FUNCTION ‘F4IF_INT_TABLE_VALUE_REQUEST’

EXPORTING

retfield = ‘BWTAR’

value_org = ‘S’

TABLES

value_tab = lt_bwtar

dynpfld_mapping = lt_map

return_tab = lt_return

EXCEPTIONS

parameter_error = 1

no_values_found = 2

OTHERS = 3.

” Read selected f4 value

READ TABLE lt_return INTO ls_return WITH KEY fieldname = ‘F0001’.

IF ls_return IS NOT INITIAL.

” Update ALV table

<l_out>-bwtar = ls_return-fieldval.

ENDIF.

ENDCASE.

ls_stable = ‘XX’. ” Set stable refresh for row and column

” ALV Refresh

CALL METHOD go_alv->refresh_table_display

EXPORTING

is_stable = ls_stable

i_soft_refresh = ‘X’

EXCEPTIONS

finished = 1

OTHERS = 2.

” Avoid possible standard Search Help

er_event_data->m_event_handled = ‘X’.

ENDFORM.

That’s it!

Alert Moderator

https://blogs.sap.com/2013/04/02/how-to-easy-create-a-search-help-in-alv-oops-editable-field/ 3/5
25/08/23, 09.44 How to Easy… Create a Search Help in ALV OOPS editable field | SAP Blogs

Assigned Tags
Follow

ABAP Development | abap | abap objects | alv | alv oopl | alv-grid | cl gui alv grid
 Like
View more... 

 RSS Feed
Similar Blog Posts 
How to Easy... Create a Search Help by code and fill more than one field in screen How to create a Class in ABAP 00 - 6 Steps to start
By Guilherme Frisoni Mar 15, 2013 By Joachim Rees Feb 24, 2022

Simple event handling in ABAP OOPS Part 3


By Former Member May 27, 2016

Related Questions 
Update value in a cell in ALV using OOPS Disable few fields in SM30 (TMG)
By Jitendra Soni Mar 19, 2018 By Former Member Jun 14, 2013

display into two rows in ALV GRID disaply using OO ALVS


By Sudhakara Reddy May 23, 2008

7 Comments

You must be Logged on to comment or reply to a post.

khushbu Agarwal
March 18, 2015 at 7:25 am

very nice and helpful blog, it would be great if mentioned step by step approach with the reason of doing it.

Like 0 | Share

Radouane Sbaa
September 25, 2017 at 8:11 pm

Thanks, very useful !

Like 0 | Share

Sandra Rossi
March 19, 2018 at 2:13 pm

The title of your post is a little bit misleading: you are not using a Search Help, you are implementing the F4 Help. A Search Help is an object from the ABAP Dictionary (DDIC).

Like 0 | Share

Mohamed Hamdy
May 12, 2018 at 4:03 pm

Perfect, Thank you

Like 0 | Share

Vivin Gomez
July 13, 2019 at 10:00 am

https://blogs.sap.com/2013/04/02/how-to-easy-create-a-search-help-in-alv-oops-editable-field/ 4/5
25/08/23, 09.44 How to Easy… Create a Search Help in ALV OOPS editable field | SAP Blogs

It is displaying F4 help and picking the values perfectly, but an internal error occurs “Search help: Internal error: DestroyTab 2” that makes my SAP to crash

Like 0 | Share

madjid khanevadegi
May 18, 2020 at 11:11 am

Hi

useful and very good

thanks

Like 0 | Share

Edwin García Ospina


June 26, 2020 at 8:58 pm

Hi,

Thank you, useful and very good

Like 0 | Share

Find us on

Privacy Terms of Use

Legal Disclosure Copyright

Trademark Cookie Preferences

Newsletter Support

https://blogs.sap.com/2013/04/02/how-to-easy-create-a-search-help-in-alv-oops-editable-field/ 5/5

You might also like