Archive for the 'BASIS' Category

SAP: How to use Lock Objects in ABAP

Let say we have a customized table ZCUST_INFO that holds a specific customer information with MANDT(client number) and KUNNR(customer number) as the key field.

So let’s create a Lock Object for our customized table:
1. Go to transaction SE11
2. Click on Lock Object radio button and type-in EZCUST_INFO on name field and click on create button.
3. On Tables Tab, type-in ZCUST_INFO on name field and choose Write Lock on Lock Mode.
4. Go to Lock Parameter Tab and on the first row, type-in mandt on lock parameter, zcust_info on
table, and mandt on field.
5. On second row, type-in custnum on lock parameter, zcust_info on table, and kunnr on field.
6. Click save and activate.

Now let say we also have a dialog program for managing this the content of this table. We have screen 100 for our selection screen with customer number as selection parameter, screen 200 for editing screen, and screen 300 for display screen.

On the PBO of screen 200, let’s add the code below.

  CALL FUNCTION ‘ENQUEUE_EZCUST_INFO’
    EXPORTING
    MODE_ZCUST_INFO = ‘X’
    MANDT = sy-mandt
    CUSTNUM = <customer number from screen 100>
  EXCEPTIONS
    FOREIGN_LOCK = 1
    SYSTEM_FAILURE = 2
    OTHERS = 3.
  IF sy-subrc = 1.
    MESSAGE ‘This record is currently locked by another user!’ type ‘I’.
leave to screen 300.
  ENDIF.

The code above will request for lock on the table zcust_info specifically on the record specified on
the mandt and custnum parameter. If the record is already locked by another user, the user will be
prompted and will be redirected to screen 300 which is the display screen.

Lastly, on the PAI of screen 200, add the code below to release and unlock the object queued on the PBO:

  CALL FUNCTION ‘DEQUEUE_EZCUST_INFO’
    EXPORTING
    MODE_ZCUST_INFO = ‘X’
    MANDT = sy-mandt
    CUSTNUM = <customer number from screen 100>
  EXCEPTIONS
    FOREIGN_LOCK = 1
    SYSTEM_FAILURE = 2
    OTHERS = 3.

SAP: How to Create and Use the Authorization Objects in ABAP

Authorization Objects are used to manipulate the current user’s privileges for specific data selection and activities from within a program.

We could always create our own authorization objects and implement it in our own abap programs. As an example, we will create our own authorization field similar to TCD used in S_TCODE Authorization object (see #3 in figure 1).

Figure 1
Figure 1

Steps to create authorization field
1. Go to transaction code SU20
2. Click the create new button on the application toolbar.
3. Enter “ZTCODE” in the Field Name and “TCODE” in the Data Element, then hit Enter.
4. Click the save button on the system toolbar.

Next step is to create the authorization class(see #1 in figure 1) and authorization object(see #2 in figure 1).

Steps to create authorization class
1. Go to transaction code SU21
2. Click on the Create button’s drop down icon and select “Object Class”.
3. Enter “ZTRN” on the Object Class field.
4. Give it a description and save it.

Steps to create authorization object
1. Again in SU21, in the list of authorization class(folder icon), click the one that we’ve created(ZTRN).
2. Click on the Create buttodrop down, this time selecting “Authorization Object”.
3. Enter “Z_TCODE” on the Object field and give it a description.
4. On the authorization fields section, enter ACTVT and ZTCODE. ACTVT is used to set and limit the activity of the user, while the ZTCODE is the authorization field that we’ve created earlier which is
responsible for holding a list of tcodes.
5. On the Further Authorization Object Settings, click on “Permitted activities” button. Here we will select the specific activities that we want to be available for our authorization object.
6. As an example, we will select 01(Create), 02(Change), and 03(Display).
7. Save and Exit.

Now we’re done creating our own authorization object, let us now use and assign it to a user.

Steps to create a role(see figure 2)
1. Go to transaction code PFCG.
2. Enter “ZAUTHTEST” on Role field and click the “Single Role” button.
3. Now give it a description, click the save button and click the Authorization tab.
4. Click the “Change Authorization Data” button inside the authorization tab.
5. Then click the “Manually” button on the application toolbar and type in the name of the authorization object that we’ve created earlier(”Z_TCODE”) and press enter.
6. Expand all the nodes, double click on the input field of the Activity and select activity 01 and 02.
7. Enter the tcode of our own abap program in ZTCODE field, in our example I used “ZCOMM” .
8. And also don’t forget to add the S_TCODE authorization object and enter ZCOMM on it’s field.
9. Now Click on the Generate button in the application toolbar and press enter on the pop-up screen.
10. press the back button and assign a specific user on the user tab and click User Comparison button.
11. Now create another role by repeating steps 1 to 9 but this time select activity 03 on step 6.
12. Then assign this 2nd role to another user.

Figure 2
Figure 2

Now let’s implement this authorization in our ABAP program. Let say we have a dialog program(ZCOMM) wherein we have a button on the screen that when clicked, the user will go to the Create/Edit screen(1000) if he’s authorized. On the other hand, he will go to display only screen(2000) if he’s not authorized. To do that, simply add the code below on your program.

  AUTHORITY-CHECK OBJECT ‘Z_TCODE’    “authorization object that we’ve created
      ID ‘ACTVT’ FIELD ‘01′                        “Activity = 01, authorized to create
      ID ‘ZTCODE’ FIELD ‘ZCOMM’.            “tcodes that we wants to check for authorization
  IF sy-subrc EQ 0.
      CALL SCREEN 1000.        “The user is authorized to create
  ELSE.
      CALL SCREEN 2000.        “User is not authorized to create (Display only)
  ENDIF.

SAP: How to disable SAP Menu and User Menu

There are two ways to disable/enable the SAP menu and the User menu.

1. Configuration for all SAP users.

Go to transaction code SM30(Maintain Table Views) and maintain SSM_CUST table. Set ALL_USER_MENUS_OFF = YES if you want to disable the user menu for all SAP users and set it to NO to enable it again. For the SAP Menu, set SAP_MENU_OFF = YES to disable it or NO to enable it.

2. Configuration for individual specific SAP user

Again go to transaction code SM30(Maintain Table Views) and this time maintain USERS_SSM table. Initially there will be no data for this table. Now Click the “New entries” button on the application toolbar. The User Name field should be now editable. Now type in the user name that you want to configure. As you can see, there’s another four columns (User Menu, SAP Menu, Web Menu and Company Menu) with checkboxes on all of its rows. Just check it if you want to enable that menu or uncheck it to disable it.

SAP: Table Pool Inconsistency (ATAB, KAPOL, etc.)

I am trying to perform a copy client when I encountered a pool tables inconsistency error.

The client copy log displays pool tables as incorrect: DDIC Error (See SE14).
These table pools have an inconsistent database object in field VARDATA in transaction SE14.

I tried to google for a solution and found out that this is an SAP known issue (Note 686357 - Table pool length incorrect after Unicode conversion).

Reason

As part of the Unicode migration or the new installation using UNICODE, the program UMG_POOL_TABLE is to be executed, which executes the report RADPOCNV.
The report sets the dictionary length for table pools that have to be converted during the Unicode migration due to the extension of the VARDATA field.
If you run the report repeatedly, the length values of the nametab and dictionary are also extended repeatedly which causes an inconsistency.

Solution

Run the program RATPONTC in transaction code SE38 to reset the dictionary and nametab lengths to the correct values. If this program does not yet exist in your system, import it from the attached archive. It contains the data fiels and co files. Copy them to your local harddisk and import them in accordance with Note 13719.

Click here to view the SAP note 686357. You must have a SAP Service Marketplace username and password.

SAP* Password Reset

When you forgot the password of SAP* user on a certain client on SAP, you could always reset it by deleting its record on your database.

DELETE FROM <db name>.USR02
WHERE BNAME=’SAP*’ AND MANDT=’<client no.>’

On the script above, <db name> is the database name of your system which is usually the same with system id and <client no.> is of course the specific client you want a password reset of SAP* user. Let say my system id is “flq” and i want to reset the password of SAP* on client 100, my script would be like this:

DELETE FROM flq.USR02
WHERE BNAME=’SAP*’ AND MANDT=’100′

Once you successfully run this script on your database, you could now log on to your system on a specific client by using SAP* and password = pass.

Note: SAP* user is activated when parameter login/no_automatic_user_sapstar is set to 0(zero).