Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

SAP Community Network Wiki - ABAP Development - Object Model ALV - Interactive

Strona 1

Welcome, Guest Login Register Getting Started Newsletters Store

Solutions SAP Services & Support About SCN Downloads Industries Training & Education Partnership Developer Center Lines of Business University Alliances Events & Webinars Idea Place

Object Model ALV - Interactive


Added by Ashish Rawal, last edited by Ashish Rawal on May 26, 2011
Interactive Object Model ALV Object Model ALV surprises with its fast and efficient way of generating reports. We will go step by step and learn how easily we can create Interactive ALV report . There are three main classes (Fig 1) supported by Object Model ALV to generate 1) 2) 3) Two dimensional table Hierarchical Sequential List Tree Structure

Unknown macro: {gliffy}

(Fig 1.) Starting with an example of creating two dimensional table display in full screen display type. I have taken a very simple example of displaying sales document item level data, which takes document number as an input. Reference Table: VBAP - Sales Document Item. Firstly we have to design a selection screen, since we are going a little simple, I have just created a selection option on document number i.e. VBAP-VBELN. *------------------* * Selection Screen *------------------* SELECT-OPTIONS: s_vbeln FOR vbap-vbeln. Data Declaration: Now that we have created our little selection screen, we will do the data declaration as follows We have to create an instance of class CL_SALV_TABLE. *-------------------* * Data Declaration *-------------------* DATA: g_alv g_display g_agg TYPE REF TO cl_salv_table, TYPE REF TO cl_salv_display_settings, TYPE REF TO cl_salv_aggregations.

g_alv_functions TYPE REF TO cl_salv_functions,

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 STANDARD TABLE OF t_vbap, "Internal Table w_vbap LIKE LINE OF i_vbap. "Work Area

Start of Selection screen: Now we will use start of selection event to fill out internal table i_vbap.

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
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 have to call the factory method of class CL_SALV_TABLE. We can open the same in SE80 Patterns. TRY. CALL METHOD cl_salv_table=>factory IMPORTING r_salv_table = g_alv CHANGING t_table ENDTRY. Would you believe if I say ALV list is complete after you call display method of CL_SALV_TABLE class? g_alv->display( ). Yes , ALV list is ready, isnt it fast? lets learn how to make it interactive. We will create a button on application tool bar. To create a button, we will have to set the Gui Status. = i_vbap. CATCH cx_salv_msg.

Strona 2

In SE80, function group, and enter SALV_TABLE_STANDARD and copy it 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 MULTIPLE COLUMN 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. When the 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 Constants SINGLE Particular Cell Multiple Rows Rows and Columns CELL ROW_ Single

*-------------------------------------------------------* * 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 cl_salv_display_

Please see the code below, in which I have used extra classes like - cl_salv_functions, settings, Code Example TABLES: vbap. *------------------* * Selection Screen *------------------* SELECT-OPTIONS: s_vbeln FOR vbap-vbeln. *-------------------* * Data Declaration *-------------------* cl_salv_aggregations.

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 g_display g_agg g_selections g_events g_rows TYPE REF TO cl_salv_table, TYPE REF TO cl_salv_display_settings, TYPE REF TO cl_salv_aggregations, TYPE REF TO cl_salv_selections, TYPE REF TO cl_salv_events_table, TYPE salv_t_row.

Strona 3

g_alv_functions TYPE REF TO cl_salv_functions,

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 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 *--------------------------* = i_vbap. CATCH cx_salv_msg .

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
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

Strona 4

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

You might also like