report zpurchaseorder.
TYPE-POOLS: TRUXS.
*----DATA DECLARATION
TABLES: T001W, LFA1, EKKO, ekpo.
TYPES: BEGIN OF TY_EXCEL,
MATNR TYPE EKPO-MATNR,
MENGE TYPE EKPO-MENGE,
* MWSKZ TYPE ekpo-MWSKZ,
END OF TY_EXCEL.
DATA: IT_RAW TYPE TRUXS_T_TEXT_DATA.
DATA: LINE_NO TYPE I.
DATA: T_EXCEL TYPE STANDARD TABLE OF TY_EXCEL,
W_EXCEL TYPE TY_EXCEL.
DATA: IT_RETURN2 LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,
RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
DATA: IT_BAPIMEPOITEM TYPE BAPIMEPOITEM OCCURS 0 WITH HEADER LINE,
IT_BAPIMEPOITEMX TYPE BAPIMEPOITEMX OCCURS 0 WITH HEADER LINE,
IT_POSERVICES TYPE BAPIESLLC OCCURS 0 WITH HEADER LINE.
DATA DISPLAY_TEXT(100) TYPE C.
DATA: PO_NUMBER TYPE BAPIMEPOHEADER-PO_NUMBER.
TABLES: BAPIMEPOHEADER,
BAPIMEPOHEADERX.
DATA: IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
*----DATA DECLARATION FOR PO DATA DOWNLOAD
TYPES: BEGIN OF TY_EKKO_EKPO,
EBELN TYPE EKKO-EBELN,
LIFNR TYPE EKKO-LIFNR,
AEDAT TYPE EKKO-AEDAT,
MATNR TYPE EKPO-MATNR,
MENGE TYPE EKPO-MENGE,
EMLIF TYPE EKPO-EMLIF,
END OF TY_EKKO_EKPO,
BEGIN OF TY_FINAL,
AUART TYPE VBAK-AUART,
VKORG TYPE VBAK-VKORG,
VTWEG TYPE VBAK-VTWEG,
SPART TYPE VBAK-SPART,
PODATE(10) TYPE C,
SOLDP TYPE NAME2,
SHIPP TYPE NAME2,
EBELN TYPE EKKO-EBELN,
QTY TYPE I,
MATNR TYPE MATNR,
END OF TY_FINAL.
DATA: BEGIN OF T_DESC OCCURS 0,
HEADER(50) TYPE C,
END OF T_DESC,
FILENAME TYPE STRING,
SOLDP TYPE NAME2,
SHIPP TYPE NAME2,
T_EKKO_EKPO TYPE TY_EKKO_EKPO OCCURS 0 WITH HEADER LINE,
T_FINAL TYPE TY_FINAL OCCURS 0 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK DATABASE-SELECTION
WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: BSART FOR EKKO-BSART NO-EXTENSION NO INTERVALS OBLIGATORY MODIF ID s1,
ekgrp for ekko-ekgrp No-EXTENSION no INTERVALS OBLIGATORY MODIF ID s1,
VENDOR FOR LFA1-LIFNR NO-EXTENSION NO INTERVALS OBLIGATORY MODIF ID S1,
PLANT FOR ekpo-werks NO-EXTENSION NO INTERVALS OBLIGATORY MODIF ID S1.
PARAMETERS P_FILE TYPE RLGRAP-FILENAME MODIF ID S1.
SELECTION-SCREEN END OF BLOCK DATABASE-SELECTION.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
FIELD_NAME = 'P_FILE'
IMPORTING
FILE_NAME = P_FILE.
START-OF-SELECTION.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_TAB_RAW_DATA = IT_RAW
I_FILENAME = P_FILE
TABLES
I_TAB_CONVERTED_DATA = T_EXCEL[]
EXCEPTIONS
CONVERTION_FAILED = 1
OTHERS = 0.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*----START OF SELECTION
BAPIMEPOHEADER-COMP_CODE = '1000'.
BAPIMEPOHEADER-DOC_TYPE = BSART-LOW.
BAPIMEPOHEADER-ITEM_INTVL = '10'.
BAPIMEPOHEADER-VENDOR = VENDOR-LOW.
BAPIMEPOHEADER-PURCH_ORG = '1010'.
BAPIMEPOHEADER-CREAT_DATE = SY-DATUM.
BAPIMEPOHEADER-DOC_DATE = SY-DATUM.
BAPIMEPOHEADER-PUR_GROUP = EKGRP-LOW.
* BAPIMEPOHEADER-CURRENCY = 'BDT'.
BAPIMEPOHEADERX-COMP_CODE = 'X'.
BAPIMEPOHEADERX-DOC_TYPE = 'X'.
BAPIMEPOHEADERX-ITEM_INTVL = 'X'.
BAPIMEPOHEADERX-VENDOR = 'X'.
BAPIMEPOHEADERX-PURCH_ORG = 'X'.
BAPIMEPOHEADERX-CREAT_DATE = 'X'.
BAPIMEPOHEADERX-DOC_DATE = 'X'.
BAPIMEPOHEADERX-PUR_GROUP = 'X'.
* BAPIMEPOHEADERX-CURRENCY = 'X'.
CLEAR: W_EXCEL.
LOOP AT T_EXCEL INTO W_EXCEL.
LINE_NO = LINE_NO + 10.
IT_BAPIMEPOITEM-PO_ITEM = LINE_NO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = W_EXCEL-MATNR
IMPORTING
OUTPUT = W_EXCEL-MATNR(18).
* IT_BAPIMEPOITEM-MATERIAL = W_EXCEL-MATNR.
IT_BAPIMEPOITEM-MATERIAL = W_EXCEL-MATNR.
IT_BAPIMEPOITEM-PLANT = plant-low.
IT_BAPIMEPOITEM-QUANTITY = W_EXCEL-MENGE.
* IT_BAPIMEPOITEM-SUPP_VENDOR = PLANT-LOW.
* IT_BAPIMEPOITEM-TAX_CODE = W_EXCEL-MWSKZ.
IT_BAPIMEPOITEMX-PO_ITEM = LINE_NO.
IT_BAPIMEPOITEMX-MATERIAL = 'X'.
IT_BAPIMEPOITEMX-PLANT = 'X'.
IT_BAPIMEPOITEMX-QUANTITY = 'X'.
* IT_BAPIMEPOITEMX-SUPP_VENDOR = 'X'.
* IT_BAPIMEPOITEMX-TAX_CODE = 'X'.
APPEND IT_BAPIMEPOITEM TO IT_BAPIMEPOITEM.
APPEND IT_BAPIMEPOITEMX TO IT_BAPIMEPOITEMX.
CLEAR: IT_BAPIMEPOITEM, IT_BAPIMEPOITEMX, IT_POSERVICES, W_EXCEL.
ENDLOOP.
CLEAR PO_NUMBER.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = BAPIMEPOHEADER
POHEADERX = BAPIMEPOHEADERX
IMPORTING
EXPPURCHASEORDER = PO_NUMBER
TABLES
RETURN = IT_RETURN2
POITEM = IT_BAPIMEPOITEM
POITEMX = IT_BAPIMEPOITEMX.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
IMPORTING
RETURN = RETURN.
IF PO_NUMBER IS NOT INITIAL.
CONCATENATE 'Purchase Order:' PO_NUMBER 'Created!!'
INTO DISPLAY_TEXT SEPARATED BY SPACE.
MESSAGE DISPLAY_TEXT TYPE 'S' .
ENDIF.
CLEAR: PO_NUMBER, DISPLAY_TEXT, BAPIMEPOHEADER, BAPIMEPOHEADERX.
REFRESH: IT_RETURN2[], IT_BAPIMEPOITEM[], IT_BAPIMEPOITEMX[].
No comments:
Post a Comment