Wednesday, May 16, 2012

Reverse Goods Issue

This code snippet shows you how to reverse goods issue.It is pretty simple.


DATA : lv_vbtyp TYPE likp-vbtyp,
       lv_vbeln TYPE vbuk-vbeln.

DATA : lt_mesg TYPE TABLE OF mesg ,
       ls_mesg LIKE LINE OF lt_mesg.


lv_vbeln = '10000012'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input  = lv_vbeln
  IMPORTING
    output = lv_vbeln.

SELECT SINGLE vbtyp FROM likp
         INTO lv_vbtyp
        WHERE vbeln = lv_vbeln. " Check Document
CHECK sy-subrc EQ 0.  " Check Document

SELECT SINGLE COUNT(*) FROM vbuk
        WHERE vbeln = lv_vbeln
          AND wbstk = 'C'.
CHECK sy-subrc EQ 0.  " Check Status.

CALL FUNCTION 'WS_REVERSE_GOODS_ISSUE'
  EXPORTING
    i_vbeln                   = lv_vbeln
    i_budat                   = sy-datum
    i_vbtyp                   = lv_vbtyp
    i_tcode                   = 'VL09'
  TABLES
    t_mesg                    = lt_mesg
  EXCEPTIONS
    error_reverse_goods_issue = 1
    OTHERS                    = 2.
IF sy-subrc EQ 0.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.
ELSE.
  LOOP AT lt_mesg INTO ls_mesg. " Get Messages
  ENDLOOP.
ENDIF.

No comments:

Post a Comment