Application Development 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: 

Locking just a filed from a table

Former Member
0 Kudos

Hi in my report I want to block a particular filed from a ztable . I have a report which has a selection screen where few entries are made . Out of these particular entries I just want to block the fileds say plant from that ztable . I have used ENQUEUE , DEQUEUE for this but the problem is that its locking the entire entrie and not allowing other user to go ahead with his use of the report for other plants . I wnat to block other users from using same plant if someone is already using that plant. Could I get soem info on how to just block plant field for that particular plant only if someone is alreday using that particular plant . Other should be able to use other plants.

I ahve use FM Enqueue_ez..._lock and Deque .

Please advice

Thanks

1 ACCEPTED SOLUTION

Pawan_Kesari
Active Contributor
0 Kudos

If plant is the key field then pass the plant value to FM try below code..


  DATA lv_key TYPE rstable-varkey  .

  CONCATENATE sy-mandt ztable-werks INTO lv_key .

  CALL FUNCTION 'ENQUEUE_E_TABLEE'
    EXPORTING
      mode_rstable   = 'E'
      tabname        = 'ZTABLE'
      varkey         = lv_key
    EXCEPTIONS
      foreign_lock   = 1
      system_failure = 2
      OTHERS         = 3.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

19 REPLIES 19

Former Member
0 Kudos

Is it possible to do so.

Thanks

0 Kudos

if the plant is the key field, then you can lock the table at record level. i hope you are doing at the table level locking.

if you want to lock the record then you have to supply the keys the lock will happen only at plant level.

0 Kudos

Thats right , I do understand what you said, but actually I want to block the particular plant that is entered in the screen and not other plants , because it will not allow other users to makes changes or go ahead with changes in other plants . I want to block the plant filed in such a way that , that only the particular plant say 300 is enterd , it should only be blocked so that the plant 300 cannot be used by others while any other plant can be used because plant 300 is used by one of the user so nobody else should make changes when its been done by him/her.

IS there a way to only block a particular plant that is been worked upon by a user so that other cannot make chnages to that plant?

Thanks

Aarav

0 Kudos

I have used it this way which blocks any other user form entreing after this screen as it is locked.

CALL FUNCTION 'ENQUEUE_EZSPLIT_LOCK'
 EXPORTING
*   MODE_ZSPLIT_APPLY       = 'E'
*   MANDT                   = SY-MANDT
   WERKS                   = 'E'
*   LGORT                   =
*   SPYEAR                  =
*   SPMONTH                 =
*   CHARG                   =
*   KUNNR_SP                =
*   X_WERKS                 = ' '
*   X_LGORT                 = ' '
*   X_SPYEAR                = ' '
*   X_SPMONTH               = ' '
*   X_CHARG                 = ' '
*   X_KUNNR_SP              = ' '
*   _SCOPE                  = '2'
*   _WAIT                   = ' '
*   _COLLECT                = ' '
* EXCEPTIONS
*   FOREIGN_LOCK            = 1
*   SYSTEM_FAILURE          = 2
*   OTHERS                  = 3
          .
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Pawan_Kesari
Active Contributor
0 Kudos

If plant is the key field then pass the plant value to FM try below code..


  DATA lv_key TYPE rstable-varkey  .

  CONCATENATE sy-mandt ztable-werks INTO lv_key .

  CALL FUNCTION 'ENQUEUE_E_TABLEE'
    EXPORTING
      mode_rstable   = 'E'
      tabname        = 'ZTABLE'
      varkey         = lv_key
    EXCEPTIONS
      foreign_lock   = 1
      system_failure = 2
      OTHERS         = 3.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

0 Kudos

Thats right plant is the key field, but still I used you codes but still I am stuck ta the same point , when I run two screens with the same plant number the first screen allows me to get into it , but the second screen says that object locked by user (myname) which is absolutely right , but at the same time when i try runnning two screens with diffrentplants , the first screen allows me to enter , but the second screen says the same thing that the object is locked by user (my name ) , instead I want it to allow me to enter the screen if I use any other plant . Is this possible please.

Thanks

Aarav

0 Kudos

I just check the code with two diff material number putting a lock on table MARA (in dev) and it just work fine for me..

for diff material it run ok and for same material it gives message Material locked by user xxxxx .


DATA : lv_matnr TYPE mara-matnr VALUE 'XXXXXXX' .
DATA lv_key TYPE rstable-varkey .

CONCATENATE sy-mandt lv_matnr INTO lv_key .

CALL FUNCTION 'ENQUEUE_E_TABLEE'
  EXPORTING
    mode_rstable   = 'E'
    tabname        = 'MARA'
    varkey         = lv_key
  EXCEPTIONS
    foreign_lock   = 1
    system_failure = 2
    OTHERS         = 3.

IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CALL FUNCTION 'DEQUEUE_E_TABLEE'
  EXPORTING
    mode_rstable = 'E'
    tabname      = 'MARA'
    varkey       = lv_key.

what are the fields defined in your ztable?

I expect your table should have MANDT and WERKS ( use data element WERKS_D) at least and both if them should be checked as key field.

