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

How did a text display in reverse without using function in ABAP?

shrgrl
Participant
2,990

How can a text be write in reverse? How do I access the characters of a text? I want to do this manually without using a function.

DATA : c(10) VALUE 'ABCDE'.
DATA : l TYPE i,
       i TYPE i VALUE -1.
DATA : str LIKE c.
l = strlen( c ).
DO l TIMES.
  i = i + 1.
  l = l - 1.
  str+i(1) = C+l(1).
ENDDO.
WRITE str.

This code works for me but is there a shorter way?

1 ACCEPTED SOLUTION
Read only

OlegBash
Active Participant
2,881
DATA off TYPE syindex.
DO strlen( in_str ) TIMES.
    off = sy-index - 1.
    out_str = in_str+off(1) && out_str.
ENDDO.
6 REPLIES 6
Read only

OlegBash
Active Participant
2,882
DATA off TYPE syindex.
DO strlen( in_str ) TIMES.
    off = sy-index - 1.
    out_str = in_str+off(1) && out_str.
ENDDO.
Read only

0 Likes
2,881

It will not work properly since there is no gap control.

Read only

OlegBash
Active Participant
0 Likes
2,881

Could you please provide example when it does not work properly?

Also I want to specify the signature of the method

  methods REVERSER
    importing
      !IN_STR type STRING default 'any Text'
    exporting
      !OUT_STR type STRING .
Read only

0 Likes
2,881

The output of this code:

The output I want is as follows:

It should also see the gap in between.

Read only

OlegBash
Active Participant
0 Likes
2,878

The screenshot from debug.

Please pay attention that data types are strings, not char-like.

Read only

Sandra_Rossi
Active Contributor
0 Likes
2,878

Without a function means probably without any function at all, so your code is the shortest legible code.