SlideShare a Scribd company logo
1 of 16
Download to read offline
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 1
ALV Object Model – Simple 2D Table - The Basics
Applies to:
Netweaver 2004 and Netweaver 2004s
Summary
This tutorial is the first of the series, which deals with the ALV Object Model. In this tutorial, you will learn
how to create a simple two-dimensional table report using the ALV Object Model.
Author(s): Rich Heilman
Company: Yorktowne Cabinetry
Created on: 21 September 2006
Author Bio
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 - The Basics
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
Author Bio ........................................................................................................................................ 1
Main Class – CL_SALV_TABLE...................................................................................................... 3
Functions – CL_SALV_FUNCTIONS .............................................................................................. 4
Display Settings – CL_SALV_DISPLAY_SETTINGS...................................................................... 4
Columns – CL_SALV_COLUMNS_TABLE and CL_SALV_COLUMN_TABLE.............................. 5
Sorts – CL_SALV_SORTS .............................................................................................................. 8
Aggregations – CL_SALV_AGGREGATIONS .............................................................................. 10
Filters – CL_SALV_FILTERS ........................................................................................................ 12
Layouts – CL_SALV_LAYOUT...................................................................................................... 14
Related Content............................................................................................................................. 15
Disclaimer and Liability Notice....................................................................................................... 16
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 3
Main Class – CL_SALV_TABLE
The main class used to create the simple 2D table is the class CL_SALV_TABLE. Create a reference
variable for this class. Create an internal table and fill this internal table with data as show below.
REPORT ZALVOM_DEMO1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
start-of-selection.
select * into table ispfli from spfli.
Next we need to create the ALV object for the 2D table. The FACTORY method allows you to create the
ALV object in 3 ways. You can create the ALV Grid, as a classical list display, as a full screen grid, and
finally embedded into a screen container. For this example, we will be working with the full screen grid.
Create the call to the FACTORY method. We are importing the object reference into GR_TABLE and
passing the internal table ISPFLI.
cl_salv_table=>factory( importing r_salv_table = gr_table
changing t_table = ispfli ).
Next we need to display the grid, for this we use the DISPLAY method . Simply call it.
gr_table->display( ).
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 4
Functions – CL_SALV_FUNCTIONS
Next, add functions to the application toolbar. For this, use the CL_SALV_FUNCTIONS class. Create the
object reference variable and receive the object using the GET_FUNCTIONS method of the GR_TABLE
object. Call the method SET_ALL to force the ALV grid to show all standard functions.
report zalvom_demo1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table
changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_table->display( ).
The result is now you have the standard buttons on the application toolbar.
Display Settings – CL_SALV_DISPLAY_SETTINGS
Next, we can change some display settings using the class CL_SALV_DISPLAY_SETTINGS. Create the
object reference variable and receive the object using the GET_DISPLAY_SETTINGS method of the
GR_TABLE object. In this example, we are setting the “Striped Pattern” for the ALV Grid rows, and setting
the heading in the title bar.
report zalvom_demo1.
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 5
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
data: gr_display type ref to cl_salv_display_settings.
start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table
changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'This is the heading' ).
gr_table->display( ).
Columns – CL_SALV_COLUMNS_TABLE and CL_SALV_COLUMN_TABLE
Next, we can change some of the attributes of a specific column in the ALV grid. In this example we will
change the Heading Text of a column as well as the color of a column. Create the object reference variable
and receive the object using the GET_COLUMNS method of the GR_TABLE object. This will pass you the
object for all columns of the ALV grid. To access just one column, call the method GET_COLUMN from the
GR_COLUMNS object. In this example, we are accessing the CITYTO column and the CITYFROM column.
report zalvom_demo1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 6
data: gr_display type ref to cl_salv_display_settings.
data: gr_columns type ref to cl_salv_columns_table.
data: gr_column type ref to cl_salv_column_table.
data: color type lvc_s_colo.
start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table
changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'This is the heading' ).
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'CITYTO' ).
gr_column->set_long_text( 'This is long text' ).
gr_column->set_medium_text( 'This is med text' ).
gr_column->set_short_text( 'This is sh' ).
gr_column ?= gr_columns->get_column( 'CITYFROM' ).
color-col = '6'.
color-int = '1'.
color-inv = '0'.
gr_column->set_color( color ).
gr_table->display( ).
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 7
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 8
Sorts – CL_SALV_SORTS
Next, we can add some sorting to the ALV grid. Create the object reference variable and receive the object
using the GET_SORTS method of the GR_TABLE object. Next, add the sort by calling the ADD_SORT
method of the GR_SORTS object.
report zalvom_demo1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
data: gr_display type ref to cl_salv_display_settings.
data: gr_columns type ref to cl_salv_columns_table.
data: gr_column type ref to cl_salv_column_table.
data: gr_sorts type ref to cl_salv_sorts.
data: color type lvc_s_colo.
start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table
changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'This is the heading' ).
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'CITYTO' ).
gr_column->set_long_text( 'This is long text' ).
gr_column->set_medium_text( 'This is med text' ).
gr_column->set_short_text( 'This is sh' ).
gr_column ?= gr_columns->get_column( 'CITYFROM' ).
color-col = '6'.
color-int = '1'.
color-inv = '0'.
gr_column->set_color( color ).
gr_sorts = gr_table->get_sorts( ).
gr_sorts->add_sort 'CITYTO' ).
gr_table->display( ).
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 9
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 10
Aggregations – CL_SALV_AGGREGATIONS
Since we sorted by CITYTO, we can add an aggregation to subtotal the DISTANCE by CITYTO. Create the
object reference variable and receive the object using the GET_AGGREGATIONS method of the
GR_TABLE object. Next, add the aggregation by calling the ADD_AGGREGATION method of the
GR_SORTS object. We also need to modify the call to ADD_SORT to set the SUBTOTAL = ABAP_TRUE.
report zalvom_demo1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
data: gr_display type ref to cl_salv_display_settings.
data: gr_columns type ref to cl_salv_columns_table.
data: gr_column type ref to cl_salv_column_table.
data: gr_sorts type ref to cl_salv_sorts.
data: gr_agg type ref to cl_salv_aggregations.
data: color type lvc_s_colo.
start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table
changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'This is the heading' ).
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'CITYTO' ).
gr_column->set_long_text( 'This is long text' ).
gr_column->set_medium_text( 'This is med text' ).
gr_column->set_short_text( 'This is sh' ).
gr_column ?= gr_columns->get_column( 'CITYFROM' ).
color-col = '6'.
color-int = '1'.
color-inv = '0'.
gr_column->set_color( color ).
gr_sorts = gr_table->get_sorts( ).
gr_sorts->add_sort( columnname = 'CITYTO' subtotal = abap_true ).
gr_agg = gr_table->get_aggregations( ).
gr_agg->add_aggregation( 'DISTANCE' ).
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 11
gr_table->display( ).
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 12
Filters – CL_SALV_FILTERS
Using the CL_SALV_FILTERS class we can setup some filters for the data in our ALV GRID. Create the
object reference variable and receive the object using the GET_FILTERS method of the GR_TABLE object,
and then simply called the method ADD_FILTER with the parameters.
report zalvom_demo1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
data: gr_display type ref to cl_salv_display_settings.
data: gr_columns type ref to cl_salv_columns_table.
data: gr_column type ref to cl_salv_column_table.
data: gr_sorts type ref to cl_salv_sorts.
data: gr_agg type ref to cl_salv_aggregations.
data: gr_filter type ref to cl_salv_filters.
data: color type lvc_s_colo.
start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table
changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'This is the heading' ).
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'CITYTO' ).
gr_column->set_long_text( 'This is long text' ).
gr_column->set_medium_text( 'This is med text' ).
gr_column->set_short_text( 'This is sh' ).
gr_column ?= gr_columns->get_column( 'CITYFROM' ).
color-col = '6'.
color-int = '1'.
color-inv = '0'.
gr_column->set_color( color ).
gr_sorts = gr_table->get_sorts( ).
gr_sorts->add_sort( columnname = 'CITYTO' subtotal = abap_true ).
gr_agg = gr_table->get_aggregations( ).
gr_agg->add_aggregation( 'DISTANCE' ).
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 13
gr_filter = gr_table->get_filters( ).
gr_filter->add_filter( columnname = 'CARRID' low = 'LH' ).
gr_table->display( ).
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 14
Layouts – CL_SALV_LAYOUT
If you want to allow the user to manage layouts of the ALV grid, you must use the class CL_SALV_LAYOUT.
Create the object reference variable and receive the object using the GET_LAYOUT method of the
GR_TABLE object. Then simply call the method SET_KEY with the parameters and set the save restriction
using the SET_SAVE_RESTRICTION method.
report zalvom_demo1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
data: gr_display type ref to cl_salv_display_settings.
data: gr_columns type ref to cl_salv_columns_table.
data: gr_column type ref to cl_salv_column_table.
data: gr_sorts type ref to cl_salv_sorts.
data: gr_agg type ref to cl_salv_aggregations.
data: gr_filter type ref to cl_salv_filters.
data: gr_layout type ref to cl_salv_layout.
data: color type lvc_s_colo.
data: key type salv_s_layout_key.
start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory( importing r_salv_table = gr_table
changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'This is the heading' ).
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'CITYTO' ).
gr_column->set_long_text( 'This is long text' ).
gr_column->set_medium_text( 'This is med text' ).
gr_column->set_short_text( 'This is sh' ).
gr_column ?= gr_columns->get_column( 'CITYFROM' ).
color-col = '6'.
color-int = '1'.
color-inv = '0'.
gr_column->set_color( color ).
gr_sorts = gr_table->get_sorts( ).
gr_sorts->add_sort( columnname = 'CITYTO' subtotal = abap_true ).
gr_agg = gr_table->get_aggregations( ).
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 15
gr_agg->add_aggregation( 'DISTANCE' ).
gr_filter = gr_table->get_filters( ).
gr_filter->add_filter( columnname = 'CARRID' low = 'LH' ).
gr_layout = gr_table->get_layout( ).
key-report = sy-repid.
gr_layout->set_key( key ).
gr_layout->set_save_restriction( cl_salv_layout=>restrict_none ).
gr_table->display( ).
Related Content
• Help - ALV Object Model
• Utilizing the New ALV Object Model
• SDN ABAP Forum
ALV Object Model – Simple 2D Table - The Basics
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2006 SAP AG 16
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