0 Kudos

Following are the fields for the table I am using in this report.

MANDT MANDT -key

WERKS WERKS_D - key

LGORT LGORT_D - key

SPYEAR GJAHR -key

SPMONTH MONTH - key

CHARG CHARG_D - key

KUNNR_SP KUNNR - key

PBLNR OIF_PBLNR

ZVOLUME ZVOLUME

ZCOMPLETE ZCOMPLETE

ZSPTYP ZSPTYP

KUNNR_SH KUNNR

ZCUSTOPCODE ZBACCODE

ZFACCODE ZBACCODE

ZSHIPCODE ZBACCODE

ZUWI ZUWIDESC

ZEQU_DPENM3 ZEQU_DPENM3

ZEQU_SPENM3 ZEQU_SPENM3

I am using this enqueue after the value check of the selection screen and as you see above the plant and MANDt are both key fields.

Thanks

0 Kudos

I am not sure how it will behave when you specify the partial keys.. in your case plant is a part of key.

Try specifying all the values in key .i.e.

MANDT MANDT -key

WERKS WERKS_D - key

LGORT LGORT_D - key

SPYEAR GJAHR -key

SPMONTH MONTH - key

CHARG CHARG_D - key

KUNNR_SP KUNNR - key

0 Kudos

Following is what I have used.

My selection screen has these fields of which company code, plant , month and year are mandatory fileds.

Company Code

Plant

Ship to Customer No

Fiscal Year

Month

 DATA: lv_key TYPE rstable-varkey  .
  DATA: werks_d TYPE zsplit_apply-werks.
    
  CONCATENATE sy-mandt werks_d  INTO lv_key .

  CALL FUNCTION 'ENQUEUE_E_TABLE'
    EXPORTING
      mode_rstable   = 'E'
      tabname        = 'ZSPLIT_APPLY'
      varkey         = lv_key
    EXCEPTIONS
      foreign_lock   = 1
      system_failure = 2
      OTHERS         = 3.

  IF sy-subrc = 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
******************************************************************
CALL FUNCTION 'DEQUEUE_E_TABLE'
  EXPORTING
    mode_rstable = 'E'
    tabname      = 'ZSPLIT_APPLY'
    varkey       = lv_key.

0 Kudos

Its is still not happening after putting in all the key fields in the concatenation. Its locking the object irrespective of the plant numbers , even if its is different plants its locking . Is it that I am putting the FM at teh wrong position in my report , but still when it shows the lock then the lock is taking place . I am putting my lock right before the value check for selection screen and removing it right after the value check of teh selection screen . Am I right in doing so ?

Please advice Gurus.

Thanks

Aarav

0 Kudos

I am sorry but unfortunately this process after I included all the key fields in lv_key still blocks the plant field itself and not a particular plant that has been enterd. Is there a solution to this problem of mine ,please help me out.

Thanks

Aarav

0 Kudos

Thanks Pawan , that really solved my problem , you were right in saying that the code worked for you too , actually the variable for the plant had already been declared before and I created a new one and thats the reason it was not able to ready the new one , now its working fine and giving me message as I want in a soft mode. I havent used the DEQUUE FM as its just removing the lock altogether during teh process so I just left it with ENQUEUE.

I hope that DEQUEUE is not required essentially , please advice .

Thanks

0 Kudos

I advice to use the DEQUEUE_TABLE.... fm to remove the lock explicitly..

Cheers...

0 Kudos

HI Pawan,

As soon as I am putting the DEQUEUE my locking system dosent work .Or is it that I am putting the lock at a wrong place. I put the lock as soon as I make entry into the selection screen and enter and used the same FM as u advised and when I am putting the FM DEQUEUE just after the the value check of the selection screen , and I use the transaction the lock dosent seem to work then , it just lets me go in without any message or warning . Actaully I had made a little change in the fucntion module where in I put my own information message instead of the system message to make it a information rather than an error message .

  DATA: lv_key TYPE rstable-varkey  .

  CONCATENATE sy-mandt dyn_plant  INTO lv_key .

  CALL FUNCTION 'ENQUEUE_E_TABLE'
    EXPORTING
      mode_rstable   = 'E'
      tabname        = 'ZSPLIT_APPLY'
      varkey         = lv_key
    EXCEPTIONS
      foreign_lock   = 1
      system_failure = 2
      OTHERS         = 3.

  IF sy-subrc <> 0.
*    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    MESSAGE i000 WITH text-026.
  ENDIF.

. is this which is causing it to happen that I am unable to use the DEQUEUE.?

Thnaks

Former Member
0 Kudos

.

0 Kudos

I mean where exactly do I have to unlock it , becaus eas soon as I put unlock after the locking it dosent seem to work in the firts screen and lets me to go inside without any error message . I need to put the lock , then where should I put this lock so that it gives me message first and as soon as i get into the next screen it unlocks

0 Kudos

You should unlock the record when you are done with the record.... for example when user come out of the transaction.. so effectively unlocking should be at the end of your program...

Former Member
0 Kudos

.