SlideShare a Scribd company logo
1 of 12
Download to read offline
ALV Object Model – Simple 2D Table – Event Handling 
SAP DEVELOPER NETWORK |sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 
© 2006 SAP AG 1 
ALV Object Model – Simple 2D Table – Event Handling 
Applies to: 
Netweaver 2004 and Netweaver 2004s 
Summary 
This tutorial will show how to implement event handling when using the new ALV object model. For more examples, see any program which begins with SALV* in your Netweaver ABAP System. 
Author(s): Rich Heilman 
Company: Yorktowne Cabinetry 
Created on: 28 September 2006 
Rich Heilman is an ABAP/J2EE Software Engineer/Analyst for Yorktowne Cabinetry, Inc. based in Red Lion, Pennsylvania, USA. He has a total of nine years experience in the IT industry. He has spent the past five years studying ABAP and Java.
ALV Object Model – Simple 2D Table – Event Handling 
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 
© 2006 SAP AG 2 
Table of Contents 
Applies to:........................................................................................................................................1 
Summary..........................................................................................................................................1 
The Basic Program..........................................................................................................................3 
Set the Gui Status............................................................................................................................4 
Event Handlers - Event ADDED_FUNCTION...............................................................................5 
Event Handlers - Event DOUBLE_CLICK.....................................................................................8 
Related Content.............................................................................................................................11 
Disclaimer and Liability Notice.......................................................................................................12
ALV Object Model – Simple 2D Table – Event Handling 
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 
© 2006 SAP AG 3 
The Basic Program 
Starting with the program below, we will add coding to handle some events for the ALV Grid. In this example the events DOUBLE_CLICK and ADDED_FUNCTION will be handled. 
report zalvom_demo3. data: ispfli type table of spfli. data: xspfli type spfli. data: gr_table type ref to cl_salv_table. data: gr_selections type ref to cl_salv_selections. start-of-selection. select * into corresponding fields of table ispfli from spfli up to 100 rows. call method cl_salv_table=>factory importing r_salv_table = gr_table changing t_table = ispfli. * Set up selections. gr_selections = gr_table->get_selections( ). gr_selections->set_selection_mode( 1 ). "Single * Display gr_table->display( ).
ALV Object Model – Simple 2D Table – Event Handling 
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 
© 2006 SAP AG 4 
Set the Gui Status 
Next, go to function group SALV_METADATA_STATUS and copy the gui status SALV_TABLE_STANDARD into the ZALVOM_DEMO3 program. This is the standard gui status for the 2 Dimensional Table ALV grid. Once you have copied the status, set the screen status using the appropriate method of the object GR_TABLE. Go to the gui status and add a new button on the application toolbar and name it as “MYFUNCTION”. 
report zalvom_demo3. data: ispfli type table of spfli. data: xspfli type spfli. data: gr_table type ref to cl_salv_table. data: gr_selections type ref to cl_salv_selections. 
start-of-selection. select * into corresponding fields of table ispfli from spfli up to 100 rows. call method cl_salv_table=>factory importing r_salv_table = gr_table changing t_table = ispfli. gr_table->set_screen_status( pfstatus = 'SALV_TABLE_STANDARD' report = sy-repid set_functions = gr_table->c_functions_all ). * Set up selections. gr_selections = gr_table->get_selections( ). gr_selections->set_selection_mode( 1 ). "Single 
* Display gr_table->display( ).
ALV Object Model – Simple 2D Table – Event Handling 
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 
© 2006 SAP AG 5 
Event Handlers - Event ADDED_FUNCTION 
Next, create a local class which will act as the event handler, define the event handler method for the ADDED_FUNCTION event. Define an object reference variable for the local class. Retrieve the events object from the GR_TABLE, create the event handler object and set the handler method for the event. Finally, add the implementation for the ON_USER_COMMAND event handler method. 
report zalvom_demo3. data: ispfli type table of spfli. data: xspfli type spfli. data: gr_table type ref to cl_salv_table. data: gr_events type ref to cl_salv_events_table. data: gr_selections type ref to cl_salv_selections. *----------------------------------------------------------------------* * CLASS lcl_handle_events DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class lcl_handle_events definition. public section. methods: on_user_command for event added_function of cl_salv_events importing e_salv_function, endclass. "lcl_handle_events DEFINITION data: event_handler type ref to lcl_handle_events. start-of-selection. select * into corresponding fields of table ispfli from spfli up to 100 rows. call method cl_salv_table=>factory importing r_salv_table = gr_table changing t_table = ispfli. gr_table->set_screen_status( pfstatus = 'SALV_TABLE_STANDARD' report = sy-repid set_functions = gr_table->c_functions_all ). gr_events = gr_table->get_event( ). create object event_handler. set handler event_handler->on_user_command for gr_events. * Set up selections.
ALV Object Model – Simple 2D Table – Event Handling 
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 
© 2006 SAP AG 6 
gr_selections = gr_table->get_selections( ). gr_selections->set_selection_mode( 1 ). "Single * Display gr_table->display( ). 
*----------------------------------------------------------------------* * CLASS lcl_handle_events IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class lcl_handle_events implementation. method on_user_command. * Get the selection rows data: lr_selections type ref to cl_salv_selections. data: lt_rows type salv_t_row. data: ls_rows type i. data: message type string. case e_salv_function. when 'MYFUNCTION'. lr_selections = gr_table->get_selections( ). lt_rows = lr_selections->get_selected_rows( ). read table lt_rows into ls_rows index 1. read table ispfli into xspfli index ls_rows. concatenate xspfli-carrid xspfli-connid xspfli-cityfrom xspfli-cityto into message separated by space. message i001(00) with 'You pushed the button!' message. endcase. endmethod. "on_user_command endclass. "lcl_handle_events IMPLEMENTATION
ALV Object Model – Simple 2D Table – Event Handling 
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 
© 2006 SAP AG 7 
Run the program, select a row by single clicking on it and click the icon for the new function that you added. Notice that some of the data in the row that was clicked is now showing in the message.
ALV Object Model – Simple 2D Table – Event Handling 
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 
© 2006 SAP AG 8 
Event Handlers - Event DOUBLE_CLICK 
Define the event handler method for DOUBLE_CLICK event and add the implementation for the ON_DOUBLE_CLICK event handler method. Remember to set the handler for the event. 
report zalvom_demo3. data: ispfli type table of spfli. data: xspfli type spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions_list. data: gr_events type ref to cl_salv_events_table. data: gr_selections type ref to cl_salv_selections. *----------------------------------------------------------------------* * CLASS lcl_handle_events DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class lcl_handle_events definition. public section. methods: on_user_command for event added_function of cl_salv_events importing e_salv_function, on_double_click for event double_click of cl_salv_events_table importing row column. endclass. "lcl_handle_events DEFINITION data: event_handler type ref to lcl_handle_events. start-of-selection. select * into corresponding fields of table ispfli from spfli up to 100 rows. call method cl_salv_table=>factory importing r_salv_table = gr_table changing t_table = ispfli. gr_table->set_screen_status( pfstatus = 'SALV_TABLE_STANDARD' report = sy-repid set_functions = gr_table->c_functions_all ). gr_events = gr_table->get_event( ). create object event_handler. set handler event_handler->on_user_command for gr_events.
ALV Object Model – Simple 2D Table – Event Handling 
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 
© 2006 SAP AG 9 
set handler event_handler->on_double_click for gr_events. * Set up selections. gr_selections = gr_table->get_selections( ). gr_selections->set_selection_mode( 1 ). "Single * Display gr_table->display( ). *----------------------------------------------------------------------* * CLASS lcl_handle_events IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class lcl_handle_events implementation. method on_user_command. * Get the selection rows data: lr_selections type ref to cl_salv_selections. data: lt_rows type salv_t_row. data: ls_rows type i. data: message type string. case e_salv_function. when 'MYFUNCTION'. lr_selections = gr_table->get_selections( ). lt_rows = lr_selections->get_selected_rows( ). read table lt_rows into ls_rows index 1. read table ispfli into xspfli index ls_rows. concatenate xspfli-carrid xspfli-connid xspfli-cityfrom xspfli-cityto into message separated by space. message i001(00) with 'You pushed the button!' message. endcase. endmethod. "on_user_command method on_double_click. data: message type string. data: row_c(4) type c. row_c = row. concatenate 'Row' row_c 'Column' column into message separated by space. message i001(00) with 'You double-clicked on ' message. endmethod. "on_double_click endclass. "lcl_handle_events IMPLEMENTATION
ALV Object Model – Simple 2D Table – Event Handling 
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 
© 2006 SAP AG 10 
Run the program, double click on the fifth row in the Depart. City column, notice the information message contains the row number and column name of the cell which you double clicked.
ALV Object Model – Simple 2D Table – Event Handling 
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 
© 2006 SAP AG 11 
Related Content 
Help - ALV Object Model 
Utilizing the New ALV Object Model 
SDN ABAP Forum
ALV Object Model – Simple 2D Table – Event Handling 
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 
© 2006 SAP AG 12 
Disclaimer and Liability Notice 
This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade. 
SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk. 
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.

More Related Content

What's hot

Smartforms interview questions with answers
Smartforms interview questions with answersSmartforms interview questions with answers
Smartforms interview questions with answersUttam Agrawal
 
Abap coding standards
Abap coding standardsAbap coding standards
Abap coding standardssurendra1579
 
Call transaction method
Call transaction methodCall transaction method
Call transaction methodKranthi Kumar
 
1000 solved questions
1000 solved questions1000 solved questions
1000 solved questionsKranthi Kumar
 
HR ABAP Programming Training Material | http://sapdocs.info
HR ABAP Programming Training Material | http://sapdocs.infoHR ABAP Programming Training Material | http://sapdocs.info
HR ABAP Programming Training Material | http://sapdocs.infosapdocs. info
 
Validation and substitution -sap fi advance functions 2019
Validation and substitution -sap fi advance functions 2019Validation and substitution -sap fi advance functions 2019
Validation and substitution -sap fi advance functions 2019GuangfuDavidLi
 
Sap abap interview questions
Sap abap interview questionsSap abap interview questions
Sap abap interview questionskssr99
 
SAP BADI Implementation Learning for Functional Consultant
SAP BADI Implementation Learning for Functional ConsultantSAP BADI Implementation Learning for Functional Consultant
SAP BADI Implementation Learning for Functional ConsultantAnkit Sharma
 
