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

Split command

Former Member
0 Likes
885

Hello ,

Í´m uploading a file with OPEN DATASET fron the app server. I read the contents into a string. I then want to split the contents of each string into my internal table/ work area. For some reason it packs everything into the first field (type string). When I test with other data in the string, everything is fine. The contents of the string is eg. '01#AED#EUR#1001#' . I´m worried that the '#' symbol is for tabulator or something and therefore the SPLIT command does not work correctly. But if its a string it should recognise # as a symbol?

Thanks for any ideas?

Kevin

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
669

Here is some code....




report zrich_0002 .


parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.

data: begin of itab occurs 0,
      field1(20) type c,
      field2(20) type c,
      field3(20) type c,
      end of itab.
data: wa type string.

<b>CONSTANTS: con_tab TYPE x VALUE '09'.</b>

* if you have a newer version, then you can use this instead.
<b>*constants:
*    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB.</b>


start-of-selection.

  open dataset d1 for input in text mode.
  if sy-subrc = 0.
    do.
      read dataset d1 into wa.
      if sy-subrc <> 0.
        exit.
      endif.

* Here you are splitting at the hex value of "tab" not at
* the # sign.  

      split wa at con_tab into itab-field1 itab-field2 itab-field3.
      append itab.
    enddo.
  endif.
  close dataset d1.

This worked good in my system.

Regards,

Rich Heilman

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
670

Here is some code....




report zrich_0002 .


parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.

data: begin of itab occurs 0,
      field1(20) type c,
      field2(20) type c,
      field3(20) type c,
      end of itab.
data: wa type string.

<b>CONSTANTS: con_tab TYPE x VALUE '09'.</b>

* if you have a newer version, then you can use this instead.
<b>*constants:
*    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB.</b>


start-of-selection.

  open dataset d1 for input in text mode.
  if sy-subrc = 0.
    do.
      read dataset d1 into wa.
      if sy-subrc <> 0.
        exit.
      endif.

* Here you are splitting at the hex value of "tab" not at
* the # sign.  

      split wa at con_tab into itab-field1 itab-field2 itab-field3.
      append itab.
    enddo.
  endif.
  close dataset d1.

This worked good in my system.

Regards,

Rich Heilman

Read only

0 Likes
669

Hi Rich,

nice one! Its working fine now. I´m using SAP ERP and the 'type x value '09' wasn´t working for me.

The following value definition did the trick!!

con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB

Thanks a lot!

Kevin

Read only

0 Likes
669

Can you please award points accordingly and mark this post as solved. Thanks.

Regards,

Rich Heilman

Read only

0 Likes
669

If Rich's answer solved your problem, please reward him with full points and close the post.

Read only

Former Member
0 Likes
669

Looks like it is the tabulator. What you can do is declare a variable as follows:

data:c_tab type x value '09'.

After that you can use your split command as follows

SPLIT v_string at c_tab.

Regards,

Srinivas