Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Locking a document when printing?

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

Former Member
Former Member replied

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

1 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question