Structured query language constraints
Structured query language constraintsStructured query language constraints
Structured query language constraintsVineeta Garg
 
Forecast stock prices python
Forecast stock prices pythonForecast stock prices python
Forecast stock prices pythonUtkarsh Asthana
 
Has Many And Belongs To Many
Has Many And Belongs To ManyHas Many And Belongs To Many
Has Many And Belongs To Manyguest80d303
 
Oracle SQL Functions
Oracle SQL FunctionsOracle SQL Functions
Oracle SQL FunctionsA Data Guru
 
Vinoth sas presentation RANE industries
Vinoth sas presentation RANE industriesVinoth sas presentation RANE industries
Vinoth sas presentation RANE industriesVinoth Kalaimegan
 
Classification of Compiler
Classification of CompilerClassification of Compiler
Classification of Compilermaharajdey
 
Structured query language functions
Structured query language functionsStructured query language functions
Structured query language functionsVineeta Garg
 
Functional programming-advantages
Functional programming-advantagesFunctional programming-advantages
Functional programming-advantagesSergei Winitzki
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracleLogan Palanisamy
 
Sas Plots Graphs
Sas Plots GraphsSas Plots Graphs
Sas Plots Graphsguest2160992
 
Scala Validation with Functional Programming
Scala Validation with Functional ProgrammingScala Validation with Functional Programming
Scala Validation with Functional ProgrammingSukant Hajra
 
