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

Upload file from presentation server and splitting fields

Former Member
0 Likes
1,672

Hi ,

I am trying to upload a file (tab delimited file) which has header data as well as item data. I need to separate header data and line item data and individual fields.

I am using GUI_UPLOAD to load the file into an internal table with one element with 250 character . Now I need to separate the fields depending on tab. How can I do this.

the file is of the format.

field1 field2 field3 -


>header heading.

1213 xxxx 2121 -


> values

field4 field5 field6 -


>item heading

XXXXXXXX 2132143 YYYYYYYYY -


> item values.

thanks,

Regards,

Hemanth

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,485

Hi Hemanth

If your structure only contains only one field of character type then SPILT your record with

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

and move respective fields to structure.Generally tab will be displayed as # in debugging.

constants:c_tab type c value cl_abap_char_utilities=>horizontal_tab.
loop at itab.

split itab-field at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB 
into f1 f2 f3.

itab_new-f1 = f1
itab_new-f2 = f2
itab_new-f3 = f3

append itab_new.
clear itab_new.

endloop.

(or)

If the defined record contains fields of structure then use function module 'GUI_UPLOAD'.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = LV_FILENAME
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = IT_DATA
EXCEPTIONS

Regards

Naresh

Hi Hemanth

If your structure only contains only one field of character type then SPILT your record with

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

and move respective fields to structure.Generally tab will be displayed as # in debugging.

constants:c_tab type c value cl_abap_char_utilities=>horizontal_tab.
loop at itab.

split itab-field at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB 
into f1 f2 f3.

itab_new-f1 = f1
itab_new-f2 = f2
itab_new-f3 = f3

append itab_new.
clear itab_new.

endloop.

(or)

If the defined record contains fields of structure then use function module 'GUI_UPLOAD'.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = LV_FILENAME
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = IT_DATA
EXCEPTIONS

Regards

Naresh

9 REPLIES 9
Read only

Former Member
0 Likes
1,485

Hi,

pass HAS_FIELD_SEPARATOR = 'X' for tab delimited file..

THanks,

Naren

Read only

Former Member
0 Likes
1,485

Hello Hemanth,

What U can do ii upload the data from file to an itab.

Read table itab index 2.

Move the header to first line of the final tab.

COnstant con_tab type X value 09.

SPLIT itab at contab into final tab field

Append final tab.

Vasanth

Read only

0 Likes
1,485

Hi ,

Thanks for the all the help. I feel I was not clear with my question.

The internal table looks like this in debug mode. Now I need to split individual fields into respective fields. some times few fields have no values. Then there will be more tabs to split.

1 Document Date#Document Type#Company Code#Posting Date#Currency#Reference#D

2 1/18/2007#RA#1100#1/22/2007#USD#mtrtest 987654#GL Upload1#######

3 Posting Key#G/L Account#Amount in Doc. Cur.#Cost Center#Text #Tax Code?#Co

4 40#73110#123.45#110200#Test Line 1#I0#######1080#

5 50#73210#-23.01##Test Line 2#I0##100000######

6 50#75310#-51.45##Test Line 3#I0###10001E#####

7 50#73210#-48.99##Test Line 4#I0####300002#0###

Read only

0 Likes
1,485

Hello,

If the itab doesnt have any values fro the field then if u split at # then blank value goes to the filed.

better create a structure similar to the file.

It will easirer for u to split.

Vasanth

Read only

amit_khare
Active Contributor
0 Likes
1,485

Hi,

Check the link, reply from Raghvendra, its a working example..

Regards,

Amit

Reward all helpul replies.

If you are looking in debugging mode, so the space in tab delimited file will always appear as # only.

Message was edited by:

Amit Khare

Read only

0 Likes
1,485

Hi Amit,

I have read this link. The problem is the '#" you see is not character , they are tabs, and what is the character for tab to split.

In the examples they declare c_tab as X. But split can take only character/ string type. And also the number of tabs vary depending field has value or not. sometime if there is no value in one field there can be 2 tabs.

thanks,

Regards,

Hemanth

Read only

Former Member
0 Likes
1,486

Hi Hemanth

If your structure only contains only one field of character type then SPILT your record with

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

and move respective fields to structure.Generally tab will be displayed as # in debugging.

constants:c_tab type c value cl_abap_char_utilities=>horizontal_tab.
loop at itab.

split itab-field at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB 
into f1 f2 f3.

itab_new-f1 = f1
itab_new-f2 = f2
itab_new-f3 = f3

append itab_new.
clear itab_new.

endloop.

(or)

If the defined record contains fields of structure then use function module 'GUI_UPLOAD'.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = LV_FILENAME
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = IT_DATA
EXCEPTIONS

Regards

Naresh

Read only

0 Likes
1,485

Hi Naresh,

Your solution worked and you deserve full points. Can you please explain me the logic of this. I am not so good at ABAP OO.

thanks,

Regards,

Hemanth

Read only

0 Likes
1,485

Hi Hemath,

Would you mind if I explain..:)

constants:c_tab type c value cl_abap_char_utilities=>horizontal_tab.

  • the above decalration is for recognizing the TAB character .

NOw onwards c_tab is nothing but the tab character(it will hold a hex value of the TAB character).

loop at itab.

  • For each record in the uploaded table,

split itab-field at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

into f1 f2 f3.

  • Split the continuos string with the TAB separator at the TAB into different variables f1,f2,f3 etc.

itab_new-f1 = f1

itab_new-f2 = f2

itab_new-f3 = f3

( Move the field values into another table)

append itab_new.

clear itab_new.

(Append them).

endloop.

Regards,

Ravi