FUNCTION YPOBAPI_COPY.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(FNAME) LIKE RLGRAP-FILENAME
*" VALUE(FNAME1) LIKE RLGRAP-FILENAME
*" VALUE(FNAME2) LIKE RLGRAP-FILENAME
*" EXPORTING
*" VALUE(SUBRC) LIKE SYST-SUBRC
*" VALUE(PODATAFILE) LIKE SY-MSGV1
*" VALUE(PO) LIKE BAPIRET2-MESSAGE
*" VALUE(POHEADERTEXT) LIKE SY-MSGV2
*" VALUE(POPRICINGTYPE) LIKE SY-MSGV3
*" VALUE(RET) LIKE BAPIRET2-MESSAGE
*" VALUE(TEXT_SUBRC) LIKE SYST-SUBRC
*"----------------------------------------------------------------------
* BAPI CREATED BY ANAND RAMAIYA
* NOTE : BAPI WILL UPLOAD A FLAT FILE (TEXT DOCUMENT) FROM NON-SAP AND
* CREATE A PURCHASE ORDER .
*"----------------------------------------------------------------------
DATA: BEGIN OF ITAB OCCURS 0,
BSART LIKE EKKO-BSART,
EKORG LIKE EKKO-EKORG,
EKGRP LIKE EKKO-EKGRP,
BUKRS TYPE EKKO-BUKRS,
VENDOR LIKE LFA1-LIFNR,
ZTERM LIKE EKKO-ZTERM,
WAERS LIKE EKKO-WAERS,
ZBD1T LIKE EKKO-ZBD1T,
EMATN LIKE EKPO-EMATN,
NETPR LIKE EKPO-NETPR,
PLANT LIKE EKPO-WERKS,
MENGE LIKE EKPO-MENGE,
AFNAM LIKE EKPO-AFNAM,
BEDNR LIKE EKPO-BEDNR,
REPOS LIKE EKPO-REPOS,
TAX_CODE LIKE EKPO-MWSKZ,
TXJCD LIKE EKPO-TXJCD,
EEIND(10) TYPE C,
PR LIKE EBAN-BANFN,
PRITEM LIKE EBAN-BNFPO,
END OF ITAB.
* POPULATING HEADER TEXT DATA
DATA : BEGIN OF ITAB1 OCCURS 10,
HEADERTEXT LIKE BAPIMEPOTEXT,
PRICEINGTYPE LIKE BAPIMEPOTEXT,
PAYTERMS LIKE BAPIMEPOTEXT,
END OF ITAB1.
DATA: HEADER LIKE BAPIMEPOHEADER, " Header
HEADER_IND LIKE BAPIMEPOHEADERX, " Header index
PO_ITEMS LIKE BAPIMEPOITEM OCCURS 0 WITH HEADER LINE, " Item table
ITEMS_IND LIKE BAPIMEPOITEMX OCCURS 0 WITH HEADER LINE, " Item index table
HEADERTEXT LIKE BAPIMEPOTEXT ,
PRICEINGTYPE LIKE BAPIMEPOTEXT,
PAYTERMS LIKE BAPIMEPOTEXT,
Return LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE . " Message Return table
*Structures to hold PO account data
DATA : ACCOUNT LIKE BAPIMEPOACCOUNT OCCURS 0 WITH HEADER LINE ,
ACCOUNTX LIKE BAPIMEPOACCOUNTX OCCURS 0 WITH HEADER LINE .
*Structures to hold PO schedule data
DATA : ITEMSCHEDULE LIKE BAPIMEPOSCHEDULE OCCURS 0 WITH HEADER LINE ,
ITEMSCHEDULEX LIKE BAPIMEPOSCHEDULX OCCURS 0 WITH HEADER LINE .
*Structures to hold PO services data
DATA : SERVICES LIKE BAPIESLLC OCCURS 0 WITH HEADER LINE .
DATA : CTR type N .
*---------GETTING FLAT FILE DATA------
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = FNAME
FILETYPE = 'DAT'
TABLES
data_tab = ITAB
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
NO_AUTHORITY = 10
OTHERS = 11.
SUBRC = SY-SUBRC.
IF SUBRC = 2.
PODATAFILE = ' ERROR IN FLAT FILE...CHECKED THE FILENAME,PATH.'.
ELSEIF SUBRC EQ 0.
PODATAFILE = 'Successfully Uploaded the Flat File into Structure ITAB ..'.
* *---------GETTING FLAT FILE HEADER Text DATA------
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = FNAME1
FILETYPE = 'DAT'
TABLES
data_tab = ITAB1
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
NO_AUTHORITY = 10
OTHERS = 11.
SUBRC = SY-SUBRC.
IF SUBRC = 2.
POHEADERTEXT = ' ERROR IN FLAT FILE...CHECKED THE FILENAME,PATH.'.
ELSEIF SUBRC EQ 0.
POHEADERTEXT = 'Successfully Uploaded the Flat File into Structure ITAB1 ..'.
APPEND ITAB1.
ELSE.
ENDIF.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = FNAME2
FILETYPE = 'DAT'
TABLES
data_tab = ITAB1
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
NO_AUTHORITY = 10
OTHERS = 11.
SUBRC = SY-SUBRC.
IF SUBRC = 2.
POPRICINGTYPE = ' ERROR IN FLAT FILE...CHECKED THE FILENAME,PATH.'.
ELSEIF SUBRC EQ 0.
POPRICINGTYPE = 'Successfully Uploaded the Flat File into Structure ITAB1 ..'.
APPEND ITAB1.
ELSE.
ENDIF.
* LOOP AT ITAB1.
** WRITE : / ITAB1-POTEXT.
* ENDLOOP.
clear ctr.
ctr = ctr + 1.
Endif.
LOOP AT ITAB.
* Initialize Header values
HEADER-VENDOR = ITAB-VENDOR.
HEADER-COMP_CODE = ITAB-BUKRS.
HEADER-PURCH_ORG = ITAB-EKORG.
HEADER-PUR_GROUP = ITAB-EKGRP.
HEADER-DOC_TYPE = ITAB-BSART.
HEADER-CURRENCY = ITAB-WAERS.
HEADER-PMNTTRMS = ITAB-ZTERM.
* Initialize Index values
HEADER_IND-DOC_TYPE = 'X'.
HEADER_IND-COMP_CODE = 'X'.
HEADER_IND-VENDOR = 'X'.
HEADER_IND-PURCH_ORG = 'X'.
HEADER_IND-PUR_GROUP = 'X'.
HEADER_IND-CURRENCY = 'X'.
HEADER_IND-PMNTTRMS = 'X'.
***Initialize Item values
PO_ITEMS-PO_ITEM = CTR.
PO_ITEMS-MATERIAL = ITAB-EMATN.
PO_ITEMS-PLANT = ITAB-PLANT.
PO_ITEMS-QUANTITY = ITAB-MENGE.
PO_ITEMS-NET_PRICE = ITAB-NETPR.
PO_ITEMS-PREQ_NAME = ITAB-AFNAM.
PO_ITEMS-TRACKINGNO = ITAB-BEDNR.
PO_ITEMS-TAX_CODE = ITAB-TAX_CODE.
PO_ITEMS-TAXJURCODE = ITAB-TXJCD.
PO_ITEMS-PREQ_NO = ITAB-PR.
PO_ITEMS-PREQ_ITEM = ITAB-PRITEM.
APPEND PO_ITEMS.
**
***Initialize Item index values
ITEMS_IND-PO_ITEM = CTR.
ITEMS_IND-MATERIAL = 'X'.
ITEMS_IND-PLANT = 'X'.
ITEMS_IND-QUANTITY = 'X'.
ITEMS_IND-NET_PRICE = ITAB-NETPR.
ITEMS_IND-PREQ_NAME = ITAB-AFNAM.
ITEMS_IND-TRACKINGNO = ITAB-BEDNR.
ITEMS_IND-TAX_CODE = ITAB-TAX_CODE.
ITEMS_IND-TAXJURCODE = ITAB-TXJCD.
ITEMS_IND-PREQ_NO = ITAB-PR.
ITEMS_IND-PREQ_ITEM = ITAB-PRITEM.
APPEND ITEMS_IND.
* Initialize PO Account values
ACCOUNT-PO_ITEM = CTR.
ACCOUNT-QUANTITY = CTR.
ACCOUNT-NET_VALUE = ITAB-NETPR.
ACCOUNT-GL_ACCOUNT = CTR.
ACCOUNT-BUS_AREA = CTR.
account-costcenter = CTR.
APPEND ACCOUNT.
LOOP AT ITAB1.
* * PO HEADER TEXT
HEADERTEXT-PO_NUMBER = HEADER-PO_NUMBER.
HEADERTEXT-TEXT_ID = 'F01'.
HEADERTEXT-TEXT_FORM = '/'.
HEADERTEXT-TEXT_LINE = ITAB1-HEADERTEXT.
* PO PRICING TYPE
PRICEINGTYPE-PO_NUMBER = HEADER-po_number.
PRICEINGTYPE-TEXT_ID = 'F03'.
PRICEINGTYPE-TEXT_FORM = '/'.
PRICEINGTYPE-TEXT_LINE = itab1-priceingtype.
* PO DELIVERY TERMS
*POTEXT-PO_NUMBER = HEADER-po_number.
*POTEXT-TEXT_ID = 'F05'.
*POTEXT-TEXT_FORM = '/'.
*POTEXT-TEXT_LINE = ITAB1-PODELTERMS.
* PO PAYMENT TERMS
*PAYTERMS-PO_NUMBER = HEADER-po_number.
*PAYTERMS-TEXT_ID = 'F07'.
*PAYTERMS-TEXT_FORM = '/'.
*PAYTERMS-TEXT_LINE = ITAB1-PAYTERMS.
APPEND ITAB1.
ctr = ctr + 1.
***Create Production order
*CALL FUNCTION 'BAPI_PO_CREATE1'
* EXPORTING
* POHEADER = HEADER
* POHEADERX = HEADER_IND
* TABLES
* RETURN = RETURN
* POITEM = PO_ITEMS
* POITEMX = ITEMS_IND
* POTEXTHEADER = POTEXT.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = HEADER
POHEADERX = HEADER_IND
* POADDRVENDOR =
* TESTRUN =
* MEMORY_UNCOMPLETE =
* MEMORY_COMPLETE =
* POEXPIMPHEADER =
* POEXPIMPHEADERX =
* VERSIONS =
* NO_MESSAGING =
* NO_MESSAGE_REQ =
* NO_AUTHORITY =
NO_PRICE_FROM_PO = 'X'
* IMPORTING
* EXPPURCHASEORDER =
* EXPHEADER =
* EXPPOEXPIMPHEADER =
TABLES
RETURN = RETURN
POITEM = PO_ITEMS
POITEMX = ITEMS_IND
* POADDRDELIVERY =
* POSCHEDULE =
* POSCHEDULEX =
POACCOUNT = ACCOUNT
* POACCOUNTPROFITSEGMENT =
* POACCOUNTX =
* POCONDHEADER =
* POCONDHEADERX =
* POCOND =
* POCONDX =
* POLIMITS =
* POCONTRACTLIMITS =
* POSERVICES =
* POSRVACCESSVALUES =
* POSERVICESTEXT =
* EXTENSIONIN =
* EXTENSIONOUT =
* POEXPIMPITEM =
* POEXPIMPITEMX =
POTEXTHEADER = ITAB1.
.
* Commit BAPI
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
READ TABLE RETURN WITH KEY TYPE = 'S'.
If SY-SUBRC EQ 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH Return.
*
PO = RETURN-MESSAGE.
ELSEIF SY-SUBRC <> 0.
READ TABLE RETURN WITH KEY TYPE = 'E'.
RET = RETURN-MESSAGE.
PO = 'PURCHASE ORDER HAS NOT BEEN CREATED :'.
ELSE.
PO = 'ERROR OCCUR .....PURCHASE ORDER HAS NOT BEEN CREATED...'.
ENDIF.
LOOP AT ITAB1.
WRITE : / priceingtype-text_line.
ENDLOOP.
ENDLOOP.
Endloop.
ENDFUNCTION.
阅读(3896) | 评论(0) | 转发(2) |