New features in abap
New features in abapNew features in abap
New features in abapSrihari J
 
Excel 2013 Chapter 3: SAM Project 1a Flex Cab Company FORMAT A REVENUE REPORT...
Excel 2013 Chapter 3: SAM Project 1a Flex Cab Company FORMAT A REVENUE REPORT...Excel 2013 Chapter 3: SAM Project 1a Flex Cab Company FORMAT A REVENUE REPORT...
Excel 2013 Chapter 3: SAM Project 1a Flex Cab Company FORMAT A REVENUE REPORT...AlexHunetr
 
"Excelling in Excel" workshop
"Excelling in Excel" workshop"Excelling in Excel" workshop
"Excelling in Excel" workshopAngelina Teneva
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to RAngshuman Saha
 
06. operator overloading
06. operator overloading06. operator overloading
06. operator overloadingHaresh Jaiswal
 
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...Flink Forward
 

What's hot (20)

Structured query language constraints
Structured query language constraintsStructured query language constraints
Structured query language constraints
 
Forecast stock prices python
Forecast stock prices pythonForecast stock prices python
Forecast stock prices python
 
Reports
ReportsReports
Reports
 
Has Many And Belongs To Many
Has Many And Belongs To ManyHas Many And Belongs To Many
Has Many And Belongs To Many
 
