Showing posts with label Table Maintenance. Show all posts
Showing posts with label Table Maintenance. Show all posts

Add Custom Button on Maintianence View (SM30)

Posted by Krishh Webworld | 12:45 PM | , , | 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
  *----------------------------------------------------------------------*
***INCLUDE LZTEST_TABLESI01 .

*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module CUSTOM_PF_BUTTON INPUT
*&---------------------------------------------------------------------*
* Custom Button Handling
* Here TOTAL table is avliable with all the data.
* User command is stored in the field FUNCTION
*----------------------------------------------------------------------*
MODULE 0custom_pf_button INPUT.
*
DATA: l_count TYPE i.
* Table of the same structure of the TOTAL which can be exported
DATA: BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE ztest_pf_status.
INCLUDE STRUCTURE vimflagtab.
DATA: END OF itab.
*
CASE function.
WHEN '0POPUP'.
itab[] = total[].
*
DELETE itab WHERE mark IS INITIAL.
DESCRIBE TABLE itab LINES l_count.

*
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = 'Information'
txt1 = 'Selected number of entries'
txt2 = l_count.
*
CLEAR l_count.
*
ENDCASE.
*
ENDMODULE. " CUSTOM_PF_BUTTON INPUT


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:

Posted by Krishh Webworld | 12:43 PM | , , | 0 comments »

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
 
*&---------------------------------------------------------------------*
*& Form EXPORT_TOTAL_TABLE
*&---------------------------------------------------------------------*
* This form is called in the Event 01 of the table maintainence
* events
*----------------------------------------------------------------------*
FORM EXPORT_TOTAL_TABLE.
*
* Table of the same structure of the TOTAL which can be exported
DATA: BEGIN OF ITAB OCCURS 0.
INCLUDE STRUCTURE ZTEST_NP_EVENT.
INCLUDE STRUCTURE VIMFLAGTAB.
DATA: END OF ITAB.
*
* Moving data to ITAB from total
ITAB[] = TOTAL[].
*
* Clearing memory
FREE MEMORY ID 'ZTEST_EVENT'.
*
* Exporting data to Memory
EXPORT ITAB = ITAB TO MEMORY ID 'ZTEST_EVENT'.
*
ENDFORM. "EXPORT_TOTAL_TABLE



Code Snippet of the Report
 
*&---------------------------------------------------------------------*
*& Report ZTEST_NP_EVENT
*&---------------------------------------------------------------------*
*& This Report will start the Table Maintainence and after saving the
*& data in the table maintinence, it will generate a list which will
*& what data has been newly added, updated or deleted
*&---------------------------------------------------------------------*
REPORT ZTEST_NP_EVENT.
*
* Table with the Same structure of the table which is exported.
DATA: BEGIN OF ITAB OCCURS 0.
INCLUDE STRUCTURE ZTEST_NP_EVENT.
INCLUDE STRUCTURE VIMFLAGTAB.
DATA: END OF ITAB.
*
* Output table
TYPES: BEGIN OF TY_OUT.
INCLUDE TYPE ZTEST_NP_EVENT.
INCLUDE TYPE VIMFLAGTAB.
TYPES: END OF TY_OUT.
*
DATA: IT_OUTPUT TYPE STANDARD TABLE OF TY_OUT.
*
* Output ALV reference
DATA: O_ALV TYPE REF TO CL_SALV_TABLE.
*
*
START-OF-SELECTION.
* Start the Table maintainence
CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
EXPORTING
ACTION = 'U'
VIEW_NAME = 'ZTEST_NP_EVENT'
EXCEPTIONS
CLIENT_REFERENCE = 1
FOREIGN_LOCK = 2
INVALID_ACTION = 3
NO_CLIENTINDEPENDENT_AUTH = 4
NO_DATABASE_FUNCTION = 5
NO_EDITOR_FUNCTION = 6
NO_SHOW_AUTH = 7
NO_TVDIR_ENTRY = 8
NO_UPD_AUTH = 9
ONLY_SHOW_ALLOWED = 10
SYSTEM_FAILURE = 11
UNKNOWN_FIELD_IN_DBA_SELLIST = 12
VIEW_NOT_FOUND = 13
MAINTENANCE_PROHIBITED = 14
OTHERS = 15.
IF SY-SUBRC <> 0.
ENDIF.
*
* Importing the memory from the Memory ID
* Table has been exported in the Event 01 of the Table
* maintenance events.
IMPORT ITAB TO ITAB FROM MEMORY ID 'ZTEST_EVENT'.
*
* Clear the memory id
FREE MEMORY ID 'ZTEST_EVENT'.
*
* Moving data to output
IT_OUTPUT = ITAB[].
DELETE IT_OUTPUT WHERE ACTION IS INITIAL.
*
* New ALV Instance
TRY.
CL_SALV_TABLE=>FACTORY(
EXPORTING
LIST_DISPLAY = ABAP_FALSE
IMPORTING
R_SALV_TABLE = O_ALV
CHANGING
T_TABLE = IT_OUTPUT ).
CATCH CX_SALV_MSG. "#EC NO_HANDLER
ENDTRY.
*
* Display the ALV
O_ALV->DISPLAY( ).

Archives

Subscribe Now: Feed Icon