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

String Length upto specific chars

Former Member
0 Likes
723

Hi Gurus,

I would like to pull the value of string from ZST to ZLP in the given example ....

ZSTB2L10ZLPZLSZGC*

i.e B2L10

Please advise me your logic.....

Thanks

Ganesh Reddy.

1 ACCEPTED SOLUTION
Read only

_IvanFemia_
Active Contributor
0 Likes
693

Hi

supposing it starts always with 'ZST'

DATA: lv_string TYPE String VALUE 'ZSTB2L10ZLP*ZLS*ZGC*'.

DATA: mlen TYPE i.

FIND REGEX '.*(?=ZLP)' IN lv_string MATCH LENGTH mlen.

SUBTRACT 3 FROM mlen.

WRITE lv_string+3(mlen).

This is more general, it gets the substring everywhere

DATA: lv_string TYPE String VALUE 'AZSTB2L10ZLP*ZLS*ZGC*'.

DATA: moff TYPE i,
      mlen TYPE i.

FIND REGEX '(?=ZST).*(?=ZLP)' IN lv_string MATCH OFFSET moff MATCH LENGTH mlen.

ADD 3 TO moff.
SUBTRACT 3 FROM mlen.

WRITE lv_string+moff(mlen).

Regards,

Ivan

4 REPLIES 4
Read only

naveen_inuganti2
Active Contributor
0 Likes
693

data: lv_string type string.

data: lv_res type char10.

data: lv_var1 type char10,

data: lv_var2 type char10.

lv_string = ZSTB2L10ZLP*ZLS*ZGC*

split lv_string at 'ZST' into lv_var1 lv_var2.

split lv_var2 at 'ZLP' into lv_res lv_var1.

write: lv_res.

-- Why don't you try some ting like above..

--Naveen Inuganti.

Read only

0 Likes
693

Hi Naveen,

Thanks for your quick reply,

Instead of your are taking value into the variable can we read directly from the table.

Table : ZPERFORM

Fielld : AUT_KEY

AUT_KEY contains all values i.e ZSTB2L10ZLPZLSZGC*.

Please could you give me the logic

Thanks

Ganesh Reddy.

Read only

0 Likes
693

Hi Ivan,

Thanks it worked....

Thanks

Ganesh Reddy.

Read only

_IvanFemia_
Active Contributor
0 Likes
694

Hi

supposing it starts always with 'ZST'

DATA: lv_string TYPE String VALUE 'ZSTB2L10ZLP*ZLS*ZGC*'.

DATA: mlen TYPE i.

FIND REGEX '.*(?=ZLP)' IN lv_string MATCH LENGTH mlen.

SUBTRACT 3 FROM mlen.

WRITE lv_string+3(mlen).

This is more general, it gets the substring everywhere

DATA: lv_string TYPE String VALUE 'AZSTB2L10ZLP*ZLS*ZGC*'.

DATA: moff TYPE i,
      mlen TYPE i.

FIND REGEX '(?=ZST).*(?=ZLP)' IN lv_string MATCH OFFSET moff MATCH LENGTH mlen.

ADD 3 TO moff.
SUBTRACT 3 FROM mlen.

WRITE lv_string+moff(mlen).

Regards,

Ivan