2007 May 23 11:50 AM
Hello friends,
How to upload a CSV file into internal table and provide data to BAPI?
Could you give one example.
Hello friends,
How to upload a CSV file into internal table and provide data to BAPI?
Could you give one example.
2007 May 23 12:04 PM
hi,
TYPES : BEGIN OF ty_data,
data TYPE char2000,
END OF ty_data.
data : it_data TYPE STANDARD TABLE OF ty_data,
wa_data type ty_data.
let
v_filepath = //pmicstc.in.com/sing/factory/1234.csv.
1234.csv has three columns data (market, product, quantity)
so declare an internal table with these three fields
TYPES : BEGIN OF ty_csv,
markt TYPE zmarket,
matnr TYPE matnr,
quan(15),
END OF ty_csv.
data it_csv type standara table of ty_csv,
wa_csv type ty_csv.
*Open the file and transfer the data into the internal table
OPEN DATASET v_filepath "file path from application server..
FOR
INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
DO.
READ DATASET v_filepath
INTO wa_data .
IF sy-subrc = 0.
APPEND wa_data TO it_data. "it_data will cotains all the rows with delimeter comma
CLEAR wa_data.
ELSE.
EXIT.
ENDIF.
ENDDO.
Now get that file into it_csv
LOOP AT it_data INTO wa_data.
*Spliting the File and appending internal table
SPLIT wa_data AT ',' INTO wa_csv-markt
wa_csv-matnr
wa_csv-quan .
APPEND wa_csv TO it_csv.
ENDLOOP.
now you can loop on it_csv and pass data to BAPI..
This coding will work for sure
rewards if useful..
regards,
nazeer
null
2007 May 23 12:17 PM
Hope the code below serves ypur purpose.
.
DATA: BEGIN OF itab OCCURS 0,
vbeln LIKE vbak-vbeln,
ernam LIKE vbak-ernam,
END OF itab.
DATA itab2 LIKE TABLE OF KCDE_CELLS WITH HEADER LINE.
CALL FUNCTION 'KCD_CSV_FILE_TO_INTERN_CONVERT'
EXPORTING
i_filename = 'D:\data\upl.txt'
i_separator = ','
tables
e_intern = itab2
EXCEPTIONS
UPLOAD_CSV = 1
UPLOAD_FILETYPE = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT itab2.
SPLIT itab2-value AT ',' INTO itab-vbeln itab-ernam.
APPEND itab.
CLEAR itab.
ENDLOOP.
Pass the table ITAB to your BAPI
2007 May 23 1:43 PM
Hi,
You can upload data from presentation server to an internal table using gui_upload. Use gui_download to download from internal table to flat file.
The FILETYPE refer to the type of file format you need: For e.g 'WK1' - Excel format , 'ASC' - Text Format etc.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\test.csv'
FILETYPE = 'ASC'
TABLES
DATA_TAB = itab
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17.
Hope this helps.
Reward if helpful.
Regards,
Sipra
2011 Jun 16 2:14 PM