This code provides logic to remove the Header generated by TOP-OF-PAGE from the Last Page.
| CODE Snippet |
*&---------------------------------------------------------------------* |
This code provides logic to remove the Header generated by TOP-OF-PAGE from the Last Page.
| CODE Snippet |
*&---------------------------------------------------------------------* |
I was wondering if it is possible to have the same functionality of the Excel: Press Enter and cursor will move to next row.
As OO ABAP using the class CL_GUI_ALV_GRID provides so many methods for the processing at the Cell Levels. After looking to all the methods of the CL_GUI_ALV_GRID, I found there are so many methods which can do the processing at the Cell level. I have started to give the try. After certain tries, I was able to achieve what I was looking for.
| Code Snippet for the Class handler for ALV Grid Call |
*&---------------------------------------------------------------------* |
| Code Snippet for the Class handler definition and Implementation |
*&---------------------------------------------------------------------* |
Today we will try to explore the design patterns in the ABAP Objects. We will start with the Singleton design pattern, which is the simplest of its family of design patterns.
| Code Snippet to check instance |
|

| Code Snippet for Design Patterns: Singleton |
|

Sometimes we need to modify the subtotals on the ALV, specially when we have to give the average of the percentages or something like that. To change the subtotal we need to follow certain steps:
1. we need to get the ALV object form the ALV function module. We can use the FM GET_GLOBALS_FROM_SLVC_FULLSCR to get the Global data of the ALV. From this FM we will get the ALV object.
2. After getting the ALV object, we need to get the subtotal using the method GET_SUBTOTALS of the ALV object. We will get the first level subtotal using the parameter EP_COLLECT01.
3. Now, we need to modify the subtotal. Here we need to take help of Field-symbols since the EP_COLLECT01 is reference to data.
4. We need to refresh the Table display. For this purpose we can use the method REFRESH_TABLE_DISPLAY.
Here is the code snippet which performs all the steps mentioned above:| Code Snippet to change the Subtotal |
|
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 |
*----------------------------------------------------------------------* |
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 |
|
| Code Snippet to create Dynamic ITAB |
|
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..*$*$* |

| Code Snippet |
|
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:

| Code Snippet to Generate ALV with Colors |
|
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) |
|

| Code Snippet for Class ANIMAL & LION |
|
| Code Snippet |
|
Output from this code snippet:
In the series of the SALV model table display, today we will see how to add the hotspot and after adding, how to handle that hotspot. You can find all the previous discussion at Tutorials > SALV Table Display.
Hotspot is useful in most of the ALV reports to drill-down from the main list. For example, in the Sales order report, it would be great if we provide a drill-down to VA03 (Sales Order display). By this way users would have better flexibility to look into the respective document information.
To add the Hotspot, we need to get the object reference of the CL_SALV_COLUMNS_TABLE from the ALV object (reference to CL_SALV_TABLE). This object reference contains the properties related to ALL the columns. For implementing HOTSPOT, we need to change the specific column properties (i.e. Sales Order or Customer). For this purpose, we need to have an access of the object reference CL_SALV_COLUMN_TABLE - which will contain the properties of the speicific column. We will set the specific Cell type for the HOTSPOT. Here we will use the Casting concept of the Object Oriented to refer the properties of the CL_SAL_COLUMN_TABLE. Read this for casting: ABAP OBjects - Narrowing Cast & ABAP Objects: Widening Cast
Ater implementing the Hotspot, we need to implement the Event Hanlder to handle the Hotspot. Here, we will implement the event listner method for the event LINK_CLICK of the class CL_SALV_EVENTS_TABLE. We need to set the handler of this events to let the system know, where to go when the event occurs.
Note: Here we have used the class CL_SALV_COLUMNS_TABLE which is different than the class CL_SALV_COLUMNS discussed as in the previous post SALV Model 7 - Changing Column settings.
Here is the code snippet to which provides the ADD-ON code to our Base program. The base program can be found in the SALV Model 1: Normal ALV Table Display.
UML Diagram would be like:
| Code Snippet for Hotspot and event handling |
|