500+ SAP ABAP INTERVIEW QUESTIONS WITH ANSWERS
500+ SAP ABAP INTERVIEW QUESTIONS WITH ANSWERS500+ SAP ABAP INTERVIEW QUESTIONS WITH ANSWERS
500+ SAP ABAP INTERVIEW QUESTIONS WITH ANSWERSIICT Chromepet
 
SAP Validation and substitution
SAP Validation and  substitution SAP Validation and  substitution
SAP Validation and substitution Hari Krishna
 
How to deploy sap standard fiori app in the s4 hana on premise system
How to deploy sap standard fiori app in the s4 hana on premise systemHow to deploy sap standard fiori app in the s4 hana on premise system
How to deploy sap standard fiori app in the s4 hana on premise systemRezaRanjbaraan
 
Core Data Service
Core Data ServiceCore Data Service
Core Data ServiceSujoy Saha
 
GST_Configuration Document_GANESH_SAPSD
GST_Configuration Document_GANESH_SAPSD GST_Configuration Document_GANESH_SAPSD
GST_Configuration Document_GANESH_SAPSD Ganesh Tarlana
 
Personalization Validate Po Quantity With PR
Personalization Validate Po Quantity With PRPersonalization Validate Po Quantity With PR
Personalization Validate Po Quantity With PRAhmed Elshayeb
 

What's hot (20)

Smartforms interview questions with answers
Smartforms interview questions with answersSmartforms interview questions with answers
Smartforms interview questions with answers
 
Abap coding standards
Abap coding standardsAbap coding standards
Abap coding standards
 
Call transaction method
Call transaction methodCall transaction method
Call transaction method
 
1000 solved questions
1000 solved questions1000 solved questions
1000 solved questions
 
HR ABAP Programming Training Material | http://sapdocs.info
HR ABAP Programming Training Material | http://sapdocs.infoHR ABAP Programming Training Material | http://sapdocs.info
HR ABAP Programming Training Material | http://sapdocs.info
 
