PR Extraction v1
PR Extraction v1
PR Extraction v1
REPORT ZPR_FILE_TRANSFER_1.
TYPES : BEGIN OF TS_PR_FINAL,
PURCHASE_REQUISITION TYPE EBAN-BANFN,
PR_ORIGINAL_NO TYPE EBAN-BANFN,
PR_DATE TYPE EBAN-ERDAT,
CREATOR_NAME TYPE EBAN-ERNAM,
S_NO TYPE CHAR20,"EBAN-BNFPO,
MATERIAL_CODE TYPE EBAN-MATNR,
SHORT_DESC TYPE EBAN-TXZ01,
LONG_DESC TYPE MATNR,
UOM TYPE EBAN-MEINS,
QTY_REQ TYPE CHAR20,"eban-MENGE,
ESTIMATED_PRICE TYPE CHAR20,"eban-preis,
DELIVERY_DATE TYPE EBAN-LFDAT,
LASTPOOPENQTY TYPE MATNR,
STOCKASON TYPE MATNR,
PURCHASEORDER1 TYPE EKPO-EBELN,
ORDERDATE1 TYPE EKKO-AEDAT,
VENDOR1 TYPE EKKO-LIFNR,
PO1BASICPRICE TYPE CHAR20,"ekpo-netpr,
PURCHASEORDER2 TYPE EKPO-EBELN,
ORDERDATE2 TYPE EKPO-AEDAT,
VENDOR2 TYPE EKKO-LIFNR,
PO2BASICPRICE TYPE CHAR20,"ekpo-netpr,
PURCHASEORDER3 TYPE EKPO-EBELN,
ORDERDATE3 TYPE EKKO-AEDAT,
VENDOR3 TYPE EKKO-LIFNR,
PO3BASICPRICE TYPE CHAR20,"ekpo-netpr,
CONSUMEDLASTFY TYPE MATNR,
CONSUMED2NDLASTFY TYPE MATNR,
HSN_CODE TYPE MARC-STEUC,
DELIVERY_LOCATION TYPE EBAN-LGORT,
PURCHASINGORG TYPE EBAN-EKORG,
COMPANYNAME TYPE MATNR,
RFQCREATORID TYPE MATNR,
PRCREATIONDATE TYPE EBAN-BADAT,
SERVICELTEXT TYPE ESLL-KTEXT1,
PRCATEGORY TYPE EBAN-BSART,
USEREMAILID TYPE MATNR,
MATERIAL_GROUP TYPE EBAN-MATKL,
WBSCODE TYPE MATNR,
COSTCENTER TYPE EBKN-KOSTL,
TRACKINGNO TYPE EBAN-BEDNR,
PLANTNAME TYPE EBAN-WERKS,
EPSMATERIALCODE TYPE MATNR,
ESTIMATEDTOTVAL TYPE CHAR20,"eban-MENGE,
SERACTNO TYPE ESLL-SRVPOS,
GL TYPE EBKN-SAKTO,
FUND TYPE EBKN-GEBER,
FUNDCENTER TYPE EBKN-FISTL,
COMMITMENTITEM TYPE EBKN-FIPOS,
ASSETCODE TYPE EBKN-ANLN1,
INTERNALORDER TYPE EBKN-AUFNR,
ACCASSIGCATEGORY TYPE EBAN-KNTTP,
ITEMCATEGORY TYPE EBAN-PSTYP,
END OF TS_PR_FINAL.
DATA : LS_PR_FINAL TYPE TS_PR_FINAL.
DATA : LS_PR_FINAL_T TYPE TS_PR_FINAL.
TEXT(250),
END OF TY_TEXT.
DATA : LW_MENGE TYPE CHAR20.
DATA : LW_PREIS TYPE CHAR20.
DATA:IT_TEXT TYPE TABLE OF TY_TEXT,
IS_TEXT TYPE TY_TEXT.
SELECT *
FROM EBAN
INTO TABLE GT_EBAN
WHERE BANFN = LW_BANFN."IM_BANFN.
IF SY-SUBRC EQ 0.
IF LT_FRKZ IS NOT INITIAL..
DELETE GT_EBAN WHERE FRGKZ NOT IN LT_FRKZ.
ENDIF.
ENDIF.
IF GT_EBAN IS INITIAL.
MESSAGE 'No new PR document found to be transfered' TYPE 'S' DISPLAY LIKE
'E'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
REFRESH LT_EBKN.
SELECT BANFN
BNFPO
SAKTO
KOSTL
GEBER
FISTL
FIPOS
ANLN1
AUFNR
FROM EBKN
INTO TABLE LT_EBKN
FOR ALL ENTRIES IN GT_EBAN
WHERE BANFN = GT_EBAN-BANFN
AND BNFPO = GT_EBAN-BNFPO.
IF SY-SUBRC EQ 0.
SORT LT_EBKN BY BANFN BNFPO.
ENDIF.
REFRESH LT_EKPO.
SELECT EBELN
EBELP
AEDAT
BANFN
BNFPO
NETPR
FROM EKPO
INTO TABLE LT_EKPO
FOR ALL ENTRIES IN GT_EBAN
WHERE BANFN = GT_EBAN-BANFN
AND BNFPO = GT_EBAN-BNFPO.
IF SY-SUBRC EQ 0.
REFRESH LT_EKPO_TEMP.
LT_EKPO_TEMP = LT_EKPO.
SORT LT_EKPO_TEMP BY EBELN.
DELETE ADJACENT DUPLICATES FROM LT_EKPO_TEMP COMPARING EBELN.
SELECT EBELN
AEDAT
LIFNR
FROM EKKO
INTO TABLE LT_EKKO
FOR ALL ENTRIES IN LT_EKPO_TEMP
WHERE EBELN = LT_EKPO_TEMP-EBELN.
IF SY-SUBRC EQ 0.
SORT LT_EKKO BY EBELN.
ENDIF.
ENDIF.
ENDIF.
CLEAR LS_USER.
SELECT SINGLE *
FROM ZFTP_USERNAME
INTO LS_USER.
G_DPWD = LS_USER-PASSWORD.
P_USER = LS_USER-USER_NAME.
IMPORTING
HANDLE = G_DHDL
EXCEPTIONS
NOT_CONNECTED.
IF SY-SUBRC NE 0.
ELSE.
ENDIF.
IF GT_EBAN IS NOT INITIAL.
CLEAR GS_EBAN.
READ TABLE GT_EBAN INTO GS_EBAN INDEX 1.
CONCATENATE 'OUT/PR/New' GS_EBAN-BANFN '.CSV' INTO P_FILE.
CONDENSE P_FILE.
REFRESH IT_TEXT[].
CLEAR IS_TEXT.
"Prepare header of file with comma ',' separated.
CONCATENATE
* 'PR Document Type'
* 'PR number'
* 'Account Assignment Category'
* 'Item Category'
* 'Material'
* 'Short TEXT'
* 'Quantity'
* 'UNIT'
* 'Delivery DATE Category'
* 'Delivery DATE'
* 'Material GROUP'
* 'Valuation Price'
* 'Plant'
* 'Purchase GROUP'
* 'REQUESTED BY'
* 'Purchase Organization'
* 'Short TEXT'
* 'Gross Price'
* 'GL Account'
* 'Cost Center'
* 'Fund'
* 'Fund Center'
* 'Commitment Item'
* 'Asset CODE'
* 'Internal ORDER'
* 'Last 3 PO'
'Purchase_Requisition'
'PR_Original_No'
'PR_Date'
'Creator_Name'
'S_No'
'Material_Code'
'Short_Desc'
'Long_Desc'
'UOM'
'Qty_Req'
'Estimated_Price'
'Delivery_Date'
'LastPOOpenQty'
'Stockason'
'PurchaseOrder1'
'OrderDate1'
'Vendor1'
'PO1BasicPrice'
'PurchaseOrder2'
'OrderDate2'
'Vendor2'
'PO2BasicPrice'
'PurchaseOrder3'
'OrderDate3'
'Vendor3'
'PO3BasicPrice'
'ConsumedLASTFY'
'Consumed2ndLASTFY'
'HSN_CODE'
'Delivery_Location'
'PurchasingOrg'
'CompanyName'
'RFQCreatorID'
'PRCreationDATE'
'ServicelTEXT'
'PRcategory'
'Useremailid'
'Material GROUP'
'WBS CODE'
'Cost Center'
'Tracking NO'
'Plant Name'
'EPS Material CODE'
'Estimated Tot Val'
'Ser Act NO'
'GL'
'Fund'
'Fund Center'
'Commitment Item'
'Asset CODE'
'Internal ORDER'
'Acc.Assig Category'
'Item Category'
INTO IS_TEXT SEPARATED BY ','.
CONDENSE IS_TEXT.
APPEND IS_TEXT TO IT_TEXT[].
CLEAR IS_TEXT.
IF LS_PR_FINAL-PURCHASEORDER2 IS INITIAL.
LS_PR_FINAL-PURCHASEORDER2 = LS_EKPO-EBELN.
LS_PR_FINAL-ORDERDATE2 = LS_EKPO-AEDAT.
LS_PR_FINAL-VENDOR2 = LS_EKKO-LIFNR.
LS_PR_FINAL-PO2BASICPRICE = LS_EKPO-NETPR.
ENDIF.
IF LS_PR_FINAL-PURCHASEORDER3 IS INITIAL.
LS_PR_FINAL-PURCHASEORDER3 = LS_EKPO-EBELN.
LS_PR_FINAL-ORDERDATE3 = LS_EKKO-AEDAT.
LS_PR_FINAL-VENDOR3 = LS_EKKO-LIFNR.
LS_PR_FINAL-PO3BASICPRICE = LS_EKPO-NETPR.
ELSE.
EXIT.
ENDIF.
ENDLOOP.
CLEAR LS_EBKN.
READ TABLE LT_EBKN INTO LS_EBKN WITH KEY BANFN = GS_EBAN-BANFN
BNFPO = GS_EBAN-BNFPO BINARY SEARCH.
CLEAR IS_TEXT.
CLEAR LW_MENGE .
LW_MENGE = GS_EBAN-MENGE.
CLEAR LW_PREIS.
LW_PREIS = GS_EBAN-PREIS.
LS_PR_FINAL-PURCHASE_REQUISITION = GS_EBAN-BANFN.
LS_PR_FINAL-PR_ORIGINAL_NO = GS_EBAN-BANFN.
LS_PR_FINAL-PR_DATE = GS_EBAN-ERDAT.
LS_PR_FINAL-CREATOR_NAME = GS_EBAN-ERNAM.
REFRESH LT_RPBENERR.
CALL FUNCTION 'HR_FBN_GET_USER_EMAIL_ADDRESS'
EXPORTING
USER_ID = LS_PR_FINAL-CREATOR_NAME
REACTION = 'S'
IMPORTING
EMAIL_ADDRESS = LS_PR_FINAL-USEREMAILID
* SUBRC =
TABLES
ERROR_TABLE = LT_RPBENERR
.
IF GS_EBAN-PSTYP = 9.
READ TABLE LT_ESLL_T INTO LS_ESLL_T WITH KEY PACKNO = GS_EBAN-PACKNO
BINARY SEARCH.
IF SY-SUBRC EQ 0.
READ TABLE LT_ESLL WITH KEY SUB_PACKNO = LS_ESLL_T-SUB_PACKNO BINARY
SEARCH TRANSPORTING NO FIELDS.
IF SY-SUBRC EQ 0.
CLEAR LW_TABIX.
LW_TABIX = SY-TABIX.
LOOP AT LT_ESLL INTO LS_ESLL FROM LW_TABIX.
IF LS_ESLL-SUB_PACKNO <> LS_ESLL_T-SUB_PACKNO.
EXIT.
ENDIF.
CLEAR LS_PR_FINAL_T.
MOVE-CORRESPONDING LS_PR_FINAL TO LS_PR_FINAL_T.
LS_PR_FINAL-S_NO = GS_EBAN-BNFPO.
CONCATENATE LS_PR_FINAL-S_NO LS_ESLL-EXTROW INTO LS_PR_FINAL-S_NO.
LS_PR_FINAL-MATERIAL_CODE = GS_EBAN-MATNR.
LS_PR_FINAL-SHORT_DESC = GS_EBAN-TXZ01.
LS_PR_FINAL-UOM = LS_ESLL-MEINS.
LS_PR_FINAL-QTY_REQ = LS_ESLL-MENGE.
LS_PR_FINAL-ESTIMATED_PRICE = LS_ESLL-NETWR.
LS_PR_FINAL-DELIVERY_DATE = GS_EBAN-LFDAT.
LS_PR_FINAL-HSN_CODE = LS_MARC-STEUC.
LS_PR_FINAL-DELIVERY_LOCATION = GS_EBAN-LGORT.
LS_PR_FINAL-PURCHASINGORG = GS_EBAN-EKORG.
LS_PR_FINAL-PRCREATIONDATE = GS_EBAN-BADAT.
LS_PR_FINAL-SERVICELTEXT = LS_ESLL-KTEXT1.
LS_PR_FINAL-PRCATEGORY = GS_EBAN-BSART.
LS_PR_FINAL-MATERIAL_GROUP = LS_ESLL-MATKL.
LS_PR_FINAL-COSTCENTER = LS_EBKN-KOSTL.
LS_PR_FINAL-TRACKINGNO = GS_EBAN-BEDNR.
LS_PR_FINAL-PLANTNAME = GS_EBAN-WERKS.
CONCATENATE LS_PR_FINAL-PURCHASE_REQUISITION
LS_PR_FINAL-S_NO
LS_PR_FINAL-MATERIAL_CODE
INTO LS_PR_FINAL-EPSMATERIALCODE SEPARATED BY '.'.
LS_PR_FINAL-ESTIMATEDTOTVAL = LS_ESLL-NETWR.
LS_PR_FINAL-SERACTNO = LS_ESLL-SRVPOS.
LS_PR_FINAL-GL = LS_EBKN-SAKTO.
LS_PR_FINAL-FUND = LS_EBKN-GEBER.
LS_PR_FINAL-FUNDCENTER = LS_EBKN-FISTL.
LS_PR_FINAL-COMMITMENTITEM = LS_EBKN-FIPOS.
LS_PR_FINAL-ASSETCODE = LS_EBKN-ANLN1.
LS_PR_FINAL-INTERNALORDER = LS_EBKN-AUFNR.
LS_PR_FINAL-ACCASSIGCATEGORY = GS_EBAN-KNTTP.
LS_PR_FINAL-ITEMCATEGORY = GS_EBAN-PSTYP.
LS_PR_FINAL-HSN_CODE = LS_MARC-STEUC.
LS_PR_FINAL-DELIVERY_LOCATION = GS_EBAN-LGORT.
LS_PR_FINAL-PURCHASINGORG = GS_EBAN-EKORG.
LS_PR_FINAL-PRCREATIONDATE = GS_EBAN-BADAT.
LS_PR_FINAL-PRCATEGORY = GS_EBAN-BSART.
LS_PR_FINAL-MATERIAL_GROUP = GS_EBAN-MATKL.
LS_PR_FINAL-COSTCENTER = LS_EBKN-KOSTL.
LS_PR_FINAL-TRACKINGNO = GS_EBAN-BEDNR.
LS_PR_FINAL-PLANTNAME = GS_EBAN-WERKS.
CONCATENATE LS_PR_FINAL-PURCHASE_REQUISITION
LS_PR_FINAL-S_NO
LS_PR_FINAL-MATERIAL_CODE
INTO LS_PR_FINAL-EPSMATERIALCODE SEPARATED BY '.'.
LS_PR_FINAL-ESTIMATEDTOTVAL = GS_EBAN-MENGE * GS_EBAN-PREIS.
LS_PR_FINAL-GL = LS_EBKN-SAKTO.
LS_PR_FINAL-FUND = LS_EBKN-GEBER.
LS_PR_FINAL-FUNDCENTER = LS_EBKN-FISTL.
LS_PR_FINAL-COMMITMENTITEM = LS_EBKN-FIPOS.
LS_PR_FINAL-ASSETCODE = LS_EBKN-ANLN1.
LS_PR_FINAL-INTERNALORDER = LS_EBKN-AUFNR.
LS_PR_FINAL-ACCASSIGCATEGORY = GS_EBAN-KNTTP.
LS_PR_FINAL-ITEMCATEGORY = GS_EBAN-PSTYP.
ENDLOOP.
CALL FUNCTION 'FTP_R3_TO_SERVER'
EXPORTING
HANDLE = G_DHDL
FNAME = P_FILE " FILE NAME 'MATERIAL_DATA.txt'
CHARACTER_MODE = 'X'
TABLES
TEXT = IT_TEXT " CONCATENATED MATERIAL DATA
EXCEPTIONS
TCPIP_ERROR = 1
COMMAND_ERROR = 2
DATA_ERROR = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
ELSE.
ENDIF.
ENDIF.