ALV参考文档 ( 14 ) - 表单修改内容处理

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.
 
 SORT ir_data_changed->nt_mod_cells BY row_id.
 LOOP AT ir_data_changed->nt_mod_cells
                        INTO ls_mod_cell
                       WHERE fieldname = ‘SEATSMAX’.
CALL METHOD ir_data_changed->get_cell_value
     EXPORTING i_row_id = ls_mod_cell-row_id
                 I_fieldname = ‘CARRID’
     IMPORTING e_value    = lv_value.
 IF lv_value = ‘THY’ AND ls_mod_cell-value > ‘500’.
   CALL METHOD ir_data_changed->add_protocol_entry
         EXPORTING
            I_msgid = ‘SU’
            I_msgno = ‘000’
            I_msgty = ‘E’
            I_msgv1 = ‘This number can not exceed 500 for ‘
            I_msgv2 = lv_value
            I_msgv3 = ‘The value is et to ‘’500’’’
            I_fieldname = ls_mod_cell-fieldname
            I_row_id = ls_mod_cell-rowid.
   CALL METHOD ir_data_changed->modify_cell
         EXPORTING i_row_id = ls_mod_cell-row_id
                      I_fieldname = ls_mod_cell-fieldname
                     I_value = ‘500’.
 ENDIF.
 ENDLOOP.
ENDFORM.
给字段添加f1帮助功能
只要使用时间onf1就可以为字段添加f1帮助功能。这个事件有下面几个参数
Ø         E_FIELDNAME 类型LVC_FNAME
Ø         ES_ROW_NO 类型LVC_S_ROID
Ø         ER_EVENT_DATA 指向类CL_ALV_EVENT_DATA的指针变量
下面是一段简单的代码:
METHOD handle_on_f1.
 PERFORM f1_help USING e_fieldname es_row_no.
 Er_event->m_event_handle = ‘X’.
ENDMETHOD.
这里设置了er_event->m_event_handle用来阻止标准的F1功能。
给字段添加f4功能
最后我们将介绍如何为字段添加F4功能。同样简单,只要使用时间onf4就可以了。首先要确定哪个字段要触发f4功能。需要准备一个类型为LVC_T_F4的内表并使用方法register_f4_for_fields来注册它。对于这个表每个要触发f4事件的就是一行。
Ø         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
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[].
METHOD handle_on_f4.
   PERFORM f4_help USING e_fieldname es_row_no.
   Er_event_data->m_event_handle = ‘X’.
ENDMETHOD.
同样,er_event_data->m_event_handle=’X’是为了阻止标准的F4功能。
常见问题
NO
Question
Answer
1
I register my local class as event handler for all ALV instances. How can it be known which instance evoke 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 propable problem is that you are trying to filter a text field and since you don’t set the lowercase property at the field catalog. ALV just look for 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 register the method register_edit_event by which you also select the way ALV grid perceive changes
5
My function buttons are not visible on the tool bar
You should have forgotten to call the method set_toolbar_interactive
6
Can I modify the grid 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’ in the fieldcatalog. 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 my class definition above data declarations, then variables are not reconized
Before your global 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 definition related to this class after it is included.
11
Can I display hierarchical lists using the ALV GRID control?
No.ALV GRID control doesn’t support hierarchical lists.
12
I made an editable ALV GRID control and I’m utilizing data_changed event to control the data input. However I got entries some of which exist there although the are corrected. Is there a refresh problem?Where?
Exaclty. Use the method refresh_control 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 restriced so.Try to change your page header layout
14
Does the ALV GRID control support the drag and drop ?
At other than SAPGUI for HTML interfaces, the ALV GRID control supports drag and drop.But this topis 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 this reason, inspect your field catalog again.
 

你可能感兴趣的:(filter,layout,Class,文档,sorting,structure)