Validation and substitution -sap fi advance functions 2019
Validation and substitution -sap fi advance functions 2019Validation and substitution -sap fi advance functions 2019
Validation and substitution -sap fi advance functions 2019
 
Sap query for task list data extraction
Sap query for task list data extractionSap query for task list data extraction
Sap query for task list data extraction
 
Sap abap interview questions
Sap abap interview questionsSap abap interview questions
Sap abap interview questions
 
07.Advanced Abap
07.Advanced Abap07.Advanced Abap
07.Advanced Abap
 
Sap scripts
Sap scriptsSap scripts
Sap scripts
 
Module pool programming
Module pool programmingModule pool programming
Module pool programming
 
SAP BADI Implementation Learning for Functional Consultant
SAP BADI Implementation Learning for Functional ConsultantSAP BADI Implementation Learning for Functional Consultant
SAP BADI Implementation Learning for Functional Consultant
 
Badi document
Badi documentBadi document
Badi document
 
500+ SAP ABAP INTERVIEW QUESTIONS WITH ANSWERS
500+ SAP ABAP INTERVIEW QUESTIONS WITH ANSWERS500+ SAP ABAP INTERVIEW QUESTIONS WITH ANSWERS
500+ SAP ABAP INTERVIEW QUESTIONS WITH ANSWERS
 
SAP Validation and substitution
SAP Validation and  substitution SAP Validation and  substitution
SAP Validation and substitution
 
How to deploy sap standard fiori app in the s4 hana on premise system
How to deploy sap standard fiori app in the s4 hana on premise systemHow to deploy sap standard fiori app in the s4 hana on premise system
How to deploy sap standard fiori app in the s4 hana on premise system
 
Core Data Service
Core Data ServiceCore Data Service
Core Data Service
 
SAP ABAP data dictionary
SAP ABAP data dictionarySAP ABAP data dictionary
SAP ABAP data dictionary
 
GST_Configuration Document_GANESH_SAPSD
GST_Configuration Document_GANESH_SAPSD GST_Configuration Document_GANESH_SAPSD
GST_Configuration Document_GANESH_SAPSD
 
Personalization Validate Po Quantity With PR
Personalization Validate Po Quantity With PRPersonalization Validate Po Quantity With PR
Personalization Validate Po Quantity With PR
 

Viewers also liked

Rizvi_Shaik
Rizvi_ShaikRizvi_Shaik
Rizvi_Shaikrizvi_s
 
Resume joseph gregory java
Resume   joseph gregory javaResume   joseph gregory java
Resume joseph gregory javaJoseph Gregory
 
How to create_an_ecatt
How to create_an_ecattHow to create_an_ecatt
How to create_an_ecattMohammed Azhad
 
oracle developer
oracle developeroracle developer
oracle developerAhmed Shams
 
IT & Oracle Specialist
IT & Oracle SpecialistIT & Oracle Specialist
IT & Oracle Specialistashahbou
 
R Tanenbaum .Net Developer August 2010
R Tanenbaum .Net Developer August 2010R Tanenbaum .Net Developer August 2010
R Tanenbaum .Net Developer August 2010Robert Tanenbaum
 
Hassan has Over 5 Years Oracle Developer
Hassan has Over 5 Years Oracle DeveloperHassan has Over 5 Years Oracle Developer
Hassan has Over 5 Years Oracle DeveloperHassan Shahouta
 
Background jobs in rar
Background jobs in rarBackground jobs in rar
Background jobs in rarshivaindia
 
web_developer_resume
web_developer_resumeweb_developer_resume
web_developer_resumePhu Ho
 
Mark Kurzava, SQL Server Developer
Mark Kurzava, SQL Server DeveloperMark Kurzava, SQL Server Developer
Mark Kurzava, SQL Server DeveloperMark Kurzava
 
