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: 

how to read tab delimited text file line by line in internal table?????

Former Member
0 Kudos

Hello experts,

IS there any Function module for reading text file line by line??

I have following internal table

types : begin of ty_itab,

line(3000),

end of ty_itab.

Data : it_itab type standard table of ty_itab with header line.

My input file is tab delimited text file.

I want to read file in internal table it_itab.

Plz provide me any function module for this.

I tried gui_upload but it does not give output as I want.

-Shweta

10 REPLIES 10

Former Member
0 Kudos

Why not just import the file and then loop at the internal table and filter out the entries you don't need.

Former Member
0 Kudos

Hi,

Can you paste your code here, coz GUI_UPLOAD IS THE FM which you need to use..also let us know what are your requirements in the format ..

santhosh

Former Member
0 Kudos

Hi,

GUI_UPLOAD is getting the result u wanted.


TYPES : BEGIN OF ty_itab,
          line(3000),
        END OF ty_itab.
        
DATA : it_itab TYPE STANDARD TABLE OF ty_itab WITH HEADER LINE.

CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename                      = 'C:\SDN.TXT'
*   FILETYPE                      = 'ASC'
*   HAS_FIELD_SEPARATOR           = ' '
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
*   VIRUS_SCAN_PROFILE            =
*   NO_AUTH_CHECK                 = ' '
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  TABLES
    data_tab                      = it_itab

          .

Former Member
0 Kudos

Try this...

Upload Tab delimited file from application server into internal table

ABAP code for uploading a TAB delimited file into an internal table. See code below for structures. The code is based on uploading a simple txt file.

&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

*& Report ZUPLOADTAB *

*& *

&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

*& Example of Uploading tab delimited file *

*& *

&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

REPORT zuploadtab .

PARAMETERS: p_infile LIKE rlgrap-filename

OBLIGATORY DEFAULT u2018/usr/sap/u2019..

DATA: ld_file LIKE rlgrap-filename.

*Internal tabe to store upload data

TYPES: BEGIN OF t_record,

name1 like pa0002-VORNA,

name2 like pa0002-name2,

age type i,

END OF t_record.

DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,

wa_record TYPE t_record.

*Text version of data table

TYPES: begin of t_uploadtxt,

name1(10) type c,

name2(15) type c,

age(5) type c,

end of t_uploadtxt.

DATA: wa_uploadtxt TYPE t_uploadtxt.

*String value to data in initially.

DATA: wa_string(255) type c.

constants: con_tab TYPE x VALUE u201809u2032.

*If you have Unicode check active in program attributes then you will

*need to declare constants as follows:

*class cl_abap_char_utilities definition load.

*constants:

  • con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

************************************************************************

*START-OF-SELECTION

START-OF-SELECTION.

ld_file = p_infile.

OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

ELSE.

DO.

CLEAR: wa_string, wa_uploadtxt.

READ DATASET ld_file INTO wa_string.

IF sy-subrc NE 0.

EXIT.

ELSE.

SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1

wa_uploadtxt-name2

wa_uploadtxt-age.

MOVE-CORRESPONDING wa_uploadtxt TO wa_upload.

APPEND wa_upload TO it_record.

ENDIF.

ENDDO.

CLOSE DATASET ld_file.

ENDIF.

************************************************************************

*END-OF-SELECTION

END-OF-SELECTION.

*!! Text data is now contained within the internal table IT_RECORD

  • Display report data for illustration purposes

loop at it_record into wa_record.

write:/ sy-vline,

(10) wa_record-name1, sy-vline,

(10) wa_record-name2, sy-vline,

(10) wa_record-age, sy-vline.

endloop.

regards

vivek

0 Kudos

hello Vivek,

This program is exactly meet my requirement.But my loading file is txt file and having 9 columns.

My purpose i want to maintain historic data in a table.i will upload daily in cg3z with daily date.

I am attaching the file which i need to load in application server.

and everyday minimum record is 200000.

can you please help me out?

I am new to SAP ABAP.I am really confused in internal table and structure.

Thanks

former_member15255
Active Participant
0 Kudos

Hello,

Try Making use of Split Command

SPLIT dobj AT sep INTO

{ {result1 result2 ...} | {TABLE result_tab} }

regards

Suresh Nair

Former Member
0 Kudos

My input file strucure is not fix... no of columns may varry....

i have only one column in my internal table. i want to read whole row from file in internal table.

for example my input file is like:

abc prq 123 ....

www 678 455 ...

i want to read this input file as it is in my it_itab.

i tried with fm gou_upload.. but it reads only first col in file i.e abc and www

how to read whole line in one column of internal table.?????

0 Kudos

hi...

use example given by me...it will work in ur case.

regards

vivek

Former Member
0 Kudos

Hi,

Make sure in GUI_UPLOAD the parameter

HAS_FIELD_SEPARATOR = ' '

is not 'X' and it is Space then it would read the total line.

santhosh

Former Member
0 Kudos

thanks