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 a document when printing?

Former Member
0 Kudos

Hi Gurus,

I hope you can help me with this issue.

I made a customized printing program in ABAP that will print a certain document. My requirement is, I need to prohibit/lock the document to be printed until SAP is done passing the spool request to the printer. I tried to research the concept of enqueue and dequeue but I guess i need sample code for customized programs so that I can understand it.

I hope you can help me with this requirement.

Thanks,

Mon Magallanes

1 ACCEPTED SOLUTION

Former Member
0 Kudos

The simplest example i can give is given below.

Make a program with given code.

Run this program with some value of Billing document and press LOCK on selection screen.

In another session open the same program with same values, and press lock, it won't allow unless u unlock.


tables:vbrk.

data: begin of i_vbrk occurs 0,
        vbeln like vbrk-vbeln,
      end of i_vbrk.

select-options: s_vbeln for vbrk-vbeln.
SELECTION-SCREEN PUSHBUTTON /10(20) B_LOCK USER-COMMAND LOCK.
SELECTION-SCREEN PUSHBUTTON /10(20) B_UNLOCK USER-COMMAND UNLOCK.

*----------------------------------------------------------------------*
* INITIALIZATION
*----------------------------------------------------------------------*
INITIALIZATION.
  MOVE 'Lock'   TO B_LOCK.
  MOVE 'UnLock' TO B_UNLOCK.

at selection-screen.
  if sy-ucomm eq 'LOCK'.
    perform LOCK_DATA.
  elseif sy-ucomm eq 'UNLOCK'.
    perform UNLOCK_DATA.
  endif.

*&---------------------------------------------------------------------*
*&      Form  LOCK_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form lock_data.
  select vbeln from vbrk into table i_vbrk
  where vbeln in s_vbeln.
  if sy-subrc eq 0.
    loop at i_vbrk.
     CALL FUNCTION 'ENQUEUE_EVVBRKE'
         EXPORTING
              MODE_VBRK      = 'E'
              MANDT          = SY-MANDT
              VBELN          = i_vbrk-vbeln
*              X_VBELN        = ' '
*              _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.

    endloop.
  else.
    message I999(FG) with 'No Billing document found.'.
    leave list-processing.
  endif.
endform.                    " LOCK_DATA

*&---------------------------------------------------------------------*
*&      Form  UNLOCK_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form unlock_data.
 CALL FUNCTION 'DEQUEUE_ALL'
*     EXPORTING
*          _SYNCHRON = ' '
           .
  endform.                    " UNLOCK_DATA

16 REPLIES 16

Former Member
0 Kudos

Hi gurus,

any idea?

Regards,

Mon Magallanes

Former Member
0 Kudos

Create a Lock Object, for Table TSP01, then use that LOCK OBJECT to ENQUE and DEQUE in your program.

0 Kudos

Hi Tripat,

Thanks for your reply.

Yes, I can lock the spool table as you suggested but I believe, if I will do that, I will prohibit everyone in printing other documents. I only need to lock the specific document which i'm currently printing and unlock this document after spool request was passed to the printer.

I hope you can help me with this requirement.

Thanks a lot,

Mon Magallanes

0 Kudos

Don't lock whole table, in SE11 see LOCK OBJECT 'ENQ_TSP01'.It has RQIDENT as the only LOCK PARAMETER, so in your Program LOCK only that record of your given RQIDENT.

Pass RQUIDENT(Spool request number) to the below FM in ur code, and at end Deque it.

CALL FUNCTION 'ENQUEUE_ENQ_TSP01'

  • EXPORTING

  • MODE_TSP01 = 'E'

  • RQIDENT =

  • X_RQIDENT = ' '

  • _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.

0 Kudos

Hi,

We can use FMs ENQUE_E_table and Deque_table.

there table name is u r table name

and KEY, concatinamte the Primary fields into a variable for your document number

and pass it to KEY.

Ex: Let u r printing sales order 0000001000,

then then KEY = '0000001000' TABLE VBAK

Ex: Let u r printing sales order 0000001000 item 0010,

then then KEY = '00000010000010' TABLE VBAP

Kiran

0 Kudos

Hi Tripat,

Thanks for the suggestion. I will try it. Just a favor. Can you provide a sample code for dequeue?

I'll update you with this issue.

Thanks a lot.

Regards,

Mon Magallanes

0 Kudos

Hi Kiran,

Thanks for your reply.

I hope you can provide a sample code on how to use the function you were suggesting, as well as with its dequeue counter-part. Also, I get the information from different tables specifically vbak, vbap, vbrk, vbrp, etc. in my form.

Thanks a lot.

Regards,

Mon Magallanes

0 Kudos

Data:v_tabname TYPE tabname VALUE 'ANLB',

v_varkey TYPE vim_enqkey.

CONCATENATE sy-mandt wa_asset-bukrs wa_asset-anln1