Oracle SQL Functions
Oracle SQL FunctionsOracle SQL Functions
Oracle SQL Functions
 
Vinoth sas presentation RANE industries
Vinoth sas presentation RANE industriesVinoth sas presentation RANE industries
Vinoth sas presentation RANE industries
 
Classification of Compiler
Classification of CompilerClassification of Compiler
Classification of Compiler
 
Structured query language functions
Structured query language functionsStructured query language functions
Structured query language functions
 
Functional programming-advantages
Functional programming-advantagesFunctional programming-advantages
Functional programming-advantages
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracle
 
Sas Plots Graphs
Sas Plots GraphsSas Plots Graphs
Sas Plots Graphs
 
Scala Validation with Functional Programming
Scala Validation with Functional ProgrammingScala Validation with Functional Programming
Scala Validation with Functional Programming
 
New features in abap
New features in abapNew features in abap
New features in abap
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Excel 2013 Chapter 3: SAM Project 1a Flex Cab Company FORMAT A REVENUE REPORT...
Excel 2013 Chapter 3: SAM Project 1a Flex Cab Company FORMAT A REVENUE REPORT...Excel 2013 Chapter 3: SAM Project 1a Flex Cab Company FORMAT A REVENUE REPORT...
Excel 2013 Chapter 3: SAM Project 1a Flex Cab Company FORMAT A REVENUE REPORT...
 
"Excelling in Excel" workshop
"Excelling in Excel" workshop"Excelling in Excel" workshop
"Excelling in Excel" workshop
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to R
 
06. operator overloading
06. operator overloading06. operator overloading
06. operator overloading
 
Alv for web
Alv for webAlv for web
Alv for web
 
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
Flink Forward San Francisco 2019: Build a Table-centric Apache Flink Ecosyste...
 

Similar to Alv object model simple 2 d table - the basics

Alv object model simple 2 d table - event handling
Alv object model   simple 2 d table - event handlingAlv object model   simple 2 d table - event handling
Alv object model simple 2 d table - event handlinganil kumar
 
Lecture15 abap on line
Lecture15 abap on lineLecture15 abap on line
Lecture15 abap on lineMilind Patil
 
Alv theory
Alv theoryAlv theory
Alv theoryPhani Kumar
 
Object oriented approach to ALV Lists in ABAP
Object oriented approach to ALV Lists in ABAPObject oriented approach to ALV Lists in ABAP
Object oriented approach to ALV Lists in ABAPNoman Mohamed Hanif
 
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
 
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
 
Scilab as a calculator
Scilab as a calculatorScilab as a calculator
Scilab as a calculatorScilab
 
OLAP Reporting In CR v2
OLAP Reporting In CR v2OLAP Reporting In CR v2
OLAP Reporting In CR v2Mickey Wong
 
How to grow GraphQL and remove SQLAlchemy and REST API from a high-load Pytho...
How to grow GraphQL and remove SQLAlchemy and REST API from a high-load Pytho...How to grow GraphQL and remove SQLAlchemy and REST API from a high-load Pytho...
How to grow GraphQL and remove SQLAlchemy and REST API from a high-load Pytho...Oleksandr Tarasenko
 
React table tutorial use filter (part 2)
React table tutorial use filter (part 2)React table tutorial use filter (part 2)
React table tutorial use filter (part 2)Katy Slemon
 
Applicative Functor - Part 3
Applicative Functor - Part 3Applicative Functor - Part 3
Applicative Functor - Part 3Philip Schwarz
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsAhsanul Karim
 
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
 
abap list viewer (alv)
abap list viewer (alv)abap list viewer (alv)
abap list viewer (alv)Kranthi Kumar
 
Abap Questions
Abap QuestionsAbap Questions
Abap QuestionsKaustav Pyne
 

