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: 

Flat file to internal table

Former Member
0 Kudos

Hi all,

I have a structure where i am reading flat file from Open Dataset in text mode in a variable of character type with length 1000.

then seperating the fields from that row by horizontal tab.

now i got values in structure and i want to store it in internal table.

Pls tell me how to do it.

My Code is like this:

DATA: BEGIN OF str_bsik,

bukrs TYPE bsik-bukrs,

lifnr TYPE bsik-lifnr,

gjahr TYPE bsik-gjahr,

belnr TYPE bsik-belnr,

END OF str_bsik.

DATA: it_bsik_flat TYPE STANDARD TABLE OF str_bsik "Flat file values

INITIAL SIZE 0, it_bsik_flat_wa TYPE str_bsik.

data : infile(20) type C value 'vendor8', "Default Flat File.

V_RECORD(1000) type C. "to store 1 row.

OPEN DATASET infile FOR INPUT IN TEXT MODE encoding default.

DO.

READ DATASET infile INTO V_RECORD.

SPLIT V_RECORD

AT cl_abap_char_utilities=>horizontal_tab

INTO

str_bsik-bukrs

str_bsik-lifnr

str_bsik-gjahr

str_bsik-belnr.

IF sy-subrc <> 0 or V_RECORD = ''.

EXIT.

ELSE.

MOVE str_bsik-bukrs to it_bsik_flat_wa-bukrs.

MOVE str_bsik-lifnr to it_bsik_flat_wa-lifnr.

MOVE str_bsik-gjahr to it_bsik_flat_wa-gjahr.

MOVE str_bsik-belnr to it_bsik_flat_wa-belnr.

append str_bsik to it_bsik_flat_wa.

ENDIF.

ENDDO.

CLOSE DATASET infile.

Regards,

Sachin.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Sachin,

Your internal table is it_bsik_flat.

do not use this after move statements.

append str_bsik to it_bsik_flat_wa.

use this after move.

append it_bsik_flat_wa to it_bsik_flat.

Regards,

Ravi G

6 REPLIES 6

former_member223537
Active Contributor
0 Kudos

> My Code is like this:

> DATA: BEGIN OF str_bsik,

> bukrs TYPE bsik-bukrs,

> lifnr TYPE bsik-lifnr,

> gjahr TYPE bsik-gjahr,

> belnr TYPE bsik-belnr,

> END OF str_bsik.

> it_bsik_flat TYPE STANDARD TABLE OF str_bsik "Flat

> file values

> INITIAL SIZE 0, it_bsik_flat_wa TYPE

> str_bsik.

>

>

> data : infile(20) type C value 'vendor8', "Default

> Flat File.

> V_RECORD(1000) type C. "to

> store 1 row.

>

> OPEN DATASET infile FOR INPUT IN TEXT MODE encoding

> default.

>

> DO.

> READ DATASET infile INTO V_RECORD.

> SPLIT V_RECORD

> AT cl_abap_char_utilities=>horizontal_tab

> INTO

> str_bsik-bukrs

> str_bsik-lifnr

> str_bsik-gjahr

> str_bsik-belnr.

> IF sy-subrc <> 0 or V_RECORD = ''.

> EXIT.

> ELSE.

> MOVE str_bsik-bukrs to it_bsik_flat_wa-bukrs.

> MOVE str_bsik-lifnr to it_bsik_flat_wa-lifnr.

> MOVE str_bsik-gjahr to it_bsik_flat_wa-gjahr.

> MOVE str_bsik-belnr to it_bsik_flat_wa-belnr.

> append str_bsik to <b>it_bsik_flat</b>.

> ENDIF.

>

> ENDDO.

> CLOSE DATASET infile.

>

>

> Regards,

> Sachin.

<b> it_bsik_flat will have all the data</b>

0 Kudos

Hi prashant,

thats what. MOVE statement is giving error.

Regards,

Sachin

0 Kudos

use <b>append it_bsik_flat_wa to it_bsik_flat.</b>

after move.

Former Member
0 Kudos

u already have data in internal table it_bsik_flat_wa..

wht else u want?

Thanks and Best Regards,

Vikas Bittera.

Former Member
0 Kudos

Hi Sachin,

Your internal table is it_bsik_flat.

do not use this after move statements.

append str_bsik to it_bsik_flat_wa.

use this after move.

append it_bsik_flat_wa to it_bsik_flat.

Regards,

Ravi G

Former Member
0 Kudos