Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

want to convert .CSV file into an internal table

Former Member
0 Kudos

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.

3 REPLIES 3

abdulazeez12
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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.

varma_narayana
Active Contributor
0 Kudos

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>