SALV Table (2D) Dispaly
1. SALV Table Display - Normal (2D) Table Display
Shows how to use the CL_SALV_TABLE class to generate a new ALV instance. Also contains the Base program used as the example.
2. SALV Table Display - Add default PF status
Shows how to add the default PF status in the ALV. This contains the Code snippet as ADD-ON as well as the downloadable example program file.
3. SALV Table Display - Add custom PF status
Shows how to add the Custom PF status in the ALV. Also shows the easy way to create a custom pf status for ALV
4. SALV Table Display - Set Layout
Shows how to set the Layout for the ALV.
5. SALV Table Display - Add Header & Footer
Shows how to add the Header (top of page) and Footer (End of Page) in the ALV. It also shows how to bring that information in the Print out.
6. SALV Table Display - Display Settings
Shows how to set the Zebra type display, Title of the ALV using the SALV model.
7. SALV Table Display - Column Properties
Shows how to individual column properties of the columns as well as the all columns properties.
8. SALV Table Display - Add & Handle Hotspot
Shows how to add hotspot for specific column and handle it using the event handler.
9. SALV Table Display - Apply Colors to List
Shows how to apply colors at - Specific Cell, Specific Column and Specific Row level.
10. SALV Table Display - Editable SALV Model (Overcome the restriction of SALV Model)
Shows how to make the SALV model ALV editable. It overcomes the restriction of SALV model.
SALV Hierarchical (Sequential) List Dispaly
1. SALV Hierarchical Table - Simple List Display
Shows how to use the CL_SALV_HIERSEQ_TABLE class to generate a new ALV instance for the Hierarchical List display. Sometimes, we call this as a Sequential List. This post contains the Base program used as the example.
2. SALV Hierarchical Table - Adding Default PF Status
Shows how add default PF status in the Hierarchical ALV generated using the CL_SALV_HIERSEQ_TABLE.
3. SALV Hierarchical Table - Add Expand/Collapse Option
Shows how add the option to Expand or Collapse the List in the Hierarchical ALV generated using the CL_SALV_HIERSEQ_TABLE.
Dynamic Internal Table
1. Dynamic Internal Table Creation
Shows how to create a dynamic Internal table with help of Run Time Type Services (RTTS). This post also shows how to select the data into dynamic internal table, modify the table and generate output.
2. Dynamic Internal Table with Deep structure
Shows how to create a dynamic Internal table with Deep Structure with help of Run Time Type Services (RTTS).
3. Dynamic Internal table creation using CL_ALV_TABLE_CREATE
Shows how to create a dynamic Internal table with help of class CL_ALV_TABLE_CREATE from the fieldcatalog.
Table Maintenance
Capture Changed Contents after FM VIEW_MAINTENANCE_CALL
Describes how to caputre changed data after the Maintenance FM call.
Add Custom GUI Button in Table Maintenance (SM30)
Describes the steps to add the GUI button on the Table Maintenance when we maintain the data using transaction SM30.
Add Custom Button on Maintianence View (SM30)
Posted by Krishh Webworld | 12:45 PM | Code, SAP ABAP, Table Maintenance | 0 comments »Whenever we generate the table maintianence, SAP generates some new code and use the Shared code for the Table maintainence generator. Since long time, I was wondering how can I add my own custom PF buttons in the table maintainence screen which comes in SM30. Today, this discussion in the SDN form raised this point in my mind again - Adding Custon button on Maintainance View.
I have started searching the GUI status in the Function Group which I have provided in the Table maintainence generator, but I didn't find it in the object browser (SE80) of the Function group. So, I thought this must be taken care by the Events in the Table maintainence. I searched the list and I found suitable one - ST (GUI Menu Main Program Name). Follow this link for mor information on Table maintenace events - Extended Table Maintenance Events
To add a custom button we need to follow couple of steps:
1. Create Table Maintainence.
Obviously today's discussion is based on the Table maintaince, we must have that before we start it. For a information purpose, I will attach a screen shot of the Table maintaince.2. Copy user Interface of program SAPLSVIM to our FG
We will copy all the user interface of the main table maintainence program to our Fuction Group. Table maintainence runtime uses the user interface from the program SAPLSVIM. So, we are unable to find any user interface in our FG.
There will be one popup of language compatability, which you can pass it on by pressing Enter.
3. Add Custom Button in the PF-Status
Here we need to identify the proper PF-Status from all the statues. We will use the EULG pf-status which is being called when you enter in SM30 with Change mode. We will add the button with code "0POPUP" We can simply check which pf-status is being used in the each screen of the SM30 by going System > Status > GUI status. We will activate the changed status.4. Add Event ST in the Table modification Events
Open the table maintainence generator screen and follow: Environment -> Modification -> Events. Select ST from the values and enter the FG main program name. For this example SAPLZTEST_TABLES.
5. Add PAI module in the Screen
Now, we need to create a new PAI module in the Screen flow. We will create the module 0CUSTOM_PF_BUTTON in the Screen. We will create this module in a New Custom include by selecting it from the popup.
In this code snippet, I am showing how to handle our user command. Here I am just giving information popup when user interact with the button in the change mode.
Code Snippet for Handling custom button |
*----------------------------------------------------------------------* |
Don't forget to activate the Function Group, since we have created a new include in it.
6. Custom button on the SM30
Here is the screenshot of the SM30 with our new added custom button.
After pressing button, it will react like this:

The requirement is to capture the changed contents – updated, deleted or inserted – after the table maintenance call using the FM VIEW_MAINTENANCE_CALL.
The simple solution to handle this requirement is:
1. Get all the data from the database table for which we will call the FM VIEW_MAINTENANCE_CALL.
2. Call FM VIEW_MAINTENANCE_CALL
3. Get all the data from the database table again in separate internal table Compare the contents of the data using some utility.
This kind of generic solution would be possible, but the performance of the report would be slow. I thought of having something which can tell us directly just after the FM call, which line was changed: update or deleted or inserted. Suddenly, I thought of implementing the Event and use the same data which are there in the global tables of the Maintenance Function.
Based on the thought, new steps to achieve this solution would be:
1. Implement Event in the Maintenance. Export the Main internal table to ABAP memory, which can be accessed later from the calling program.
2. Call the FM VIEW_MAINTENANCE_CALL
3. Import the data from the ABAP memory
In this later approach, we can get the data instantly from the memory. Since we will have the indicators (ACTION field in the table) which will help us to identify the type of change made to table entries.
You can find more information on the Events of the Table Maintenance at: Extended Table Maintenance Events
To implement the solution, I have used the Event 01 - Before Saving the data into Database. We need to create the subroutine which can be called when the event gets hit. When we create a subroutine, it will be created in the same Function group in which we have created the Table mainteinance. Hence, it will provide us the access to all the global tabbles. From all of these tables, we will export the internal table TOTAL to the memory.
TOTAL table contains the fields: ACTION and MARK.
Content of the ACTION field would help us to indetify the type of change:
D – Delete
U – Update
N – New Entry
Code Snippet to Export data in Event 01 |
|
Code Snippet of the Report |
|
Dynamic Internal Table Creation using class CL_ALV_TABLE_CREATE
Posted by Krishh Webworld | 12:40 PM | Dynamic ITAB | 0 comments »In the post Dynamic Internal Table creation and Dynamic Internal Table with Deep Structure, we have seen how we can use the RTTS - Run Time Type Services to create dynamic internal table.
Today we will eloborate another way of creating the dynamic internal table. We will see how we can use the class CL_ALV_TABLE_CREATE to create a dynamic internal table for ALV.
Basic pricipal would be, we need to fill the field catalog table and pass it to static method CREATE_DYNAMIC_TABLE from class CL_ALV_TABLE_CREATE.
We will use the same example as the reference in the post Dynamic Internal Table creation.
Here is the code snippet:
Code Snippet to Display ALV output on the Selection Screen |
|
I would suggest to use the RTTS to create dynamic internal table as depicted in posts:
Dynamic Internal Table with Deep structure
Posted by Krishh Webworld | 12:37 PM | Dynamic ITAB | 0 comments »We have seen how we can use Run Time Type Services (RTTS) to create a dynamic internal table in the post: Dynamic Internal Table Creation. On the other day, after publishing the post SALV Table 9 - Apply Colors, I was thinking how I can apply these color settings when I have a Dynamic Internal Table. As we have seen into that post, we require an internal table for Color in our Output table means a dynamic internal table with deep structure.
Dyanmic internal table with deep structure is specially useful when we have to create an ALV with Colors or Style etc. Since we have CL_ABAP_TABLEDESCR class from RTTS, it is also possible to create a dynamic internal table with the deep structure. To create an internal table with deep structure, we need to first get the object definition of the table type. Than we have to add that as a component of our table definition and that's it.
This code snippet is in the continuation with the code given in the post Dynamic Internal Table Creation. You can put this code just after the DO..ENDO and before 3. Create a New Type.
Code Snippet to add the deep component in Dynamic Itab |
|
Dynamic Internal Table Creation
Posted by Krishh Webworld | 12:35 PM | Dynamic ITAB, OO ALV, SAP ABAP | 1 comments »From the ABAP release 6.40, SAP has provided RTTS - Run Time Type Services to create types, internal tables at run-time. This RTTS can also be used to describe the properties of the types as well as the fields, internal tables etc.
Sometimes, when we write a program, we don't have all the information of the fields of the internal table. For example: we are accessing the cost element Actul posting data from the table COSP. Now, we have a requirement to generate an output which will have some specified columns - like amount of period 4 to 8 or Amount of period 1 to 3 or some other combination. This kind of secnarioes are perfect examples of the RTTS. We will see how to create a dynamic internal table using this example.
To create a dynamic internal table, we need to:
1. Gather all the Components
2. Generate a Type from this components
3. Generate a Table Type from this created type
4. Create a Data reference of this Table Type
5. Assign this data reference to the Field-Symbol of table type. This Field-symbol will act as our dyanmic internal table
In today's example we will see how to:
1. Create Dynamic internal table
2. Write dynamic select query to data into this dynamic table
3. Change the contents of this dynamic internal table
4. Generate the ALV display using SALV model for this dynamic internal table. Explore how to create ALV using SALV from Tutorials > SALV Table
We will provide the selection of the period for which user wants to generate an output. Based on the entered periods we will create a dynamic type containg the KSTAR (Costing Element) and Amount fields for the month. After creating the dynamic type, we will create a dynamic table type. Using this table type we will create a reference of the data. From this data reference we will assign the internal table to field-symbols.
So, let's see the code snippet:
Code Snippet to create Dynamic ITAB |
|
SALV Hierarchical Table 3 - Add Expand/Collapse Option
Posted by Krishh Webworld | 12:31 PM | OO ALV, SALV Tutorial, SAP ABAP | 0 comments »Today in the series of the SALV Hiearchical list display, we will see how to add the Expand/Collapse button in the Hierarchical ALV. All discussion related to the Hierarchical table display can be found under Tutorials > SALV HS List.
Expand/Collapse button will provide an option to users to only see the Header List. By selecting the expand button, it will show both Header and detail List. By selecting the same button again it will collapse the list and gives only the header list.
Here is the code Snippet which provides the ADD-ON code. This ADD-ON code can be replaced with the relevent section from this code snippet in the base program. You can find the base program code snippet in the post SALV Hierarchical Table 1 : Simple table display. Adding code to base program is like adding the code correction from the OSS Note. Additionally, we will always include the default PF-status in all the code snippet.
UML diagram for the application would be like:Code snippet to get the Expand / Collapse option in Hierarchical ALV.
Code Snippet to get Expand / Collapse option |
*$*$*.....CODE_ADD_1 - Begin..................................1..*$*$* |
This code will generate output like:
SALV Hierarchical Table 2 - Adding Default PF Status
Posted by Krishh Webworld | 11:45 AM | OO ALV, SALV Tutorial, SAP ABAP | 0 comments »To add a default PF status in the hierarchial (sequential) list created using the reference of the class CL_SALV_HIERSEQ_TABLE, we need to get the all the default PF status functions using the method GET_FUNCTIONS of the reference of the CL_SALV_HIERSEQ_TABLE.
Here is the code Snippet which provides the ADD-ON code. This ADD-ON code can be replaced with the relevent section from this code snippet in the base program. You can find the base program code snippet in the post SALV Hierarchical Table 1 : Simple table display. Adding code to base program is like adding the code correction from the OSS Note.
UML diagram of the our test program would be like:

Code Snippet |
|
This code add-on will generate the default pf status like this:
SALV Hierarchical Table 1 - Simple table display
Posted by Krishh Webworld | 11:40 AM | OO ALV, SALV Tutorial | 0 comments »The new model of ALV - SALV Model - also provides the interface for application developer to develop the Hierarchical list. This type of list are also known as the Sequential List.
We use the hierarchical-sequential table to display simple hierarchical structures. In addition, exactly two hierarchy levels are available for the use: the header level and the position level. For each hierarchy level, we have to specify a table and also the key columns, like foreign keys.
We can use the model by using the reference of the calss CL_SALV_HIERSEQ_TABLE. We can use this class instead of the function module REUSE_ALV_HIERSEQ_LIST_DISPLAY.
Class CL_SALV_HIERSEQ_TABLE has a FACTORY method. We will call this method and ask for the object for the Hierarchical Table. After getting the HS (Hierarchical - Sequential) Object, we will call the DISPLAY method to generate a list on the screen. Isn't it sound too simple? Infact, it is simple.
You can visit the here to know more about the SALV models: SAP List Viewer : New Programming Model --> https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/5dc3e690-0201-0010-1ebf-b85b3bed962d
Check out the Code snippet for the simplest Hierarchical Table:
Code Snippet to generate Hierarchical List |
|
This code will generate an output like this:
Note: I had tried to build this report in the Object Oriented manner. You can check the UML diagram as below. This desgin will provide us the great flexibility to add more methods will set and get different properties of the O_HS_ALV object. For example, if want to add the expand & collapse button, we will add one private method SET_EXPAND_OPTION. We will implement this method by adding the relative code and call this method before the list display.
In the code snippet, I have tried to differential three section which can be changed easily. In next blog posts, I will use this program as the base program and provide the code snippet to add the new functionality. Like: Section of CODE_ADD_1 can be replaced with the code provided in the future blog post.
SALV Table 10 - Editable SALV Model (Overcome the restriction of SALV Model)
Posted by Krishh Webworld | 11:36 AM | SALV Tutorial | 0 comments »This is one of my published blog on the SAP Community Network --> https://www.sdn.sap.com/irj/scn.
In this blog, I described a way to overcome the restrictions of SALV models.
Follow:
Power of ABAP Objects: Overcome the Restrictions of SALV Model --> https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/12187
This is only possible because of the power of the ABAP objects which gives us the access to the protected attributes in the derived child class.
Warning: Here I am trying to overcome the restriction and accessing the SALV attributes which SAP has not intented to expose to outside world and it made it protected. Read Thomas Jung's warning below the post.
SALV Table 9 - Apply Colors
Posted by Krishh Webworld | 11:31 AM | OO ALV, SALV Tutorial, SAP ABAP | 2 comments »In the series of the SALV Model Table display, today we will see how to apply colors to the ALV Grid. In this regards, we will see how to apply colors to the Specific Cell, Specific Row or Specific Column. You can find all the Previous discussion at Tutorials > SALV Table Display.
Color plays a very important role in the formatting. It will help us to generate the a rich list which can help users to notice the exceptional data - for example, negative salary to employee or Low material availabilty.
At most colors can be applied to three levels:
- Perticular Cell: To apply color at perticular cell, we need to add the details about the field and color in COLOR table at each record. Than we have to set this Color Table in the object of the COLUMNS which contains the information about all our information (CL_SALV_COLUMNS_TABLE).
- Entire Row: To apply color to Entire row, we have to do the same thing as the applying the color to Perticular Cell, but we will not specify the FIELDNAME. This way system will understand that it has to apply the color to entire row.
- Entire Column: To apply color to Entire column, we have to get the specific Column from the COLUMNS object and than we need to set the Color Property of the Specific Column and we are done.
In this example I need to change the output table sturcture as compared to previous discussion in this series, so I will provide the entire code which generate the output which has all three scenario. For test purpose, We will apply: Red color to Sales Doc Type in 3rd Row, Green Color to 5th row, Yellow color to Created on Column.
UML Diagram for this application is like:

Code snippet to generate the ALV with Colors using the SALV model.
Code Snippet to Generate ALV with Colors |
|
Without Colors it will look like:
With Colors it will look like:
ABAP Objects: Widening Cast (Down Casting)
Posted by Krishh Webworld | 11:21 AM | Code, Objects, SAP ABAP | 0 comments »When we assign the instance of the Superclass to the Subclass, than it is called the Widening Cast, because we are moving to the "More Specific View" from the "Less specific view". Due to this reason it is also called the "Down Casting".
Everytime it is not possible to move the Superclass reference to the Subclass, because subclass will(or might) have always more functionality compare to the Superclass. So, we need to be more careful when we use the down casting.
We will use the same ANIMAL Superclass and LION subclass as per the blog post - ABAP Objects: Narrowing Cast
When this Widening Cast is used?
Widening cast can be used when we need to access the Specific functionality of the subclass from the Superclass.
In ABAP, it is necessary to catch the exception CX_SY_MOVE_CAST_ERROR while doing the widening cast to avoid the short-dump.
Code Snippet for Widening Cast (Downcasting) |
|
Output of this code snippet is: