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: 

split at carriage Return, Fieldformat string

Former Member
0 Kudos

Hi at all,

i've a string field, where some carriage returns (##) occur. Now i want to split this string at the carriage return into a table. Now the question is, how can i split the string at the carriage return??

After the converting the value of the internal table should be concatenated again by carriage return.

Thanks for Your help,

Andi

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate

Something like this?



data: itab type table of string with header line.

split str at CL_ABAP_CHAR_UTILITIES=>CR_LF into table itab.


Regards,

Rich Heilman

7 REPLIES 7

RichHeilman
Developer Advocate
Developer Advocate

Something like this?



data: itab type table of string with header line.

split str at CL_ABAP_CHAR_UTILITIES=>CR_LF into table itab.


Regards,

Rich Heilman

Former Member
0 Kudos

u can use

split str at '##' into itab.

loop at itab.

concatenate itab '##' into str_new.

endloop.

rahulkavuri
Active Contributor
0 Kudos
data : a(10),b(10),c(10),d(40).
	D = ‘Apple##Orange##Banana’.
	Split d at ‘##’ into a b c.

Now u need to append the internal table or table where u want to hold these fields.

data: begin of itab occurs 0,
first(10),
second(10),
third(10),
end of itab.


itab-first = a.
itab-second = b.
itab-third = c.

append itab.

Now u need not even concatenate the string D again as we havent changed its value anywhere

Hope this helps, please award points if found helpful

0 Kudos

Just to clarify, I don't think that splitting at ## will do it, because this is an internal representation of the carriage return, so it will not recognize it as ##. You must either use the class attribute above, or the hex value for it.

Regards,

Rich Heilman

0 Kudos

Hi Rich,

I am having problem with this carriage return. I have a record which is split due to a carriage return. I want the record to be together in a single line, i want to check all the records and if there is a carriage return in the line, then i want the record to be in one single line. the file is a tab delimited file. The hex value for the carriage return is hex00d.

Pls help.

Thanks.

Former Member
0 Kudos

Hi Rich,

i agree with you. Before i posted my question, i tried split at '##'. It doesn't work.

Andi

0 Kudos

hI,

Check this code this may be of some use.

  • begin of change by 0114_temp

data: cr type x value '0A', "(carriage return)

length type sy-fdpos.

  • end of change by 0114_temp

loop at it_data.

  • begin of change by 0114_temp

  • search for carriage returns and replace them

length = 1.

do.

search it_data-sgtxt for cr starting at length.

if sy-subrc = 0.

length = length + sy-fdpos .

replace cr with space into it_data-sgtxt.

modify it_data index sy-tabix transporting sgtxt.

else.

exit.

endif.

enddo.

Thanks,

Mahesh