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: 

Handle tab delimit file

Former Member
0 Kudos

Hi ,

I am trying to upload a tab delimited file which is of the format (header and item). This file is created using Excel.

FIELD1 FIELD2

value1 value2

FIELD3 FIELD4 FIELD5 FIELD6

value3 value4 value5 value6

I am upload the file using GUI_UPLOAD into a internal table of flat structure. Then I am splitting the fields by tab and moving the individual fields. The problem is field2 and field6 is moved along with a tab at the end ie the value2# and value6#. How can I remove the tab at the end of these fields. But if I create a tab delimited file using just notepad every this is fine. I really appreciate if someone can help.

thanks,

Regards,

Hemanth

Message was edited by: Hemanth raya

Here how it looks in debug mode after moving the fields.

DOC_DATE C 10 20070118

DOC_TYPE C 2 RA

COMP_CODE C 4 1100

PSTNG_DATE C 10 20070122

CURRENCY_ISO C 3 USD

REF_DOC_NO C 16 mtrtest 987654

HEADER_TXT C 25 GL Upload1######

1 ACCEPTED SOLUTION

Clemenss
Active Contributor
0 Kudos

Hi,

try this:

After GUI_UPLOAD into itab:


field-symbols:
  <string> type string,
  <itab> like itab,
  <field> type any.
data:
  lt_string type table of string.
loop at itab assigning <itab>.
  split itab at at cl_abap_char_utilities=>Horizontal_tab into table lt_string.
  loop at lt_string assigning <string>.
    assign component sy-tabix of structure wa_itab_final to <field>.
    replace cl_abap_char_utilities=>Horizontal_tab in <string> with ''.
    <field> = <string>.
  endloop.
  append wa_itab_final to itab_final,
endloop.
append
  endloop.

But I remember there is a parameter you can tell gui_upload that it's tab-delimited and then load direclty into target table.

Regards,

Clemens

8 REPLIES 8

abdul_hakim
Active Contributor
0 Kudos

For removing #

use either one of the below code...

split wa_string at cl_abap_char_utilities=>Horizontal_tab

into wa_itab-col0

wa_itab-col1.

or

CONSTANTS : c_tab TYPE x VALUE '09'.

split wa_string at C_tab

into wa_itab-col0

wa_itab-col1.

Cheers,

Hakim

Mark all useful answers.......

0 Kudos

Hi Hakim,

I am splitting the field in the same way. My problem is the last field contains tab along with value after splitting. Please see the values in debug mode I have posted.

thanks,

Hemanth

0 Kudos

hi

why there is a need to have a tab after a last field??

Could you plz explain me??

Cheers,

Hakim

0 Kudos

Hi Hakim,

The tab file has header and line item. And Header has 7 colum and item line has 13 column. When a tab file is created from excel it adds 6 tab at the end of header column. When I split, these extra 6 tabs are added to end of last field of header line.

thanks,

Regards,

Hemanth

0 Kudos

hi

Well pass HAS_FIELD_SEPARATOR = 'X' in GUI_UPLOAD and upload....

Cheers,

Hakim

0 Kudos

Hi Hakim,

You can pass field separator only when file and internal table has same structure. when you have different fields in header and different fields at line item you cannot use field separator. The only way is to load it to flat structure and separate the fields by tab separator......

Clemenss
Active Contributor
0 Kudos

Hi,

try this:

After GUI_UPLOAD into itab:


field-symbols:
  <string> type string,
  <itab> like itab,
  <field> type any.
data:
  lt_string type table of string.
loop at itab assigning <itab>.
  split itab at at cl_abap_char_utilities=>Horizontal_tab into table lt_string.
  loop at lt_string assigning <string>.
    assign component sy-tabix of structure wa_itab_final to <field>.
    replace cl_abap_char_utilities=>Horizontal_tab in <string> with ''.
    <field> = <string>.
  endloop.
  append wa_itab_final to itab_final,
endloop.
append
  endloop.

But I remember there is a parameter you can tell gui_upload that it's tab-delimited and then load direclty into target table.

Regards,

Clemens

Former Member
0 Kudos

Hi Clemens ,

thanks for the help. Your logic is excellent . I think the split command splits the fields into maximum no. of columns in the tab file and if no field is there in that row it inserts '#' in the field.

That was happening in my case. I had 7 header columns and 12 item column. So when we split into a table of string the table would have 12 rows for header. So when loop through the string table to replace ###, the last field is replaced with blank from 8 the row( which does not have any value ).

I was able to get away with the issue by having a dummy field in the header internal table and when I split the extra tabs are moved to the dummy field.

thanks,

Regards,

Hemanth