Application Development and Automation 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: 
Read only

Updating internal table with CSV file

Former Member
0 Likes
850

I have a flat file as below:

aaaa, bbbb, asdc, dfgfhg, sdfsg, sdf, sdf, sdf, dfg, sdf, sgf, drgftfgh, sgf, drgtf, swftgd, sgf,

'sjhdfjhf','2003-10-11 07:52:37','167','alkjd',NULL,NULL,NULL,NULL,NULL,'MX1',NULL,NULL,'dkjffdj ,',NULL,NULL,NULL,'1',NULL,NULL,'AR, dfkj ',

Where we can see it is separated by commas.I want to upload this one into onr internal table.I used GUI_UPLOAD and gave the logic as folows:

TYPES: BEGIN OF ttab,

rec(1000) TYPE c,

END OF ttab.

TYPES: BEGIN OF tdat,

aaaa type char10

bbbb type char10,

asdc type char10,

dfgfhg type char10,

sdfsg type char10,

sdf type char10,

sdf type char10,

sdf type char10,

dfg type char10,

sdf type char10,

sgf type char10,

drgftfgh type char10,

sgf type char10,

drgtf type char10,

swftgd type char10,

sgf type char10,

END OF tdat.

DATA: itab TYPE TABLE OF ttab WITH HEADER LINE.

DATA: idat TYPE TABLE OF tdat WITH HEADER LINE.

DATA: file_str TYPE string.

PARAMETERS: p_file TYPE localfile.

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.

file_str = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = file_str

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.

LOOP AT itab.

CLEAR idat.

SPLIT itab-rec AT ',' INTO idat-aaaa

idat-bbbb ,

idat-asdc ,

idat-dfgfhg ,

idat-sdfsg ,

idat-sdf ,

idat-sdf ,

idat-sdf ,

idat-dfg ,

idat-sdf ,

idat-sgf ,

idat-drgftfgh ,

idat-sgf ,

idat-drgtf ,

idat-swftgd ,

idat-sgf ,

APPEND idat.

ENDLOOP.

Now the issue is when I use the statement SPLIT itab-rec AT ',' this is not updating the table idat properly.Because the flat file contains the value as 'dkjffdj ,', too.

Can anyone give me some solution to update the internal table.

4 REPLIES 4
Read only

Former Member
0 Likes
718

hI

or you delete ' from csv file before uploading it or after uploading it, in this last case u can use statament replace:

REPLACE ''' WITH SPACE INTO ITAB-FIELD.

Max

Read only

0 Likes
718

Hey Max,

Thanks for the reply.But my issue is the record are having comma value too.If I split at comma then the reocrd which has comma also gets splitted at comma.

Read only

Former Member
0 Likes
718

hi..

try replacing ,', with ', before splitting.

as in dfkj ,','asdasd', .

if u replace it will become dfkj ',asdasd',

will this work fro you??

Read only

0 Likes
718

Hi Sowmya,

These record values has been provided by customer and hence I can not change the value.