Posted: Wed Sep 05, 2007 8:03 pm Post subject: Purchase Order Receipt Notification
Author: Ashish Patel
A Report for Purchase Order Receipt Notification.
Its self explainatory.
Code:
REPORT ZAshish LINE-SIZE 170 LINE-COUNT 63 NO STANDARD PAGE HEADING.
**********************************************************************
* Program : ZAshish: Purchase Order Receipt Notification
* Author : Ashish Patel
*
**********************************************************************
*-----------------------------------------------------------------------
* Progname / Pgmr: Zashish / Created: 26-SEP-00
* Change Management request #: DBAR-4P6G-1228
*
* Description:
* Purchase Order Receipt Notification
*
* CLONED_FROM_ALB_PROGRAM ZFPPDSR
*-----------------------------------------------------------------------
TABLES : EKBE, EKPO, EKKN, ZMAIL.
DATA: W_DAYS LIKE T052-ZTAG1,
W_AGING(4) TYPE P,
W_CURRENT LIKE BSEG-WRBTR,
W_1-30 LIKE BSEG-WRBTR,
W_31-XX LIKE BSEG-WRBTR,
W_TOTAL LIKE BSEG-WRBTR,
W_TOTCOM LIKE BSEG-WRBTR,
W_TCOCUR LIKE BSEG-DMBTR,
W_TCOCUR1 LIKE BSEG-DMBTR,
W_TCOCUR2 LIKE BSEG-DMBTR,
W_TCOCUR3 LIKE BSEG-DMBTR,
W_FLAG1(1) TYPE C,
W_PAGE(1) TYPE C,
DUEDATE LIKE BSID-ZFBDT,LINETYP,
W_TRANSIT(70) TYPE C.
DATA:
* W_OUTFIL1(78) TYPE C "3/10/99 JRT
W_OUTFIL1(80) TYPE C "jrt1/8/01
VALUE '/sapmnt/export/mailsmtp/', "3/10/99 JRT
* VALUE '/sapmnt/export/imp/', "3/10/99 JRT
* VALUE '/sapmnt/export/europe/', "3/10/99 JRT
W_TIME(8) TYPE N, "time for ds name"jrt4/23/98
W_LIN TYPE P,
S_OPEN(1) TYPE C VALUE ' ', "open extract files"4/23/99 JR
S_HEAD(1) TYPE C, "write headers for extract
* W_OUTPUT(78) TYPE C, "3/10/99 JRT
W_OUTPUT(80) TYPE C, "jrt1/8/01
W_EMAIL(50) TYPE C, "jrt1/8/01
W_DATA(200) TYPE C, "3/10/99 JRT
* W_OUTFIL2(78) TYPE C "3/10/99 JRT
* VALUE '/sapmnt/export/sap/', "3/10/99 JRT
* VALUE '/tmp/', "3/10/99 JRT
W_OUTREC(200) TYPE C, "jrt 9/29/99
W_CATWRK(20) TYPE C, "jrt 9/29/99
W_QTYWRK(13) TYPE C, "jrt 9/29/99
W_CPUDT LIKE EKBE-CPUDT, "jrt 9/29/99
W_CPUTM LIKE EKBE-CPUTM. "jrt 9/29/99
DATA: BEGIN OF KEY_EKBE,
CPUDT LIKE EKBE-CPUDT,
CPUTM LIKE EKBE-CPUTM,
END OF KEY_EKBE.
DATA: BEGIN OF START_ZMAIL,
CPUDT LIKE EKBE-CPUDT,
CPUTM LIKE EKBE-CPUTM,
END OF START_ZMAIL.
DATA: BEGIN OF END_ZMAIL,
CPUDT LIKE EKBE-CPUDT,
CPUTM LIKE EKBE-CPUTM,
END OF END_ZMAIL.
DATA: BEGIN OF T_ZPMEML OCCURS 1.
INCLUDE STRUCTURE ZMAIL.
DATA: END OF T_ZPMEML.
DATA: BEGIN OF THEADER.
INCLUDE STRUCTURE THEAD.
DATA: END OF THEADER.
DATA: BEGIN OF WHEAD.
INCLUDE STRUCTURE THEAD.
DATA: END OF WHEAD.
SELECT-OPTIONS: S_WEMPF FOR EKKN-WEMPF.
* S_CPUDT FOR EKBE-CPUDT.
* S_CPUTM FOR EKBE-CPUTM.
*PARAMETERS: P_OVERD AS CHECKBOX DEFAULT 'X',
* P_SUMM AS CHECKBOX,
* P_SENDIT AS CHECKBOX DEFAULT 'X', "Send email?
* P_EMAIL(50) TYPE C DEFAULT '[email protected]'.
************************************************************************
************************************************************************
* F I E L D - G R O U P S *
************************************************************************
FIELD-GROUPS:
HEADER,
DETAIL.
INSERT:
EKKN-WEMPF
EKBE-EBELN
EKBE-EBELP
INTO HEADER,
EKBE-BWART "5/3/01 LHO
EKPO-TXZ01
EKBE-MENGE
EKKN-AUFNR
EKKN-ABLAD
ZMAIL-LANGU
INTO DETAIL.
INITIALIZATION.
PERFORM SET_SELECT_OPTS.
START-OF-SELECTION.
*-----------------------------------------------------------------------
SELECT * FROM EKBE
WHERE VGABE = 1
AND CPUDT >= START_ZMAIL-CPUDT.
* AND CPUTM IN S_CPUTM.
MOVE EKBE-CPUDT TO KEY_EKBE-CPUDT.
MOVE EKBE-CPUTM TO KEY_EKBE-CPUTM.
IF KEY_EKBE < START_ZMAIL. "date/time less?
CONTINUE.
ENDIF.
IF KEY_EKBE > END_ZMAIL. "date/time more?
CONTINUE.
ENDIF.
* WHERE EBELN = '9500263471'.
* WHERE CPUDT > '20000900'.
* WHERE CPUDT = SY-DATUM..
* CHECK EKBE-VGABE = 1.
* CHECK EKBE-CPUTM IN S_CPUTM.
* CHECK EKBE-CPUTM > ( SY-UZEIT - 3600 )."less than 1 hour?
*
SELECT * FROM EKKN
WHERE EBELN = EKBE-EBELN
AND EBELP = EKBE-EBELP.
* AND ZEKKN = EKBE-ZEKKN.
* IF EKKN-AUFNR = ' ' "6/28/01 lho
* AND EKKN-ABLAD = ' '. "6/14/01 lho
* CONTINUE. "6/28/01 lho
* ELSE. "6/28/01 lho
* EXIT. "6/28/01 lho
* ENDIF. "6/28/01 lho
ENDSELECT.
IF SY-SUBRC = 0.
* IF EKKN-AUFNR = ' ' "6/14/01 lho
* AND EKKN-ABLAD = ' '. "6/14/01 lho
* CONTINUE. "6/28/01 lho
* ENDIF. "6/28/01 lho
* EKKN-WEMPF = 'thomajr'.
CHECK EKKN-WEMPF NE ' '.
* IF EKKN-WEMPF = 'BAIRDB'.
* BREAK-POINT.
* ENDIF.
CHECK EKKN-WEMPF IN S_WEMPF.
SELECT SINGLE * FROM ZMAIL
WHERE WEMPF = EKKN-WEMPF.
CHECK SY-SUBRC = 0.
* IF EKBE-CPUDT < ZMAIL-CPUDT.
* CONTINUE.
* ENDIF.
* IF EKBE-CPUDT = ZMAIL-CPUDT
* AND EKBE-CPUTM < ZMAIL-CPUTM.
* CONTINUE.
* ENDIF.
* ZPMEML-WEMPF = 'thomajr'.
*
SELECT SINGLE * FROM EKPO
WHERE EBELN = EKBE-EBELN
AND EBELP = EKBE-EBELP.
CHECK SY-SUBRC = 0.
PERFORM UPDATE_T_ZPMEML.
EXTRACT DETAIL.
ENDIF.
ENDSELECT.
END-OF-SELECTION.
*----------------------------------------------------------------------
* ---------- start of the list -----------------------------------
SORT.
LOOP.
AT NEW EKKN-WEMPF.
IF S_OPEN = 'X'.
CLOSE DATASET W_OUTFIL1.
S_OPEN = ' '.
ENDIF.
MOVE 'X' TO S_OPEN.
WRITE SY-UZEIT TO W_TIME.
W_OUTFIL1+24(12) = EKKN-WEMPF.
W_OUTFIL1+36(01) = '.'.
W_OUTFIL1+37(08) = W_TIME.
W_OUTFIL1+45(04) = '.imp'.
CONDENSE W_OUTFIL1 NO-GAPS.
OPEN DATASET W_OUTFIL1 FOR OUTPUT IN TEXT MODE.
PERFORM WRITE_EMAIL_HEADER.
ENDAT.
PERFORM WRITE_PO_DATA.
ENDLOOP.
IF S_OPEN = 'X'.
CLOSE DATASET W_OUTFIL1.
S_OPEN = ' '.
ENDIF.
* update ZPMEML with current values
DESCRIBE TABLE T_ZPMEML LINES W_LIN.
IF W_LIN > 0.
LOOP AT T_ZPMEML.
SELECT SINGLE * FROM ZMAIL
WHERE WEMPF = T_ZPMEML-WEMPF.
IF SY-SUBRC = 0.
ZMAIL-CPUDT = T_ZPMEML-CPUDT.
ZMAIL-CPUTM = T_ZPMEML-CPUTM.
UPDATE ZMAIL.
ELSE.
ZMAIL-WEMPF = T_ZPMEML-WEMPF.
ZMAIL-CPUDT = T_ZPMEML-CPUDT.
ZMAIL-CPUTM = T_ZPMEML-CPUTM.
INSERT ZMAIL.
ENDIF.
ENDLOOP.
ENDIF.
*---------------------------------------------------------------------*
* FORM WRITE_PO_DATA *
*---------------------------------------------------------------------*
FORM WRITE_PO_DATA.
CLEAR W_OUTREC.
MOVE 'Purchase Order Number/item :' TO W_OUTREC+1.
IF ZMAIL-LANGU = 'F'.
MOVE 'N° de commande/Poste : ' TO W_OUTREC+1.
ENDIF.
MOVE EKBE-EBELN TO W_OUTREC+31.
MOVE '/' TO W_OUTREC+42.
MOVE EKBE-EBELP TO W_OUTREC+43.
PERFORM WRITE_EXTRACT.
* Movement type added 5/3/01 LHO
CLEAR W_OUTREC.
MOVE 'Movement Type:' TO W_OUTREC+1.
IF ZMAIL-LANGU = 'F'.
MOVE 'Code Mouvement:' TO W_OUTREC+1.
ENDIF.
MOVE EKBE-BWART TO W_OUTREC+17.
PERFORM WRITE_EXTRACT.
CLEAR W_OUTREC.
MOVE 'Description:' TO W_OUTREC+1.
IF ZMAIL-LANGU = 'F'.
MOVE 'Designation :' TO W_OUTREC+1.
ENDIF.
MOVE EKPO-TXZ01 TO W_OUTREC+15.
PERFORM WRITE_EXTRACT.
CLEAR W_OUTREC.
MOVE EKBE-MENGE TO W_QTYWRK.
MOVE 'Qty Received :' TO W_OUTREC+1.
MOVE W_QTYWRK TO W_OUTREC+16. "jrt125
IF ZMAIL-LANGU = 'F'.
MOVE 'Quantite receptionnee :' TO W_OUTREC+1.
MOVE W_QTYWRK TO W_OUTREC+24.
ENDIF.
PERFORM WRITE_EXTRACT.
CLEAR W_OUTREC.
MOVE 'Account Assign Order # :' TO W_OUTREC+1.
IF ZMAIL-LANGU = 'F'.
MOVE 'Imputation :' TO W_OUTREC+1.
ENDIF.
MOVE EKKN-AUFNR TO W_OUTREC+27.
PERFORM WRITE_EXTRACT.
CLEAR W_OUTREC.
MOVE 'Goods Recipient :' TO W_OUTREC+1.
IF ZMAIL-LANGU = 'F'.
MOVE 'Receptionnaire :' TO W_OUTREC+1.
ENDIF.
MOVE EKKN-WEMPF TO W_OUTREC+20.
MOVE 'Unloading point:' TO W_OUTREC+35.
MOVE EKKN-ABLAD TO W_OUTREC+53.
IF ZMAIL-LANGU = 'F'.
MOVE 'Pt de dechargement :' TO W_OUTREC+35.
MOVE EKKN-ABLAD TO W_OUTREC+56.
ENDIF.
PERFORM WRITE_EXTRACT.
MOVE
'********************************************************************'
TO W_OUTREC+1.
PERFORM WRITE_EXTRACT.
*
ENDFORM.
*----------------------------------------------------------------------*
* Form WRITE_EXTRACT
*----------------------------------------------------------------------*
FORM WRITE_EXTRACT.
TRANSFER W_OUTREC TO W_OUTFIL1.
CLEAR W_OUTREC.
ENDFORM.
***********************************************************************
* FORM WRITE_EMAIL_HEADER
***********************************************************************
FORM WRITE_EMAIL_HEADER.
CLEAR W_OUTPUT.
MOVE 'From: [email protected]' TO W_OUTPUT. "jrt1/8/01
* MOVE 'From:' TO W_OUTPUT.
* W_OUTPUT+6(12) = EKKN-WEMPF.
TRANSFER W_OUTPUT TO W_OUTFIL1.
CLEAR W_OUTPUT.
* W_OUTPUT = 'To:'.
* W_OUTPUT+6(50) = EKKN-WEMPF.
CONCATENATE 'To: ' EKKN-WEMPF '@albemarle.com' INTO W_OUTPUT. "jrt1/8
TRANSFER W_OUTPUT TO W_OUTFIL1.
CLEAR W_OUTPUT.
MOVE 'Subject: Purchase Order Receipt(s)' TO W_OUTPUT.
TRANSFER W_OUTPUT TO W_OUTFIL1.
CLEAR W_OUTPUT.
TRANSFER W_OUTPUT TO W_OUTFIL1.
ENDFORM.
***********************************************************************
* FORM UPDATE_T_ZPMEML
***********************************************************************
FORM UPDATE_T_ZPMEML.
READ TABLE T_ZPMEML WITH KEY WEMPF = ZMAIL-WEMPF.
IF SY-SUBRC <> 0.
T_ZPMEML-WEMPF = ZMAIL-WEMPF.
T_ZPMEML-CPUDT = EKBE-CPUDT.
T_ZPMEML-CPUTM = EKBE-CPUTM.
APPEND T_ZPMEML.
ELSE.
IF EKBE-CPUDT = T_ZPMEML-CPUDT.
IF EKBE-CPUTM > T_ZPMEML-CPUTM.
T_ZPMEML-CPUDT = EKBE-CPUDT.
T_ZPMEML-CPUTM = EKBE-CPUTM.
MODIFY T_ZPMEML INDEX SY-TABIX TRANSPORTING CPUDT CPUTM.
ENDIF.
ELSE.
IF EKBE-CPUDT > T_ZPMEML-CPUDT.
T_ZPMEML-CPUDT = EKBE-CPUDT.
T_ZPMEML-CPUTM = EKBE-CPUTM.
MODIFY T_ZPMEML INDEX SY-TABIX TRANSPORTING CPUDT CPUTM.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
***********************************************************************
* FORM SET_SELECT_OPTS
***********************************************************************
FORM SET_SELECT_OPTS.
CLEAR: START_ZMAIL, END_ZMAIL.
SELECT * FROM ZMAIL.
MOVE ZMAIL-CPUDT TO START_ZMAIL-CPUDT.
MOVE ZMAIL-CPUTM TO START_ZMAIL-CPUTM.
IF START_ZMAIL > END_ZMAIL.
MOVE START_ZMAIL TO END_ZMAIL.
ENDIF.
ENDSELECT.
MOVE END_ZMAIL-CPUDT TO W_CPUDT.
MOVE END_ZMAIL-CPUTM TO W_CPUTM.
CLEAR: START_ZMAIL, END_ZMAIL.
W_CPUTM = W_CPUTM + 1.
* MOVE: 'I' TO S_CPUDT-SIGN,
* 'BT' TO S_CPUDT-OPTION,
* W_CPUDT TO S_CPUDT-LOW,
* SY-DATUM TO S_CPUDT-HIGH.
* APPEND S_CPUDT.
*
* set comparison keys
MOVE W_CPUDT TO START_ZMAIL-CPUDT.
MOVE W_CPUTM TO START_ZMAIL-CPUTM.
MOVE SY-DATUM TO END_ZMAIL-CPUDT.
MOVE SY-UZEIT TO END_ZMAIL-CPUTM.
* MOVE: 'I' TO S_CPUTM-SIGN,
* 'BT' TO S_CPUTM-OPTION,
* W_CPUTM TO S_CPUTM-LOW,
* SY-UZEIT TO S_CPUTM-HIGH.
* APPEND S_CPUTM.
ENDFORM.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.