IBM Cloud Solution for SAP. Integrating IBM Management (Flex System Manager o...
IBM Cloud Solution for SAP. Integrating IBM Management (Flex System Manager o...IBM Cloud Solution for SAP. Integrating IBM Management (Flex System Manager o...
IBM Cloud Solution for SAP. Integrating IBM Management (Flex System Manager o...Doddi Priyambodo
 
Robert Sheppard Software
Robert Sheppard SoftwareRobert Sheppard Software
Robert Sheppard SoftwareRobert Sheppard
 

Viewers also liked (15)

CV-Suliman
CV-SulimanCV-Suliman
CV-Suliman
 
Rizvi_Shaik
Rizvi_ShaikRizvi_Shaik
Rizvi_Shaik
 
Resume joseph gregory java
Resume   joseph gregory javaResume   joseph gregory java
Resume joseph gregory java
 
Publication
PublicationPublication
Publication
 
How to create_an_ecatt
How to create_an_ecattHow to create_an_ecatt
How to create_an_ecatt
 
oracle developer
oracle developeroracle developer
oracle developer
 
IT & Oracle Specialist
IT & Oracle SpecialistIT & Oracle Specialist
IT & Oracle Specialist
 
R Tanenbaum .Net Developer August 2010
R Tanenbaum .Net Developer August 2010R Tanenbaum .Net Developer August 2010
R Tanenbaum .Net Developer August 2010
 
Hassan has Over 5 Years Oracle Developer
Hassan has Over 5 Years Oracle DeveloperHassan has Over 5 Years Oracle Developer
Hassan has Over 5 Years Oracle Developer
 
Background jobs in rar
Background jobs in rarBackground jobs in rar
Background jobs in rar
 
downloadfile
downloadfiledownloadfile
downloadfile
 
web_developer_resume
web_developer_resumeweb_developer_resume
web_developer_resume
 
Mark Kurzava, SQL Server Developer
Mark Kurzava, SQL Server DeveloperMark Kurzava, SQL Server Developer
Mark Kurzava, SQL Server Developer
 
IBM Cloud Solution for SAP. Integrating IBM Management (Flex System Manager o...
IBM Cloud Solution for SAP. Integrating IBM Management (Flex System Manager o...IBM Cloud Solution for SAP. Integrating IBM Management (Flex System Manager o...
IBM Cloud Solution for SAP. Integrating IBM Management (Flex System Manager o...
 
Robert Sheppard Software
Robert Sheppard SoftwareRobert Sheppard Software
Robert Sheppard Software
 

Similar to Alv object model simple 2 d table - event handling

Alv object model simple 2 d table - the basics
Alv object model   simple 2 d table - the basicsAlv object model   simple 2 d table - the basics
Alv object model simple 2 d table - the basicsFaina Fridman
 
Learning & using new technology
Learning & using new technologyLearning & using new technology
Learning & using new technologyMichelle Crapo
 
Learning & using new technology
Learning & using new technologyLearning & using new technology
Learning & using new technologyMichelle Crapo
 
12c SQL Plan Directives
12c SQL Plan Directives12c SQL Plan Directives
12c SQL Plan DirectivesFranck Pachot
 
Integrating powl with web dynpro abap.
Integrating powl with web dynpro abap.Integrating powl with web dynpro abap.
Integrating powl with web dynpro abap.Adesh Chauhan
 
Integrating powl with web dynpro abap.
Integrating powl with web dynpro abap.Integrating powl with web dynpro abap.
Integrating powl with web dynpro abap.Adesh Chauhan
 
Lecture15 abap on line
Lecture15 abap on lineLecture15 abap on line
Lecture15 abap on lineMilind Patil
 
Advanced tips of dbms statas
Advanced tips of dbms statasAdvanced tips of dbms statas
Advanced tips of dbms statasLouis liu
 
Sap Abap Reports
Sap Abap ReportsSap Abap Reports
Sap Abap Reportsvbpc
 
Adaptive Query Optimization
Adaptive Query OptimizationAdaptive Query Optimization
Adaptive Query OptimizationAnju Garg
 
An easy reference for alv grid control (1)
An easy reference for alv grid control (1)An easy reference for alv grid control (1)
An easy reference for alv grid control (1)Faina Fridman
 
Automate sap security user audit
Automate sap security user auditAutomate sap security user audit
Automate sap security user auditSatyajit Deb
 
SAP BI Generic Extraction Using a Function Module.pdf
SAP BI Generic Extraction Using a Function Module.pdfSAP BI Generic Extraction Using a Function Module.pdf
SAP BI Generic Extraction Using a Function Module.pdfKoushikGuna
 
Structuring An ABAP Report In An Optimal Way
Structuring An ABAP Report In An Optimal WayStructuring An ABAP Report In An Optimal Way
Structuring An ABAP Report In An Optimal WayBlackvard
 
Dolibarr - information for developers and partners - devcamp Pau 2019
Dolibarr - information for developers and partners - devcamp Pau 2019Dolibarr - information for developers and partners - devcamp Pau 2019
Dolibarr - information for developers and partners - devcamp Pau 2019Laurent Destailleur
 
Looking for best Sap abap training institute in Chennai
Looking for best Sap abap training institute in ChennaiLooking for best Sap abap training institute in Chennai
Looking for best Sap abap training institute in ChennaiRaja AMEKS Infotech
 
Performance schema and_ps_helper
Performance schema and_ps_helperPerformance schema and_ps_helper
Performance schema and_ps_helperMark Leith
 

Similar to Alv object model simple 2 d table - event handling (20)

Alv object model simple 2 d table - the basics
Alv object model   simple 2 d table - the basicsAlv object model   simple 2 d table - the basics
Alv object model simple 2 d table - the basics
 
Learning & using new technology
Learning & using new technologyLearning & using new technology
Learning & using new technology
 
Learning & using new technology
Learning & using new technologyLearning & using new technology
Learning & using new technology
 
12c SQL Plan Directives
12c SQL Plan Directives12c SQL Plan Directives
12c SQL Plan Directives
 
Integrating powl with web dynpro abap.
Integrating powl with web dynpro abap.Integrating powl with web dynpro abap.
Integrating powl with web dynpro abap.
 
Integrating powl with web dynpro abap.
Integrating powl with web dynpro abap.Integrating powl with web dynpro abap.
Integrating powl with web dynpro abap.
 
Lecture15 abap on line
Lecture15 abap on lineLecture15 abap on line
Lecture15 abap on line
 
sap
sap sap
sap
 
Advanced tips of dbms statas
Advanced tips of dbms statasAdvanced tips of dbms statas
Advanced tips of dbms statas
 
Alv theory
Alv theoryAlv theory
Alv theory
 
Sap Abap Reports
Sap Abap ReportsSap Abap Reports
Sap Abap Reports
 
Adaptive Query Optimization
Adaptive Query OptimizationAdaptive Query Optimization
Adaptive Query Optimization
 
An easy reference for alv grid control (1)
An easy reference for alv grid control (1)An easy reference for alv grid control (1)
An easy reference for alv grid control (1)
 
Automate sap security user audit
Automate sap security user auditAutomate sap security user audit
Automate sap security user audit
 
SAP BI Generic Extraction Using a Function Module.pdf
SAP BI Generic Extraction Using a Function Module.pdfSAP BI Generic Extraction Using a Function Module.pdf
SAP BI Generic Extraction Using a Function Module.pdf
 
Structuring An ABAP Report In An Optimal Way
Structuring An ABAP Report In An Optimal WayStructuring An ABAP Report In An Optimal Way
Structuring An ABAP Report In An Optimal Way
 
Dolibarr - information for developers and partners - devcamp Pau 2019
Dolibarr - information for developers and partners - devcamp Pau 2019Dolibarr - information for developers and partners - devcamp Pau 2019
Dolibarr - information for developers and partners - devcamp Pau 2019
 
Looking for best Sap abap training institute in Chennai
Looking for best Sap abap training institute in ChennaiLooking for best Sap abap training institute in Chennai
Looking for best Sap abap training institute in Chennai
 
Jsf intro
Jsf introJsf intro
Jsf intro
 
Performance schema and_ps_helper
Performance schema and_ps_helperPerformance schema and_ps_helper
Performance schema and_ps_helper
 

Alv object model simple 2 d table - event handling

  • 1. ALV Object Model – Simple 2D Table – Event Handling SAP DEVELOPER NETWORK |sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 1 ALV Object Model – Simple 2D Table – Event Handling Applies to: Netweaver 2004 and Netweaver 2004s Summary This tutorial will show how to implement event handling when using the new ALV object model. For more examples, see any program which begins with SALV* in your Netweaver ABAP System. Author(s): Rich Heilman Company: Yorktowne Cabinetry Created on: 28 September 2006 Rich Heilman is an ABAP/J2EE Software Engineer/Analyst for Yorktowne Cabinetry, Inc. based in Red Lion, Pennsylvania, USA. He has a total of nine years experience in the IT industry. He has spent the past five years studying ABAP and Java.
  • 2. ALV Object Model – Simple 2D Table – Event Handling SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 2 Table of Contents Applies to:........................................................................................................................................1 Summary..........................................................................................................................................1 The Basic Program..........................................................................................................................3 Set the Gui Status............................................................................................................................4 Event Handlers - Event ADDED_FUNCTION...............................................................................5 Event Handlers - Event DOUBLE_CLICK.....................................................................................8 Related Content.............................................................................................................................11 Disclaimer and Liability Notice.......................................................................................................12
  • 3. ALV Object Model – Simple 2D Table – Event Handling SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 3 The Basic Program Starting with the program below, we will add coding to handle some events for the ALV Grid. In this example the events DOUBLE_CLICK and ADDED_FUNCTION will be handled. report zalvom_demo3. data: ispfli type table of spfli. data: xspfli type spfli. data: gr_table type ref to cl_salv_table. data: gr_selections type ref to cl_salv_selections. start-of-selection. select * into corresponding fields of table ispfli from spfli up to 100 rows. call method cl_salv_table=>factory importing r_salv_table = gr_table changing t_table = ispfli. * Set up selections. gr_selections = gr_table->get_selections( ). gr_selections->set_selection_mode( 1 ). "Single * Display gr_table->display( ).
  • 4. ALV Object Model – Simple 2D Table – Event Handling SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 4 Set the Gui Status Next, go to function group SALV_METADATA_STATUS and copy the gui status SALV_TABLE_STANDARD into the ZALVOM_DEMO3 program. This is the standard gui status for the 2 Dimensional Table ALV grid. Once you have copied the status, set the screen status using the appropriate method of the object GR_TABLE. Go to the gui status and add a new button on the application toolbar and name it as “MYFUNCTION”. report zalvom_demo3. data: ispfli type table of spfli. data: xspfli type spfli. data: gr_table type ref to cl_salv_table. data: gr_selections type ref to cl_salv_selections. start-of-selection. select * into corresponding fields of table ispfli from spfli up to 100 rows. call method cl_salv_table=>factory importing r_salv_table = gr_table changing t_table = ispfli. gr_table->set_screen_status( pfstatus = 'SALV_TABLE_STANDARD' report = sy-repid set_functions = gr_table->c_functions_all ). * Set up selections. gr_selections = gr_table->get_selections( ). gr_selections->set_selection_mode( 1 ). "Single * Display gr_table->display( ).
  • 5. ALV Object Model – Simple 2D Table – Event Handling SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 5 Event Handlers - Event ADDED_FUNCTION Next, create a local class which will act as the event handler, define the event handler method for the ADDED_FUNCTION event. Define an object reference variable for the local class. Retrieve the events object from the GR_TABLE, create the event handler object and set the handler method for the event. Finally, add the implementation for the ON_USER_COMMAND event handler method. report zalvom_demo3. data: ispfli type table of spfli. data: xspfli type spfli. data: gr_table type ref to cl_salv_table. data: gr_events type ref to cl_salv_events_table. data: gr_selections type ref to cl_salv_selections. *----------------------------------------------------------------------* * CLASS lcl_handle_events DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class lcl_handle_events definition. public section. methods: on_user_command for event added_function of cl_salv_events importing e_salv_function, endclass. "lcl_handle_events DEFINITION data: event_handler type ref to lcl_handle_events. start-of-selection. select * into corresponding fields of table ispfli from spfli up to 100 rows. call method cl_salv_table=>factory importing r_salv_table = gr_table changing t_table = ispfli. gr_table->set_screen_status( pfstatus = 'SALV_TABLE_STANDARD' report = sy-repid set_functions = gr_table->c_functions_all ). gr_events = gr_table->get_event( ). create object event_handler. set handler event_handler->on_user_command for gr_events. * Set up selections.
  • 6. ALV Object Model – Simple 2D Table – Event Handling SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 6 gr_selections = gr_table->get_selections( ). gr_selections->set_selection_mode( 1 ). "Single * Display gr_table->display( ). *----------------------------------------------------------------------* * CLASS lcl_handle_events IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class lcl_handle_events implementation. method on_user_command. * Get the selection rows data: lr_selections type ref to cl_salv_selections. data: lt_rows type salv_t_row. data: ls_rows type i. data: message type string. case e_salv_function. when 'MYFUNCTION'. lr_selections = gr_table->get_selections( ). lt_rows = lr_selections->get_selected_rows( ). read table lt_rows into ls_rows index 1. read table ispfli into xspfli index ls_rows. concatenate xspfli-carrid xspfli-connid xspfli-cityfrom xspfli-cityto into message separated by space. message i001(00) with 'You pushed the button!' message. endcase. endmethod. "on_user_command endclass. "lcl_handle_events IMPLEMENTATION
  • 7. ALV Object Model – Simple 2D Table – Event Handling SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 7 Run the program, select a row by single clicking on it and click the icon for the new function that you added. Notice that some of the data in the row that was clicked is now showing in the message.
  • 8. ALV Object Model – Simple 2D Table – Event Handling SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 8 Event Handlers - Event DOUBLE_CLICK Define the event handler method for DOUBLE_CLICK event and add the implementation for the ON_DOUBLE_CLICK event handler method. Remember to set the handler for the event. report zalvom_demo3. data: ispfli type table of spfli. data: xspfli type spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions_list. data: gr_events type ref to cl_salv_events_table. data: gr_selections type ref to cl_salv_selections. *----------------------------------------------------------------------* * CLASS lcl_handle_events DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class lcl_handle_events definition. public section. methods: on_user_command for event added_function of cl_salv_events importing e_salv_function, on_double_click for event double_click of cl_salv_events_table importing row column. endclass. "lcl_handle_events DEFINITION data: event_handler type ref to lcl_handle_events. start-of-selection. select * into corresponding fields of table ispfli from spfli up to 100 rows. call method cl_salv_table=>factory importing r_salv_table = gr_table changing t_table = ispfli. gr_table->set_screen_status( pfstatus = 'SALV_TABLE_STANDARD' report = sy-repid set_functions = gr_table->c_functions_all ). gr_events = gr_table->get_event( ). create object event_handler. set handler event_handler->on_user_command for gr_events.
  • 9. ALV Object Model – Simple 2D Table – Event Handling SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 9 set handler event_handler->on_double_click for gr_events. * Set up selections. gr_selections = gr_table->get_selections( ). gr_selections->set_selection_mode( 1 ). "Single * Display gr_table->display( ). *----------------------------------------------------------------------* * CLASS lcl_handle_events IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class lcl_handle_events implementation. method on_user_command. * Get the selection rows data: lr_selections type ref to cl_salv_selections. data: lt_rows type salv_t_row. data: ls_rows type i. data: message type string. case e_salv_function. when 'MYFUNCTION'. lr_selections = gr_table->get_selections( ). lt_rows = lr_selections->get_selected_rows( ). read table lt_rows into ls_rows index 1. read table ispfli into xspfli index ls_rows. concatenate xspfli-carrid xspfli-connid xspfli-cityfrom xspfli-cityto into message separated by space. message i001(00) with 'You pushed the button!' message. endcase. endmethod. "on_user_command method on_double_click. data: message type string. data: row_c(4) type c. row_c = row. concatenate 'Row' row_c 'Column' column into message separated by space. message i001(00) with 'You double-clicked on ' message. endmethod. "on_double_click endclass. "lcl_handle_events IMPLEMENTATION
  • 10. ALV Object Model – Simple 2D Table – Event Handling SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 10 Run the program, double click on the fifth row in the Depart. City column, notice the information message contains the row number and column name of the cell which you double clicked.
  • 11. ALV Object Model – Simple 2D Table – Event Handling SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 11 Related Content Help - ALV Object Model Utilizing the New ALV Object Model SDN ABAP Forum
  • 12. ALV Object Model – Simple 2D Table – Event Handling SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 12 Disclaimer and Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade. SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.