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

To split a field

Former Member
0 Likes
712

Hi ,

In my previous thread..I got a solvation..but I just overlooked somethings in that.

Prease anyone answer my requirement.

I get the field values like this :

14.8KG g

13.1 KG g

now I need to split these into 2 parts giving14.8 & 13.1 into one field F1 of an ITAB and KG g into F2 of ITAB

Please tell me the code

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
689

Check out this sample code.



REPORT zrich_0001.

data: str type string.
data: p1 type string.
data: p2 type string.
data: offset type i.
data: len type i.
data: lowercase type sy-abcde.

lowercase = sy-abcde.
translate lowercase to LOWER CASE.

str = '14.8KG g'.

TRANSLATE str using ' %'.
len = strlen( str ).
len = len - 1.

do len times.

  offset = offset + 1.
  if str+offset(1) ca '0123456789.'.
    concatenate p1 str+offset(1) into p1.
  elseif ( str+offset(1) ca sy-abcde
        or str+offset(1) ca lowercase
        or str+offset(1) = '%' ).
      concatenate p2 str+offset(1) into p2.
  endif.

enddo.

TRANSLATE p2 using '% '.

write:/ p1, p2.

Regards,

Rich Heilman

5 REPLIES 5
Read only

Former Member
0 Likes
689

See the last reply which worked for you...

If u split at SPACE taht is enough it will work, I tried it in an example.

DATA: string(20) TYPE c VALUE 'st ri ng120',

string1(10) TYPE c ,

string2(10) TYPE c .

SPLIT string AT space INTO string1 string2.

Write string2.

Thanks

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
690

Check out this sample code.



REPORT zrich_0001.

data: str type string.
data: p1 type string.
data: p2 type string.
data: offset type i.
data: len type i.
data: lowercase type sy-abcde.

lowercase = sy-abcde.
translate lowercase to LOWER CASE.

str = '14.8KG g'.

TRANSLATE str using ' %'.
len = strlen( str ).
len = len - 1.

do len times.

  offset = offset + 1.
  if str+offset(1) ca '0123456789.'.
    concatenate p1 str+offset(1) into p1.
  elseif ( str+offset(1) ca sy-abcde
        or str+offset(1) ca lowercase
        or str+offset(1) = '%' ).
      concatenate p2 str+offset(1) into p2.
  endif.

enddo.

TRANSLATE p2 using '% '.

write:/ p1, p2.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
689

Ramana,

Just clicked a good solution for your problem.

Use the below code:

IF itab-f1 CS 'KG'.

IF sy-subrc = 0.

MOVE itab-f1+sy-fdpos(4) TO itab-f2.

itab-f1 = itab-f1+0(sy-fdpos).

ENDIF.

ENDIF.

This will definitely work.

Thanks

Read only

Former Member
0 Likes
689

Ramana,

DATA : POS TYPE I.

DATA : VAR TYPE STRING VALUE '14.8KG g',

v_num(10),

v_char(10).

LOOP.

IF VAR+0(SY-INDEX) BETWEEN 0 AND 9.

concatenate v_num VAR+0(SY-INDEX) to v_num.

ELSE

concatenate v_char VAR+0(SY-INDEX) to v_char.

EXIT.

ENDIF.

ENDLOOP.

Pls. mark if useful.

VAR1 = VAR+0(SY-INDEX).

VAR2 = VAR+SY-INDEX(LENGTH OF THE STRING).

Read only

Former Member
0 Likes
689

pls close the thread if your problem is solved

regards

shiba dutta