Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to restrict the entries of a database table based on the user name

former_member687052
Participant
0 Kudos
3,282

Hi All,

I have created a Database Table. Table maintenance generator is generated for the table.

UNAME(user name) is one of the fields in the table. whenever the user creates a new entry, the field UNAME will be populated automatically with SY-UNAME value. I have used Table event '05' to do this.

My requirement is...

When a user tries to maintain the entries of the table using SM30, when 'DISPLAY' is chosen, all the records of the table should be displayed.

When 'MAINTAIN' is chosen, only those records which have UNAME = SY-UNAME(User Logged in) should be in EDIT mode. and rest all the records should be in DISPLAY mode(greyed out). It should allow to edit only those records which are created by the user logged in.

Could you please tell me how to do this..? Thanks in advance.

Thanks & Regards,

Paddu.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
1,238

Hi Paddu,

Search for Enhancement Spots for SM30.

Or

copy the SM30 program to a new Z program and make the change yourself. Although this practice is not recommended because you're scuppered if the table structure changes, unless you manually changing the Z code.

Or

Search for BADI/UserExit and do the Changes.

Look http://help.sap.com/saphelp_47x200/helpdata/en/2a/fa0029493111d182b70000e829fbfe/content.htm or basics.

And http://help.sap.com/saphelp_47x200/helpdata/en/91/ca9f1aa9d111d1a5690000e82deaaa/frameset.htm for events available.

Regards,

Amarnath S

7 REPLIES 7

Former Member
0 Kudos
1,239

Hi Paddu,

Search for Enhancement Spots for SM30.

Or

copy the SM30 program to a new Z program and make the change yourself. Although this practice is not recommended because you're scuppered if the table structure changes, unless you manually changing the Z code.

Or

Search for BADI/UserExit and do the Changes.

Look http://help.sap.com/saphelp_47x200/helpdata/en/2a/fa0029493111d182b70000e829fbfe/content.htm or basics.

And http://help.sap.com/saphelp_47x200/helpdata/en/91/ca9f1aa9d111d1a5690000e82deaaa/frameset.htm for events available.

Regards,

Amarnath S

0 Kudos
1,238

Hi Amarnath,

Thank you for your responce.

But, I think instead of changing the existing logic, it can be done using the table events. Any idea how to do this using Table events?

Thanks & Regards,

Paddu.

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Kudos
1,238

You have to implement the event 'AA' (Instead of the standard data read routine). SAP documentation on [Extended Table Maintenance Events|http://help.sap.com/saphelp_nw04/helpdata/en/91/ca9f0ea9d111d1a5690000e82deaaa/frameset.htm].

Sample subroutine you can use:

FORM read_data.
  DATA: st_view TYPE zmv01335.

* Read the data from the view using standard routine
  PERFORM get_data_zmv01335.

* UPD & AEND are for change entries event.
  CHECK sy-ucomm = 'UPD' OR sy-ucomm = 'AEND'.

  LOOP AT total INTO st_view.
    IF st_view-uname NE sy-uname.
      DELETE total.
    ENDIF.
  ENDLOOP.
ENDFORM.

BR,

Suhas

BH2408
Active Contributor
0 Kudos
1,238

HI,

In table main. gen there are number of events , try to select one event like 05 for the Sy-uname.

For the requirement:

In that event write the code like

this is basic idea not the code:

Case ' Sy-ucomm'.

when 'display'. " button

Nomally for the display button it will show all the records, but we need to write a code like this.

select all records frm the table.

( Need to write the code in case if the user first maintained the data then again press the display , list has to be refreshed.)

when ' Maintain'. " button.

Fetch the records that are with SY-UNAME and find out the edit function and implement it on each and every record.

endcase.

Thanks and Regards,

Bharani.

0 Kudos
1,027

FORM ZZ_READ_TABLE.
Datals_table TYPE ZTABLE
      lt_table TYPE TABLE OF ZTABLE,
      lv_index TYPE sy-index,
     

SELECT FROM Ztable INTO TABLE lt_table.

CHECK sy-ucomm 'SHOW'.
LOOP AT LT_TABLE INTO ls_table.
AUTHORITY-CHECK OBJECT '
DELETE LT_TABLE INDEX sy-index.
ENDLOOP.

IF LT_TABLE[] IS INITIAL.
MESSAGE 'No Authorization to view contents of ZTable' TYPE 'É'.
ENDIF.

LOOP AT LT_TABLE INTO <vim_total_struc>.
APPEND TOTAL.
ENDLOOP.

ENDFORM.

0 Kudos
932

Why are you replying to a 14 year old question which is furthermore marked as solved?!

Beside that, please use the code format option in the editor if you post abap code here.

anup_deshmukh4
Active Contributor
0 Kudos
1,238

If you want to have certain Checks to be implemented...then you will have to code the events for same.

1. Go to table maintenance generator - > environment -> Modification -> events

2. implement the 01(Check for all the events F4 help ) event ( it is Record Before Save event ) all your checking will be done in the subroutine you will write for this event ( Which is written their itself....).

Hope it helps,

Anup