Similar to Alv object model simple 2 d table - the basics (20)

Alv object model simple 2 d table - event handling
Alv object model   simple 2 d table - event handlingAlv object model   simple 2 d table - event handling
Alv object model simple 2 d table - event handling
 
Lecture15 abap on line
Lecture15 abap on lineLecture15 abap on line
Lecture15 abap on line
 
Alv theory
Alv theoryAlv theory
Alv theory
 
Object oriented approach to ALV Lists in ABAP
Object oriented approach to ALV Lists in ABAPObject oriented approach to ALV Lists in ABAP
Object oriented approach to ALV Lists in ABAP
 
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)
 
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.
 
Scilab as a calculator
Scilab as a calculatorScilab as a calculator
Scilab as a calculator
 
Jsf intro
Jsf introJsf intro
Jsf intro
 
Abap 7.40
Abap 7.40Abap 7.40
Abap 7.40
 
OLAP Reporting In CR v2
OLAP Reporting In CR v2OLAP Reporting In CR v2
OLAP Reporting In CR v2
 
How to grow GraphQL and remove SQLAlchemy and REST API from a high-load Pytho...
How to grow GraphQL and remove SQLAlchemy and REST API from a high-load Pytho...How to grow GraphQL and remove SQLAlchemy and REST API from a high-load Pytho...
How to grow GraphQL and remove SQLAlchemy and REST API from a high-load Pytho...
 
React table tutorial use filter (part 2)
React table tutorial use filter (part 2)React table tutorial use filter (part 2)
React table tutorial use filter (part 2)
 
Applicative Functor - Part 3
Applicative Functor - Part 3Applicative Functor - Part 3
Applicative Functor - Part 3
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
 
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
 
abap list viewer (alv)
abap list viewer (alv)abap list viewer (alv)
abap list viewer (alv)
 
Abap Questions
Abap QuestionsAbap Questions
Abap Questions
 
Abap
AbapAbap
Abap
 

More from Faina Fridman

294151805 end-to-end-o data-service-sapui5-application
294151805 end-to-end-o data-service-sapui5-application294151805 end-to-end-o data-service-sapui5-application
294151805 end-to-end-o data-service-sapui5-applicationFaina Fridman
 
377776000 call-badi-from-report
377776000 call-badi-from-report377776000 call-badi-from-report
377776000 call-badi-from-reportFaina Fridman
 
Acro6 js guide
Acro6 js guideAcro6 js guide
Acro6 js guideFaina Fridman
 
Alv report-tutorial-www.sapexpert.co .uk-
Alv report-tutorial-www.sapexpert.co .uk-Alv report-tutorial-www.sapexpert.co .uk-
Alv report-tutorial-www.sapexpert.co .uk-Faina Fridman
 
Abap objects in action
Abap objects in actionAbap objects in action
Abap objects in actionFaina Fridman
 
Javascript beginner-handbook
Javascript beginner-handbookJavascript beginner-handbook
Javascript beginner-handbookFaina Fridman
 
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-viewFaina Fridman
 
R3 tosrm attach
R3 tosrm attachR3 tosrm attach
R3 tosrm attachFaina Fridman
 

More from Faina Fridman (10)

294151805 end-to-end-o data-service-sapui5-application
294151805 end-to-end-o data-service-sapui5-application294151805 end-to-end-o data-service-sapui5-application
294151805 end-to-end-o data-service-sapui5-application
 
377776000 call-badi-from-report
377776000 call-badi-from-report377776000 call-badi-from-report
377776000 call-badi-from-report
 
Acro6 js guide
Acro6 js guideAcro6 js guide
Acro6 js guide
 
Bcsrvcommsx
BcsrvcommsxBcsrvcommsx
Bcsrvcommsx
 
Alv report-tutorial-www.sapexpert.co .uk-
Alv report-tutorial-www.sapexpert.co .uk-Alv report-tutorial-www.sapexpert.co .uk-
Alv report-tutorial-www.sapexpert.co .uk-
 
Bcsrvalv
BcsrvalvBcsrvalv
Bcsrvalv
 
Abap objects in action
Abap objects in actionAbap objects in action
Abap objects in action
 
Javascript beginner-handbook
Javascript beginner-handbookJavascript beginner-handbook
Javascript beginner-handbook
 
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
 
