*&---------------------------------------------------------------------*
*& Include ZVVF_MI050_BATCH_NUMBERING *
*&---------------------------------------------------------------------*
DATA : W_WEEK TYPE SCAL-WEEK,
W_WEEKNO(2) TYPE N,
W_MONTHNO(2) TYPE N,
W_YEARNO(2) TYPE N,
W_YEAR(4) TYPE N,
W_SRNO TYPE ZVVF_MT050_BATSR-LAST_NO,
W_MRP_INDICATOR TYPE ZVVF_MRP_INDCTR-MRP_IND,
W_ANSWER(1) TYPE C,
IT_AFRU TYPE STANDARD TABLE OF AFRU WITH HEADER LINE,
WA_AFRU TYPE AFRU,
IT_AFVC TYPE STANDARD TABLE OF AFVC,
WA_AFVC TYPE AFVC,
WA_CRHD TYPE CRHD,
W_LINECNT TYPE I,
W_CONDTNTYPE_FOUND TYPE C,
W_AUFPL TYPE AFKO-AUFPL.
DATA : IT_POPUPDATA TYPE STANDARD TABLE OF SVAL,
WA_POPUPDATA TYPE SVAL.
TYPES : BEGIN OF TY_MCH1.
INCLUDE STRUCTURE MCH1.
TYPES : W_SRNO(4) TYPE N,
END OF TY_MCH1.
DATA : IT_MCH1 TYPE STANDARD TABLE OF TY_MCH1,
WA_MCH1 TYPE TY_MCH1,
W_CHARG TYPE MCH1-CHARG,
W_TITLE(200) TYPE C,
W_STRLEN TYPE I.
CLEAR : W_WEEK,W_WEEKNO,W_MONTHNO,W_SRNO,WA_MCH1.
REFRESH : IT_MCH1.
W_MONTHNO = SY-DATUM+4(2).
W_YEARNO = SY-DATUM+2(2).
W_YEAR = SY-DATUM+0(4).
CASE WA_MARA-PROFL.
********COMMENTED BY SOURABH FOR B01*********************************
* WHEN 'B01'.
*
***** 1) Batch No Generation for Raw Materials(Oils-Local) - B01 *******
*
* CALL FUNCTION 'DATE_GET_WEEK'
* EXPORTING
* DATE = SY-DATUM
* IMPORTING
* WEEK = W_WEEK
* EXCEPTIONS
* DATE_INVALID = 1
* OTHERS = 2.
* IF SY-SUBRC EQ 0.
*
* W_WEEKNO = W_WEEK+4(2).
* W_YEARNO = W_WEEK+2(2).
*
* ENDIF.
*
* CONCATENATE W_PLANT_CODE W_WEEKNO W_YEARNO INTO NEW_CHARG.
********COMMENTED BY SOURABH FOR B01*********************************
*********************************************************************
WHEN 'B02'.
** 2) Batch No Generation for Raw Materials(Oils-Imported) - B02 *******
SELECT SINGLE * FROM ZVVF_MT050_BATSR
INTO CORRESPONDING FIELDS OF WA_SERIALNO
WHERE BT_PROFL = 'B02'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
IF WA_SERIALNO-LAST_NO EQ WA_SERIALNO-TO_NO.
*** error message Series Fully used"
MESSAGE E106(ZMM) WITH 'B02' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ELSE.
W_SRNO = WA_SERIALNO-LAST_NO + 1.
ENDIF.
ELSE.
*** error message "Batch Serial no not maintained"
MESSAGE E107(ZMM) WITH 'B02' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ENDIF.
**** note : following IF loop is written assuming that one document will
**** contain multiple materials having same DG profile indicator.
IF X_BNCOM-EBELP LE '00010'.
CLEAR W_CHARG.
CONCATENATE W_PLANT_CODE W_MONTHNO W_YEARNO "w_srno+1(3)
INTO W_CHARG.
SELECT MATNR CHARG FROM ZVVF_MV050_BATCH
INTO CORRESPONDING FIELDS OF TABLE IT_MCH1
WHERE PROFL = WA_MARA-PROFL.
IF SY-SUBRC EQ 0.
SORT IT_MCH1 BY CHARG.
CONCATENATE W_CHARG '*' INTO W_CHARG.
DELETE IT_MCH1 WHERE NOT ( CHARG CP W_CHARG ).
CLEAR W_LINECNT.
DESCRIBE TABLE IT_MCH1 LINES W_LINECNT.
IF W_LINECNT GT 0.
LOOP AT IT_MCH1 INTO WA_MCH1.
WA_MCH1-W_SRNO = WA_MCH1-CHARG+5(3).
MODIFY IT_MCH1 FROM WA_MCH1 TRANSPORTING W_SRNO.
ENDLOOP.
SORT IT_MCH1 BY W_SRNO DESCENDING.
READ TABLE IT_MCH1 INTO WA_MCH1 INDEX 1.
CLEAR W_SRNO.
W_SRNO = WA_MCH1-CHARG+5(3) + 1.
ENDIF.
ELSE.
*** accept the running serial no as given by ZVVF_MT050_BATSR table
ENDIF.
ENDIF.
CONCATENATE W_PLANT_CODE W_MONTHNO W_YEARNO W_SRNO+1(3)
INTO NEW_CHARG.
UPDATE ZVVF_MT050_BATSR
SET LAST_NO = W_SRNO
WHERE BT_PROFL = 'B02'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
*Commit Work must not be present in User Exit since it triggers an
*Error message for object status not maintained.
* commit work.
ELSE.
**** error message.
MESSAGE E108(ZMM) WITH 'B02' W_YEAR W_MONTHNO.
ENDIF.
*********************************************************************
WHEN 'B03'.
** 3) Batch No Generation for Raw Materials( Soaps / Others ) - B03 ***
SELECT SINGLE * FROM ZVVF_MT050_BATSR
INTO CORRESPONDING FIELDS OF WA_SERIALNO
WHERE BT_PROFL = 'B03'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
IF WA_SERIALNO-LAST_NO EQ WA_SERIALNO-TO_NO.
*** error message Series Fully used"
MESSAGE E106(ZMM) WITH 'B03' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ELSE.
W_SRNO = WA_SERIALNO-LAST_NO + 1.
ENDIF.
ELSE.
*** error message "Batch Serial no not maintained"
MESSAGE E107(ZMM) WITH 'B03' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ENDIF.
**** note : following IF loop is written assuming that one document will
**** contain multiple materials having same DG profile indicator.
IF X_BNCOM-EBELP LE '00010'.
CLEAR W_CHARG.
CONCATENATE W_PLANT_CODE W_MONTHNO W_YEARNO "w_srno+1(3)
INTO W_CHARG.
SELECT MATNR CHARG FROM ZVVF_MV050_BATCH
INTO CORRESPONDING FIELDS OF TABLE IT_MCH1
WHERE PROFL = WA_MARA-PROFL.
IF SY-SUBRC EQ 0.
SORT IT_MCH1 BY CHARG.
CONCATENATE W_CHARG '*' INTO W_CHARG.
DELETE IT_MCH1 WHERE NOT ( CHARG CP W_CHARG ).
CLEAR W_LINECNT.
DESCRIBE TABLE IT_MCH1 LINES W_LINECNT.
IF W_LINECNT GT 0.
LOOP AT IT_MCH1 INTO WA_MCH1.
WA_MCH1-W_SRNO = WA_MCH1-CHARG+5(3).
MODIFY IT_MCH1 FROM WA_MCH1 TRANSPORTING W_SRNO.
ENDLOOP.
SORT IT_MCH1 BY W_SRNO DESCENDING.
READ TABLE IT_MCH1 INTO WA_MCH1 INDEX 1.
CLEAR W_SRNO.
W_SRNO = WA_MCH1-CHARG+5(3) + 1.
ENDIF.
ELSE.
*** accept the running serial no as given by ZVVF_MT050_BATSR table
ENDIF.
ENDIF.
CONCATENATE W_PLANT_CODE W_MONTHNO W_YEARNO W_SRNO+1(3)
INTO NEW_CHARG.
UPDATE ZVVF_MT050_BATSR
SET LAST_NO = W_SRNO
WHERE BT_PROFL = 'B03'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
*** must not be present in User Exit since it triggers an Error message
*** for object status not maintained.
* commit work.
ELSE.
**** error message.
MESSAGE E108(ZMM) WITH 'B03' W_YEAR W_MONTHNO.
ENDIF.
*******************************************************************
WHEN 'B04'.
REFRESH : IT_AFRU.
CLEAR : WA_AFRU,WA_CRHD,W_ANSWER.
** 4) Batch No Generation for SemiFinished Goods - B04 ***
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
* TITLEBAR = ' '
* DIAGNOSE_OBJECT = ' '
TEXT_QUESTION = 'Select Batch No:-'
TEXT_BUTTON_1 = 'Existing Batch No'(001)
* ICON_BUTTON_1 = ' '
TEXT_BUTTON_2 = 'New Batch No'(002)
* ICON_BUTTON_2 = ' '
DEFAULT_BUTTON = '1'
DISPLAY_CANCEL_BUTTON = 'X'
* USERDEFINED_F1_HELP = ' '
* START_COLUMN = 25
* START_ROW = 6
* POPUP_TYPE =
* IV_QUICKINFO_BUTTON_1 = ' '
* IV_QUICKINFO_BUTTON_2 = ' '
IMPORTING
ANSWER = W_ANSWER
* TABLES
* PARAMETER =
EXCEPTIONS
TEXT_NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
IF W_ANSWER = '2'.
SELECT AUFPL BUDAT ERZET FROM AFRU
INTO CORRESPONDING FIELDS OF TABLE IT_AFRU
WHERE AUFNR = X_BNCOM-AUFNR
AND WERKS = X_BNCOM-WERKS
AND STOKZ NE 'X'
AND STZHL = '00000000'
ORDER BY BUDAT ERZET.
IF SY-SUBRC EQ 0.
SORT IT_AFRU BY BUDAT DESCENDING ERZET DESCENDING.
READ TABLE IT_AFRU INTO WA_AFRU INDEX 1.
SELECT VORNR ARBID PHFLG STEUS FROM AFVC
INTO CORRESPONDING FIELDS OF TABLE IT_AFVC
* FOR ALL ENTRIES IN IT_AFRU
WHERE AUFPL = WA_AFRU-AUFPL.
* AND APLZL = WA_AFRU-APLZL.
IF SY-SUBRC EQ 0.
W_CONDTNTYPE_FOUND = ''.
READ TABLE IT_AFVC INTO WA_AFVC
WITH KEY PHFLG = 'X'
STEUS = 'PI03'.
IF SY-SUBRC NE 0.
READ TABLE IT_AFVC INTO WA_AFVC
WITH KEY PHFLG = 'X'
STEUS = 'PI04'.
IF SY-SUBRC EQ 0.
W_CONDTNTYPE_FOUND = 'X'.
ENDIF.
ELSE.
W_CONDTNTYPE_FOUND = 'X'.
ENDIF.
IF W_CONDTNTYPE_FOUND EQ 'X'.
SELECT SINGLE ARBPL FROM CRHD
INTO CORRESPONDING FIELDS OF WA_CRHD
WHERE OBJID = WA_AFVC-ARBID.
IF SY-SUBRC EQ 0.
SELECT SINGLE * FROM ZVVF_MT050_BATSR
INTO CORRESPONDING FIELDS OF WA_SERIALNO
WHERE BT_PROFL = 'B04'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
IF WA_SERIALNO-LAST_NO EQ WA_SERIALNO-TO_NO.
*** error message Series Fully used"
MESSAGE E106(ZMM) WITH 'B04' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ELSE.
* Start of insertion of code by niraj on 07-03-2005
if x_bncom-posnr > '0001'.
W_SRNO = WA_SERIALNO-LAST_NO.
else.
W_SRNO = WA_SERIALNO-LAST_NO + 1.
endif.
* End of insertion of code by niraj on 07-03-2005
* Start of deletion of code by niraj on 07-03-2005
* W_SRNO = WA_SERIALNO-LAST_NO + 1.
* End of deletion of code by niraj on 07-03-2005
ENDIF.
ELSE.
*** error message "Batch Serial no not maintained"
MESSAGE E107(ZMM) WITH 'B04' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ENDIF.
**** note : following IF loop is written assuming that one document will
**** contain multiple materials having same DG profile indicator.
IF X_BNCOM-EBELP LE '00010'.
CLEAR W_CHARG.
CONCATENATE W_PLANT_CODE W_MONTHNO W_YEARNO
" wa_crhd-arbpl+6(2) w_srno+1(3)
INTO W_CHARG.
SELECT MATNR CHARG FROM ZVVF_MV050_BATCH
INTO CORRESPONDING FIELDS OF TABLE IT_MCH1
WHERE PROFL = WA_MARA-PROFL.
IF SY-SUBRC EQ 0.
SORT IT_MCH1 BY CHARG.
CONCATENATE W_CHARG '*' INTO W_CHARG.
DELETE IT_MCH1 WHERE NOT ( CHARG CP W_CHARG ).
CLEAR W_LINECNT.
DESCRIBE TABLE IT_MCH1 LINES W_LINECNT.
IF W_LINECNT GT 0.
LOOP AT IT_MCH1 INTO WA_MCH1.
WA_MCH1-W_SRNO = WA_MCH1-CHARG+7(3).
MODIFY IT_MCH1 FROM WA_MCH1 TRANSPORTING W_SRNO.
ENDLOOP.
SORT IT_MCH1 BY W_SRNO DESCENDING.
READ TABLE IT_MCH1 INTO WA_MCH1 INDEX 1.
CLEAR W_SRNO.
W_SRNO = WA_MCH1-CHARG+7(3) + 1.
ENDIF.
ELSE.
*** accept the running serial no as given by ZVVF_MT050_BATSR table
ENDIF.
ENDIF.
******** code to get the last two digits of resource no ********
CONDENSE WA_CRHD-ARBPL NO-GAPS.
CLEAR W_STRLEN.
W_STRLEN = STRLEN( WA_CRHD-ARBPL ).
W_STRLEN = W_STRLEN - 2.
*******************************************************
CONCATENATE W_PLANT_CODE W_MONTHNO W_YEARNO
WA_CRHD-ARBPL+W_STRLEN(2) W_SRNO+1(3)
INTO NEW_CHARG.
* update table "zvvf_mt050_batsr" with latest srno.
UPDATE ZVVF_MT050_BATSR
SET LAST_NO = W_SRNO
WHERE BT_PROFL = 'B04'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
*** Commit Work must not be present in User Exit since it triggers an
*** Error message for object status not maintained.
* commit work.
ELSE.
**** error message.
MESSAGE E108(ZMM) WITH 'B04' W_YEAR W_MONTHNO.
ENDIF.
ELSE.
**** error message : Resource Id(Wrok Center not found for order)
MESSAGE E109(ZMM) WITH X_BNCOM-AUFNR.
ENDIF.
ELSE.
**** error message : Routing Number not found for order)
MESSAGE E111(ZMM) WITH X_BNCOM-AUFNR.
ENDIF.
ELSE.
**** error message : Routing Number not found for order)
MESSAGE E111(ZMM) WITH X_BNCOM-AUFNR.
ENDIF.
ELSE.
**** error message : Confirmation not done for order
* Start of Insertion by Niraj on 07-03-2005
SELECT single AUFPL FROM AFKO
INTO W_AUFPL
WHERE AUFNR = X_BNCOM-AUFNR.
IF SY-SUBRC EQ 0.
SELECT VORNR ARBID PHFLG STEUS FROM AFVC
INTO CORRESPONDING FIELDS OF TABLE IT_AFVC
* FOR ALL ENTRIES IN IT_AFRU
WHERE AUFPL = w_AUFPL.
* AND APLZL = IT_AFRU-APLZL.
IF SY-SUBRC EQ 0.
W_CONDTNTYPE_FOUND = ''.
READ TABLE IT_AFVC INTO WA_AFVC
WITH KEY PHFLG = 'X'
STEUS = 'PI03'.
IF SY-SUBRC NE 0.
READ TABLE IT_AFVC INTO WA_AFVC
WITH KEY PHFLG = 'X'
STEUS = 'PI04'.
IF SY-SUBRC EQ 0.
W_CONDTNTYPE_FOUND = 'X'.
ENDIF.
ELSE.
W_CONDTNTYPE_FOUND = 'X'.
ENDIF.
IF W_CONDTNTYPE_FOUND EQ 'X'.
SELECT SINGLE ARBPL FROM CRHD
INTO CORRESPONDING FIELDS OF WA_CRHD
WHERE OBJID = WA_AFVC-ARBID.
IF SY-SUBRC EQ 0.
SELECT SINGLE * FROM ZVVF_MT050_BATSR
INTO CORRESPONDING FIELDS OF WA_SERIALNO
WHERE BT_PROFL = 'B04'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
IF WA_SERIALNO-LAST_NO EQ WA_SERIALNO-TO_NO.
*** error message Series Fully used"
MESSAGE E106(ZMM) WITH 'B04' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ELSE.
W_SRNO = WA_SERIALNO-LAST_NO + 1.
ENDIF.
ELSE.
*** error message "Batch Serial no not maintained"
MESSAGE E107(ZMM) WITH 'B04' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ENDIF.
**** note : following IF loop is written assuming that one document will
**** contain multiple materials having same DG profile indicator.
IF X_BNCOM-EBELP LE '00010'.
CLEAR W_CHARG.
CONCATENATE W_PLANT_CODE W_MONTHNO W_YEARNO
" wa_crhd-arbpl+6(2) w_srno+1(3)
INTO W_CHARG.
SELECT MATNR CHARG FROM ZVVF_MV050_BATCH
INTO CORRESPONDING FIELDS OF TABLE IT_MCH1
WHERE PROFL = WA_MARA-PROFL.
IF SY-SUBRC EQ 0.
SORT IT_MCH1 BY CHARG.
CONCATENATE W_CHARG '*' INTO W_CHARG.
DELETE IT_MCH1 WHERE NOT ( CHARG CP W_CHARG ).
CLEAR W_LINECNT.
DESCRIBE TABLE IT_MCH1 LINES W_LINECNT.
IF W_LINECNT GT 0.
LOOP AT IT_MCH1 INTO WA_MCH1.
WA_MCH1-W_SRNO = WA_MCH1-CHARG+7(3).
MODIFY IT_MCH1 FROM WA_MCH1 TRANSPORTING W_SRNO.
ENDLOOP.
SORT IT_MCH1 BY W_SRNO DESCENDING.
READ TABLE IT_MCH1 INTO WA_MCH1 INDEX 1.
CLEAR W_SRNO.
W_SRNO = WA_MCH1-CHARG+7(3) + 1.
ENDIF.
ELSE.
*** accept the running serial no as given by ZVVF_MT050_BATSR table
ENDIF.
ENDIF.
******** code to get the last two digits of resource no ********
CONDENSE WA_CRHD-ARBPL NO-GAPS.
CLEAR W_STRLEN.
W_STRLEN = STRLEN( WA_CRHD-ARBPL ).
W_STRLEN = W_STRLEN - 2.
*******************************************************
CONCATENATE W_PLANT_CODE W_MONTHNO W_YEARNO
WA_CRHD-ARBPL+W_STRLEN(2) W_SRNO+1(3)
INTO NEW_CHARG.
* update table "zvvf_mt050_batsr" with latest srno.
UPDATE ZVVF_MT050_BATSR
SET LAST_NO = W_SRNO
WHERE BT_PROFL = 'B04'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
*** Commit Work must not be present in User Exit since it triggers an
*** Error message for object status not maintained.
* commit work.
ELSE.
**** error message.
MESSAGE E108(ZMM) WITH 'B04' W_YEAR W_MONTHNO.
ENDIF.
ELSE.
**** error message : Resource Id(Wrok Center not found for order)
MESSAGE E109(ZMM) WITH X_BNCOM-AUFNR.
ENDIF.
ELSE.
**** error message : Routing Number not found for order)
MESSAGE E111(ZMM) WITH X_BNCOM-AUFNR.
ENDIF.
ELSE.
**** error message : Routing Number not found for order)
MESSAGE E111(ZMM) WITH X_BNCOM-AUFNR.
ENDIF.
endif.
* End of Insertion by Niraj on 07-03-2005
* MESSAGE E110(ZMM) WITH X_BNCOM-AUFNR.
ENDIF.
CLEAR : WA_AFRU .
ELSEIF ( W_ANSWER = '1' ) OR ( W_ANSWER = 'A' ).
NEW_CHARG = ''.
** if user selects Existing Batch or Cancel option then Exit this code
** and let user select the Batch no manually from available list.
EXIT.
ENDIF.
ENDIF.
*******************************************************************
WHEN 'B05'.
** 5) Batch No Generation for Finished Goods Oils & FA - B05 ***
CLEAR : W_ANSWER.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
* TITLEBAR = ' '
* DIAGNOSE_OBJECT = ' '
TEXT_QUESTION = 'Select Batch No:-'
TEXT_BUTTON_1 = 'Existing Batch No'(001)
* ICON_BUTTON_1 = ' '
TEXT_BUTTON_2 = 'New Batch No'(002)
* ICON_BUTTON_2 = ' '
DEFAULT_BUTTON = '1'
DISPLAY_CANCEL_BUTTON = 'X'
* USERDEFINED_F1_HELP = ' '
* START_COLUMN = 25
* START_ROW = 6
* POPUP_TYPE =
* IV_QUICKINFO_BUTTON_1 = ' '
* IV_QUICKINFO_BUTTON_2 = ' '
IMPORTING
ANSWER = W_ANSWER
* TABLES
* PARAMETER =
EXCEPTIONS
TEXT_NOT_FOUND = 1
OTHERS = 2
.
IF SY-SUBRC EQ 0.
IF W_ANSWER = '2'.
SELECT SINGLE * FROM ZVVF_MT050_BATSR
INTO CORRESPONDING FIELDS OF WA_SERIALNO
WHERE BT_PROFL = 'B05'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
IF WA_SERIALNO-LAST_NO EQ WA_SERIALNO-TO_NO.
*** error message Series Fully used"
MESSAGE E106(ZMM) WITH 'B05' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ELSE.
W_SRNO = WA_SERIALNO-LAST_NO + 1.
ENDIF.
ELSE.
*** error message "Batch Serial no not maintained"
MESSAGE E107(ZMM) WITH 'B05' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ENDIF.
**** note : following IF loop is written assuming that one document will
**** contain multiple materials having same DG profile indicator.
IF X_BNCOM-EBELP LE '00010'.
CLEAR W_CHARG.
CONCATENATE W_PLANT_CODE W_MONTHNO W_YEARNO "w_srno
INTO W_CHARG.
SELECT MATNR CHARG FROM ZVVF_MV050_BATCH
INTO CORRESPONDING FIELDS OF TABLE IT_MCH1
WHERE PROFL = WA_MARA-PROFL.
IF SY-SUBRC EQ 0.
SORT IT_MCH1 BY CHARG.
CONCATENATE W_CHARG '*' INTO W_CHARG.
DELETE IT_MCH1 WHERE NOT ( CHARG CP W_CHARG ).
CLEAR W_LINECNT.
DESCRIBE TABLE IT_MCH1 LINES W_LINECNT.
IF W_LINECNT GT 0.
LOOP AT IT_MCH1 INTO WA_MCH1.
WA_MCH1-W_SRNO = WA_MCH1-CHARG+5(4).
MODIFY IT_MCH1 FROM WA_MCH1 TRANSPORTING W_SRNO.
ENDLOOP.
SORT IT_MCH1 BY W_SRNO DESCENDING.
READ TABLE IT_MCH1 INTO WA_MCH1 INDEX 1.
CLEAR W_SRNO.
W_SRNO = WA_MCH1-CHARG+5(4) + 1.
ENDIF.
ELSE.
*** accept the running serial no as given by ZVVF_MT050_BATSR table
ENDIF.
ENDIF.
CONCATENATE W_PLANT_CODE W_MONTHNO W_YEARNO W_SRNO
INTO NEW_CHARG.
UPDATE ZVVF_MT050_BATSR
SET LAST_NO = W_SRNO
WHERE BT_PROFL = 'B05'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
*** Commit Work must not be present in User Exit since it triggers an
*** Error message for object status not maintained.
* commit work.
ELSE.
**** error message.
MESSAGE E108(ZMM) WITH 'B05' W_YEAR W_MONTHNO.
ENDIF.
*******************************************************************
ELSEIF ( W_ANSWER = '1' ) OR ( W_ANSWER = 'A' ).
NEW_CHARG = ''.
** if user selects Existing Batch or Cancel option then Exit this code
** and let user select the Batch no manually from available list.
EXIT.
ENDIF.
ENDIF.
WHEN 'B06'.
** 6) Batch No Generation for Finished Goods SOAPS - B06 ***
REFRESH IT_POPUPDATA.
CLEAR: W_ANSWER,W_MONTHNO,W_YEARNO,W_YEAR.
CLEAR W_TITLE.
CONCATENATE 'Enter MNTH & YEAR for Item:'
X_BNCOM-EBELP INTO W_TITLE.
CLEAR WA_POPUPDATA.
WA_POPUPDATA-TABNAME = 'ZVVF_MT050_BATSR'.
WA_POPUPDATA-FIELDNAME = 'BT_MNTH'.
WA_POPUPDATA-FIELDTEXT = 'Month'.
APPEND WA_POPUPDATA TO IT_POPUPDATA.
CLEAR WA_POPUPDATA.
WA_POPUPDATA-TABNAME = 'ZVVF_MT050_BATSR'.
WA_POPUPDATA-FIELDNAME = 'BT_YEAR'.
WA_POPUPDATA-FIELDTEXT = 'Year'.
APPEND WA_POPUPDATA TO IT_POPUPDATA.
CALL FUNCTION 'POPUP_GET_VALUES'
EXPORTING
* NO_VALUE_CHECK = ' '
POPUP_TITLE = W_TITLE
START_COLUMN = '5'
START_ROW = '5'
IMPORTING
RETURNCODE = W_ANSWER
TABLES
FIELDS = IT_POPUPDATA
EXCEPTIONS
ERROR_IN_FIELDS = 1
OTHERS = 2
.
IF SY-SUBRC EQ 0.
IF ( W_ANSWER EQ ' ' ).
LOOP AT IT_POPUPDATA INTO WA_POPUPDATA.
IF WA_POPUPDATA-FIELDNAME = 'BT_MNTH'.
W_MONTHNO = WA_POPUPDATA-VALUE.
IF ( W_MONTHNO EQ '01' OR W_MONTHNO EQ '02'
OR W_MONTHNO EQ '03' OR W_MONTHNO EQ '04'
OR W_MONTHNO EQ '05' OR W_MONTHNO EQ '06'
OR W_MONTHNO EQ '07' OR W_MONTHNO EQ '08'
OR W_MONTHNO EQ '09' OR W_MONTHNO EQ '10'
OR W_MONTHNO EQ '11' OR W_MONTHNO EQ '12' ).
** do nothing
ELSE.
*** error message Invalid Month
MESSAGE E112(ZMM) WITH W_MONTHNO.
ENDIF.
ENDIF.
IF WA_POPUPDATA-FIELDNAME = 'BT_YEAR'.
W_YEAR = WA_POPUPDATA-VALUE.
IF ( W_YEAR CP '20*').
** do nothing
W_YEARNO = W_YEAR+2(2).
ELSE.
*** error message Invalid Month
MESSAGE E113(ZMM) WITH W_YEAR.
ENDIF.
ENDIF.
ENDLOOP.
*************************
SELECT SINGLE * FROM ZVVF_MT050_BATSR
INTO CORRESPONDING FIELDS OF WA_SERIALNO
WHERE BT_PROFL = 'B06'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
IF WA_SERIALNO-LAST_NO EQ WA_SERIALNO-TO_NO.
*** error message Series Fully used"
MESSAGE E106(ZMM) WITH 'B06' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ELSE.
W_SRNO = WA_SERIALNO-LAST_NO + 1.
ENDIF.
ELSE.
*** error message "Batch Serial no not maintained"
MESSAGE E107(ZMM) WITH 'B06' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ENDIF.
**** Get the Valid MRP Indicator
SELECT SINGLE MRP_IND FROM ZVVF_MRP_INDCTR
INTO W_MRP_INDICATOR
WHERE MATNR = X_BNCOM-MATNR
AND WERKS = X_BNCOM-WERKS
AND ( VALID_FROM LE SY-DATUM AND
VALID_TO GE SY-DATUM ).
IF SY-SUBRC EQ 0.
**** note : following IF loop is written assuming that one document will
**** contain multiple materials having same DG profile indicator.
IF X_BNCOM-EBELP LE '00010'.
CLEAR W_CHARG.
CONCATENATE W_PLANT_CODE W_MONTHNO
W_YEARNO "w_mrp_indicator w_srno+1(3)
INTO W_CHARG.
SELECT MATNR CHARG FROM ZVVF_MV050_BATCH
INTO CORRESPONDING FIELDS OF TABLE IT_MCH1
WHERE PROFL = WA_MARA-PROFL.
IF SY-SUBRC EQ 0.
SORT IT_MCH1 BY CHARG.
CONCATENATE W_CHARG '*' INTO W_CHARG.
DELETE IT_MCH1 WHERE NOT ( CHARG CP W_CHARG ).
CLEAR W_LINECNT.
DESCRIBE TABLE IT_MCH1 LINES W_LINECNT.
IF W_LINECNT GT 0.
LOOP AT IT_MCH1 INTO WA_MCH1.
WA_MCH1-W_SRNO = WA_MCH1-CHARG+6(3).
MODIFY IT_MCH1 FROM WA_MCH1 TRANSPORTING W_SRNO.
ENDLOOP.
SORT IT_MCH1 BY W_SRNO DESCENDING.
READ TABLE IT_MCH1 INTO WA_MCH1 INDEX 1.
CLEAR W_SRNO.
W_SRNO = WA_MCH1-CHARG+6(3) + 1.
ENDIF.
ELSE.
*** accept the running serial no as given by ZVVF_MT050_BATSR table
ENDIF.
ENDIF.
CONCATENATE W_PLANT_CODE W_MONTHNO
W_YEARNO W_MRP_INDICATOR W_SRNO+1(3)
INTO NEW_CHARG.
* UPDATE TABLE zvvf_mt050_batsr WITH LATEST SERIAL NO
UPDATE ZVVF_MT050_BATSR
SET LAST_NO = W_SRNO
WHERE BT_PROFL = 'B06'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
*** Commit Work must not be present in User Exit since it triggers an
*** Error message for object status not maintained.
* commit work.
ELSE.
**** error message.
MESSAGE E108(ZMM) WITH 'B06' W_YEAR W_MONTHNO.
ENDIF.
ELSE.
*** error message "MRP indicator is NOT maintained
MESSAGE E115(ZMM) WITH X_BNCOM-MATNR X_BNCOM-WERKS.
ENDIF.
ELSE.
*** ERROR MESSAGE
MESSAGE E114(ZMM).
ENDIF.
ELSE.
*** ERROR MESSAGE
MESSAGE E114(ZMM).
ENDIF.
WHEN 'B07'.
** 7) Batch No Generation for Packing Material SOAPS - B07 ***
REFRESH IT_POPUPDATA.
CLEAR: W_ANSWER,W_MONTHNO,W_YEARNO,W_YEAR.
CLEAR W_TITLE.
CONCATENATE 'Enter MNTH & YEAR for Item:'
X_BNCOM-EBELP INTO W_TITLE.
CLEAR WA_POPUPDATA.
WA_POPUPDATA-TABNAME = 'ZVVF_MT050_BATSR'.
WA_POPUPDATA-FIELDNAME = 'BT_MNTH'.
WA_POPUPDATA-FIELDTEXT = 'Month'.
APPEND WA_POPUPDATA TO IT_POPUPDATA.
CLEAR WA_POPUPDATA.
WA_POPUPDATA-TABNAME = 'ZVVF_MT050_BATSR'.
WA_POPUPDATA-FIELDNAME = 'BT_YEAR'.
WA_POPUPDATA-FIELDTEXT = 'Year'.
APPEND WA_POPUPDATA TO IT_POPUPDATA.
CALL FUNCTION 'POPUP_GET_VALUES'
EXPORTING
* NO_VALUE_CHECK = ' '
POPUP_TITLE = W_TITLE
START_COLUMN = '5'
START_ROW = '5'
IMPORTING
RETURNCODE = W_ANSWER
TABLES
FIELDS = IT_POPUPDATA
EXCEPTIONS
ERROR_IN_FIELDS = 1
OTHERS = 2
.
IF SY-SUBRC EQ 0.
IF ( W_ANSWER EQ ' ' ).
LOOP AT IT_POPUPDATA INTO WA_POPUPDATA.
IF WA_POPUPDATA-FIELDNAME = 'BT_MNTH'.
W_MONTHNO = WA_POPUPDATA-VALUE.
IF ( W_MONTHNO EQ '01' OR W_MONTHNO EQ '02'
OR W_MONTHNO EQ '03' OR W_MONTHNO EQ '04'
OR W_MONTHNO EQ '05' OR W_MONTHNO EQ '06'
OR W_MONTHNO EQ '07' OR W_MONTHNO EQ '08'
OR W_MONTHNO EQ '09' OR W_MONTHNO EQ '10'
OR W_MONTHNO EQ '11' OR W_MONTHNO EQ '12' ).
** do nothing
ELSE.
*** error message Invalid Month
MESSAGE E112(ZMM) WITH W_MONTHNO.
ENDIF.
ENDIF.
IF WA_POPUPDATA-FIELDNAME = 'BT_YEAR'.
W_YEAR = WA_POPUPDATA-VALUE.
IF ( W_YEAR CP '20*').
** do nothing
W_YEARNO = W_YEAR+2(2).
ELSE.
*** error message Invalid Month
MESSAGE E113(ZMM) WITH W_YEAR.
ENDIF.
ENDIF.
ENDLOOP.
**************************
SELECT SINGLE * FROM ZVVF_MT050_BATSR
INTO CORRESPONDING FIELDS OF WA_SERIALNO
WHERE BT_PROFL = 'B07'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
IF WA_SERIALNO-LAST_NO EQ WA_SERIALNO-TO_NO.
*** error message Series Fully used"
MESSAGE E106(ZMM) WITH 'B07' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ELSE.
W_SRNO = WA_SERIALNO-LAST_NO + 1.
ENDIF.
ELSE.
*** error message "Batch Serial no not maintained"
MESSAGE E107(ZMM) WITH 'B07' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ENDIF.
**** Get the Valid MRP Indicator
SELECT SINGLE MRP_IND FROM ZVVF_MRP_INDCTR
INTO W_MRP_INDICATOR
WHERE MATNR = X_BNCOM-MATNR
AND WERKS = X_BNCOM-WERKS
AND ( VALID_FROM LE SY-DATUM AND
VALID_TO GE SY-DATUM ).
IF SY-SUBRC EQ 0.
**** note : following IF loop is written assuming that one document will
**** contain multiple materials having same DG profile indicator.
IF X_BNCOM-EBELP LE '00010'.
CLEAR W_CHARG.
CONCATENATE W_PLANT_CODE W_MONTHNO
W_YEARNO " w_mrp_indicator w_srno+1(3)
INTO W_CHARG.
SELECT MATNR CHARG FROM ZVVF_MV050_BATCH
INTO CORRESPONDING FIELDS OF TABLE IT_MCH1
WHERE PROFL = WA_MARA-PROFL.
IF SY-SUBRC EQ 0.
SORT IT_MCH1 BY CHARG.
CONCATENATE W_CHARG '*' INTO W_CHARG.
DELETE IT_MCH1 WHERE NOT ( CHARG CP W_CHARG ).
CLEAR W_LINECNT.
DESCRIBE TABLE IT_MCH1 LINES W_LINECNT.
IF W_LINECNT GT 0.
LOOP AT IT_MCH1 INTO WA_MCH1.
WA_MCH1-W_SRNO = WA_MCH1-CHARG+6(3).
MODIFY IT_MCH1 FROM WA_MCH1 TRANSPORTING W_SRNO.
ENDLOOP.
SORT IT_MCH1 BY W_SRNO DESCENDING.
READ TABLE IT_MCH1 INTO WA_MCH1 INDEX 1.
CLEAR W_SRNO.
W_SRNO = WA_MCH1-CHARG+6(3) + 1.
ENDIF.
ELSE.
*** accept the running serial no as given by ZVVF_MT050_BATSR table
ENDIF.
ENDIF.
CONCATENATE W_PLANT_CODE W_MONTHNO
W_YEARNO W_MRP_INDICATOR W_SRNO+1(3)
INTO NEW_CHARG.
UPDATE ZVVF_MT050_BATSR
SET LAST_NO = W_SRNO
WHERE BT_PROFL = 'B07'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
*** Commit Work must not be present in User Exit since it triggers an
*** Error message for object status not maintained.
* commit work.
ELSE.
**** error message.
MESSAGE E108(ZMM) WITH 'B07' W_YEAR W_MONTHNO.
ENDIF.
ELSE.
*** error message "MRP indicator is NOT maintained
MESSAGE E115(ZMM) WITH X_BNCOM-MATNR X_BNCOM-WERKS.
ENDIF.
ELSE.
*** ERROR MESSAGE
MESSAGE E114(ZMM).
ENDIF.
ELSE.
*** ERROR MESSAGE
MESSAGE E114(ZMM).
ENDIF.
WHEN 'B08'.
** 8) Batch No Generation for PCP material - B08 ***
SELECT SINGLE * FROM ZVVF_MT050_BATSR
INTO CORRESPONDING FIELDS OF WA_SERIALNO
WHERE BT_PROFL = 'B08'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
IF WA_SERIALNO-LAST_NO EQ WA_SERIALNO-TO_NO.
*** error message Series Fully used"
MESSAGE E106(ZMM) WITH 'B08' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ELSE.
W_SRNO = WA_SERIALNO-LAST_NO + 1.
ENDIF.
ELSE.
*** error message "Batch Serial no not maintained"
MESSAGE E107(ZMM) WITH 'B08' W_YEAR W_MONTHNO X_BNCOM-WERKS.
ENDIF.
**** note : following IF loop is written assuming that one document will
**** contain multiple materials having same DG profile indicator.
IF X_BNCOM-EBELP LE '00010'.
CLEAR W_CHARG.
CONCATENATE W_PLANT_CODE W_MONTHNO W_YEARNO "w_srno
INTO W_CHARG.
SELECT MATNR CHARG FROM ZVVF_MV050_BATCH
INTO CORRESPONDING FIELDS OF TABLE IT_MCH1
WHERE PROFL = WA_MARA-PROFL.
IF SY-SUBRC EQ 0.
SORT IT_MCH1 BY CHARG.
CONCATENATE W_CHARG '*' INTO W_CHARG.
DELETE IT_MCH1 WHERE NOT ( CHARG CP W_CHARG ).
CLEAR W_LINECNT.
DESCRIBE TABLE IT_MCH1 LINES W_LINECNT.
IF W_LINECNT GT 0.
LOOP AT IT_MCH1 INTO WA_MCH1.
WA_MCH1-W_SRNO = WA_MCH1-CHARG+5(4).
MODIFY IT_MCH1 FROM WA_MCH1 TRANSPORTING W_SRNO.
ENDLOOP.
SORT IT_MCH1 BY W_SRNO DESCENDING.
READ TABLE IT_MCH1 INTO WA_MCH1 INDEX 1.
CLEAR W_SRNO.
W_SRNO = WA_MCH1-CHARG+5(4) + 1.
ENDIF.
ELSE.
*** accept the running serial no as given by ZVVF_MT050_BATSR table
ENDIF.
ENDIF.
CONCATENATE W_PLANT_CODE W_MONTHNO W_YEARNO W_SRNO+1(3)
INTO NEW_CHARG.
UPDATE ZVVF_MT050_BATSR
SET LAST_NO = W_SRNO
WHERE BT_PROFL = 'B08'
AND BT_MNTH = W_MONTHNO
AND BT_YEAR = W_YEAR
AND WERKS = X_BNCOM-WERKS.
IF SY-SUBRC EQ 0.
*** Commit Work must not be present in User Exit since it triggers an
*** Error message for object status not maintained.
* commit work.
ELSE.
**** error message.
MESSAGE E108(ZMM) WITH 'B08' W_YEAR W_MONTHNO.
ENDIF.
*******************************************************************
WHEN 'B09'.
** NOT REQUIRED
CLEAR NEW_CHARG.
WHEN OTHERS.
MESSAGE E103(ZMM) WITH WA_MARA-PROFL.
ENDCASE.
No comments:
Post a Comment