PR Extraction v1

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 17

*&---------------------------------------------------------------------*

*& Report ZPR_FILE_TRANSFER_1


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

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.

DATA : IT_SET_FRKZ TYPE STANDARD TABLE OF SETVALUES,


IS_SET_FRKZ TYPE SETVALUES.
DATA : LW_BANFN TYPE EBAN-BANFN.
DATA : GT_EBAN TYPE STANDARD TABLE OF EBAN,
GS_EBAN TYPE EBAN,
LT_EBAN TYPE STANDARD TABLE OF EBAN,
GT_EKBE TYPE STANDARD TABLE OF EKBE,
GT_EKPO TYPE STANDARD TABLE OF EKPO.
DATA : LS_USER TYPE ZFTP_USERNAME.
DATA : LT_RPBENERR TYPE STANDARD TABLE OF RPBENERR.

CONSTANTS: C_KEY TYPE I VALUE 26101957,

C_DEST TYPE RFCDES-RFCDEST VALUE 'SAPFTPA'.

DATA: G_DHDL TYPE I, " Handle

G_DLEN TYPE I, " password length

G_DPWD(30). " For storing password


DATA: P_USER(30) TYPE C," VALUE '[email protected]', "User-name of
ftp server
P_PWD(30) TYPE C ,"VALUE 'EPS@789#', "Password of ftp server

P_HOST(64) TYPE C VALUE '103.53.41.216', "IP-ADDRESS of FTP server


P_FILE(50) TYPE C.

TYPES: BEGIN OF TY_TEXT,

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.

TYPES : BEGIN OF LTS_EBKN,


BANFN TYPE EBKN-BANFN,
BNFPO TYPE EBKN-BNFPO,
SAKTO TYPE EBKN-SAKTO,
KOSTL TYPE EBKN-KOSTL,
GEBER TYPE EBKN-GEBER,
FISTL TYPE EBKN-FISTL,
FIPOS TYPE EBKN-FIPOS,
ANLN1 TYPE EBKN-ANLN1,
AUFNR TYPE EBKN-AUFNR,
END OF LTS_EBKN.

DATA : LT_EBKN TYPE STANDARD TABLE OF LTS_EBKN,


LS_EBKN TYPE LTS_EBKN.

TYPES: BEGIN OF LTS_EKPO,


EBELN TYPE EKPO-EBELN,
EBELP TYPE EKPO-EBELP,
AEDAT TYPE EKPO-AEDAT,
BANFN TYPE EKPO-BANFN,
BNFPO TYPE EKPO-BNFPO,
NETPR TYPE EKPO-NETPR,
END OF LTS_EKPO.
TYPES : BEGIN OF TS_EKKO,
EBELN TYPE EKKO-EBELN,
AEDAT TYPE EKKO-AEDAT,
LIFNR TYPE EKKO-LIFNR,
END OF TS_EKKO.
DATA : LT_EKKO TYPE STANDARD TABLE OF TS_EKKO,
LS_EKKO TYPE TS_EKKO.

DATA : LT_EKPO TYPE STANDARD TABLE OF LTS_EKPO,


LT_EKPO_TEMP TYPE STANDARD TABLE OF LTS_EKPO,
LS_EKPO TYPE LTS_EKPO.
DATA : LT_FRKZ TYPE RANGE OF EBAN-FRGKZ,
LS_FRKZ LIKE LINE OF LT_FRKZ.
TYPES : BEGIN OF TS_MARC,
MATNR TYPE MARC-MATNR,
WERKS TYPE MARC-WERKS,
STEUC TYPE MARC-STEUC,
END OF TS_MARC.
DATA : LT_MARC TYPE STANDARD TABLE OF TS_MARC,
LS_MARC TYPE TS_MARC.
TYPES : BEGIN OF TS_ESLL,
PACKNO TYPE ESLL-PACKNO,
INTROW TYPE ESLL-INTROW,
EXTROW TYPE ESLL-EXTROW,
SRVPOS TYPE ESLL-SRVPOS,
SUB_PACKNO TYPE ESLL-SUB_PACKNO,
MENGE TYPE ESLL-MENGE,
MEINS TYPE ESLL-MEINS,
NETWR TYPE ESLL-NETWR,
KTEXT1 TYPE ESLL-KTEXT1,
MATKL TYPE ESLL-MATKL,
END OF TS_ESLL.
DATA : LT_ESLL TYPE STANDARD TABLE OF TS_ESLL,
LS_ESLL TYPE TS_ESLL,
LS_ESLL_T TYPE TS_ESLL,
LT_ESLL_T TYPE STANDARD TABLE OF TS_ESLL.

