Logic To Change The Distribution Status

This example program is useful for those who have external warehousing where inbound and outbound document are completely grey off due to the status change once it has been created. 

By changing the delivery note status, you can manually post or modify it in exceptional cases.

This works for inbound deliveries as well.

Text Symbol:
011 Confirmation
012 Do you want to change the distribution status?
013 Yes
014 No
E01 Delivery does not exists!
E02 No authorization to change the distribution status!
E03 Internal error occured!
E04 Delivery is blocked for processing!
E05 Error during delivery update!
P00 Delivery number:
P01 Old distribution status:
P02 New distribution status:
S01 Processing canceled!
S02 Distribution status was updated successfully

Selection text: 
P_VBELN    Delivery/Shipping Notification
P_VLSTKA Distr.Status: Relevant
P_VLSTKB Distr.Status: Distributed
P_VLSTKC Distr.Status: Confirmed
P_VLSTKR Distr.Status: Local Reversal
P_VLSTKS Distr.Status: Not relevant

*&---------------------------------------------------------------------* 
*& Report  ZCHG_VLSTK                                                  
*&                                                                     
*& Author:  http://www.erpgreat.com                                    
*&                                                                     
*& Date:    13.04.2012                                                 
*&                                                                     
*& The aim of this report is to change the distribution status in      
*& outbound deliveries relevant for external controlled warehouses.     
*&---------------------------------------------------------------------
 
REPORT ZCHG_VLSTK.
 
* data declaration
 
TABLES LIKP.
 
DATA: L_CONFIRMATION(1) TYPE C.
DATA: LIKP_OLD TYPE LIKP.
 
* selection screen
 
SELECTION-SCREEN BEGIN OF BLOCK B00
  WITH FRAME
  TITLE TEXT-001.
 
PARAMETERS:  P_VBELN LIKE LIKP-VBELN MATCHCODE OBJECT VMVL
                                      OBLIGATORY.
 
SELECTION-SCREEN END OF BLOCK B00.
  
SELECTION-SCREEN BEGIN OF BLOCK B05
  WITH FRAME 
  TITLE TEXT-005.
 
PARAMETERS:  P_VLSTKS LIKE LIKP-VLSTK RADIOBUTTON GROUP 01, 
             P_VLSTKA LIKE LIKP-VLSTK RADIOBUTTON GROUP 01, 
             P_VLSTKB LIKE LIKP-VLSTK RADIOBUTTON GROUP 01, 
             P_VLSTKC LIKE LIKP-VLSTK RADIOBUTTON GROUP 01, 
             P_VLSTKR LIKE LIKP-VLSTK RADIOBUTTON GROUP 01.
 
SELECTION-SCREEN END OF BLOCK B05.
  
* does delivery exists?
 
AT SELECTION-SCREEN.
 
  IF NOT P_VBELN IS INITIAL.
 
    SELECT SINGLE FOR UPDATE * 
                 FROM LIKP
                WHERE VBELN EQ P_VBELN. 
    LIKP_OLD = LIKP.
   
    IF NOT SY-SUBRC IS INITIAL. 
      MESSAGE E000(38) WITH TEXT-E01.
    ELSE.
 
*-- check authority in productive environmen
*-- you put in your own authorization checks here or comment it
 
      AUTHORITY-CHECK OBJECT 'ZDECWMS'
                      ID     'LGNUM'      FIELD LIKP-LGNUM 
                      ID     'ZACTION' FIELD '*'.
 
      IF NOT SY-SUBRC IS INITIAL AND SY-SYSID(1) NE 'K'. 
        MESSAGE E000(38) WITH TEXT-E02.
      ENDIF.
 
    ENDIF.
 
  ENDIF.
 
START-OF-SELECTION.
 
* safety check before update
 
  CALL FUNCTION 'POPUP_TO_CONFIRM' 
       EXPORTING 
            TITLEBAR              = TEXT-011
            TEXT_QUESTION         = TEXT-012 
            TEXT_BUTTON_1         = TEXT-013 
            ICON_BUTTON_1         = 'ICON_CHECKED' 
            TEXT_BUTTON_2         = TEXT-014 
            ICON_BUTTON_2         = 'ICON_INCOMPLETE' 
            DISPLAY_CANCEL_BUTTON = '' 
       IMPORTING 
            ANSWER                = L_CONFIRMATION 
       EXCEPTIONS 
            TEXT_NOT_FOUND        = 1 
            OTHERS                = 2.
 
  IF NOT SY-SUBRC IS INITIAL. 
    MESSAGE E000(38) WITH TEXT-E03. 
  ENDIF.
 
* check for lock entries
 
  CALL FUNCTION 'ENQUEUE_EVVBLKE' 
       EXPORTING 
            VBELN          = LIKP-VBELN 
       EXCEPTIONS 
            FOREIGN_LOCK   = 1 
            SYSTEM_FAILURE = 2 
            OTHERS         = 3.
 
  IF SY-SUBRC <> 0. 
    MESSAGE E000(38) WITH TEXT-E04. 
  ENDIF.
  