R3 tosrm attach
R3 tosrm attachR3 tosrm attach
R3 tosrm attach
 

Recently uploaded

Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 

Recently uploaded (20)

Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 

Alv object model simple 2 d table - the basics

  • 1. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 1 ALV Object Model – Simple 2D Table - The Basics Applies to: Netweaver 2004 and Netweaver 2004s Summary This tutorial is the first of the series, which deals with the ALV Object Model. In this tutorial, you will learn how to create a simple two-dimensional table report using the ALV Object Model. Author(s): Rich Heilman Company: Yorktowne Cabinetry Created on: 21 September 2006 Author Bio 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 - The Basics 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 Author Bio ........................................................................................................................................ 1 Main Class – CL_SALV_TABLE...................................................................................................... 3 Functions – CL_SALV_FUNCTIONS .............................................................................................. 4 Display Settings – CL_SALV_DISPLAY_SETTINGS...................................................................... 4 Columns – CL_SALV_COLUMNS_TABLE and CL_SALV_COLUMN_TABLE.............................. 5 Sorts – CL_SALV_SORTS .............................................................................................................. 8 Aggregations – CL_SALV_AGGREGATIONS .............................................................................. 10 Filters – CL_SALV_FILTERS ........................................................................................................ 12 Layouts – CL_SALV_LAYOUT...................................................................................................... 14 Related Content............................................................................................................................. 15 Disclaimer and Liability Notice....................................................................................................... 16
  • 3. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 3 Main Class – CL_SALV_TABLE The main class used to create the simple 2D table is the class CL_SALV_TABLE. Create a reference variable for this class. Create an internal table and fill this internal table with data as show below. REPORT ZALVOM_DEMO1. data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. start-of-selection. select * into table ispfli from spfli. Next we need to create the ALV object for the 2D table. The FACTORY method allows you to create the ALV object in 3 ways. You can create the ALV Grid, as a classical list display, as a full screen grid, and finally embedded into a screen container. For this example, we will be working with the full screen grid. Create the call to the FACTORY method. We are importing the object reference into GR_TABLE and passing the internal table ISPFLI. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). Next we need to display the grid, for this we use the DISPLAY method . Simply call it. gr_table->display( ).
  • 4. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 4 Functions – CL_SALV_FUNCTIONS Next, add functions to the application toolbar. For this, use the CL_SALV_FUNCTIONS class. Create the object reference variable and receive the object using the GET_FUNCTIONS method of the GR_TABLE object. Call the method SET_ALL to force the ALV grid to show all standard functions. report zalvom_demo1. data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions. start-of-selection. select * into table ispfli from spfli. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). gr_functions = gr_table->get_functions( ). gr_functions->set_all( abap_true ). gr_table->display( ). The result is now you have the standard buttons on the application toolbar. Display Settings – CL_SALV_DISPLAY_SETTINGS Next, we can change some display settings using the class CL_SALV_DISPLAY_SETTINGS. Create the object reference variable and receive the object using the GET_DISPLAY_SETTINGS method of the GR_TABLE object. In this example, we are setting the “Striped Pattern” for the ALV Grid rows, and setting the heading in the title bar. report zalvom_demo1.
  • 5. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 5 data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions. data: gr_display type ref to cl_salv_display_settings. start-of-selection. select * into table ispfli from spfli. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). gr_functions = gr_table->get_functions( ). gr_functions->set_all( abap_true ). gr_display = gr_table->get_display_settings( ). gr_display->set_striped_pattern( cl_salv_display_settings=>true ). gr_display->set_list_header( 'This is the heading' ). gr_table->display( ). Columns – CL_SALV_COLUMNS_TABLE and CL_SALV_COLUMN_TABLE Next, we can change some of the attributes of a specific column in the ALV grid. In this example we will change the Heading Text of a column as well as the color of a column. Create the object reference variable and receive the object using the GET_COLUMNS method of the GR_TABLE object. This will pass you the object for all columns of the ALV grid. To access just one column, call the method GET_COLUMN from the GR_COLUMNS object. In this example, we are accessing the CITYTO column and the CITYFROM column. report zalvom_demo1. data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions.
  • 6. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 6 data: gr_display type ref to cl_salv_display_settings. data: gr_columns type ref to cl_salv_columns_table. data: gr_column type ref to cl_salv_column_table. data: color type lvc_s_colo. start-of-selection. select * into table ispfli from spfli. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). gr_functions = gr_table->get_functions( ). gr_functions->set_all( abap_true ). gr_display = gr_table->get_display_settings( ). gr_display->set_striped_pattern( cl_salv_display_settings=>true ). gr_display->set_list_header( 'This is the heading' ). gr_columns = gr_table->get_columns( ). gr_column ?= gr_columns->get_column( 'CITYTO' ). gr_column->set_long_text( 'This is long text' ). gr_column->set_medium_text( 'This is med text' ). gr_column->set_short_text( 'This is sh' ). gr_column ?= gr_columns->get_column( 'CITYFROM' ). color-col = '6'. color-int = '1'. color-inv = '0'. gr_column->set_color( color ). gr_table->display( ).
  • 7. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 7
  • 8. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 8 Sorts – CL_SALV_SORTS Next, we can add some sorting to the ALV grid. Create the object reference variable and receive the object using the GET_SORTS method of the GR_TABLE object. Next, add the sort by calling the ADD_SORT method of the GR_SORTS object. report zalvom_demo1. data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions. data: gr_display type ref to cl_salv_display_settings. data: gr_columns type ref to cl_salv_columns_table. data: gr_column type ref to cl_salv_column_table. data: gr_sorts type ref to cl_salv_sorts. data: color type lvc_s_colo. start-of-selection. select * into table ispfli from spfli. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). gr_functions = gr_table->get_functions( ). gr_functions->set_all( abap_true ). gr_display = gr_table->get_display_settings( ). gr_display->set_striped_pattern( cl_salv_display_settings=>true ). gr_display->set_list_header( 'This is the heading' ). gr_columns = gr_table->get_columns( ). gr_column ?= gr_columns->get_column( 'CITYTO' ). gr_column->set_long_text( 'This is long text' ). gr_column->set_medium_text( 'This is med text' ). gr_column->set_short_text( 'This is sh' ). gr_column ?= gr_columns->get_column( 'CITYFROM' ). color-col = '6'. color-int = '1'. color-inv = '0'. gr_column->set_color( color ). gr_sorts = gr_table->get_sorts( ). gr_sorts->add_sort 'CITYTO' ). gr_table->display( ).
  • 9. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 9
  • 10. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 10 Aggregations – CL_SALV_AGGREGATIONS Since we sorted by CITYTO, we can add an aggregation to subtotal the DISTANCE by CITYTO. Create the object reference variable and receive the object using the GET_AGGREGATIONS method of the GR_TABLE object. Next, add the aggregation by calling the ADD_AGGREGATION method of the GR_SORTS object. We also need to modify the call to ADD_SORT to set the SUBTOTAL = ABAP_TRUE. report zalvom_demo1. data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions. data: gr_display type ref to cl_salv_display_settings. data: gr_columns type ref to cl_salv_columns_table. data: gr_column type ref to cl_salv_column_table. data: gr_sorts type ref to cl_salv_sorts. data: gr_agg type ref to cl_salv_aggregations. data: color type lvc_s_colo. start-of-selection. select * into table ispfli from spfli. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). gr_functions = gr_table->get_functions( ). gr_functions->set_all( abap_true ). gr_display = gr_table->get_display_settings( ). gr_display->set_striped_pattern( cl_salv_display_settings=>true ). gr_display->set_list_header( 'This is the heading' ). gr_columns = gr_table->get_columns( ). gr_column ?= gr_columns->get_column( 'CITYTO' ). gr_column->set_long_text( 'This is long text' ). gr_column->set_medium_text( 'This is med text' ). gr_column->set_short_text( 'This is sh' ). gr_column ?= gr_columns->get_column( 'CITYFROM' ). color-col = '6'. color-int = '1'. color-inv = '0'. gr_column->set_color( color ). gr_sorts = gr_table->get_sorts( ). gr_sorts->add_sort( columnname = 'CITYTO' subtotal = abap_true ). gr_agg = gr_table->get_aggregations( ). gr_agg->add_aggregation( 'DISTANCE' ).
  • 11. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 11 gr_table->display( ).
  • 12. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 12 Filters – CL_SALV_FILTERS Using the CL_SALV_FILTERS class we can setup some filters for the data in our ALV GRID. Create the object reference variable and receive the object using the GET_FILTERS method of the GR_TABLE object, and then simply called the method ADD_FILTER with the parameters. report zalvom_demo1. data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions. data: gr_display type ref to cl_salv_display_settings. data: gr_columns type ref to cl_salv_columns_table. data: gr_column type ref to cl_salv_column_table. data: gr_sorts type ref to cl_salv_sorts. data: gr_agg type ref to cl_salv_aggregations. data: gr_filter type ref to cl_salv_filters. data: color type lvc_s_colo. start-of-selection. select * into table ispfli from spfli. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). gr_functions = gr_table->get_functions( ). gr_functions->set_all( abap_true ). gr_display = gr_table->get_display_settings( ). gr_display->set_striped_pattern( cl_salv_display_settings=>true ). gr_display->set_list_header( 'This is the heading' ). gr_columns = gr_table->get_columns( ). gr_column ?= gr_columns->get_column( 'CITYTO' ). gr_column->set_long_text( 'This is long text' ). gr_column->set_medium_text( 'This is med text' ). gr_column->set_short_text( 'This is sh' ). gr_column ?= gr_columns->get_column( 'CITYFROM' ). color-col = '6'. color-int = '1'. color-inv = '0'. gr_column->set_color( color ). gr_sorts = gr_table->get_sorts( ). gr_sorts->add_sort( columnname = 'CITYTO' subtotal = abap_true ). gr_agg = gr_table->get_aggregations( ). gr_agg->add_aggregation( 'DISTANCE' ).
  • 13. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 13 gr_filter = gr_table->get_filters( ). gr_filter->add_filter( columnname = 'CARRID' low = 'LH' ). gr_table->display( ).
  • 14. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 14 Layouts – CL_SALV_LAYOUT If you want to allow the user to manage layouts of the ALV grid, you must use the class CL_SALV_LAYOUT. Create the object reference variable and receive the object using the GET_LAYOUT method of the GR_TABLE object. Then simply call the method SET_KEY with the parameters and set the save restriction using the SET_SAVE_RESTRICTION method. report zalvom_demo1. data: ispfli type table of spfli. data: gr_table type ref to cl_salv_table. data: gr_functions type ref to cl_salv_functions. data: gr_display type ref to cl_salv_display_settings. data: gr_columns type ref to cl_salv_columns_table. data: gr_column type ref to cl_salv_column_table. data: gr_sorts type ref to cl_salv_sorts. data: gr_agg type ref to cl_salv_aggregations. data: gr_filter type ref to cl_salv_filters. data: gr_layout type ref to cl_salv_layout. data: color type lvc_s_colo. data: key type salv_s_layout_key. start-of-selection. select * into table ispfli from spfli. cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = ispfli ). gr_functions = gr_table->get_functions( ). gr_functions->set_all( abap_true ). gr_display = gr_table->get_display_settings( ). gr_display->set_striped_pattern( cl_salv_display_settings=>true ). gr_display->set_list_header( 'This is the heading' ). gr_columns = gr_table->get_columns( ). gr_column ?= gr_columns->get_column( 'CITYTO' ). gr_column->set_long_text( 'This is long text' ). gr_column->set_medium_text( 'This is med text' ). gr_column->set_short_text( 'This is sh' ). gr_column ?= gr_columns->get_column( 'CITYFROM' ). color-col = '6'. color-int = '1'. color-inv = '0'. gr_column->set_color( color ). gr_sorts = gr_table->get_sorts( ). gr_sorts->add_sort( columnname = 'CITYTO' subtotal = abap_true ). gr_agg = gr_table->get_aggregations( ).
  • 15. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 15 gr_agg->add_aggregation( 'DISTANCE' ). gr_filter = gr_table->get_filters( ). gr_filter->add_filter( columnname = 'CARRID' low = 'LH' ). gr_layout = gr_table->get_layout( ). key-report = sy-repid. gr_layout->set_key( key ). gr_layout->set_save_restriction( cl_salv_layout=>restrict_none ). gr_table->display( ). Related Content • Help - ALV Object Model • Utilizing the New ALV Object Model • SDN ABAP Forum
  • 16. ALV Object Model – Simple 2D Table - The Basics SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 16 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.