DATA : LW_EBELN(50) TYPE C.


DATA : LW_TABIX TYPE SY-TABIX.
DATA : LW_TABIX1 TYPE SY-TABIX.
BREAK-POINT.

CALL FUNCTION 'G_SET_TREE_IMPORT'


EXPORTING
SETID = '0000ZMM_FRKZ'
TABLES
SET_VALUES = IT_SET_FRKZ
EXCEPTIONS
SET_NOT_FOUND = 1
ILLEGAL_FIELD_REPLACEMENT = 2
ILLEGAL_TABLE_REPLACEMENT = 3
SET_IS_DAMAGED = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

SORT IT_SET_FRKZ BY FROM.


REFRESH LT_FRKZ.
LOOP AT IT_SET_FRKZ INTO IS_SET_FRKZ.
LS_FRKZ-SIGN = 'I'.
LS_FRKZ-OPTION = 'EQ'.
LS_FRKZ-LOW = IS_SET_FRKZ-FROM.
APPEND LS_FRKZ TO LT_FRKZ.
ENDLOOP.

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.

IF GT_EBAN IS NOT INITIAL.


REFRESH LT_EBAN.
LT_EBAN = GT_EBAN.
SORT LT_EBAN BY PACKNO.
DELETE ADJACENT DUPLICATES FROM LT_EBAN COMPARING PACKNO.
DELETE LT_EBAN WHERE PACKNO IS INITIAL.
IF LT_EBAN IS NOT INITIAL.
REFRESH LT_ESLL_T.
SELECT PACKNO
INTROW
EXTROW
SRVPOS
SUB_PACKNO
MENGE
MEINS
NETWR
KTEXT1
MATKL
FROM ESLL
INTO TABLE LT_ESLL_T
FOR ALL ENTRIES IN LT_EBAN
WHERE PACKNO = LT_EBAN-PACKNO.
IF SY-SUBRC EQ 0.
SORT LT_ESLL_T BY PACKNO.
REFRESH LT_ESLL.
SELECT PACKNO
INTROW
EXTROW
SRVPOS
SUB_PACKNO
MENGE
MEINS
NETWR
KTEXT1
MATKL
FROM ESLL
INTO TABLE LT_ESLL
FOR ALL ENTRIES IN LT_ESLL_T
WHERE PACKNO = LT_ESLL_T-SUB_PACKNO.
IF SY-SUBRC EQ 0.
SORT LT_ESLL BY SUB_PACKNO.
ENDIF.
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.

" To get the length of the password.

G_DLEN = STRLEN( G_DPWD ).

" Below Function module is used to Encrypt the Password.

CALL FUNCTION 'HTTP_SCRAMBLE'


EXPORTING
SOURCE = G_DPWD " Actual password
SOURCELEN = G_DLEN
KEY = C_KEY
IMPORTING
DESTINATION = G_DPWD. " Encyrpted Password

* Connects to the FTP Server as specified by user.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'


EXPORTING
TEXT = 'Connecting to FTP Server'.

* Below function module is used to connect the FTP Server.

* It Accepts only Encrypted Passwords.

* This Function module will provide a handle to perform different

* operations on the FTP Server via FTP Commands.

CALL FUNCTION 'FTP_CONNECT'


EXPORTING

USER = P_USER " FTP USER-NAME

PASSWORD = G_DPWD " FTP PASSWORD

HOST = P_HOST " FTP IP-ADDRESS

RFC_DESTINATION = C_DEST " RFC Destination 'SAPFTP'

IMPORTING

HANDLE = G_DHDL

EXCEPTIONS

NOT_CONNECTED.

IF SY-SUBRC NE 0.

FORMAT COLOR COL_NEGATIVE.

WRITE:/ 'Error in Connection'.

ELSE.

WRITE:/ 'FTP Connection is opened '.

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.

SORT LT_EKPO BY EBELN EBELP AEDAT DESCENDING.


LOOP AT GT_EBAN INTO GS_EBAN.
CLEAR LW_EBELN.
CLEAR LS_PR_FINAL.
CLEAR LS_EKKO.
CLEAR LS_ESLL.
CLEAR LS_ESLL_T.

READ TABLE LT_EKPO INTO LS_EKPO WITH KEY BANFN = GS_EBAN-BANFN