* perform further processing
 
  IF L_CONFIRMATION NE 1.              " no confirmation 
    MESSAGE S000(38) WITH TEXT-S01. 
  ELSE.                                " update dist. status
 
*- write protocol / old status
 
    WRITE: / TEXT-P00, 
             LIKP-VBELN, 
          /  TEXT-P01, 
             LIKP-VLSTK.
 
*- set new distribution status
 
    IF NOT P_VLSTKS IS INITIAL. 
      LIKP-VLSTK = ' '.                " not relevant 
    ELSEIF NOT P_VLSTKA IS INITIAL. 
      LIKP-VLSTK = 'A'.                " relevant for distribution 
    ELSEIF NOT P_VLSTKB IS INITIAL. 
      LIKP-VLSTK = 'B'.                " distributed 
    ELSEIF NOT P_VLSTKC IS INITIAL. 
      LIKP-VLSTK = 'C'.                " confirmed 
    ELSEIF NOT P_VLSTKR IS INITIAL. 
      LIKP-VLSTK = 'R'.                " local cancellation 
    ENDIF.
 
*- write protocol / new status
 
    WRITE: / TEXT-P02, 
             LIKP-VLSTK.
 
*-- update delivery status
 
    UPDATE LIKP.
 
    IF SY-SUBRC IS INITIAL. 
      PERFORM CREATE_CHANGE_DOC     USING LIKP 
                                          LIKP_OLD. 
      COMMIT WORK.
      MESSAGE S000(38) WITH TEXT-S02.
    ELSE.
      ROLLBACK WORK.
      MESSAGE E000(38) WITH TEXT-E05.
    ENDIF.
 
  ENDIF.                               " confirmation
 
*&---------------------------------------------------------------------* 
*&      Form  CREATE_CHANGE_DOC 
*&---------------------------------------------------------------------* 
*       text 
*----------------------------------------------------------------------* 
*      -->P_LIKP      changed LIKP 
*      -->P_LIKP_OLD  old LIKP 
*----------------------------------------------------------------------*
 
FORM CREATE_CHANGE_DOC     USING    P_LIKP TYPE LIKP 
                                    P_LIKP_OLD TYPE LIKP.
 
  DATA: L_OBJECTCLAS LIKE CDHDR-OBJECTCLAS, 
        L_OBJECTID   LIKE CDHDR-OBJECTID, 
        L_TCODE      LIKE SY-TCODE,   
        L_REFTAB     LIKE CDPOS-TABNAME VALUE 'LIKP', 
        L_TAB        LIKE CDPOS-TABNAME VALUE 'LIKP'.
 
  IF P_LIKP-VLSTK <> P_LIKP_OLD-VLSTK.
    L_OBJECTCLAS = 'LIEFERUNG'.
    L_OBJECTID   = P_LIKP-VBELN.
    IF P_LIKP-VBELN(3) = '225'.
      L_TCODE = 'VL32'.
    ELSEIF P_LIKP-VBELN(3) = '175'.
      L_TCODE = 'VL02'.
    ELSE.
      CLEAR L_TCODE.
    ENDIF.
 
    CALL FUNCTION 'CHANGEDOCUMENT_OPEN'
         EXPORTING 
              OBJECTCLASS      = L_OBJECTCLAS
              OBJECTID         = L_OBJECTID
         EXCEPTIONS
              SEQUENCE_INVALID = 1
              OTHERS           = 2.
 
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
 
    CALL FUNCTION 'CHANGEDOCUMENT_SINGLE_CASE'
         EXPORTING
              TABLENAME              = L_TAB
             WORKAREA_NEW           = P_LIKP
             WORKAREA_OLD           = P_LIKP_OLD
        EXCEPTIONS
             NAMETAB_ERROR          = 1
             OPEN_MISSING           = 2
             POSITION_INSERT_FAILED = 3
             OTHERS                 = 4.
 
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO 
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
 
    CALL FUNCTION 'CHANGEDOCUMENT_CLOSE'
         EXPORTING
              DATE_OF_CHANGE          = SY-DATUM
              OBJECTCLASS             = L_OBJECTCLAS
              OBJECTID                = L_OBJECTID
              TCODE                   = L_TCODE
              TIME_OF_CHANGE          = SY-UZEIT
              USERNAME                = SY-UNAME
        EXCEPTIONS
             HEADER_INSERT_FAILED    = 1
             NO_POSITION_INSERTED    = 2
             OBJECT_INVALID          = 3
             OPEN_MISSING            = 4
             POSITION_INSERT_FAILED  = 5
             OTHERS                  = 6.
 
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
 
  ENDIF.
 
ENDFORM.                               " CREATE_CHANGE_POINTER
*-- End of program

ABAP Tips

See Also
Working Days Between Dates Using HR Calendar

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Main Index
SAP ERP Modules, Basis, ABAP and Other IMG Stuff

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.