2007 Feb 22 9:35 PM
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
2007 Feb 22 11:32 PM
Hi Hemanth
If your structure only contains only one field of character type then SPILT your record with
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TABand 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
EXCEPTIONSRegards
Naresh
Hi Hemanth
If your structure only contains only one field of character type then SPILT your record with
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TABand 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
EXCEPTIONSRegards
Naresh
2007 Feb 22 9:45 PM
Hi,
pass HAS_FIELD_SEPARATOR = 'X' for tab delimited file..
THanks,
Naren
2007 Feb 22 9:55 PM
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
2007 Feb 22 10:41 PM
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###
2007 Feb 22 10:48 PM
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
2007 Feb 22 10:48 PM
2007 Feb 22 10:55 PM
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
2007 Feb 22 11:32 PM
Hi Hemanth
If your structure only contains only one field of character type then SPILT your record with
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TABand 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
EXCEPTIONSRegards
Naresh
2007 Feb 23 3:24 PM
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
2007 Feb 23 3:43 PM
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
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |