Материал: grid

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
background image

An Easy Reference for ALV Grid Control

 
 
 The 

event 

“

data_changed

” makes you aware about F4 functions. It sets the appropriate parameter 

from the group with respect to where it was triggered. These parameters are { 

E_ONF4, 

E_ONF4_BEFORE, E_ONF4_AFTER

 }. 

 
 

Linking F1 Help to Fields 

 
 
 

To link your own F1 help to a field, you should simply utilize the event “

onf1

”. At this point, it is 

assumed that you know how to define, implement and register an event. 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

 
 

And, here is a simple sample code for the method. 

  

METHOD handle_on_f1 . 

    PERFORM f1_help USING e_fieldname es_row_no . 

    er_event_data->m_event_handled = 'X' . 

  ENDMETHOD 

.

Code Part 35 - 

A sample code for the event”onf1” 

 
 

Here we set the attribute “

er_event_data->m_event_handled

” to prevent further processing of 

standard F1 help. 
 
 

Linking F4 Help to Fields 

 
 
 

For the last section, we will deal with linking F4 help to fields. It is easy. As usual, define, 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. 

 
 
 
 
 

© 2005 SAP AG 

51 

background image

An Easy Reference for ALV Grid Control

DATA: lt_f4 TYPE lvc_t_f4 WITH HEADER LINE . 

.. .. 

    lt_f4-fieldname = 'PRICE'. 

    lt_f4-register = 'X' . 

    lt_f4-getbefore = 'X' . 

    APPEND lt_f4 . 

    CALL METHOD gr_alvgrid->register_f4_for_fields 

      EXPORTING 

        it_f4  = lt_f4[] . 

Code Part 36 – 

Preparing table for the fields to be registered to trigger F4 event 

  

METHOD handle_on_f4 . 

    PERFORM f4_help USING e_fieldname es_row_no . 

    er_event_data->m_event_handled = 'X' . 

  ENDMETHOD . 

Code Part 37 – 

A sample “onf4” method implementation 

 
 

Again, we set the attribute “

er_event_data->m_event_handled

” to prevent further processing of 

standard F4 help. 
 

© 2005 SAP AG 

52 

background image

An Easy Reference for ALV Grid Control

A Piece of Troubleshooting 

No Question 

Answer 

1 

I register my local class as the 
event handler for all ALV 
instances. How can it be known 
which instance evokes the 
handler? 

As a property of ABAP OOP, you can use 
the predefined parameter “

sender

” in the 

event interface. This parameter refers to 
the caller instance. 

2 

When I wanted to filter with 
respect to a field, it couldn’t 
handle it. There were matching 
records but it didn’t retrieve 
them. 

The most probable problem is that you 
are trying to filter a text field and since 
you didn’t set the “

lowercase

” property 

at the field catalog, ALV just looks for the 
upper case. Set this property for that field 
while generating the field catalog. 

3 

I make some style settings to 
individual rows or cells before I 
call first display method. 
However, I can’t get the result 
as I want. 

Follow all the steps described in related 
sections. 

1.  You may have forgotten to call 

“

set_ready_for_input

” if you are 

talking about making cells editable. 

2.  There may be a filter which makes the 

row of styled cell invisible or a sorting 
may have changed the order of the 
row making it somewhere downwards 
so that you can’t realize it. 

4 

The event “

data_changed

” is 

not triggered 

You should have not called the method 
“

register_edit_event

” by which you 

also select the way ALV Grid perceives 
changes 

5 

My function buttons are not 
visible on the toolbar 

You should have forgotten to call the 
method “

set_toolbar_interactive

”. 

6 

Can I modify the grid title during 
execution? 

Yes. Use the method “

set_gridtitle

”. 

7 

I want to add a pushbutton with 
an icon for a column. Can I do 
that? 

Yes. Set the property ‘

ICON

” for the 

column to ‘X’ at the field catalog. Then do 
the style setting as to make it pushbutton. 
Pass the icon name to the field as its 
content. 

8 

Can I hide the header? 

Yes. Set the property “

no_headers

” of 

the layout structure to ‘X’. 

9 

Can I hide the ALV toolbar? 

Yes. Set the property “

no_toolbar

” of 

the layout structure to ‘X’. 

10 

It cannot find my local class on 
the line where I declare my 
event handler reference 
variable. When I take my class 
definition above data 
declarations, then variables are 
not recognized. 

Before your global data definitions, make 
the interpreter be aware that your local 
class is defined somewhere in your 
program. For this, use  
“

CLASS <class> DEFINITION DEFERRED

” 

or simply make your definitions related to 
this class after it is included. 

11 

Can I display hierarchical lists 
using the ALV Grid Control? 

No. ALV Grid Control does not support 
hierarchical lists. 

© 2005 SAP AG 

53 

background image

An Easy Reference for ALV Grid Control

12 

I made an editable ALV Grid 
and I am utilizing 
“

data_changed

” event to 

control the data input. However, 
I got log entries some of which 
exist there although they are 
corrected. Is there a refresh 
problem? Where? 

Exactly. Use the method 
“

REFRESH_PROTOCOL

” of the instance 

came via the parameter at appropriate 
place to overcome. 

13 

I utilize 
“

print_top_of_page

” event. 

However, at preview, it sets the 
line size to the maximum of 80 
and the list size. How can I 
overcome this? 

Its line-size is restricted so. Try to change 
your page header layout. 

14 

Does the ALV Grid Control 
support Drag & Drop? 

At other than SAPGUI for HTML 
interfaces, the ALV Grid control supports 
Drag & Drop. However, this topic was not 
included in the context of this tutorial. 

15 

Displayed columns are not as I 
programmed 

Check whether a display variant is 
activated. If this is not the reason, inspect 
your field catalog again. 

 
 
 

Author Bio 

 Serdar 

Ş

im

ş

ekler

 is an SAP application developer working for 

Havelsan Inc., 

Turkey

. He has experience with ABAP program development. He is also studying for 

an M.A. degree at the department of philosophy at METU. 

ssimsekler@yahoo.com

  

 
 
 
 

© 2005 SAP AG 

54 

Источник: https://files.student-it.ru/previewfile/15386