SAP Community Community Network Wiki - ABAP Development - Object Model ALV - Interactive
Strona 1
Welcome, Welcome, Guest Guest Login Register Getting Sta Getting Started rted Newsletters Store
Solutions SAP SAP Serv Servic ices es & Supp Suppor ortt Abou Aboutt SCN SCN Downloads Industries Traini Training ng & Educat Education ion Partnership Developer Devel oper Cente Centerr Line Lines s of Busi Busine ness ss University University Alliances Alliances Even Events ts & Webin Webinar ars s Idea Ide a Pla Place ce
Obje Ob ject ct Mo Mode dell AL ALV V - In Inte tera ract ctiv ive e Adde Ad ded d by Ash Ashish ish Raw Rawal,last al,last ed edite ited d by Ash Ashish ish Ra Rawa wall on Ma May y 26 26,, 20 2011 11 Interactiv Interactive e Object Object Model ALV ALV Objec Objectt Mode Modell ALV ALV surpr surpris ises es with with its its fast fast and and effi effici cien entt way way of gene genera rati ting ng repor reports ts.. We willgo willgo step step by step step and and lear learn n how how easil easily y we can crea create te Inte Intera ract ctiv ive e ALV ALV repo report rt . Ther There e are are thre three e main main clas classes ses (Fig (Fig 1) suppor supporte ted d by Objec Objectt ModelALV ModelALV to gener generat ate e 1)
Two dimensional dimensional table
2)
Hierarchical Hierarchical Sequential Sequential List
3)
Tree Structure Structure
Unknown Unknown macro: {gliffy} {gliffy}
(Fig (Fig 1.) Starti Starting ng with with an exampl example e of creati creating ng two dimensi dimensional onal table table displa display y in full full screen screen displa display y type. I have have take taken n a very very simpl simple e examp example le of disp displa layi ying ng sales sales docum documen entt item item level level data, data, whic which h takes takes docum documentnumb entnumber er as an input input.. Refere Reference nce Table Table:: VBAP VBAP - Sales Sales Documen Documentt Item. Item. Firs Firstl tly y we have have to desi design gn a select selectio ion n scree screen, n, since since we are are goin going g a litt little le simp simple,I le,I have have just just crea create ted d a sele select ctio ion n opti option on on docume document nt numbe numberr i.e. i.e. VBAPVBAP-VB VBEL ELN. N. *------------------* * Selection Screen *------------------* SELECT-OPTIONS: s_vbeln FOR vbap-vbeln. Data Data Declar Declarati ation: on: Nowthat we have create created d our littl little e select selection ion screen screen,, we will will do the data data declara declaratio tion n as follow follows sWe have have to crea create te an inst instan ance ce of class classCL_SALV_TABLE CL_SALV_TABLE . *-------------------* * Data Declaration *-------------------* DATA: g_alv
TYPE REF TO cl_salv_table,
g_alv_functions TYPE REF TO cl_salv_functions, g_display g_agg
TYPE REF TO cl_salv_display_settings, TYPE REF TO cl_salv_aggregations.
TYPES: BEGIN OF t_vbap, vbeln TYPE vbap-vbeln, matnr TYPE vbap-matnr, netwr TYPE vbap-netwr, END OF t_vbap. DATA: i_vbap TYPE TYPE STANDARD STANDARD TABLE TABLE OF t_vbap, "Internal Table w_vbap LIKE LINE OF i_vbap.
"Work Area
Start Start of Selecti Selection on screen screen:: Now we willuse willuse start start of selecti selection on event event to fill fill out intern internal al table table i_vbap i_vbap..
http://wiki.sdn.sap.com/wiki/display/AB http://wiki.sdn.sap.com /wiki/display/ABAP/Object+Model+ALV+-+Interactive AP/Object+Model+ALV+-+Interactive
2012-06-04 14:40:22
SAP Community Network Wiki - ABAP Development - Object Model ALV - Interactive
Strona 2
SELECT vbeln matnr netwr FROM vbap INTO TABLE i_vbap WHERE vbeln IN s_vbeln. On successful retrieval of values in the internal table, we will haveto call the factory method of class CL_SALV_TABLE. We can open the samein SE80 Patterns. TRY. CALL METHOD cl_salv_table=>factory IMPORTING r_salv_table = g_alv CHANGING t_table
= i_vbap.
CATCH cx_salv_msg. ENDTRY. Would you believe if I say ALV list is complete after you calldisplay method of CL_SALV_TABLE class? g_alv->display( ). , ALV list is ready, isnt itfast? lets learn how to make it interactive. We willcreate a button on application tool bar. To create a button,we willhave to set the Gui Status.
Yes
In SE80, function group, and enter SALV_TABLE_STANDARD and copyit to the report. After PF status has been copied, we set screen status *------------------------* * Making ALV Interactive. *------------------------* g_alv->set_screen_status (pfstatus = 'SALV_TABLE_STANDARD' report = sy-repid set_functions = g_alv->c_functions_all ). Here c_functions_all, sets all function keys. Similarly there are other constants like C_FUNCTIONS_NONE and C_FUNCTIONS_DEFAULT. ALV object model has four selection modes. Selection Mode rows
Single
Constants SINGLE
Multiple Rows
MULTIPLE
Rows and Columns
COLUMN
Particular Cell
ROW_
CELL
g_selections = g_alv->get_selections( ). g_selections->set_selection_mode( g_selections->single ). After we have set the selection mode, we create a event handler class. Whenthe event is triggered method on_user_command is called and OK_CODE is captured in e_salv_function, based on which case statement executes. *&----------------------------------------------* *&
Class LCL_EVENT_HANDLER
*&----------------------------------------------* CLASS lcl_handle_events DEFINITION. PUBLIC SECTION. METHODS: on_user_command FOR EVENT added_function OF cl_salv_events_table IMPORTING e_salv_function. ENDCLASS.
"LCL_EVENT_HANDLER DEFINITION
*-------------------------------------------------------* *
CLASS lcl_event_handler IMPLEMENTATION
*--------------------------------------------------------* CLASS lcl_handle_events IMPLEMENTATION. METHOD on_user_command. CASE e_salv_function. WHEN 'MYFUNCTION'. g_selections = g_alv->get_selections( ) . MESSAGE : i001(00) WITH 'You have selected a row '. WHEN OTHERS. ENDCASE. ENDMETHOD. ENDCLASS.
"on_user_command "lcl_event_handler IMPLEMENTATION
Please see the code below, in which I have used extra classes like - cl_salv_functions, settings,
cl_salv_display_
cl_salv_aggregations.
Code Example TABLES: vbap. *------------------* * Selection Screen *------------------* SELECT-OPTIONS: s_vbeln FOR vbap-vbeln. *-------------------* * Data Declaration *-------------------*
http://wiki.sdn.sap.com/wiki/display/ABAP/Object+Model+ALV+-+Interactive
2012-06-04 14:40:22
SAP Community Network Wiki - ABAP Development - Object Model ALV - Interactive DATA: g_alv
Strona 3
TYPE REF TO cl_salv _table ,
g_alv_functions TYPE REF TO cl_salv_functions, g_display
TYPE REF TO cl_salv_display_settings,
g_agg
TYPE REF TO cl_salv_aggregations,
g_selections g_events g_rows
TYPE REF TO cl_salv_selections, TYPE REF TO cl_salv_events_table, TYPE salv_t_row.
TYPES: BEGIN OF t_vbap, vbeln TYPE vbap-vbeln, matnr TYPE vbap-matnr, netwr TYPE vbap-netwr, END OF t_vbap. * Internal Table DATA: i_vbap TYPE STANDARD TABLE OF t_vbap. * Work area DATA: w_vbap LIKE LINE OF i_vbap. *&-------------------------------------------------* *&
Class LCL_EVENT_HANDLER
*&-------------------------------------------------* CLASS lcl_handle_events DEFINITION. PUBLIC SECTION. METHODS: on_user_command FOR EVENT added_function OF cl_salv_events_table IMPORTING e_salv_function. ENDCLASS.
"LCL_EVENT_HANDLER DEFINITION
DATA : g_event_handler TYPE REF TO lcl_handle_events. *---------------------* * Start of Selection *---------------------* START-OF-SELECTION. SELECT vbeln matnr netwr FROM vbap INTO TABLE i_vbap WHERE vbeln IN s_vbeln. IF sy-subrc = 0. *----------------------------------* * Create the instance of the class. *----------------------------------* TRY. CALL METHOD cl_salv_table=>factory IMPORTING r_salv_table = g_alv CHANGING t_table
= i_vbap.
CATCH cx_salv_msg . ENDTRY. * ALV functions g_alv_functions = g_alv->get_functions( ). g_alv_functions->set_all( abap_true ). **---------------------* ** Display Settings **---------------------* g_display = g_alv->get_display_settings( ) . g_display->set_striped_pattern( cl_salv _display_settings=>true ). g_display->set_list_header('Heading by Ashish Rawal'). ENDIF. *-------------------------* * Aggregation Functions *-------------------------* g_agg = g_alv->get_aggregations( ). g_agg->add_aggregation('NETWR'). *------------------------* * Making ALV Interactive. *------------------------* g_alv->set_screen_status( pfstatus = 'SALV_TABLE_STANDARD' report = sy-repid set_functions = g_alv->c_functions_all ). g_selections = g_alv->get_selections( ). g_selections->set_selection_mode( g_selections->single ). *--------------------------* * Event Handling Starts *--------------------------*
http://wiki.sdn.sap.com/wiki/display/ABAP/Object+Model+ALV+-+Interactive
2012-06-04 14:40:22
SAP Community Network Wiki - ABAP Development - Object Model ALV - Interactive
Strona 4
g_events = g_alv->get_event( ). CREATE OBJECT g_event_handler. SET HANDLER g_event_handler->on_user_command FOR g_events. *-----------------------* * Displaying the ALV *-----------------------* g_alv->display( ). *-------------------------------------------------------------------* *
CLASS lcl_event_handler IMPLEMENTATION
*-------------------------------------------------------------------* CLASS lcl_handle_events IMPLEMENTATION. METHOD on_user_command. CASE e_salv_function. WHEN 'MYFUNCTION'. g_selections = g_alv->get_selections( ) . MESSAGE : i001(00) WITH 'You have selected a row'. WHEN OTHERS. ENDCASE. ENDMETHOD. ENDCLASS.
"on_user_command "lcl_event_handler IMPLEMENTATION
Labels code gallery netweaver sdn teched sap abap object tips wiki
Comments (7)
Follow SCN Contact Us SAP Help Portal Privacy Terms of Use Legal Disclosure Copyright
http://wiki.sdn.sap.com/wiki/display/ABAP/Object+Model+ALV+-+Interactive
2012-06-04 14:40:22