BNFPO = GS_EBAN-BNFPO BINARY
SEARCH.
IF SY-SUBRC EQ 0.
CLEAR LW_TABIX.
LW_TABIX = SY-TABIX.
CLEAR LS_EKKO.
READ TABLE LT_EKKO INTO LS_EKKO WITH KEY EBELN = LS_EKPO-EBELN BINARY
SEARCH.
ENDIF.
CLEAR LS_EKPO.
LOOP AT LT_EKPO INTO LS_EKPO FROM LW_TABIX.
IF LS_PR_FINAL-PURCHASEORDER1 IS INITIAL.
LS_PR_FINAL-PURCHASEORDER1 = LS_EKPO-EBELN.
LS_PR_FINAL-ORDERDATE1 = LS_EKKO-AEDAT.
LS_PR_FINAL-VENDOR1 = LS_EKKO-LIFNR.
LS_PR_FINAL-PO1BASICPRICE = LS_EKPO-NETPR.
ENDIF.

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.

"Prepare data of file with comma ',' separated.


CONCATENATE
LS_PR_FINAL-PURCHASE_REQUISITION
LS_PR_FINAL-PR_ORIGINAL_NO
LS_PR_FINAL-PR_DATE
LS_PR_FINAL-CREATOR_NAME
LS_PR_FINAL-S_NO
LS_PR_FINAL-MATERIAL_CODE
LS_PR_FINAL-SHORT_DESC
LS_PR_FINAL-LONG_DESC
LS_PR_FINAL-UOM
LS_PR_FINAL-QTY_REQ
LS_PR_FINAL-ESTIMATED_PRICE
LS_PR_FINAL-DELIVERY_DATE
LS_PR_FINAL-LASTPOOPENQTY
LS_PR_FINAL-STOCKASON
LS_PR_FINAL-PURCHASEORDER1
LS_PR_FINAL-ORDERDATE1
LS_PR_FINAL-VENDOR1
LS_PR_FINAL-PO1BASICPRICE
LS_PR_FINAL-PURCHASEORDER2
LS_PR_FINAL-ORDERDATE2
LS_PR_FINAL-VENDOR2
LS_PR_FINAL-PO2BASICPRICE
LS_PR_FINAL-PURCHASEORDER3
LS_PR_FINAL-ORDERDATE3
LS_PR_FINAL-VENDOR3
LS_PR_FINAL-PO3BASICPRICE
LS_PR_FINAL-CONSUMEDLASTFY
LS_PR_FINAL-CONSUMED2NDLASTFY
LS_PR_FINAL-HSN_CODE
LS_PR_FINAL-DELIVERY_LOCATION
LS_PR_FINAL-PURCHASINGORG
LS_PR_FINAL-COMPANYNAME
LS_PR_FINAL-RFQCREATORID
LS_PR_FINAL-PRCREATIONDATE
LS_PR_FINAL-SERVICELTEXT
LS_PR_FINAL-PRCATEGORY
LS_PR_FINAL-USEREMAILID
LS_PR_FINAL-MATERIAL_GROUP
LS_PR_FINAL-WBSCODE
LS_PR_FINAL-COSTCENTER
LS_PR_FINAL-TRACKINGNO
LS_PR_FINAL-PLANTNAME
LS_PR_FINAL-EPSMATERIALCODE
LS_PR_FINAL-ESTIMATEDTOTVAL
LS_PR_FINAL-SERACTNO
LS_PR_FINAL-GL
LS_PR_FINAL-FUND
LS_PR_FINAL-FUNDCENTER
LS_PR_FINAL-COMMITMENTITEM
LS_PR_FINAL-ASSETCODE
LS_PR_FINAL-INTERNALORDER
LS_PR_FINAL-ACCASSIGCATEGORY
LS_PR_FINAL-ITEMCATEGORY
INTO IS_TEXT SEPARATED BY ','.
"Remove spaces.
CONDENSE IS_TEXT.
APPEND IS_TEXT TO IT_TEXT[].
CLEAR IS_TEXT.
ENDLOOP.
ENDIF.
ENDIF.
ELSE.
LS_PR_FINAL-S_NO = GS_EBAN-BNFPO.
LS_PR_FINAL-MATERIAL_CODE = GS_EBAN-MATNR.
LS_PR_FINAL-SHORT_DESC = GS_EBAN-TXZ01.
LS_PR_FINAL-UOM = GS_EBAN-MEINS.
LS_PR_FINAL-QTY_REQ = GS_EBAN-MENGE.
LS_PR_FINAL-ESTIMATED_PRICE = GS_EBAN-PREIS.
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-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.

