REPORT ZPSFC001.
*----------------------------------------------------------------------*
* This reports inactivates the deletion indicator for production orders.
* Please run this report in testmode first to check if only orders are
* included which should not be archived.
* It will not remove the deletion flag from the order. This must be
* done manually by inactivating the deletion flag within the order.
* --> Testmode: 'X' -> no update performed
* --> PARTDLVD: 'X' -> partially delivered orders will not be updated
* --> PARTCONF: 'X' -> partially confirmed orders will not be updated
* --> ORDER : Range of orders to be selected
* --> MATNR : Range of materials for which orders exist
*----------------------------------------------------------------------*
* Caution: If you want to use this report for other order types than *
* production orders please modify lines where
* 'auftragstyp-fert' is used
*----------------------------------------------------------------------*
* I0010(stk_tru)-partially confirmed, I0074(stk_tli)-partially deliverd
INCLUDE LCOKOSTA. "get constants for status
INCLUDE LCOKOTYP. "get constants for order type
* parameter definition
TABLES: VJAUFK, AUFK.
PARAMETERS:
TESTMODE DEFAULT 'X',
PARTDLVD DEFAULT 'X', "check for partially delivered
PARTCONF DEFAULT 'X'. "check for partially confirmed
SELECT-OPTIONS:
ORDER FOR VJAUFK-AUFNR MATCHCODE OBJECT ORDE,
MATNR FOR VJAUFK-MATNR MATCHCODE OBJECT MAT1.
DATA: BEGIN OF FERT OCCURS 1.
INCLUDE STRUCTURE VJAUFK.
DATA: END OF FERT.
DATA: BEGIN OF COLL_TAB OCCURS 1,
AUFNR LIKE AUFK-AUFNR,
END OF COLL_TAB.
DATA: BEGIN OF STATUS OCCURS 1.
INCLUDE STRUCTURE JSTAT.
DATA: END OF STATUS.
DATA: LAST_LEAD_AUFNR LIKE AFKO-LEAD_AUFNR.
* To set status I0013 - stk_loe inactive
STATUS-STAT = STK_LOE.
STATUS-INACT = 'X'.
APPEND STATUS.
IF MATNR[] IS INITIAL AND
ORDER[] IS INITIAL.
message i889(CO) with
'Please enter at least one selection criteria.'.
exit.
ENDIF.
SELECT * FROM VJAUFK INTO TABLE FERT
WHERE AUFNR IN ORDER
AND MATNR IN MATNR
AND STAT = STK_LOE
AND INACT = SPACE
AND AUTYP = AUFTRAGSTYP-FERT.
IF SY-SUBRC <> 0.
WRITE 'NO PRODUCTION ORDERS FOUND'.
EXIT.
ENDIF.
* for collective orders we have to guarantee, that all orders for
* one collective order are member of the selection
* --> we need to add orders not included yet.
PERFORM CORRECT_COLLECTIVE_ORDER.
LOOP AT FERT.
* Commit - Logic:
* With first enter in loop do not commit (commit_flag)
* For each single order commit work
* Collective orders are committed at once
IF FERT-PRODNET EQ 'X'.
* collective order
IF LAST_LEAD_AUFNR NE FERT-LEAD_AUFNR.
* there is a new (collective) order --> commit amd refresh
IF TESTMODE IS INITIAL.
COMMIT WORK.
ENDIF.
CALL FUNCTION 'STATUS_BUFFER_REFRESH'.
LAST_LEAD_AUFNR = FERT-LEAD_AUFNR.
ENDIF.
ELSE.
IF TESTMODE IS INITIAL.
COMMIT WORK.
ENDIF.
CALL FUNCTION 'STATUS_BUFFER_REFRESH'.
ENDIF.
IF NOT PARTDLVD IS INITIAL.
* check if order is partially delivered if requested
CALL FUNCTION 'STATUS_CHECK'
EXPORTING
OBJNR = FERT-OBJNR
STATUS = STK_TLI
EXCEPTIONS
STATUS_NOT_ACTIVE = 2.
IF SY-SUBRC = 2.
CONTINUE.
ENDIF.
ENDIF.
IF NOT PARTCONF IS INITIAL.
* check if order is partially confirmed if requested
CALL FUNCTION 'STATUS_CHECK'
EXPORTING
OBJNR = FERT-OBJNR
STATUS = STK_TRU
EXCEPTIONS
STATUS_NOT_ACTIVE = 2.
IF SY-SUBRC = 2.
CONTINUE.
ENDIF.
ENDIF.
CALL FUNCTION 'STATUS_CHECK'
EXPORTING
OBJNR = FERT-OBJNR
STATUS = STK_LOE
EXCEPTIONS
STATUS_NOT_ACTIVE = 2.
IF SY-SUBRC = 2.
WRITE: / 'ORDER ', FERT-AUFNR, ': DELETION INDICATOR NOT ACTIVE'.
CONTINUE.
ENDIF.
IF TESTMODE IS INITIAL.
CALL FUNCTION 'STATUS_CHANGE_INTERN'
EXPORTING
OBJNR = FERT-OBJNR
TABLES
STATUS = STATUS.
UPDATE AUFK SET AENAM = SY-UNAME
AEDAT = SY-DATUM
aezeit = sy-uzeit "as of release 4.0
WHERE AUFNR = FERT-AUFNR.
LAST_LEAD_AUFNR = FERT-LEAD_AUFNR.
ENDIF.
IF SY-SUBRC IS INITIAL.
WRITE: / 'ORDER ', FERT-AUFNR, ': DELETION INDICATOR REMOVED'.
ENDIF.
IF NOT TESTMODE IS INITIAL.
WRITE: ' - TESTMODE'.
ENDIF.
ENDLOOP.
COMMIT WORK.
SKIP 1.
WRITE: 'Program finished'.
*---------------------------------------------------------------------*
* FORM CORRECT_COLLECTIVE_ORDER *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM CORRECT_COLLECTIVE_ORDER.
DATA: HELP_DATE LIKE SY-DATUM,
HELP_COUNTER TYPE I.
SORT FERT BY LEAD_AUFNR AUFNR.
* add each leading order into coll_tab
LOOP AT FERT WHERE LEAD_AUFNR NE SPACE.
* CHECK fert-aufnr NE fert-lead_aufnr.
COLL_TAB-AUFNR = FERT-LEAD_AUFNR.
COLLECT COLL_TAB.
ENDLOOP.
IF NOT COLL_TAB[] IS INITIAL.
SELECT * FROM VJAUFK APPENDING TABLE FERT
FOR ALL ENTRIES IN COLL_TAB
WHERE LEAD_AUFNR EQ COLL_TAB-AUFNR
AND STAT = STK_LOE
AND AUTYP = AUFTRAGSTYP-FERT
AND LOEKZ = 'X'.
SORT FERT BY LEAD_AUFNR AUFNR.
DELETE ADJACENT DUPLICATES FROM FERT.
ENDIF.
ENDFORM.