Monday, April 13, 2009

Locking a table without using lock object.

In most of cases user execute the same program at the same time.They access the database table for read/write operation.
Where we use the lock object to lock the table for a single user at a time.In this case other user can't update the table at the same time.

I faced an issue where i was using the Lock object on the database table but it was generating the same Batch number at the same time.

Solution:
I used select statement in diffrent way that stops to access the respective database table at the same time.

SELECT SINGLE FOR UPDATE * FROM z09_2_3_2_1__001
WHERE nryear EQ l-nryear
AND z_nrmonth EQ l-nrmonth.

This select statement is locking the database table z09_2_3_2_1__001 until it gets updated.
Hence no other user can access this table at the same time.
After using this,there is no need to use the Lock objects.

Add a 'List' button in the application toolbar of a table for SM30 tcode



Follow the following given steps to add a 'List' button in the application toolbar of a table for SM30 tcode.

1. In the table maintenance generator of a table check the Function group(FG).
2. Check the Main screen no for that FG and the main program of that FG.
3. Go to the screen of the main program.In the PAI part of that screen add a module
MODULE custom_pf_button..

4. In this module add the code for data selection from that table.

Let's for example:
DATA: itab TYPE TABLE OF z00__3_2_3_4_001.
SELECT * FROM z00__3_2_3_4_001 INTO TABLE itab.
CASE function.
WHEN 'LIST'.
* Call ABAP List Viewer (ALV)
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_structure_name = 'Z00__3_2_3_4_001'
TABLES
t_outtab = itab.
ENDCASE.
whenever the List button will be pressed the selected data from table Z00__3_2_3_4_001 will be displayed.

5. After that check the PF status for that screen and add button 'LIST' in the application toolbar.
we need to make sure that all the required gui status contains the 'LIST' button in the application toolbar.

6. Then come back to the Table maintenance generator and maintain the program name in the Event of the table maintenance generator.

to do this follow the path Environment->Modification->Events.

Add a new item Maintenance event as 'ST' and Form routine as ' Main Program name' of that screen.

7.Save and activate all the screens.