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

UPLOADING A TEXT FILE

Former Member
0 Likes
1,744

hI,

i need to upload a txt file into ztable.I HAVE FEW UNWANTED FIELDS IN MY TEXT FILE.

i WANT TO READ ONLY THE USEFUL DATA INTO INTERNAL TABLE.

HOW SHOULD I MOVE THE DATA INTO INTERNAL TABLE WHEN I UPLOAD IT.

hOW CAN I KNOW WHETHER ITS A TAB DELIMITED FILE OR NOT.

tHANKS

6 REPLIES 6
Read only

Former Member
0 Likes
1,155

Hi deepthi,

Read all the data into internal table from text file and then get rid of the unwanted data.

Regards,

Vivek

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,155

I would suggest using a comma delimited file for all data upload, I think that it makes an easier. You can use GUI_UPLOAD to upload the test file. Make your internal table flat like....

data: itab type table of string with header line.

Then use GUI_UPLOAD to upload into ITAB.

Now you have an internal table with lots of rows with comma delimited data in it. Lets separate it..

Declase another internal table with your fields. Now loop at the ITAB and split it apart into your fields..

Loop at itab.

  clear itab2.
  split itab at ',' into itab2-fld1 itab2-fld2, itab2-fld3.
append itab2.
endloop.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,155

hi

good

do like this

1- store the text file in the excel format

2- delete the unnecessary column from the file in excel sheet

3- save it again into text file by choosing the option taxt(tab delimited).

4-delare the internal table(dont include the fields that you r not going to upload)

5-upload the data from the text file using bdc or lsmw

thanks

mrutyun^

Read only

baskaran00
Active Participant
0 Likes
1,155

Hi,

1. First u read the file and load it into ur internal table. U can use the FM GUI_UPLOAD.

2. Don't make any change to flat file. U create another structure where it has the needed fields alone.

Once u load the data into the internal table.

Copy the data into ur structure(Which has needed field).

Eg. it_neededfields[] = it_wholefields[].

This will copy the needed fields.

3.Open the file, at the end of the field place the cursor and press delete, if the next fields comes very closer, then it is tab delimiter field else if deletes only one space it is not a tab delimiter file.

Hope it will help u.

Read only

Former Member
0 Likes
1,155

Hi deepthi,

1. These are the steps, which we can follow :

a) create two internal tables.

1) for upload - with all fields available in text file eg. ITAB

2) for z table - exactly like z table.

eg PTAB

(make sure the field names are same)

b) then using GUI_UPLOAD,

upload in ITAB

c) Then use :

LOOP AT ITAB.

CLEAR PTAB.

MOVE-CORRESPONDING ITAB TO PTAB.

MODIFY ZDBTAB FROM PTAB.

ENDLOOP.

(Modify will automatically take care of

insert / update

based upon the primary key combination

found / not found in db table,

w.r.t to values in internal table work area.

)

2. hOW CAN I KNOW WHETHER ITS A TAB DELIMITED FILE OR NOT

U will have to open the file in notepad,

and look for yourself.

regards,

amit m.

Read only

Former Member
0 Likes
1,155

Hi,

<b>I WANT TO READ ONLY THE USEFUL DATA INTO INTERNAL TABLE.</b>

Here u have two options

a. delete the unwanted data directly from the text file.

(or)

b. read all data from text file to internal table using gui_upload function

then,

delete the unwanted data from the internal table itself

 
loop at itab.
if itab-f1 = 'xxxx'.
delete itab.
modify itab.
endloop.

or

move the required data to another internal table

 
loop at itab.
if itab-f1 <> 'xxxx'.
move-corresponding itab to itab2
endloop.

<b>HOW SHOULD I MOVE THE DATA INTO INTERNAL TABLE WHEN I UPLOAD IT.</b>

declare the an internal table of same structue as the internal table that u have used for uploading text file

then, use

itab2[] = itab[]. or

move itab[] to itab2[].

<b>HOW CAN I KNOW WHETHER ITS A TAB DELIMITED FILE OR NOT.</b>

goto end of the text file then use the tab button. Then if the cursor is positioning at the begin of field, we can say its is tab delimited. or the fields length may specified in characters.