Skip to Content
Author's profile photo Former Member

How to create custom button in TMG

Adding Custom button in Table maintenance Generator and their functionality        

Multiple events are defined by SAP to  handle PF status.

Following are the steps to create our own custom button on TMG.

Our example table is ZTEST.

pic1.PNG

   Create Table maintenance generator for ZTEST.

pic2.PNG

Now Go to the Event tab on table maintenance generator as shown in below screen shot.

Go to Environment->modification->events.

pic3.PNG

Click on New entries.

pic4.PNG

SAP has predefined events maintained for TMG, in which you can write your own logic if you want to do some processing. This events are triggered based on its criteria.

pic5.PNG

pic6.PNG

We are going to add one custom button in PF status.So enter event no as ‘ST’.Enter Form Routine no and press enter.You will get an error message as shown below.

pic7.PNG

pic23.PNG

Now enter the correct routine name and press enter.

pic8.PNG

Now click on Editor. Menu painter screen will open.

pic9.PNG

Now click on ‘Copy Interface’ as shown below.

pic10.PNG

We will copy all the user interface of the main table maintenance program to our Function Group. Table maintenance runtime uses the user interface from the program SAPLSVIM. So, we are unable to find any user interface in our FG.

pic11.PNG

Press Continue.

You will get one popup of language compatibility. Press Continue.

pic12.PNG

pic13.PNG

Now interface from the main program is copied to our FG.

We can check the status our table is using. Go to SM30.Give your table name.

Go to System->status->GUI status.

pic14.PNG

Now enter status name as ‘EULG’ and press Change.

pic15.PNG

Add another button.

pic16.PNG

Save and activate.

Now go to TMG. Go to Environment->Modification->Maintenance Screens.

pic17.PNG

Press Enter.

pic18.PNG

Now create a module in PAI.

pic19.PNG

pic20.PNG

pic21.PNG

pic22.PNG

You can add your functionality of pushbutton here.

Add this piece of code to your module.

CASE function.

WHEN ‘POP’.
CALL FUNCTION ‘POPUP_TO_INFORM’EXPORTING
titel =
‘Information’
txt1 =
‘No of selected entries are’
txt2 = mark_extract.endcase.

ENDCASE.

Scenario 2:

Add another pushbutton to our status.

Functionality: To download all the entries on action of a pushbutton.

Add the below code to your same module to achieve this functionality.

data l_filename like IBIPPARMS-PATH.data l_filename1 type string.

when ‘DOWNLOAD’.
   
CALL FUNCTION ‘F4_FILENAME’
    
EXPORTING
       PROGRAM_NAME        = sy-repid*     

      DYNPRO_NUMBER       = SYST-DYNNR*    

       FIELD_NAME          = ‘ ‘
    
IMPORTING
       FILE_NAME           = l_filename
              .
    l_filename1 = l_filename.

CALL FUNCTION ‘GUI_DOWNLOAD’
 
EXPORTING*   BIN_FILESIZE                    =
    filename                        = l_filename1*   FILETYPE                        =
 
tables
    data_tab                        = extract[] .

Test the POPUP functionality:

Go TO SM30 and enter out table name ‘ZTEST’. Click on Maintain.

pic24.PNG

pic25.PNG

Remember that our TMG should be in change mode as we have added the pushbuttons to our change view status i.e. EULG.

Now we have 4 entries.

Select 3 entries and click on Pushbutton POPUP.

pic26.PNG

pic27.PNG

Test the DOWNLOAD functionality:

Now go back and click on DOWNLOAD pushbutton.

You will be asked to enter your file name into which you want to download your entries.

pic28.PNG

Give file name and enter.

pic29.PNG

pic30.PNG

Assigned Tags

      10 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Never tried this, as the event list for TMG is too long and this option is at bottom and icing over the cake am very lazy 😉 .

      Seems useful.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks.Better you try this one. 🙂

      Author's profile photo Former Member
      Former Member

      But I think this code will go away if I have to regenerate the screen.

      (Screenshot after "Now create a module in PAI.")

      eg. If I add a new field, I will have to regenerate the screen. At that point, my module statement would be erased, right? I am not sure what happens to events or GUI statuses. I guess that will be retained, but my module statement will definitely go away.

      Is there any standard alternative to avoid this?

      Author's profile photo Kiran K
      Kiran K

      Thanks for sharing this Dipti.Will be damn usefull when we work with a more demanding client who is well verssed with Custom screens and the possibilities 🙂

      Chinmay,

      While regenerating you will get the option to what all needs to be considered for regeneration in the form of checkboxes.May be unchecking the maintenance screen checkbox will avoid the code getting erased.Have to be explored.

      K.Kiran.

      Author's profile photo Former Member
      Former Member

      Hi ,

      I tried to create custom button , But it was not displayed once activated. I followed the same steps , with scenario 1 . But when i went to sm30 i could just see my screen. Please help

      Author's profile photo Stevanic Artana
      Stevanic Artana

      Hi Sukanya,

      Make sure you have added your button to the correct GUI status. The example above uses status EULG which is used when you change the table maintenance records.

      Author's profile photo Amy King
      Amy King

      Hi Diptilata,

      Fantastic!! I just got this working and it's exactly what I needed. Thanks for writing this up with such detailed steps.

      Cheers,

      Amy King

      Author's profile photo Somnath Mitra
      Somnath Mitra

      Excellent article.. Worked perfectly.. Thanks..

      Author's profile photo Ulf Bauer
      Ulf Bauer

      Great! Very well done! Just what i needed.

      It certainly would have taken quite some time to figure that one out.

      Thank you.

      Ulf

      Author's profile photo Khadeer Abdul
      Khadeer Abdul

      copy the status but still shows different program and Screen Number