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: 
Read only

error when executing transaction with same parameter value

Former Member
0 Likes
1,133

I have a transaction which executes

parameters: p_kunnr type kna1-kunnr.

start-of-selection.
write:/ p_kunnr.

if a user is executing the transaction with a specific value for kunnr, and then another user executes the transaction with the same value for kunnr, then second user should receive error msg. If the first user exits from transaction, then second user can execute transaction and view kunnr.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,104

If the program name is not too long, you can try something like this.




report zrich_0001 .

data: name type trdir-name.

parameters: p_kunnr type kna1-kunnr.

at selection-screen.

  concatenate sy-repid p_kunnr into name.

  call function 'ENQUEUE_E_TRDIR'
    exporting
*   MODE_TRDIR           = 'X'
      name                 = name
*   X_NAME               = ' '
*   _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.



start-of-selection.
  write:/ p_kunnr.

Regards,

Rich Heilman

7 REPLIES 7
Read only

Former Member
0 Likes
1,104

Megan,

Hmmmm...sounds strange. Is this the correct requirement. I dont understand why we should block someone from displaying a customer when another person is viewing it. Are you sure you are talking about display NOT change?

Rgds,

Naren

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,105

If the program name is not too long, you can try something like this.




report zrich_0001 .

data: name type trdir-name.

parameters: p_kunnr type kna1-kunnr.

at selection-screen.

  concatenate sy-repid p_kunnr into name.

  call function 'ENQUEUE_E_TRDIR'
    exporting
*   MODE_TRDIR           = 'X'
      name                 = name
*   X_NAME               = ' '
*   _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.



start-of-selection.
  write:/ p_kunnr.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,104

Well this is a test program, only one user infact only one session should be able to execute the transaction for a specific value

I was thinking something like store the userid and session number and set flag as X

as long as flag is X, as long as flag is X no one else will be able to run transaction for the same value

Read only

0 Likes
1,104

Sure you can do that too, set a flag and pass it off to memory using EXPORT statement, then simply check this flag using the IMPORT statement. You can use the lock object as well.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,104

Rich

I am not sure what the function module does

Read only

0 Likes
1,104

The function module is nothing more than a lock object for the table TRDIR, all this does it puts an entry in SM12 saying that this program is currently locked by a user. You would be just taking it one step further and applying the value of P_KUNNR to the NAME field and passing this as the program name, so then you are saying that the lock applies to this program and this value of P_KUNNR. That's really it. If another user comes along and do this program with the same value, the lock object will fail and give a mesasge saying that User 1 is currently locking the object.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,104

what is the field to get the session id .. i know username is sy-uname