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

Efficient looping over strings

Former Member
0 Likes
859

ABAPers,

I need to loop over all the characters in a string. Here is the pseudo code:


data: myData TYPE string.
data: n TYPE i.
data: ch TYPE char1.

n = STRLEN( myData).
DO n TIMES.
  ch = myData(sy-index).
  ...
ENDDO.

While this code would work, the problem is that I am actually iterating over myData two times. STRLEN itself is internally iterating over myData to compute the length.

Is there a more efficient looping mechanism without going through STRLEN?

Thank you in advance for your help.

Pradeep

1 ACCEPTED SOLUTION
Read only

eddy_declercq
Active Contributor
0 Likes
490

Hi,

You can try this when it comes to converting things

WHILE myData IS NOT INITIAL.

do something

ENDIF.

myData = myData+1(*).

Eddy

PS.

Put yourself on the SDN world map (http://sdn.idizaai.be/sdn_world/sdn_world.html) and earn 25 points.

Spread the wor(l)d!

2 REPLIES 2
Read only

eddy_declercq
Active Contributor
0 Likes
491

Hi,

You can try this when it comes to converting things

WHILE myData IS NOT INITIAL.

do something

ENDIF.

myData = myData+1(*).

Eddy

PS.

Put yourself on the SDN world map (http://sdn.idizaai.be/sdn_world/sdn_world.html) and earn 25 points.

Spread the wor(l)d!

Read only

0 Likes
490

Eddy,

Appreciate your help.

Pradeep