"Prepare data of file with comma ',' separated.


* CONCATENATE GS_EBAN-BSART
* GS_EBAN-BANFN
* GS_EBAN-KNTTP
* GS_EBAN-PSTYP
* GS_EBAN-MATNR
* GS_EBAN-TXZ01
* LW_MENGE
* GS_EBAN-MEINS
* GS_EBAN-LPEIN
* GS_EBAN-LFDAT
* GS_EBAN-MATKL
* LW_PREIS
* GS_EBAN-WERKS
* GS_EBAN-EKGRP
* GS_EBAN-AFNAM
* GS_EBAN-EKORG
*
** ls_ebkn-KTEXT1
* LS_EBKN-SAKTO
* LS_EBKN-KOSTL
* LS_EBKN-GEBER
* LS_EBKN-FISTL
* LS_EBKN-FIPOS
* LS_EBKN-ANLN1
* LS_EBKN-AUFNR
*
* LW_EBELN
CONCATENATE
LS_PR_FINAL-PURCHASE_REQUISITION
LS_PR_FINAL-PR_ORIGINAL_NO
LS_PR_FINAL-PR_DATE
LS_PR_FINAL-CREATOR_NAME
LS_PR_FINAL-S_NO
LS_PR_FINAL-MATERIAL_CODE
LS_PR_FINAL-SHORT_DESC
LS_PR_FINAL-LONG_DESC
LS_PR_FINAL-UOM
LS_PR_FINAL-QTY_REQ
LS_PR_FINAL-ESTIMATED_PRICE
LS_PR_FINAL-DELIVERY_DATE
LS_PR_FINAL-LASTPOOPENQTY
LS_PR_FINAL-STOCKASON
LS_PR_FINAL-PURCHASEORDER1
LS_PR_FINAL-ORDERDATE1
LS_PR_FINAL-VENDOR1
LS_PR_FINAL-PO1BASICPRICE
LS_PR_FINAL-PURCHASEORDER2
LS_PR_FINAL-ORDERDATE2
LS_PR_FINAL-VENDOR2
LS_PR_FINAL-PO2BASICPRICE
LS_PR_FINAL-PURCHASEORDER3
LS_PR_FINAL-ORDERDATE3
LS_PR_FINAL-VENDOR3
LS_PR_FINAL-PO3BASICPRICE
LS_PR_FINAL-CONSUMEDLASTFY
LS_PR_FINAL-CONSUMED2NDLASTFY
LS_PR_FINAL-HSN_CODE
LS_PR_FINAL-DELIVERY_LOCATION
LS_PR_FINAL-PURCHASINGORG
LS_PR_FINAL-COMPANYNAME
LS_PR_FINAL-RFQCREATORID
LS_PR_FINAL-PRCREATIONDATE
LS_PR_FINAL-SERVICELTEXT
LS_PR_FINAL-PRCATEGORY
LS_PR_FINAL-USEREMAILID
LS_PR_FINAL-MATERIAL_GROUP
LS_PR_FINAL-WBSCODE
LS_PR_FINAL-COSTCENTER
LS_PR_FINAL-TRACKINGNO
LS_PR_FINAL-PLANTNAME
LS_PR_FINAL-EPSMATERIALCODE
LS_PR_FINAL-ESTIMATEDTOTVAL
LS_PR_FINAL-SERACTNO
LS_PR_FINAL-GL
LS_PR_FINAL-FUND
LS_PR_FINAL-FUNDCENTER
LS_PR_FINAL-COMMITMENTITEM
LS_PR_FINAL-ASSETCODE
LS_PR_FINAL-INTERNALORDER
LS_PR_FINAL-ACCASSIGCATEGORY
LS_PR_FINAL-ITEMCATEGORY

INTO IS_TEXT SEPARATED BY ','.


"Remove spaces.
CONDENSE IS_TEXT.
APPEND IS_TEXT TO IT_TEXT[].
**Transferring the data from internal table to FTP Server.
ENDIF.

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.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ELSE.

WRITE:/ 'File has created on FTP Server'.

ENDIF.

ENDIF.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'


EXPORTING
TEXT = 'File has created on FTP Server'.

*To Disconnect the FTP Server.

CALL FUNCTION 'FTP_DISCONNECT'


EXPORTING
HANDLE = G_DHDL.

*To Disconnect the Destination.

CALL FUNCTION 'RFC_CONNECTION_CLOSE'


EXPORTING
DESTINATION = C_DEST
EXCEPTIONS
OTHERS = 1.

You might also like