ALV programming
Content:
Ø Introduction
Ø ALV List Display
Ø ALV Grid Display
Ø ALV Hierarchical Display
Ø ALV using OOPs
Ø Editing and coloring
Ø Code snippets
Introduction:
Common Steps:
- Data declarations
- Fetch the required data form the tables
- Prepare field catalog
- Build up the event table if required
- Display ALV output by Calling FM
All the definitions TYPES and STRUCTURES and CONSTANTS are defined in the TYPE-POOL ‘SLIS’, so it should be declared first.
ALV List Display:
- Field catalog can be prepared manually (should contain at least TABNAME, FIELDNAME, REF_TABNAME, SELTECT_M) or by using REUSE_ALV_FIELDCATALOG_MERGE.
- To get all possible events REUSE_ALV_EVENTS_GET can be used.
- To write proper comments use REUSE_ALV_COMMENTARY_WRITE.
- To print the data REUSE_ALV_LIST_DISPLAY can be used.
- Build up the event table if required
- Display ALV output by Calling FM
All the definitions TYPES and STRUCTURES and CONSTANTS are defined in the TYPE-POOL ‘SLIS’, so it should be declared first.
ALV List Display:
- Field catalog can be prepared manually (should contain at least TABNAME, FIELDNAME, REF_TABNAME, SELTECT_M) or by using REUSE_ALV_FIELDCATALOG_MERGE.
- To get all possible events REUSE_ALV_EVENTS_GET can be used.
- To write proper comments use REUSE_ALV_COMMENTARY_WRITE.
- To print the data REUSE_ALV_LIST_DISPLAY can be used.
ALV Grid Display:
- The first 3 function modules mentioned above can be used and to print the data REUSE_ALV_GRID_DISPLAY is used.
- The first 3 function modules mentioned above can be used and to print the data REUSE_ALV_GRID_DISPLAY is used.
Hierarchical ALV:
- Hierarchical display is used for displaying data that are related. Like sales order and item details.
- REUSE_ALV_HIERSEQ_LIST_DISPLAY is used to print the data.
- Hierarchical display is used for displaying data that are related. Like sales order and item details.
- REUSE_ALV_HIERSEQ_LIST_DISPLAY is used to print the data.
ALV Using OOPs:
- Create Docking/custom container.
- Create a grid inside container.
- Call function LVC_FIELDCATALOG_MERGE to get the field catalog.
- Call method SET_TABLE_FOR_FIRST_DISPLAY for o/p.
Editing and Coloring:
- Coloring an entire column
- Create Docking/custom container.
- Create a grid inside container.
- Call function LVC_FIELDCATALOG_MERGE to get the field catalog.
- Call method SET_TABLE_FOR_FIRST_DISPLAY for o/p.
Editing and Coloring:
- Coloring an entire column
To make an entire column be painted with the color you want, you can use the "emphasize" option of the field catalog. Simply assign a color code to this field of the row added for your column. Color codes are constructed as follows:
Cxyz: - x: 1-7 (1 for example is gray-blue, 6 is red), y: intensified on/off, z: inverse on/off.
- Coloring an entire row
Cxyz: - x: 1-7 (1 for example is gray-blue, 6 is red), y: intensified on/off, z: inverse on/off.
- Coloring an entire row
Coloring a row is a bit more complicated. To enable row coloring, you should add an additional field to your list data table. It should be of character type and at least 4 bit long. This field will contain the color code for the row. So for example:
DATA: BEGIN OF gt_list occurs 0.
INCLUDE STRUCTURE .
DATA rowcolor(4) TYPE c.
DATA: END OF gt_list.
As you guess, you should fill the color code to this field. Its format is as explained before. For second you must pass the name of the field to the layout structure:E.g. ps_layout-info_fname = 'ROWCOLOR'.
- Coloring an individual cell:
Likely coloring rows, you must append an internal table to each line of gt_list containing the color information:
DATA: BEGIN OF gt_list occurs 0.
INCLUDE STRUCTURE .
DATA cellcolors TYPE lvc_t_scol.
DATA: END OF gt_list.
If you want to modify the cell in the 5 row and the 2 column, you have to set:
DATA: cellcolor type line of lvc_t_scol.
READ TABLE gt_list INDEX 2.
cellcolor-fname = '.cellcolor-color-col = '6'.
cellcolor-color-int = '0'.
APPEND cellcolor TO gt_list-cellcolors.
Modify GT_LIST INDEX 5.
As like coloring rows, you have to pass the info for coloring cell to the layout-structure:
ps_layout-info_ctab_fname = 'CELLCOLOR'.
- Editing an entire column:
When you want to do edit only for particular column and not for the entire grid then you need to perform fieldcat in that particular column only. Loop the field catalog and for that column make the EDIT field of catalog as ‘X’ and then modify catalog.
- Editing a single cell:Add a table to your list data table.
Data begin of gt_grid occurs 0.
data cellstyles type lvc_t_styl.
Data end of gt_grid.Form make_field_edit using pt_grid like gt_grid[].
data: ls_grid like line of pt_grid,
ls_style type lvc_s_styl,
lt_style type lvc_t_styl.Loop at pt_grid into ls_grid.
If ls_grid-curr = xyz. 'your condition for the row
ls_style-fieldname = 'CURR'.
ls_style-style = cl_gui_alv_grid=>mc_style_enabled.
append ls_style to lt_style.
endif.
Insert lines of lt_style into ls_grid-celltyles.modify pt_grid from ls_grid.
Endloop.
Endform.
When you want to do edit only for particular column and not for the entire grid then you need to perform fieldcat in that particular column only. Loop the field catalog and for that column make the EDIT field of catalog as ‘X’ and then modify catalog.
- Editing a single cell:Add a table to your list data table.
Data begin of gt_grid occurs 0.
data cellstyles type lvc_t_styl.
Data end of gt_grid.Form make_field_edit using pt_grid like gt_grid[].
data: ls_grid like line of pt_grid,
ls_style type lvc_s_styl,
lt_style type lvc_t_styl.Loop at pt_grid into ls_grid.
If ls_grid-curr = xyz. 'your condition for the row
ls_style-fieldname = 'CURR'.
ls_style-style = cl_gui_alv_grid=>mc_style_enabled.
append ls_style to lt_style.
endif.
Insert lines of lt_style into ls_grid-celltyles.modify pt_grid from ls_grid.
Endloop.
Endform.
Code Snippet for ALV List Display, Grid Display and Using OOP.
Link : http://www.scribd.com/doc/139934961/ABAP-ALV-Programming
ABAP ALV Programming by Debesh Swain