2008 Apr 12 7:32 AM
hi guys,
i want to upload a excel file to the internal table and then to create the purchase order.
i know the name of function module and bapi.
but how to make use of them in implementation!!!
fun module : ALSM_EXCEL_TO_INTERNAL_TABLE
bapi : BAPI_PO_CREATE1.
arun and vishnu from
infotech solutions
2008 Apr 16 4:42 AM
*CREATION OF A TEMPORARY STRUCTURE FOR INSERTING FIELDS OF EXCEL TO INTERNAL TABLE.
TYPES : BEGIN OF STR_FINAL,
COMP_CODE TYPE BAPIMEPOHEADER-COMP_CODE, " STRUCTURE : BAPIMEPOHEADER
ITEM_INTVL TYPE BAPIMEPOHEADER-ITEM_INTVL,
VENDOR TYPE BAPIMEPOHEADER-VENDOR,
PMNTTRMS TYPE BAPIMEPOHEADER-PMNTTRMS,
PURCH_ORG TYPE BAPIMEPOHEADER-PURCH_ORG,
PUR_GROUP TYPE BAPIMEPOHEADER-PUR_GROUP,
CURRENCY TYPE BAPIMEPOHEADER-CURRENCY,
PO_ITEM TYPE BAPIMEPOITEM-PO_ITEM, " STRUCTURE : BAPIMEPOITEM
MATERIAL TYPE BAPIMEPOITEM-MATERIAL,
PLANT TYPE BAPIMEPOITEM-PLANT,
STGE_LOC TYPE BAPIMEPOITEM-STGE_LOC,
QUANTITY TYPE BAPIMEPOITEM-QUANTITY,
TAX_CODE TYPE BAPIMEPOITEM-TAX_CODE,
ITEM_CAT TYPE BAPIMEPOITEM-ITEM_CAT,
ACCTASSCAT TYPE BAPIMEPOITEM-ACCTASSCAT,
SCHED_LINE TYPE BAPIMEPOSCHEDULE-SCHED_LINE, " STRUCTURE : BAPIMEPOSCHEDULE
DELIVERY_DATE TYPE BAPIMEPOSCHEDULE-DELIVERY_DATE,
SERIAL_NO TYPE BAPIMEPOACCOUNT-SERIAL_NO, " STRUCTURE : BAPIMEPOACCOUNT
GL_ACCOUNT TYPE BAPIMEPOACCOUNT-GL_ACCOUNT,
COSTCENTER TYPE BAPIMEPOACCOUNT-COSTCENTER,
CO_AREA TYPE BAPIMEPOACCOUNT-CO_AREA,
END OF STR_FINAL.
DATA : IT_FINAL TYPE TABLE OF STR_FINAL,
WA_FINAL TYPE STR_FINAL.
*************************************************************************************************
DATA: ST_BAPIMEPOHEADER TYPE BAPIMEPOHEADER,
ST_BAPIMEPOHEADERX TYPE BAPIMEPOHEADERX.
*it is for item data
DATA: WA_POITEM TYPE BAPIMEPOITEM,
IT_POITEM TYPE TABLE OF BAPIMEPOITEM,
WA_POITEMX TYPE BAPIMEPOITEMX,
IT_POITEMX TYPE TABLE OF BAPIMEPOITEMX,
WA_POSCHEDULE TYPE BAPIMEPOSCHEDULE,
IT_POSCHEDULE TYPE TABLE OF BAPIMEPOSCHEDULE,
WA_POSCHEDULEX TYPE BAPIMEPOSCHEDULX,
IT_POSCHEDULEX TYPE TABLE OF BAPIMEPOSCHEDULX,
WA_POACCOUNT TYPE BAPIMEPOACCOUNT,
IT_POACCOUNT TYPE TABLE OF BAPIMEPOACCOUNT,
WA_POACCOUNTX TYPE BAPIMEPOACCOUNTX,
IT_POACCOUNTX TYPE TABLE OF BAPIMEPOACCOUNTX,
WA_RETURN TYPE BAPIRET2,
IT_RETURN TYPE TABLE OF BAPIRET2.
*******************************************************************************************************************************
selection-screen skip 1.
parameters: p_file type localfile default 'D:\VISHNU\DEMO.XLS'.
*selection-screen skip 1.
at selection-screen on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
exporting
static = 'X'
changing
file_name = p_file.
start-of-selection.
clear IT_FINAL.
refresh IT_FINAL.
perform upload_data.
loop at IT_FINAL INTO WA_FINAL.
write:/ WA_FINAL-COMP_CODE,
/ WA_FINAL-ITEM_INTVL,
/ WA_FINAL-VENDOR,
/ WA_FINAL-PMNTTRMS,
/ WA_FINAL-PURCH_ORG,
/ WA_FINAL-PUR_GROUP,
/ WA_FINAL-CURRENCY,
/ WA_FINAL-PO_ITEM,
/ WA_FINAL-MATERIAL,
/ WA_FINAL-PLANT,
/ WA_FINAL-STGE_LOC,
/ WA_FINAL-QUANTITY,
/ WA_FINAL-TAX_CODE,
/ WA_FINAL-ITEM_CAT,
/ WA_FINAL-ACCTASSCAT,
/ WA_FINAL-SCHED_LINE,
/ WA_FINAL-DELIVERY_DATE,
/ WA_FINAL-SERIAL_NO,
/ WA_FINAL-GL_ACCOUNT,
/ WA_FINAL-COSTCENTER,
/ WA_FINAL-CO_AREA.
endloop.
********************************************************************************************************************
LOOP AT IT_FINAL INTO WA_FINAL.
ST_BAPIMEPOHEADER-COMP_CODE = WA_FINAL-COMP_CODE.
ST_BAPIMEPOHEADER-DOC_TYPE = 'NB'.
ST_BAPIMEPOHEADER-ITEM_INTVL = WA_FINAL-ITEM_INTVL.
ST_BAPIMEPOHEADER-VENDOR = WA_FINAL-VENDOR.
ST_BAPIMEPOHEADER-LANGU = SY-LANGU.
ST_BAPIMEPOHEADER-PMNTTRMS = WA_FINAL-PMNTTRMS.
ST_BAPIMEPOHEADER-PURCH_ORG = WA_FINAL-PURCH_ORG.
ST_BAPIMEPOHEADER-PUR_GROUP = WA_FINAL-PUR_GROUP.
ST_BAPIMEPOHEADER-CURRENCY = WA_FINAL-CURRENCY.
*insert ST_BAPIMEPOHEADERX values
ST_BAPIMEPOHEADERX-COMP_CODE = 'X'.
ST_BAPIMEPOHEADERX-DOC_TYPE = 'X'.
ST_BAPIMEPOHEADERX-ITEM_INTVL = 'X'.
ST_BAPIMEPOHEADERX-VENDOR = 'X'.
ST_BAPIMEPOHEADERX-LANGU = 'X'.
ST_BAPIMEPOHEADERX-PMNTTRMS = 'X'.
ST_BAPIMEPOHEADERX-PURCH_ORG = 'X'.
ST_BAPIMEPOHEADERX-PUR_GROUP = 'X'.
ST_BAPIMEPOHEADERX-CURRENCY = 'X'.
*insert IT_POITEM values
WA_POITEM-PO_ITEM = WA_FINAL-PO_ITEM.
WA_POITEM-MATERIAL = WA_FINAL-MATERIAL.
WA_POITEM-PLANT = WA_FINAL-PLANT.
WA_POITEM-STGE_LOC = WA_FINAL-STGE_LOC.
WA_POITEM-QUANTITY = WA_FINAL-QUANTITY.
WA_POITEM-TAX_CODE = WA_FINAL-TAX_CODE.
WA_POITEM-ITEM_CAT = WA_FINAL-ITEM_CAT.
WA_POITEM-ACCTASSCAT = WA_FINAL-ACCTASSCAT.
APPEND WA_POITEM TO IT_POITEM.
CLEAR WA_POITEM.
*insert IT_POITEMX values
WA_POITEMX-PO_ITEM = WA_FINAL-PO_ITEM.
WA_POITEMX-PO_ITEMX = 'X'.
WA_POITEMX-MATERIAL = 'X'.
WA_POITEMX-PLANT = 'X'.
WA_POITEMX-STGE_LOC = 'X'.
WA_POITEMX-QUANTITY = 'X'.
WA_POITEMX-TAX_CODE = 'X'.
WA_POITEMX-ITEM_CAT = 'X'.
WA_POITEMX-ACCTASSCAT = 'X'.
APPEND WA_POITEMX TO IT_POITEMX.
CLEAR WA_POITEMX.
*insert IT_POSCHEDULE values
WA_POSCHEDULE-PO_ITEM = WA_FINAL-PO_ITEM.
WA_POSCHEDULE-SCHED_LINE = WA_FINAL-SCHED_LINE.
WA_POSCHEDULE-DELIVERY_DATE = WA_FINAL-DELIVERY_DATE .
WA_POSCHEDULE-QUANTITY = WA_FINAL-QUANTITY.
APPEND WA_POSCHEDULE TO IT_POSCHEDULE.
CLEAR WA_POSCHEDULE.
*insert IT_POSCHEDULEX values
WA_POSCHEDULEX-PO_ITEM = WA_FINAL-PO_ITEM.
WA_POSCHEDULEX-SCHED_LINE = WA_FINAL-SCHED_LINE.
WA_POSCHEDULEX-PO_ITEMX = 'X' .
WA_POSCHEDULEX-SCHED_LINEX = 'X' .
WA_POSCHEDULEX-DELIVERY_DATE = 'X' .
WA_POSCHEDULEX-QUANTITY = 'X' .
WA_POSCHEDULEX-PO_ITEM = WA_FINAL-PO_ITEM .
WA_POSCHEDULEX-SCHED_LINE = WA_FINAL-SCHED_LINE.
WA_POSCHEDULEX-PO_ITEMX = 'X'.
WA_POSCHEDULEX-SCHED_LINEX = 'X' .
WA_POSCHEDULEX-DELIVERY_DATE = 'X' .
WA_POSCHEDULEX-QUANTITY = 'X'.
WA_POSCHEDULEX-PO_ITEM = WA_FINAL-PO_ITEM.
WA_POSCHEDULEX-SCHED_LINE = WA_FINAL-SCHED_LINE.
WA_POSCHEDULEX-PO_ITEMX = 'X'.
WA_POSCHEDULEX-SCHED_LINEX = 'X'.
WA_POSCHEDULEX-DELIVERY_DATE = 'X' .
WA_POSCHEDULEX-QUANTITY = 'X'.
APPEND WA_POSCHEDULEX TO IT_POSCHEDULEX.
CLEAR WA_POSCHEDULEX.
*insert IT_POACCOUNT values
WA_POACCOUNT-PO_ITEM = WA_FINAL-PO_ITEM.
WA_POACCOUNT-SERIAL_NO = WA_FINAL-SERIAL_NO.
WA_POACCOUNT-QUANTITY = WA_FINAL-QUANTITY .
WA_POACCOUNT-GL_ACCOUNT = WA_FINAL-GL_ACCOUNT.
WA_POACCOUNT-COSTCENTER = WA_FINAL-COSTCENTER.
WA_POACCOUNT-CO_AREA = WA_FINAL-CO_AREA.
APPEND WA_POACCOUNT TO IT_POACCOUNT.
CLEAR WA_POACCOUNT.
*insert IT_POACCOUNTX values
WA_POACCOUNTX-PO_ITEM = 00001.
WA_POACCOUNTX-SERIAL_NO = 01.
WA_POACCOUNTX-QUANTITY = 'X'.
WA_POACCOUNTX-GL_ACCOUNT = 'X'.
WA_POACCOUNTX-COSTCENTER = 'X' .
WA_POACCOUNTX-CO_AREA = 'X'.
APPEND WA_POACCOUNTX TO IT_POACCOUNTX.
CLEAR WA_POACCOUNTX.
ENDLOOP.
***********************************************************************
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = ST_BAPIMEPOHEADER
POHEADERX = ST_BAPIMEPOHEADERX
POADDRVENDOR =
TESTRUN =
MEMORY_UNCOMPLETE =
MEMORY_COMPLETE =
POEXPIMPHEADER =
POEXPIMPHEADERX =
VERSIONS =
IMPORTING
EXPPURCHASEORDER =
EXPHEADER =
EXPPOEXPIMPHEADER =
TABLES
RETURN = IT_RETURN
POITEM = IT_POITEM
POITEMX = IT_POITEMX
POADDRDELIVERY =
POSCHEDULE = IT_POSCHEDULE
POSCHEDULEX = IT_POSCHEDULEX
POACCOUNT = IT_POACCOUNT
POACCOUNTPROFITSEGMENT =
POACCOUNTX = IT_POACCOUNTX
POCONDHEADER =
POCONDHEADERX =
POCOND =
POCONDX =
POLIMITS =
POCONTRACTLIMITS =
POSERVICES =
POSRVACCESSVALUES =
POSERVICESTEXT =
EXTENSIONIN =
EXTENSIONOUT =
POEXPIMPITEM =
POEXPIMPITEMX =
POTEXTHEADER =
POTEXTITEM =
ALLVERSIONS =
POPARTNER =
.
*this is for save the porder number
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
*dispaly the results
LOOP AT IT_RETURN INTO WA_RETURN.
WRITE:/ WA_RETURN-MESSAGE,
ST_BAPIMEPOHEADER-PO_NUMBER.
ENDLOOP.
form upload_data.
data: file type rlgrap-filename.
data: IT_XCEL type table of alsmex_tabline,
WA_XCEL TYPE ALSMEX_TABLINE.
file = p_file.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '21'
i_end_row = '1'
tables
intern = IT_xcel
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
loop at IT_xcel INTO WA_XCEL.
case
WA_XCEL-COL.
when '0001'.
WA_FINAL-COMP_CODE = WA_xcel-value.
WHEN '0002'.
WA_FINAL-ITEM_INTVL = WA_XCEL-VALUE.
WHEN '0003'.
WA_FINAL-VENDOR = WA_XCEL-VALUE.
WHEN '0004'.
WA_FINAL-PMNTTRMS = WA_XCEL-VALUE.
WHEN '0005'.
WA_FINAL-PURCH_ORG = WA_XCEL-VALUE.
WHEN '0006'.
WA_FINAL-PUR_GROUP = WA_XCEL-VALUE.
WHEN '0007'.
WA_FINAL-CURRENCY = WA_XCEL-VALUE.
WHEN '0008'.
WA_FINAL-PO_ITEM = WA_XCEL-VALUE.
WHEN '0009'.
WA_FINAL-MATERIAL = WA_XCEL-VALUE.
WHEN '00010'.
WA_FINAL-PLANT = WA_XCEL-VALUE.
WHEN '00011'.
WA_FINAL-STGE_LOC = WA_XCEL-VALUE.
WHEN '00012'.
WA_FINAL-QUANTITY = WA_XCEL-VALUE.
WHEN '00013'.
WA_FINAL-TAX_CODE = WA_XCEL-VALUE.
WHEN '00014'.
WA_FINAL-ITEM_CAT = WA_XCEL-VALUE.
WHEN '00015'.
WA_FINAL-ACCTASSCAT = WA_XCEL-VALUE.
WHEN '00016'.
WA_FINAL-SCHED_LINE = WA_XCEL-VALUE.
WHEN '00017'.
WA_FINAL-DELIVERY_DATE = WA_XCEL-VALUE.
WHEN '00018'.
WA_FINAL-SERIAL_NO = WA_XCEL-VALUE.
WHEN '00019'.
WA_FINAL-GL_ACCOUNT = WA_XCEL-VALUE.
WHEN '00020'.
WA_FINAL-COSTCENTER = WA_XCEL-VALUE.
WHEN '00021'.
WA_FINAL-CO_AREA = WA_XCEL-VALUE.
ENDCASE.
at end of row.
append WA_FINAL TO IT_FINAL.
clear WA_FINAL.
endat.
ENDLOOP.
ENDFORM.
2008 Apr 12 7:34 AM
hi,
Check out the below link ... Hope it helps
http://www.sap-basis-abap.com/sapac009.htm
Regards,
Santosh
2008 Apr 18 5:55 AM
YOU JUST WRITTEN FOR UPLOAD OF EXCEL FILE TO THE INTERNAL TABLE. I NEED TO UPDATE THE INTERNAL TABLE TO OPEN PURCHASE ORDER USING BAPI.
2008 Apr 12 7:37 AM
Hi,
Check with this sample.
DATA: G_T_FILE LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
*download the excel data into an internal table
IF NOT P_FILE IS INITIAL.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = G_C_START_COL
I_BEGIN_ROW = G_C_START_ROW
I_END_COL = G_C_END_COL
I_END_ROW = G_C_END_ROW
TABLES
INTERN = G_T_FILE
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC 0.
MESSAGE E000(SU) WITH TEXT-004.
ENDIF.
ENDIF.
LOOP AT G_T_FILE.
IF G_T_FILE-COL = '1'.
G_T_DEBI-KUNNR = G_T_FILE-VALUE.
ENDIF.
IF G_T_FILE-COL = '2'.
G_T_DEBI-LAND1 = G_T_FILE-VALUE.
ENDIF.
IF G_T_FILE-COL = '3'.
G_T_DEBI-VBUND = G_T_FILE-VALUE.
ENDIF.
IF G_T_FILE-COL = '4'.
G_T_DEBI-AKONT = G_T_FILE-VALUE.
ENDIF.
AT END OF ROW.
APPEND G_T_DEBI.
CLEAR G_T_DEBI.
ENDAT.
ENDLOOP.
BAPI EXAMPLE
REPORT ZBAPI_PO_UPLOAD_BS.
*** Tables Declaration
TABLES: ZMM_SOLOMON_PO, EKKO, LFM1.
*** Constant Declaration
DATA: L_BSART LIKE MEPO_TOPLINE-BSART VALUE 'NB'.
DATA: L_BSART1 LIKE MEPO_TOPLINE-BSART VALUE 'ZNB'.
CONSTANTS: C_EKORG LIKE MEPO1222-EKORG VALUE 'POMR',
C_EKGRP LIKE MEPO1222-EKGRP VALUE 'PG1',
C_BUKRS LIKE EKKO-BUKRS VALUE 'SBPL'.
*** Variable Declaration
DATA: A TYPE C VALUE '/'.
data : gfile(150).
data : hfile(150).
data : ifile(150).
DATA: g_file(200).
DATA: h_file(200).
data: i_file(200).
*DATA: COUNT LIKE SY-INDEX.
DATA: date(8), date1(6).
date = sy-datum.
concatenate date+6(2) date+4(2) date+0(4) into date.
date1 = date+2(6).
data: name(32).
DATA : S_MSG1(300).
DATA : V_MSG1 LIKE S_MSG1 OCCURS 0 WITH HEADER LINE.
DATA : I_MSG1 LIKE V_MSG1 OCCURS 0 WITH HEADER LINE.
DATA : I_MSG2 LIKE V_MSG1 OCCURS 0 WITH HEADER LINE.
DATA: COUNT LIKE SY-TABIX.
DATA: G_FLAG(1).
constants : c_x value 'X'.
*** Internal table Declaration
DATA: BEGIN OF i_tab OCCURS 0,
VERKF LIKE EKKO-VERKF,
VERKF1 LIKE EKKO-VERKF,
LIFNR LIKE EKKO-LIFNR,
WERKS LIKE EKPO-WERKS,
EBELP1 like ekpo-ebelp,
MATNR LIKE EKPO-MATNR,
IDNLF LIKE EKPO-IDNLF,
MENGE(16),
BPRME LIKE EKPO-BPRME,
LEWED LIKE EKPO-LEWED,
NETPR(13),
CURRKEY(5),
EBELN LIKE EORD-EBELN,
EBELP LIKE EORD-EBELN,
VERKF2 LIKE EKKO-VERKF,
KALSK LIKE LFM1-KALSK,
BSART LIKE MEPO_TOPLINE-BSART,
LIFNR1 LIKE EKKO-LIFNR,
FLAG(1),
PSTYP like ekpo-PSTYP,
END OF i_tab.
data: begin of it_usr occurs 0,
tx_id like ZMMINT_USR-tx_id,
werks like ZMMINT_USR-werks,
uname like ZMMINT_USR-uname,
end of it_usr.
constants: c_plant like zmmint_usr-werks value 'OMR'.
DATA: ETAB LIKE I_TAB OCCURS 0 WITH HEADER LINE.
DATA: I_TAB2 LIKE I_TAB OCCURS 0 WITH HEADER LINE.
DATA: I_TAB3 LIKE I_TAB OCCURS 0 WITH HEADER LINE.
DATA: I_OUT LIKE I_TAB OCCURS 0 WITH HEADER LINE.
DATA: ETAB1 LIKE I_TAB OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF i_tab1 OCCURS 0,
MATNR LIKE EORD-MATNR,
WERKS LIKE EORD-WERKS,
LIFNR LIKE EORD-LIFNR,
EBELN LIKE EORD-EBELN,
EBELP LIKE EORD-EBELP,
END OF i_tab1.
DATA: BEGIN OF i_lfm1 OCCURS 0,
KALSK LIKE LFM1-KALSK,
END OF i_lfm1.
DATA: BEGIN OF i_ekko OCCURS 0,
BSART LIKE EKKO-BSART,
END OF i_ekko.
DATA: BEGIN OF I_ZMM_SOLOMON_PO OCCURS 0,
SOLOMON_PO LIKE ZMM_SOLOMON_PO-SOLOMON_PO,
SOLOMON_DATE LIKE ZMM_SOLOMON_PO-SOLOMON_DATE,
FLAG LIKE ZMM_SOLOMON_PO-FLAG,
END OF I_ZMM_SOLOMON_PO.
********* Data Declaration for BAPI *****************
data: begin of pohead occurs 10.
include structure BAPIMEPOHEADER.
data: end of pohead.
data: begin of poheadx occurs 10.
include structure BAPIMEPOHEADERX.
data: end of poheadx.
*EXPPURCHASEORDER
data: BEGIN OF ponum.
include structure BAPIMEPOHEADER.
data: end of ponum.
data: begin of poitem occurs 100.
include structure BAPIMEPOITEM.
data: end of poitem.
data: begin of poitemx occurs 100.
include structure BAPIMEPOITEMX.
data: end of poitemx.
data: begin of poitemsch occurs 100.
include structure BAPIMEPOSCHEDULE.
data: end of poitemsch.
data: begin of poitemschx occurs 100.
include structure BAPIMEPOSCHEDULX.
data: end of poitemschx.
data: begin of errmsg occurs 10.
include structure bapiret2.
data: end of errmsg.
data : errflag.
START-OF-SELECTION.
if sy-host = 'sanyobplsap' or sy-host = 'SANYOBPLSAP'.
gfile = 'D:\SAP_INT\INBOUND\INBOX'.
ifile = 'D:\SAP_INT\INBOUND\LOG'.
hfile = 'D:\SAP_INT\INBOUND\OUTBOX'.
ENDIF.
if sy-host = 'sapqm' or sy-host = 'SAPQM'.
gfile = 'E:\SAP_INT\INBOUND\INBOX'.
ifile = 'E:\SAP_INT\INBOUND\LOG'.
hfile = 'E:\SAP_INT\INBOUND\OUTBOX'.
ENDIF.
if sy-host = 'sapgrp' or sy-host = 'SAPGRP'.
gfile = 'S:\SAP_INT\INBOUND\INBOX'.
ifile = 'S:\SAP_INT\INBOUND\LOG'.
hfile = 'S:\SAP_INT\INBOUND\OUTBOX'.
ENDIF.
PERFORM UPLOAD_DATA.
PERFORM SUB_SEND_MAIL.
*&---------------------------------------------------------------------*
*& Form UPLOAD_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM UPLOAD_DATA .
data: p_fdir(200) type c .
p_fdir = gfile.
data: begin of it_filedir occurs 10.
include structure salfldir.
data: end of it_filedir.
* Get Current Directory Listing for OUT Dir
call function 'RZL_READ_DIR_LOCAL'
EXPORTING
name = p_fdir
TABLES
file_tbl = it_filedir.
data: it_filedir1 like it_filedir occurs 0 with header line.
loop at it_filedir.
if it_filedir-name(4) = 'CPOR' or it_filedir-name(4) = 'cpor'.
move it_filedir-name to it_filedir1-name.
append it_filedir1.
endif.
endloop.
IF IT_FILEDIR1[] IS INITIAL.
* WRITE:/ 'FILE NOT FOUND'.
STOP.
ENDIF.
REFRESH I_MSG1.
CLEAR I_MSG1.
loop at it_filedir1.
REFRESH I_TAB.
REFRESH I_TAB2.
REFRESH I_TAB1.
REFRESH I_OUT.
data: g_file(100) type c .
name = it_filedir1-name.
concatenate: gfile '\' name into g_file.
data : i_tab1(200).
OPEN DATASET g_file FOR INPUT IN TEXT MODE
ENCODING DEFAULT
IGNORING CONVERSION ERRORS.
IF SY-SUBRC EQ 0.
DO.
READ DATASET g_file INTO i_tab1.
if sy-subrc = 0.
split i_tab1 at ',' into i_tab-verkf i_tab-verkf1 i_tab-lifnr
i_tab-ebelp1 i_tab-werks i_tab-matnr i_tab-idnlf
i_tab-menge i_tab-bprme i_tab-lewed i_tab-netpr
i_tab-CURRKEY i_tab-PSTYP.
else.
exit.
endif.
APPEND i_tab.
clear i_tab.
ENDDO.
ENDIF.
* *************** end error testing*******************
CLOSE DATASET g_file.
PERFORM GET_OUTLINE_AGREEMENT.
* LOOP AT I_TAB.
* MOVE: I_TAB-VERKF TO ZMM_SOLOMON_PO-SOLOMON_PO,
* I_TAB-VERKF1 TO ZMM_SOLOMON_PO-SOLOMON_DATE.
* insert ZMM_SOLOMON_PO.
* if sy-subrc eq 0.
* commit work.
* else.
* rollback work.
* endif.
* ENDLOOP.
MOVE I_TAB[] TO I_OUT[].
MOVE I_TAB[] TO I_TAB3[].
SORT I_TAB BY VERKF.
DELETE ADJACENT DUPLICATES FROM I_TAB COMPARING VERKF.
CLEAR COUNT.
loop at i_tab.
COUNT = SY-TABIX.
select SINGLE *
from ZMM_SOLOMON_PO WHERE SOLOMON_PO = I_TAB-VERKF AND
SOLOMON_DATE = I_TAB-VERKF1.
IF SY-SUBRC = 0.
I_TAB-FLAG = 'C'.
MODIFY I_TAB INDEX COUNT.
concatenate 'File Name : ' name into i_msg1.
append i_msg1.
concatenate 'File Name : ' name into i_msg2.
append i_msg2.
CONCATENATE 'ERROR : PO ' I_TAB-VERKF
' WAS ALREADY UPLOADED' INTO I_MSG1.
APPEND I_MSG1.
CONCATENATE 'ERROR : PO ' I_TAB-VERKF
' WAS ALREADY UPLOADED' INTO I_MSG2.
APPEND I_MSG2.
CLEAR I_TAB-FLAG.
CONTINUE.
ELSE.
refresh pohead.
refresh poheadx.
clear pohead.
refresh poitem.
refresh poitemX.
pohead-DOC_TYPE = i_tab-bsart.
pohead-VENDOR = i_tab-lifnr.
pohead-PURCH_ORG = c_ekorg.
pohead-CREAT_DATE = i_tab-verkf1.
pohead-PUR_GROUP = c_ekgrp.
pohead-COMP_CODE = c_bukrs.
pohead-SALES_PERS = I_TAB-VERKF2.
pohead-doc_date = sy-datum.
pohead-langu = sy-langu.
IF I_TAB-CURRKEY = 'USD'.
pohead-CURRENCY = 'USDN'.
ELSE.
pohead-CURRENCY = I_TAB-CURRKEY.
ENDIF.
pohead-ITEM_INTVL = ''.
append pohead.
poheadx-DOC_TYPE = c_x.
poheadx-VENDOR = c_x.
poheadx-PURCH_ORG = c_x.
poheadx-PUR_GROUP = c_x.
poheadx-COMP_CODE = c_x.
poheadx-SALES_PERS = c_x.
poheadx-ITEM_INTVL = c_x.
poheadx-doc_date = c_x.
poheadx-CURRENCY = c_x.
poheadx-langu = c_x.
append poheadx.
refresh poitem.
clear poitem.
refresh poitemsch.
refresh poitemschx.
clear poitemsch.
clear poitemschx.
sort i_tab3 by verkf ebelp1.
loop at i_tab3 WHERE VERKF = I_TAB-VERKF.
clear poitem.
poitem-PO_ITEM = i_tab3-ebelp1.
poitem-MATERIAL = i_tab3-MATNR.
poitem-QUANTITY = i_tab3-MENGE.
poitem-PO_UNIT = i_tab3-BPRME.
poitem-NET_PRICE = i_tab3-NETPR.
* IF I_TAB3-CURRKEY = 'USD'.
* multiply poitem-NET_PRICE by 1000.
* ENDIF.
poitem-NO_ROUNDING = 'X'.
poitem-PLANT = i_tab3-WERKS.
poitem-INFO_UPD = ''.
if i_tab3-PSTYP <> ''.
poitem-item_cat = i_tab3-PSTYP.
endif.
* poitem-GR_TO_DATE = i_tab3-LEWED.
* poitem-tax_code = c_x.
* poitem-item_cat = c_x.
*
* POITEM-ACCTASSCAT = c_x.
* poitem-AGREEMENT = i_tab3-ebeln.
* poitem-AGMT_ITEM = i_tab3-ebelp1.
poitem-VEND_MAT = i_tab3-IDNLF.
append poitem.
clear poitemx.
poitemx-PO_ITEM = i_tab3-ebelp1.
poitemx-MATERIAL = c_x.
poitemx-QUANTITY = c_x.
poitemx-PO_UNIT = c_x.
poitemx-NET_PRICE = c_x.
poitemx-NO_ROUNDING = c_x.
poitemx-PLANT = c_x.
poitemx-GR_TO_DATE = c_x.
poitemx-INFO_UPD = c_x.
poitemx-tax_code = c_x.
poitemx-item_cat = c_x.
POITEMx-ACCTASSCAT = c_x.
* poitemx-AGREEMENT = 'X'.
* poitemx-AGMT_ITEM = 'X'.
poitemx-VEND_MAT = c_x.
append poitemx.
poitemsch-PO_ITEM = i_tab3-ebelp1.
poitemsch-SCHED_LINE = '0001'.
poitemsch-DELIVERY_DATE = i_tab3-LEWED.
poitemsch-QUANTITY = i_tab3-MENGE.
append poitemsch.
poitemschx-PO_ITEM = i_tab3-ebelp1.
poitemschx-SCHED_LINE = '0001'.
poitemschx-PO_ITEMX = C_X.
poitemschx-DELIVERY_DATE = c_x.
poitemschx-QUANTITY = C_X.
append poitemschx.
endloop.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = pohead
POHEADERX = poheadx
* POADDRVENDOR =
* TESTRUN =
* MEMORY_UNCOMPLETE =
* MEMORY_COMPLETE =
* POEXPIMPHEADER =
* POEXPIMPHEADERX =
* VERSIONS =
* NO_MESSAGING =
* NO_MESSAGE_REQ =
* NO_AUTHORITY =
* NO_PRICE_FROM_PO =
IMPORTING
* EXPPURCHASEORDER =
EXPHEADER = ponum
* EXPPOEXPIMPHEADER =
TABLES
RETURN = errmsg
POITEM = poitem
POITEMX = poitemx
* POADDRDELIVERY =
POSCHEDULE = poitemsch
POSCHEDULEX = poitemschx
* POACCOUNT =
* POACCOUNTPROFITSEGMENT =
* POACCOUNTX =
* POCONDHEADER =
* POCONDHEADERX =
* POCOND =
* POCONDX =
* POLIMITS =
* POCONTRACTLIMITS =
* POSERVICES =
* POSRVACCESSVALUES =
* POSERVICESTEXT =
* EXTENSIONIN =
* EXTENSIONOUT =
* POEXPIMPITEM =
* POEXPIMPITEMX =
* POTEXTHEADER =
* POTEXTITEM =
* ALLVERSIONS =
* POPARTNER =
.
clear errflag.
loop at errmsg.
if sy-tabix = 1.
concatenate 'File Name : ' name into i_msg1.
append i_msg1.
concatenate 'Sol PO : ' I_TAB-VERKF ' '
I_TAB-VERKF1 into i_msg1.
append i_msg1.
concatenate 'File Name : ' name into i_msg1.
append i_msg2.
concatenate 'Sol PO : ' I_TAB-VERKF ' '
I_TAB-VERKF1 into i_msg2.
append i_msg2.
endif.
if errmsg-type eq 'E'.
* write:/'Error in function', errmsg-message.
errflag = 'X'.
else.
* write:/ errmsg-message.
endif.
MOVE : ERRMSG-MESSAGE TO I_MSG1.
APPEND I_MSG1.
MOVE : ERRMSG-MESSAGE TO I_MSG2.
APPEND I_MSG2.
endloop.
if errflag is initial.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
* IMPORTING
* RETURN =
.
* commit work and wait.
if sy-subrc ne 0.
* write:/ 'Error in updating'.
exit.
else.
concatenate 'File Name : ' name into i_msg1.
append i_msg1.
concatenate 'Sol PO : ' I_TAB-VERKF ' '
I_TAB-VERKF1 into i_msg1.
append i_msg1.
concatenate 'File Name : ' name into i_msg2.
append i_msg2.
concatenate 'Sol PO : ' I_TAB-VERKF ' '
I_TAB-VERKF1 into i_msg2.
append i_msg1.
* write:/ ponum-PO_NUMBER, ponum-comp_code.
ZMM_SOLOMON_PO-SOLOMON_PO = I_TAB-VERKF.
ZMM_SOLOMON_PO-SOLOMON_DATE = I_TAB-VERKF1.
INSERT ZMM_SOLOMON_PO.
COMMIT WORK AND WAIT.
I_TAB-FLAG = 'C'.
MODIFY I_TAB INDEX COUNT.
CONCATENATE ponum-PO_NUMBER ' ' ponum-comp_code
'UPLOADED SUCESSFULLY' INTO I_MSG1.
APPEND I_MSG1.
CONCATENATE ponum-PO_NUMBER ' ' ponum-comp_code
'UPLOADED SUCESSFULLY' INTO I_MSG2.
APPEND I_MSG2.
endif.
endif.
ENDIF.
WAIT UP TO 10 SECONDS.
endloop.
CLEAR G_FLAG.
LOOP AT I_TAB WHERE FLAG <> 'C'.
G_FLAG = 'X'.
ENDLOOP.
IF G_FLAG IS INITIAL.
CLEAR G_FLAG.
concatenate: hfile '\' date1 '\' name into h_file.
OPEN DATASET h_file FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT
IGNORING CONVERSION ERRORS.
IF SY-SUBRC EQ 0.
LOOP AT I_OUT.
CONCATENATE I_OUT-VERKF ',' I_OUT-VERKF1 ',' I_OUT-LIFNR ','
I_OUT-EBELP1 ',' I_OUT-WERKS ',' I_OUT-MATNR ','
I_OUT-IDNLF ',' I_OUT-MENGE ',' I_OUT-BPRME ','
I_OUT-LEWED ',' I_OUT-NETPR ',' I_OUT-CURRKEY
',' I_OUT-PSTYP
INTO I_TAB2.
TRANSFER i_tab2 TO h_file.
ENDLOOP.
DELETE DATASET g_file.
ENDIF.
CLOSE DATASET h_file.
ENDIF.
***** Begin of log creation
concatenate: ifile '\' date1 '\' name into i_file.
IF NOT I_MSG2[] IS INITIAL.
OPEN DATASET i_file FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT
IGNORING CONVERSION ERRORS.
IF SY-SUBRC EQ 0.
LOOP AT I_MSG2.
TRANSFER I_MSG2 TO i_file.
ENDLOOP.
ENDIF.
REFRESH I_MSG2.
CLEAR I_MSG2.
CLOSE DATASET I_file.
ENDIF.
****End of log creation
endloop.
ENDFORM. " UPLOAD_DATA
*&---------------------------------------------------------------------*
*& Form GET_OUTLINE_AGREEMENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_OUTLINE_AGREEMENT .
DATA: L_TABIX LIKE SY-TABIX.
DATA: L_LIFNR LIKE EKKO-LIFNR.
DATA : L_EBELP like ekpo-ebelp.
LOOP AT I_TAB.
L_TABIX = SY-TABIX.
CONCATENATE I_TAB-VERKF I_TAB-VERKF1 INTO I_TAB-VERKF2
SEPARATED BY '#'.
MODIFY I_TAB INDEX L_TABIX.
clear i_tab.
ENDLOOP.
LOOP AT I_TAB.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = I_TAB-LIFNR
IMPORTING
OUTPUT = L_LIFNR.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = I_TAB-EBELP1
IMPORTING
OUTPUT = L_EBELP.
I_TAB-LIFNR = L_LIFNR.
I_TAB-EBELP1 = L_EBELP.
SELECT SINGLE *
FROM LFM1
WHERE LIFNR EQ L_LIFNR AND
EKORG = C_EKORG.
IF SY-SUBRC EQ 0.
IF LFM1-KALSK EQ 'ZD'.
L_BSART = 'NB'.
MOVE L_BSART TO I_TAB-BSART.
MODIFY I_TAB. " INDEX 1.
clear i_tab.
ELSEIF LFM1-KALSK EQ 'ZI'.
L_BSART1 = 'ZNB'.
MOVE L_BSART1 TO I_TAB-BSART.
MODIFY I_TAB.
clear i_tab.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " GET_OUTLINE_AGREEMENT
*&---------------------------------------------------------------------*
*& Form CHECK_ENTRIES_ZMM_SOLOMON_PO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
*FORM CHECK_ENTRIES_ZMM_SOLOMON_PO .
*
* select SOLOMON_PO
* SOLOMON_DATE
* FLAG
* from ZMM_SOLOMON_PO
* into table I_ZMM_SOLOMON_PO.
*
* if I_TAB[] is NOT initial.
* loop at i_TAB.
* count = sy-tabix.
* read table I_ZMM_SOLOMON_PO with key SOLOMON_PO = I_TAB-VERKF.
* IF SY-SUBRC = 0.
* delete i_TAB index count.
* CONCATENATE 'PO : ' I_TAB-VERKF
* ' WAS ALREADY CREATED' INTO I_MSG1.
* APPEND I_MSG1.
* CLEAR I_TAB.
* endif.
* endloop.
* endif.
*
*ENDFORM. " CHECK_ENTRIES_ZMM_SOLOMON_PO
*&---------------------------------------------------------------------*
*& Form SUB_SEND_MAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SUB_SEND_MAIL .
DATA: BEGIN OF EMAIL_DATA.
INCLUDE STRUCTURE SODOCCHGI1.
DATA: END OF EMAIL_DATA.
DATA: BEGIN OF EMAIL_SEND OCCURS 10.
INCLUDE STRUCTURE SOMLRECI1.
DATA: END OF EMAIL_SEND.
if not i_msg1[] is initial.
select * from zmmint_usr into corresponding fields of table it_usr
where werks = c_plant and tx_id = 'CPOR'.
if sy-subrc = 0.
loop at it_usr.
EMAIL_DATA-OBJ_NAME = 'MESSAGE'.
EMAIL_DATA-OBJ_DESCR = 'PURCHASE ORDER CREATION'.
EMAIL_DATA-OBJ_LANGU = 'E'.
EMAIL_DATA-SENSITIVTY = 'P'.
EMAIL_DATA-OBJ_PRIO = '1'.
EMAIL_DATA-NO_CHANGE = 'X'.
EMAIL_DATA-PRIORITY = '1'.
EMAIL_SEND-RECEIVER = it_usr-uname.
EMAIL_SEND-REC_TYPE = 'B'.
* EMAIL_SEND-EXPRESS = 'X'.
* EMAIL_SEND-REC_ID = sy-uname.
APPEND EMAIL_SEND.
endloop.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = EMAIL_DATA
DOCUMENT_TYPE = 'RAW'
PUT_IN_OUTBOX = 'X'
TABLES
OBJECT_CONTENT = I_MSG1
RECEIVERS = EMAIL_SEND.
endif.
endif.
ENDFORM. " SUB_SEND_MAIL
reward if helpful
raam
2008 Apr 16 4:42 AM
*CREATION OF A TEMPORARY STRUCTURE FOR INSERTING FIELDS OF EXCEL TO INTERNAL TABLE.
TYPES : BEGIN OF STR_FINAL,
COMP_CODE TYPE BAPIMEPOHEADER-COMP_CODE, " STRUCTURE : BAPIMEPOHEADER
ITEM_INTVL TYPE BAPIMEPOHEADER-ITEM_INTVL,
VENDOR TYPE BAPIMEPOHEADER-VENDOR,
PMNTTRMS TYPE BAPIMEPOHEADER-PMNTTRMS,
PURCH_ORG TYPE BAPIMEPOHEADER-PURCH_ORG,
PUR_GROUP TYPE BAPIMEPOHEADER-PUR_GROUP,
CURRENCY TYPE BAPIMEPOHEADER-CURRENCY,
PO_ITEM TYPE BAPIMEPOITEM-PO_ITEM, " STRUCTURE : BAPIMEPOITEM
MATERIAL TYPE BAPIMEPOITEM-MATERIAL,
PLANT TYPE BAPIMEPOITEM-PLANT,
STGE_LOC TYPE BAPIMEPOITEM-STGE_LOC,
QUANTITY TYPE BAPIMEPOITEM-QUANTITY,
TAX_CODE TYPE BAPIMEPOITEM-TAX_CODE,
ITEM_CAT TYPE BAPIMEPOITEM-ITEM_CAT,
ACCTASSCAT TYPE BAPIMEPOITEM-ACCTASSCAT,
SCHED_LINE TYPE BAPIMEPOSCHEDULE-SCHED_LINE, " STRUCTURE : BAPIMEPOSCHEDULE
DELIVERY_DATE TYPE BAPIMEPOSCHEDULE-DELIVERY_DATE,
SERIAL_NO TYPE BAPIMEPOACCOUNT-SERIAL_NO, " STRUCTURE : BAPIMEPOACCOUNT
GL_ACCOUNT TYPE BAPIMEPOACCOUNT-GL_ACCOUNT,
COSTCENTER TYPE BAPIMEPOACCOUNT-COSTCENTER,
CO_AREA TYPE BAPIMEPOACCOUNT-CO_AREA,
END OF STR_FINAL.
DATA : IT_FINAL TYPE TABLE OF STR_FINAL,
WA_FINAL TYPE STR_FINAL.
*************************************************************************************************
DATA: ST_BAPIMEPOHEADER TYPE BAPIMEPOHEADER,
ST_BAPIMEPOHEADERX TYPE BAPIMEPOHEADERX.
*it is for item data
DATA: WA_POITEM TYPE BAPIMEPOITEM,
IT_POITEM TYPE TABLE OF BAPIMEPOITEM,
WA_POITEMX TYPE BAPIMEPOITEMX,
IT_POITEMX TYPE TABLE OF BAPIMEPOITEMX,
WA_POSCHEDULE TYPE BAPIMEPOSCHEDULE,
IT_POSCHEDULE TYPE TABLE OF BAPIMEPOSCHEDULE,
WA_POSCHEDULEX TYPE BAPIMEPOSCHEDULX,
IT_POSCHEDULEX TYPE TABLE OF BAPIMEPOSCHEDULX,
WA_POACCOUNT TYPE BAPIMEPOACCOUNT,
IT_POACCOUNT TYPE TABLE OF BAPIMEPOACCOUNT,
WA_POACCOUNTX TYPE BAPIMEPOACCOUNTX,
IT_POACCOUNTX TYPE TABLE OF BAPIMEPOACCOUNTX,
WA_RETURN TYPE BAPIRET2,
IT_RETURN TYPE TABLE OF BAPIRET2.
*******************************************************************************************************************************
selection-screen skip 1.
parameters: p_file type localfile default 'D:\VISHNU\DEMO.XLS'.
*selection-screen skip 1.
at selection-screen on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
exporting
static = 'X'
changing
file_name = p_file.
start-of-selection.
clear IT_FINAL.
refresh IT_FINAL.
perform upload_data.
loop at IT_FINAL INTO WA_FINAL.
write:/ WA_FINAL-COMP_CODE,
/ WA_FINAL-ITEM_INTVL,
/ WA_FINAL-VENDOR,
/ WA_FINAL-PMNTTRMS,
/ WA_FINAL-PURCH_ORG,
/ WA_FINAL-PUR_GROUP,
/ WA_FINAL-CURRENCY,
/ WA_FINAL-PO_ITEM,
/ WA_FINAL-MATERIAL,
/ WA_FINAL-PLANT,
/ WA_FINAL-STGE_LOC,
/ WA_FINAL-QUANTITY,
/ WA_FINAL-TAX_CODE,
/ WA_FINAL-ITEM_CAT,
/ WA_FINAL-ACCTASSCAT,
/ WA_FINAL-SCHED_LINE,
/ WA_FINAL-DELIVERY_DATE,
/ WA_FINAL-SERIAL_NO,
/ WA_FINAL-GL_ACCOUNT,
/ WA_FINAL-COSTCENTER,
/ WA_FINAL-CO_AREA.
endloop.
********************************************************************************************************************
LOOP AT IT_FINAL INTO WA_FINAL.
ST_BAPIMEPOHEADER-COMP_CODE = WA_FINAL-COMP_CODE.
ST_BAPIMEPOHEADER-DOC_TYPE = 'NB'.
ST_BAPIMEPOHEADER-ITEM_INTVL = WA_FINAL-ITEM_INTVL.
ST_BAPIMEPOHEADER-VENDOR = WA_FINAL-VENDOR.
ST_BAPIMEPOHEADER-LANGU = SY-LANGU.
ST_BAPIMEPOHEADER-PMNTTRMS = WA_FINAL-PMNTTRMS.
ST_BAPIMEPOHEADER-PURCH_ORG = WA_FINAL-PURCH_ORG.
ST_BAPIMEPOHEADER-PUR_GROUP = WA_FINAL-PUR_GROUP.
ST_BAPIMEPOHEADER-CURRENCY = WA_FINAL-CURRENCY.
*insert ST_BAPIMEPOHEADERX values
ST_BAPIMEPOHEADERX-COMP_CODE = 'X'.
ST_BAPIMEPOHEADERX-DOC_TYPE = 'X'.
ST_BAPIMEPOHEADERX-ITEM_INTVL = 'X'.
ST_BAPIMEPOHEADERX-VENDOR = 'X'.
ST_BAPIMEPOHEADERX-LANGU = 'X'.
ST_BAPIMEPOHEADERX-PMNTTRMS = 'X'.
ST_BAPIMEPOHEADERX-PURCH_ORG = 'X'.
ST_BAPIMEPOHEADERX-PUR_GROUP = 'X'.
ST_BAPIMEPOHEADERX-CURRENCY = 'X'.
*insert IT_POITEM values
WA_POITEM-PO_ITEM = WA_FINAL-PO_ITEM.
WA_POITEM-MATERIAL = WA_FINAL-MATERIAL.
WA_POITEM-PLANT = WA_FINAL-PLANT.
WA_POITEM-STGE_LOC = WA_FINAL-STGE_LOC.
WA_POITEM-QUANTITY = WA_FINAL-QUANTITY.
WA_POITEM-TAX_CODE = WA_FINAL-TAX_CODE.
WA_POITEM-ITEM_CAT = WA_FINAL-ITEM_CAT.
WA_POITEM-ACCTASSCAT = WA_FINAL-ACCTASSCAT.
APPEND WA_POITEM TO IT_POITEM.
CLEAR WA_POITEM.
*insert IT_POITEMX values
WA_POITEMX-PO_ITEM = WA_FINAL-PO_ITEM.
WA_POITEMX-PO_ITEMX = 'X'.
WA_POITEMX-MATERIAL = 'X'.
WA_POITEMX-PLANT = 'X'.
WA_POITEMX-STGE_LOC = 'X'.
WA_POITEMX-QUANTITY = 'X'.
WA_POITEMX-TAX_CODE = 'X'.
WA_POITEMX-ITEM_CAT = 'X'.
WA_POITEMX-ACCTASSCAT = 'X'.
APPEND WA_POITEMX TO IT_POITEMX.
CLEAR WA_POITEMX.
*insert IT_POSCHEDULE values
WA_POSCHEDULE-PO_ITEM = WA_FINAL-PO_ITEM.
WA_POSCHEDULE-SCHED_LINE = WA_FINAL-SCHED_LINE.
WA_POSCHEDULE-DELIVERY_DATE = WA_FINAL-DELIVERY_DATE .
WA_POSCHEDULE-QUANTITY = WA_FINAL-QUANTITY.
APPEND WA_POSCHEDULE TO IT_POSCHEDULE.
CLEAR WA_POSCHEDULE.
*insert IT_POSCHEDULEX values
WA_POSCHEDULEX-PO_ITEM = WA_FINAL-PO_ITEM.
WA_POSCHEDULEX-SCHED_LINE = WA_FINAL-SCHED_LINE.
WA_POSCHEDULEX-PO_ITEMX = 'X' .
WA_POSCHEDULEX-SCHED_LINEX = 'X' .
WA_POSCHEDULEX-DELIVERY_DATE = 'X' .
WA_POSCHEDULEX-QUANTITY = 'X' .
WA_POSCHEDULEX-PO_ITEM = WA_FINAL-PO_ITEM .
WA_POSCHEDULEX-SCHED_LINE = WA_FINAL-SCHED_LINE.
WA_POSCHEDULEX-PO_ITEMX = 'X'.
WA_POSCHEDULEX-SCHED_LINEX = 'X' .
WA_POSCHEDULEX-DELIVERY_DATE = 'X' .
WA_POSCHEDULEX-QUANTITY = 'X'.
WA_POSCHEDULEX-PO_ITEM = WA_FINAL-PO_ITEM.
WA_POSCHEDULEX-SCHED_LINE = WA_FINAL-SCHED_LINE.
WA_POSCHEDULEX-PO_ITEMX = 'X'.
WA_POSCHEDULEX-SCHED_LINEX = 'X'.
WA_POSCHEDULEX-DELIVERY_DATE = 'X' .
WA_POSCHEDULEX-QUANTITY = 'X'.
APPEND WA_POSCHEDULEX TO IT_POSCHEDULEX.
CLEAR WA_POSCHEDULEX.
*insert IT_POACCOUNT values
WA_POACCOUNT-PO_ITEM = WA_FINAL-PO_ITEM.
WA_POACCOUNT-SERIAL_NO = WA_FINAL-SERIAL_NO.
WA_POACCOUNT-QUANTITY = WA_FINAL-QUANTITY .
WA_POACCOUNT-GL_ACCOUNT = WA_FINAL-GL_ACCOUNT.
WA_POACCOUNT-COSTCENTER = WA_FINAL-COSTCENTER.
WA_POACCOUNT-CO_AREA = WA_FINAL-CO_AREA.
APPEND WA_POACCOUNT TO IT_POACCOUNT.
CLEAR WA_POACCOUNT.
*insert IT_POACCOUNTX values
WA_POACCOUNTX-PO_ITEM = 00001.
WA_POACCOUNTX-SERIAL_NO = 01.
WA_POACCOUNTX-QUANTITY = 'X'.
WA_POACCOUNTX-GL_ACCOUNT = 'X'.
WA_POACCOUNTX-COSTCENTER = 'X' .
WA_POACCOUNTX-CO_AREA = 'X'.
APPEND WA_POACCOUNTX TO IT_POACCOUNTX.
CLEAR WA_POACCOUNTX.
ENDLOOP.
***********************************************************************
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = ST_BAPIMEPOHEADER
POHEADERX = ST_BAPIMEPOHEADERX
POADDRVENDOR =
TESTRUN =
MEMORY_UNCOMPLETE =
MEMORY_COMPLETE =
POEXPIMPHEADER =
POEXPIMPHEADERX =
VERSIONS =
IMPORTING
EXPPURCHASEORDER =
EXPHEADER =
EXPPOEXPIMPHEADER =
TABLES
RETURN = IT_RETURN
POITEM = IT_POITEM
POITEMX = IT_POITEMX
POADDRDELIVERY =
POSCHEDULE = IT_POSCHEDULE
POSCHEDULEX = IT_POSCHEDULEX
POACCOUNT = IT_POACCOUNT
POACCOUNTPROFITSEGMENT =
POACCOUNTX = IT_POACCOUNTX
POCONDHEADER =
POCONDHEADERX =
POCOND =
POCONDX =
POLIMITS =
POCONTRACTLIMITS =
POSERVICES =
POSRVACCESSVALUES =
POSERVICESTEXT =
EXTENSIONIN =
EXTENSIONOUT =
POEXPIMPITEM =
POEXPIMPITEMX =
POTEXTHEADER =
POTEXTITEM =
ALLVERSIONS =
POPARTNER =
.
*this is for save the porder number
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
*dispaly the results
LOOP AT IT_RETURN INTO WA_RETURN.
WRITE:/ WA_RETURN-MESSAGE,
ST_BAPIMEPOHEADER-PO_NUMBER.
ENDLOOP.
form upload_data.
data: file type rlgrap-filename.
data: IT_XCEL type table of alsmex_tabline,
WA_XCEL TYPE ALSMEX_TABLINE.
file = p_file.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '21'
i_end_row = '1'
tables
intern = IT_xcel
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
loop at IT_xcel INTO WA_XCEL.
case
WA_XCEL-COL.
when '0001'.
WA_FINAL-COMP_CODE = WA_xcel-value.
WHEN '0002'.
WA_FINAL-ITEM_INTVL = WA_XCEL-VALUE.
WHEN '0003'.
WA_FINAL-VENDOR = WA_XCEL-VALUE.
WHEN '0004'.
WA_FINAL-PMNTTRMS = WA_XCEL-VALUE.
WHEN '0005'.
WA_FINAL-PURCH_ORG = WA_XCEL-VALUE.
WHEN '0006'.
WA_FINAL-PUR_GROUP = WA_XCEL-VALUE.
WHEN '0007'.
WA_FINAL-CURRENCY = WA_XCEL-VALUE.
WHEN '0008'.
WA_FINAL-PO_ITEM = WA_XCEL-VALUE.
WHEN '0009'.
WA_FINAL-MATERIAL = WA_XCEL-VALUE.
WHEN '00010'.
WA_FINAL-PLANT = WA_XCEL-VALUE.
WHEN '00011'.
WA_FINAL-STGE_LOC = WA_XCEL-VALUE.
WHEN '00012'.
WA_FINAL-QUANTITY = WA_XCEL-VALUE.
WHEN '00013'.
WA_FINAL-TAX_CODE = WA_XCEL-VALUE.
WHEN '00014'.
WA_FINAL-ITEM_CAT = WA_XCEL-VALUE.
WHEN '00015'.
WA_FINAL-ACCTASSCAT = WA_XCEL-VALUE.
WHEN '00016'.
WA_FINAL-SCHED_LINE = WA_XCEL-VALUE.
WHEN '00017'.
WA_FINAL-DELIVERY_DATE = WA_XCEL-VALUE.
WHEN '00018'.
WA_FINAL-SERIAL_NO = WA_XCEL-VALUE.
WHEN '00019'.
WA_FINAL-GL_ACCOUNT = WA_XCEL-VALUE.
WHEN '00020'.
WA_FINAL-COSTCENTER = WA_XCEL-VALUE.
WHEN '00021'.
WA_FINAL-CO_AREA = WA_XCEL-VALUE.
ENDCASE.
at end of row.
append WA_FINAL TO IT_FINAL.
clear WA_FINAL.
endat.
ENDLOOP.
ENDFORM.
2008 Apr 16 4:45 AM
i have done according to my thought, i don't know exactly.i think its a database problem.
2008 Apr 16 4:58 AM
Hi,
Try this one yaar.
*&---------------------- VARIABLE DECLARATION ------------------------*
* For Storing file name.
DATA : filename1 TYPE string.
* Flag to identify the matching entries
DATA : flag(1).
* For Display Message
DATA : g_msg(80) TYPE c.
* Declaring that as a character with length 4096.
TYPES truxs_t_text_data(4096) TYPE c OCCURS 0. " Type Group : TRUXS
* Containing RAW Data
DATA : it_raw TYPE truxs_t_text_data.
*&------------------------- INTERNAL TABLE ---------------------------*
DATA: gstest LIKE bapimepoheader.
DATA: g_ebeln LIKE bapimepoheader-po_number.
DATA: BEGIN OF g_bapimepoheader OCCURS 0.
INCLUDE STRUCTURE bapimepoheader.
DATA: END OF g_bapimepoheader.
DATA: BEGIN OF g_bapimepoheaderx OCCURS 0.
INCLUDE STRUCTURE bapimepoheaderx.
DATA: END OF g_bapimepoheaderx.
DATA: BEGIN OF g_bapimeposchedule OCCURS 0.
INCLUDE STRUCTURE bapimeposchedule.
DATA: END OF g_bapimeposchedule.
DATA: BEGIN OF g_poschedulex OCCURS 0.
INCLUDE STRUCTURE bapimeposchedulx.
DATA: END OF g_poschedulex.
*DATA: BEGIN OF g_bapieikp OCCURS 0.
* INCLUDE STRUCTURE bapieikp.
*DATA: END OF g_bapieikp.
DATA: BEGIN OF g_bapimepoitem OCCURS 0.
INCLUDE STRUCTURE bapimepoitem.
DATA: END OF g_bapimepoitem.
DATA: BEGIN OF g_poitemx OCCURS 0.
INCLUDE STRUCTURE bapimepoitemx.
DATA: END OF g_poitemx.
DATA: BEGIN OF g_bapiret2 OCCURS 0.
INCLUDE STRUCTURE bapiret2.
DATA: END OF g_bapiret2.
DATA: BEGIN OF itab OCCURS 0,
doc_type LIKE bapimepoheader-doc_type,
vendor LIKE bapimepoheader-vendor,
purch_org LIKE bapimepoheader-purch_org,
pur_group LIKE bapimepoheader-pur_group,
comp_code LIKE bapimepoheader-comp_code,
incoterms1 LIKE bapimepoheader-incoterms1,
incoterms2 LIKE bapimepoheader-incoterms2,
po_item LIKE bapimepoitem-po_item,
material LIKE bapimepoitem-material,
short_text LIKE bapimepoitem-short_text,
quantity LIKE bapimepoitem-quantity,
plant LIKE bapimepoitem-plant,
delivery_date LIKE bapimeposchedule-delivery_date,
END OF itab.
DATA: it_itab LIKE itab OCCURS 0 WITH HEADER LINE.
*&------------------------ SELECTION SCREEN --------------------------*
SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-100.
PARAMETERS : p_file LIKE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK blk.
*&-----------------------AT SELECTION SCREEN -------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
* For getting input filename
PERFORM get_filename.
*&-----------------------START OF SELECTION---------------------------*
START-OF-SELECTION.
* Open the Excel file and Update with the internal table
PERFORM update_inttable.
PERFORM bapi_upload.
*---------------------------------------------------------------------*
* FORM bapi_upload *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM bapi_upload.
it_itab[] = itab[].
SORT itab BY vendor material.
DELETE ADJACENT DUPLICATES FROM itab COMPARING vendor.
LOOP AT itab.
g_bapimepoheader-comp_code = itab-comp_code.
g_bapimepoheader-doc_type = itab-doc_type.
g_bapimepoheader-creat_date = sy-datum.
g_bapimepoheader-created_by = sy-uname.
g_bapimepoheader-vendor = itab-vendor.
g_bapimepoheader-purch_org = itab-purch_org.
g_bapimepoheader-pur_group = itab-pur_group.
g_bapimepoheader-incoterms1 = itab-incoterms1.
g_bapimepoheader-incoterms2 = itab-incoterms2.
APPEND g_bapimepoheader.
g_bapimepoheaderx-comp_code = 'X'.
g_bapimepoheaderx-vendor = 'X'.
g_bapimepoheaderx-doc_type = 'X'.
g_bapimepoheaderx-purch_org = 'X'.
g_bapimepoheaderx-pur_group = 'X'.
g_bapimepoheaderx-incoterms1 = 'X'.
g_bapimepoheaderx-incoterms2 = 'X'.
APPEND g_bapimepoheaderx.
LOOP AT it_itab WHERE vendor = itab-vendor.
MOVE-CORRESPONDING it_itab TO g_bapimepoitem.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = it_itab-material
IMPORTING
output = it_itab-material.
g_bapimepoitem-material = it_itab-material.
APPEND g_bapimepoitem.
g_poitemx-po_item = it_itab-po_item.
g_poitemx-po_itemx = 'X'.
g_poitemx-item_cat = 'X'.
g_poitemx-plant = 'X'.
g_poitemx-stge_loc = 'X'.
g_poitemx-net_price = 'X'.
g_poitemx-acctasscat = 'X'.
g_poitemx-material = 'X'.
g_poitemx-short_text = 'X'.
g_poitemx-matl_group = 'X'.
g_poitemx-quantity = 'X'.
g_poitemx-po_unit = 'X'.
g_poitemx-orderpr_un = 'X'.
g_poitemx-trackingno = 'X'.
g_poitemx-delete_ind = 'X'.
APPEND g_poitemx.
g_bapimeposchedule-po_item = it_itab-po_item.
g_bapimeposchedule-sched_line = '001'.
g_bapimeposchedule-del_datcat_ext = 'D'.
g_bapimeposchedule-delivery_date = it_itab-delivery_date.
g_bapimeposchedule-quantity = it_itab-quantity.
APPEND g_bapimeposchedule.
g_poschedulex-po_item = it_itab-po_item.
g_poschedulex-sched_line = '001'.
g_poschedulex-po_itemx = 'X'.
g_poschedulex-sched_linex = 'X'.
g_poschedulex-del_datcat_ext = 'X'.
g_poschedulex-delivery_date = 'X'.
g_poschedulex-quantity = 'X'.
g_poschedulex-deliv_time = 'X'.
g_poschedulex-stat_date = 'X'.
APPEND g_poschedulex.
ENDLOOP.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = g_bapimepoheader
poheaderx = g_bapimepoheaderx
IMPORTING
exppurchaseorder = g_ebeln
expheader = gstest
TABLES
return = g_bapiret2
poitem = g_bapimepoitem
poitemx = g_poitemx
poschedule = g_bapimeposchedule
poschedulex = g_poschedulex.
IF NOT g_ebeln IS INITIAL.
COMMIT WORK.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = ''.
REFRESH : g_bapimepoitem,
g_bapimepoheader,
g_bapimepoheaderx,
g_bapiret2,
g_poitemx,
g_bapimeposchedule,
g_poschedulex.
ENDIF.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM GET_FILENAME *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM get_filename.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = sy-cprog
dynpro_number = sy-dynnr
field_name = ''
IMPORTING
file_name = p_file.
ENDFORM.
*---------------------------------------------------------------------*
* FORM UPDATE_INTTABLE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM update_inttable.
REFRESH : itab[] , itab.
CLEAR : itab.
IF NOT p_file IS INITIAL.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = it_raw " WORK TABLE
i_filename = p_file
TABLES
i_tab_converted_data = itab[] " ACTUAL DATA
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc NE '0'.
PERFORM callerr USING 'File Error!'.
STOP.
ENDIF.
ELSE.
PERFORM callerr USING 'Choose the file'.
STOP.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM CALLERR *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> TEXT *
*---------------------------------------------------------------------*
FORM callerr USING text TYPE string.
CALL FUNCTION 'FC_POPUP_ERR_WARN_MESSAGE'
EXPORTING
popup_title = 'ZMM_BAPI_PO_CREATE'
is_error = 'X'
message_text = text
start_column = 30
start_row = 8.
ENDFORM.
reward if helpful
raam
2008 Apr 18 5:43 AM
IN OUR COMPANY, WE MUST NOT TAKE OCCURS OR HEADER LINE.ANYHOW THANK U VERY MUCH FOR YOUR HELP.
HERE I SOLVED AND GOT THE ANSWER.
types: begin of OUTPUT,
VENDOR TYPE BAPIMEPOHEADER-VENDOR,
PURCH_ORG TYPE BAPIMEPOHEADER-PURCH_ORG,
PUR_GROUP TYPE BAPIMEPOHEADER-PUR_GROUP,
COMP_CODE TYPE BAPIMEPOHEADER-COMP_CODE,
DOC_TYPE TYPE BAPIMEPOHEADER-DOC_TYPE,
DOC_DATE TYPE BAPIMEPOHEADER-DOC_DATE,
CURRENCY TYPE BAPIMEPOHEADER-CURRENCY,
REF_1 TYPE BAPIMEPOHEADER-REF_1,
OUR_REF TYPE BAPIMEPOHEADER-OUR_REF,
PO_ITEM TYPE BAPIMEPOITEM-PO_ITEM,
MATERIAL TYPE BAPIMEPOITEM-MATERIAL,
SHORT_TEXT TYPE BAPIMEPOITEM-SHORT_TEXT,
QUANTITY TYPE BAPIMEPOITEM-QUANTITY,
NET_PRICE TYPE BAPIMEPOITEM-NET_PRICE,
ACCTASSCAT TYPE BAPIMEPOITEM-ACCTASSCAT,
MATL_GROUP TYPE BAPIMEPOITEM-MATL_GROUP,
PLANT TYPE BAPIMEPOITEM-PLANT,
DEL_DATCAT_EXT TYPE BAPIMEPOSCHEDULE-DEL_DATCAT_EXT,
DELIVERY_DATE TYPE BAPIMEPOSCHEDULE-DELIVERY_DATE,
END OF OUTPUT.
DATA : IT_OUTPUT TYPE TABLE OF OUTPUT,
WA_OUTPUT TYPE OUTPUT.
*************************************************************************************************
DATA: WA_POHEADER TYPE BAPIMEPOHEADER,
WA_POHEADERX TYPE BAPIMEPOHEADERX.
DATA: WA_POITEM TYPE BAPIMEPOITEM,
IT_POITEM TYPE TABLE OF BAPIMEPOITEM,
WA_POITEMX TYPE BAPIMEPOITEMX,
IT_POITEMX TYPE TABLE OF BAPIMEPOITEMX,
WA_POSCHEDULE TYPE BAPIMEPOSCHEDULE,
IT_POSCHEDULE TYPE TABLE OF BAPIMEPOSCHEDULE,
WA_POSCHEDULEX TYPE BAPIMEPOSCHEDULX,
IT_POSCHEDULEX TYPE TABLE OF BAPIMEPOSCHEDULX,
WA_POACCOUNT TYPE BAPIMEPOACCOUNT,
IT_POACCOUNT TYPE TABLE OF BAPIMEPOACCOUNT,
WA_POACCOUNTX TYPE BAPIMEPOACCOUNTX,
IT_POACCOUNTX TYPE TABLE OF BAPIMEPOACCOUNTX,
WA_RETURN TYPE BAPIRET2,
IT_RETURN TYPE TABLE OF BAPIRET2,
PURCHASINGDOCUMENT TYPE BAPIMEPOHEADER-PO_NUMBER,
EXPPOEXPIMPHEADER TYPE BAPIEIKP,
EXP_HEADER TYPE BAPIMEPOHEADER.
*******************************************************************************************************************************
parameters: p_file type localfile default 'D:\Vishnu\ex.xls'.
at selection-screen on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
exporting
static =
'X'
changing
file_name = p_file.
start-of-selection.
perform upload_data.
loop at IT_OUTPUT INTO WA_OUTPUT.
write:/ WA_OUTPUT-VENDOR,
/ WA_OUTPUT-PURCH_ORG,
/ WA_OUTPUT-PUR_GROUP,
/ WA_OUTPUT-COMP_CODE,
/ WA_OUTPUT-DOC_TYPE,
/ WA_OUTPUT-DOC_DATE,
/ WA_OUTPUT-CURRENCY,
/ WA_OUTPUT-REF_1,
/ WA_OUTPUT-OUR_REF,
/ WA_OUTPUT-PO_ITEM,
/ WA_OUTPUT-MATERIAL,
/ WA_OUTPUT-SHORT_TEXT,
/ WA_OUTPUT-QUANTITY,
/ WA_OUTPUT-NET_PRICE,
/ WA_OUTPUT-ACCTASSCAT,
/ WA_OUTPUT-MATL_GROUP,
/ WA_OUTPUT-PLANT,
/ WA_OUTPUT-DEL_DATCAT_EXT,
/ WA_OUTPUT-DELIVERY_DATE.
endloop.
********** ************************************************* ************************************************
LOOP AT IT_OUTPUT INTO WA_OUTPUT.
WA_POHEADER-VENDOR = WA_OUTPUT-VENDOR.
WA_POHEADER-PURCH_ORG = WA_OUTPUT-PURCH_ORG.
WA_POHEADER-PUR_GROUP = WA_OUTPUT-PUR_GROUP.
WA_POHEADER-COMP_CODE = WA_OUTPUT-COMP_CODE.
WA_POHEADER-DOC_TYPE = WA_OUTPUT-DOC_TYPE.
WA_POHEADER-DOC_DATE = WA_OUTPUT-DOC_DATE.
WA_POHEADER-CURRENCY = WA_OUTPUT-CURRENCY.
WA_POHEADER-REF_1 = WA_OUTPUT-REF_1.
WA_POHEADER-OUR_REF = WA_OUTPUT-OUR_REF.
WA_POHEADERX-VENDOR = 'X'.
WA_POHEADERX-PURCH_ORG = 'X'.
WA_POHEADERX-PUR_GROUP = 'X'.
WA_POHEADERX-COMP_CODE = 'X'.
WA_POHEADERX-DOC_TYPE = 'X'.
WA_POHEADERX-DOC_DATE = 'X'.
WA_POHEADERX-CURRENCY = 'X'.
WA_POHEADER-REF_1 = 'X'.
WA_POHEADER-OUR_REF = 'X'.
WA_POITEM-PO_ITEM = WA_OUTPUT-PO_ITEM.
WA_POITEM-MATERIAL = WA_OUTPUT-MATERIAL.
WA_POITEM-SHORT_TEXT = WA_OUTPUT-SHORT_TEXT.
WA_POITEM-QUANTITY = WA_OUTPUT-QUANTITY.
WA_POSCHEDULE-PO_ITEM = WA_OUTPUT-PO_ITEM.
WA_POSCHEDULE-DEL_DATCAT_EXT = WA_OUTPUT-DEL_DATCAT_EXT.
WA_POSCHEDULE-DELIVERY_DATE = WA_OUTPUT-DELIVERY_DATE.
WA_POSCHEDULE-QUANTITY = WA_OUTPUT-QUANTITY.
WA_POITEM-NET_PRICE = WA_OUTPUT-NET_PRICE.
WA_POITEM-ACCTASSCAT = WA_OUTPUT-ACCTASSCAT.
WA_POITEM-MATL_GROUP = WA_OUTPUT-MATL_GROUP.
WA_POITEM-PLANT = WA_OUTPUT-PLANT.
APPEND WA_POITEM TO IT_POITEM.
CLEAR WA_POITEM.
APPEND WA_POSCHEDULE TO IT_POSCHEDULE.
CLEAR WA_POSCHEDULE.
WA_POITEMX-PO_ITEM = WA_OUTPUT-PO_ITEM.
WA_POITEMX-PO_ITEMX = 'X'.
WA_POITEMX-MATERIAL = 'X'.
WA_POITEMX-SHORT_TEXT = 'X'.
WA_POITEMX-QUANTITY = 'X'.
WA_POSCHEDULEX-PO_ITEM = WA_OUTPUT-PO_ITEM.
WA_POSCHEDULEX-DEL_DATCAT_EXT = 'X'.
WA_POSCHEDULEX-DELIVERY_DATE = 'X'.
WA_POSCHEDULEX-QUANTITY = 'X'.
WA_POITEMX-NET_PRICE = 'X'.
WA_POITEMX-MATL_GROUP = 'X'.
WA_POITEMX-PLANT = 'X'.
APPEND WA_POITEMX TO IT_POITEMX.
CLEAR WA_POITEMX.
APPEND WA_POSCHEDULEX TO IT_POSCHEDULEX.
CLEAR WA_POSCHEDULEX.
ENDLOOP.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = WA_POHEADER
POHEADERX = WA_POHEADERX
IMPORTING
EXPPURCHASEORDER = PURCHASINGDOCUMENT
EXPHEADER = EXP_HEADER
EXPPOEXPIMPHEADER = EXPPOEXPIMPHEADER
TABLES
RETURN = IT_RETURN
POITEM = IT_POITEM
POITEMX = IT_POITEMX
POSCHEDULE = IT_POSCHEDULE
POSCHEDULEX = IT_POSCHEDULEX.
*this is for save the porder number
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
*dispaly the results
LOOP AT IT_RETURN INTO WA_RETURN.
WRITE:/ WA_RETURN-MESSAGE,
WA_POHEADER-PO_NUMBER.
ENDLOOP.
********************************* ************************
************************************************************************
Upload_Data
************************************************************************
form upload_data.
data: file type rlgrap-filename.
data: IT_EX type table of alsmex_tabline,
WA_EX TYPE ALSMEX_TABLINE.
file = p_file.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '19'
i_end_row = '1'
tables
intern = IT_EX
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
loop at IT_EX INTO WA_EX.
case
WA_EX-COL.
WHEN '0001'.
WA_OUTPUT-VENDOR = WA_EX-VALUE.
when '0002'.
WA_OUTPUT-PURCH_ORG = WA_EX-value.
when '0003'.
WA_OUTPUT-PUR_GROUP = WA_EX-value.
when '0004'.
WA_OUTPUT-COMP_CODE = WA_EX-value.
when '0005'.
WA_OUTPUT-DOC_TYPE = WA_EX-value.
WHEN '0006'.
WA_OUTPUT-DOC_DATE = WA_EX-VALUE.
when '0007'.
WA_OUTPUT-CURRENCY = WA_EX-VALUE.
when '0008'.
WA_OUTPUT-REF_1 = WA_EX-value.
when '0009'.
WA_OUTPUT-OUR_REF = WA_EX-value.
when '00010'.
WA_OUTPUT-PO_ITEM = WA_EX-value.
when '00011'.
WA_OUTPUT-MATERIAL = WA_EX-value.
when '00012'.
WA_OUTPUT-SHORT_TEXT = WA_EX-value.
when '00013'.
WA_OUTPUT-QUANTITY = WA_EX-value.
when '00014'.
WA_OUTPUT-NET_PRICE = WA_EX-value.
when '00015'.
WA_OUTPUT-ACCTASSCAT = WA_EX-value.
when '00016'.
WA_OUTPUT-MATL_GROUP = WA_EX-value.
when '00017'.
WA_OUTPUT-PLANT = WA_EX-value.
when '00018'.
WA_OUTPUT-DEL_DATCAT_EXT = WA_EX-value.
when '00019'.
WA_OUTPUT-DELIVERY_DATE = WA_EX-value.
endcase.
at end of row.
append WA_OUTPUT TO IT_OUTPUT.
endat.
endloop.
endform.