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

help manipulating a string

Former Member
0 Likes
3,912

Hello guys , could you give any advice of how to split a string every 132 chars or every <enter> key , i need to save every part in a field of internal table .

thank you.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,523

hi guys , your ideas are great , however i need to split or every 132 OR every <ENTER> key and then create a register in the internal table for every part that i get. How do i find the <ENTER> key in the string in old fashion languages it was something with the ascii

13 REPLIES 13
Read only

Former Member
0 Likes
1,523

hI

see SPLIT statement

Seek F1 help

Read only

0 Likes
1,523

yes the problem is that i dont know , how many parts im going to get . in split you need specify the variables to save the parts.

Read only

Former Member
0 Likes
1,523

Its pretty simple..

Declare ITAB .

DATA: BEIGN OF ITAB OCCURS 1 ,

str(132) ,

end of itab.

check the length using strlen ( string ).

Now string is 1340 characters....

A = 1340 / 132 = 10 times....

B = 1340 - 132 * a= 8 charcaters...

C = 1340- B = 1332.

DATA: A TYPE I ,

DO A TIMES.

D = 132 + D.

ITAB-STR = STRING+D(132).

APPEND ITAB.

ENDDO.

ITAB-STR = STRING +C(b).

APPEND ITAB.

Is that ok???

Regards

sas

Read only

Former Member
0 Likes
1,523

Hi Jose,

Use offset or function code.

For example i have used offset in time to dispaly as : :

MOVE sy-uzeit TO l_time.
  CONCATENATE l_time+0(2) l_time+2(2) l_time+4(2) INTO l_time SEPARATED BY ':'.

Manas M.

Edited by: Kumar Manas Mishra on Jan 28, 2010 11:39 AM

Read only

0 Likes
1,523

kumar,

you dont know how many characters the string is then how can you use that ????

Regards

sas

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,523

Hello,

You can make use of the FM: RKD_WORD_WRAP or FORMAT_TEXTLINES to split the string at 132 characters.

BR,

Suhas

Read only

Former Member
0 Likes
1,523

Hello,

Use the FM TR_SPLIT_TEXT and specify the length at which it has to split to the parameter IV_LEN as 132. The export internal table will hold the splitted text

Vikranth

Read only

Former Member
0 Likes
1,524

hi guys , your ideas are great , however i need to split or every 132 OR every <ENTER> key and then create a register in the internal table for every part that i get. How do i find the <ENTER> key in the string in old fashion languages it was something with the ascii

Read only

0 Likes
1,523

Hi José,

To separate a string at enter you can use this way:


data: c_new value cl_abap_char_utilities=>newline.

split v_string at c_new into table itab.

Also can you elobarate what do you mean by creating register.

Regards,

Swarna Munukoti

Read only

0 Likes
1,523

this is exactly what i want , one more thing how is the structure of ITAB my table has 4 columns

Edited by: José M. Sánchez on Jan 28, 2010 6:30 AM

Read only

0 Likes
1,523

Hi,

You can declare itab as follows:

data: itab type table of string.

Is this what you are asking for?

But iam still confused with your statement:

 my table has 4 columns 

Regards,

Swarna Munukoti

Read only

0 Likes
1,523

if you have 4 and one string is having 4 enters only...

then you may use

SPLIT STRING AT NEWLINE INTO ITAB-A ITAB-A ITAB-C ITAB-D.

Sas

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,523

This logic will help


len = strlen( lv_string ).

lv_pos = ceil( len / 132 ).  "Holds no of fields you will get based on this you can create the itab dynamically also.

lv_off1 = 0.
lv_off2 = 132.

do lv_pos times.
wa-line = lv_string+lv_off1(lv_off2).
lv_off1 = lv_off1 + lv_off2.
append wa to itab.
clear wa.
enddo.