10-11-2007 11:59 AM
Hi Experts,
I have a file for eg. data.csv on the application server and i want to transfer its contents to an internal table.
i tried using function module 'KCD_CSV_FILE_TO_INTERN_CONVERT' but it gives the UPLOAD_CSV exception.
Please suggest..
Thanks and Regards.
10-11-2007 12:03 PM
data: lv_record type string.
Read the file contents into a string variable
clear: lv_record.
read dataset p_infile into lv_record.
if sy-subrc = 0.
split lv_record at ',' into gtab-fld1 gtab-fld2 gtab-fld3..
else.
exit.
endif.
use above logic.
Cheers
Shakir
10-11-2007 12:04 PM
you can do something like this..
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.
10-11-2007 12:10 PM
Hi
Since the File is on App server u must use the OPEN DATASET, READ DATASET...
This is the sample code:
DATA: V_RECORD(200).
OPEN DATASET P_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
DO.
READ DATASET P_FILE INTO V_RECORD.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
SPLIT V_Record at ','
INTO WA-FIELD1 WA-FIELD2.
APPEND WA TO ITAB.
ENDDO.
<b>REWARD IF HELPFUL.</b>