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

ABAP String operation

SujeetMishra
Active Contributor
0 Likes
778

Hello All,

i have value like 16173 / 0180 / KLASSIK D/300 L258D VERN in flat file.

now i need only first two value that is 16173 / 0180.

How can i find first two value.

Have a Nice Day,

Regards,

Sujeet

7 REPLIES 7
Read only

Former Member
0 Likes
751

If the length is fixed as per you requirement, then you can use variable(10) to fetch this value.

Otherwise use STRLEN Function to fetch the number of characters from left side by tracing the location of '/'.

regds,

Anil

Read only

Former Member
0 Likes
751

Hi Sujeet how r u,

TRY this,

data: v1(60) type c value '16173 / 0180 / KLASSIK D/300 L258D VERN'.

data: v2(60) type c,
      v3(60) type c,

      vfinal(60) type c.

      v1 = '16173 / 0180 / KLASSIK D/300 L258D VERN'.
      v2 = v1+0(7).
      v3 = v1+8(5).

       CONCATENATE V2 V3 INTO VFINAL SEPARATED BY SPACE.

       write: / vfinal.

Rgrds,

Nikhil.

Read only

0 Likes
751

Hello Nikhil,

Do u think that flat file has fixed variables as i have written above??

the logic you have suggested me will never work for my requirement, as data is not in any structure, so we cant image the length.

Regards,

Sujeet

Read only

0 Likes
751

Hello

Try this code:


data: str(50) type c,
      val(50) type c,
      cnt type i,
      pir type i,
      counter type i.
str = '16173 / 0180 / KLASSIK D/300 L258D VERN'.
cnt = strlen( str ).
do cnt times.
  if str+counter(1) = '/'.
    pir = pir + 1.
  endif.
  if pir = 2.
    exit.
  endif.
  counter = counter + 1.
enddo.
counter = counter - 1.
CALL FUNCTION 'COPI_STRING_SPLIT'
     EXPORTING
        string = str
        length = counter
     IMPORTING
        line   = val.
 write val.

Read only

0 Likes
751

Hello Sujeet,

If your length is not fixed than you are right my logic want ne useful which you haven't mentioned in your post than you need to use the logic of split which has been already posted.

Regrds,

Nikhil.

Read only

0 Likes
751

Thanks Mr Nikhil.

Read only

Former Member
0 Likes
751

Dear Sujeet ,

You can use "SPLIT" for the same.

You read the string in the Work area. Now Split that work area at "/".

E,g :

SPLIT WA_LINE AT '§' INTO

IT_INPUT-ROLE

IT_INPUT-GROUP

IT_INPUT-CATEGORY

IT_INPUT-CLASSIFY

IT_INPUT-TITLE

IT_INPUT-FIRST_NAME .

Append IT_INPUT.

Regards,

Nikhil