wa_asset-anln2 wa_asset-afabe wa_asset-bdatu INTO v_varkey.

CALL FUNCTION 'ENQUEUE_E_TABLE'

EXPORTING

tabname = v_tabname

varkey = v_varkey

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

kiran

0 Kudos

You can use f.modules ENQUEUE* using the key on the table, which includes also the line item! So you won't lock all the table but just one row/document line.

0 Kudos

Hi Kiran,

I used 'ENQUEUE_E_TABLE' but still I can print documents with the same document number at the same time. I believe this function only lock table for update not for getting a query. Actually the table where i'm extracting my data is VBRK and VBRP. I enqueue the key (billing document number) in VBRK and did not dequeue it. And then I ran the same printing program with the same billing document number, but it still continue to program on the line where I select in table VBRK.

I hope you can help me.

Thanks a lot!

Regards,

Mon Magallanes

0 Kudos

Hi Tripat,

Your suggestion did not run properly. I think because when I ran my program, eventhough they are the same document number they will have different spool request number. TSP01 table only have the property of the spool request but not the document itself. I have an idea to solve it by locking the table VBRK and VBRP ( tables where I get the data) from queries. Do you know any built in functions that will lock a standard table from ABAP queries?

I hope you can help.

Thanks a lot!

Mon Magallanes

0 Kudos

use the Lock Object EVVBRKE.

Ask if any further problems faced.

0 Kudos

Hi Tripat,

I used ENQUEUE_EVVBRKE form, but still I can select a query on table vbrk eventhough i haven't dequeue the same document. here is my code for your reference.


 v_varkey = invnum.

  select kunrg fkdat into (comcode, invdate) from vbrk where vbeln = invnum.
  endselect.

  CALL FUNCTION 'ENQUEUE_EVVBRKE'
    EXPORTING
      vbeln         = v_varkey
    EXCEPTIONS
      foreign_lock   = 1
      system_failure = 2
      OTHERS         = 3.

  p_dest = 'LP01'.

  gt_itcpo-tdimmed = 'X'.  "Print immediately
  gt_itcpo-tdnewid = 'X'.  "New Spool
  gt_itcpo-tddest  = p_dest.   "Output Device
  APPEND gt_itcpo.

Thanks a lot for your assistance.

Regards,

Mon Magallanes

0 Kudos

Hi,

call the function module this way...

CALL FUNCTION 'ENQUEUE_EVVBRKE'
    EXPORTING
     MODE_VBRK = 'X'
      vbeln         = v_varkey
    EXCEPTIONS
      foreign_lock   = 1
      system_failure = 2
      OTHERS         = 3.

Hope this resolves your issue

Regards,

Siddarth

Former Member
0 Kudos

The simplest example i can give is given below.

Make a program with given code.

Run this program with some value of Billing document and press LOCK on selection screen.

In another session open the same program with same values, and press lock, it won't allow unless u unlock.


tables:vbrk.

data: begin of i_vbrk occurs 0,
        vbeln like vbrk-vbeln,
      end of i_vbrk.

select-options: s_vbeln for vbrk-vbeln.
SELECTION-SCREEN PUSHBUTTON /10(20) B_LOCK USER-COMMAND LOCK.
SELECTION-SCREEN PUSHBUTTON /10(20) B_UNLOCK USER-COMMAND UNLOCK.

*----------------------------------------------------------------------*
* INITIALIZATION
*----------------------------------------------------------------------*
INITIALIZATION.
  MOVE 'Lock'   TO B_LOCK.
  MOVE 'UnLock' TO B_UNLOCK.

at selection-screen.
  if sy-ucomm eq 'LOCK'.
    perform LOCK_DATA.
  elseif sy-ucomm eq 'UNLOCK'.
    perform UNLOCK_DATA.
  endif.

*&---------------------------------------------------------------------*
*&      Form  LOCK_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form lock_data.
  select vbeln from vbrk into table i_vbrk
  where vbeln in s_vbeln.
  if sy-subrc eq 0.
    loop at i_vbrk.
     CALL FUNCTION 'ENQUEUE_EVVBRKE'
         EXPORTING
              MODE_VBRK      = 'E'
              MANDT          = SY-MANDT
              VBELN          = i_vbrk-vbeln
*              X_VBELN        = ' '
*              _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.

    endloop.
  else.
    message I999(FG) with 'No Billing document found.'.
    leave list-processing.
  endif.
endform.                    " LOCK_DATA

*&---------------------------------------------------------------------*
*&      Form  UNLOCK_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form unlock_data.
 CALL FUNCTION 'DEQUEUE_ALL'
*     EXPORTING
*          _SYNCHRON = ' '
           .
  endform.                    " UNLOCK_DATA

0 Kudos

Hi Tripat,

I successfully blocked the document using your sample code.

Thanks a lot!

Regards,

Mon Magallanes