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

reverse or oposit help

Former Member
0 Likes
952

i have field ( 3 - 8 )

i need to look like ( 8 - 3 ) how i can do it.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
930

try this it may help you


data : text(10) value '( 3 - 8 )',
       text1(10),
       text2(10),
       text3(10).

split text at '(' into text1 text2.
split text2 at ')' into text3 text1.

CALL FUNCTION 'STRING_REVERSE'
  EXPORTING
    STRING          = text3
    LANG            = sy-langu
 IMPORTING
   RSTRING         = text3
 EXCEPTIONS
   TOO_SMALL       = 1
   OTHERS          = 2
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

concatenate '(' text3 ')' into text separated by space.
write : / text.

regards

shiba dutta

i have field ( 3 - 8 )

i need to look like ( 8 - 3 ) how i can do it.

6 REPLIES 6
Read only

Former Member
0 Likes
930

Hi,

do you mean reversing a string of characters? If so, please try function module STRING_REVERSE.

I hope it helps. Best regards,

Alvaro

Read only

0 Likes
930

thanks

but i get ) 8 - 3 (

how can i handle with ()

Read only

0 Likes
930

Hi again,

I know it might sound funny but you may try to do TRANSLATE ... USING '())(' after the string reversal. If the string is well-built (I mean, if the parentheses make sense), this should work, doesn't it?

Best regards,

Alvaro

Read only

Former Member
0 Likes
930

Hi little richi

Please try to use this code.

DATA v_text(20) TYPE c.

DATA v_new_text(20) TYPE c.

DATA v_num TYPE i.

DATA v_i TYPE i.

DATA v_2i TYPE i.

v_text = '( 8- 3 )'.

v_num = STRLEN( v_text ).

v_2i = 0.

v_i = v_num - 1.

DO v_num TIMES.

IF v_textv_i(1) <> '(' AND v_textv_i(1) <> ')'.

WRITE v_textv_i(1) TO v_new_textv_2i(1).

v_i = v_i - 1.

ELSE.

WRITE v_textv_i(1) TO v_new_textv_i(1).

v_i = v_i - 1.

ENDIF.

v_2i = v_2i + 1.

ENDDO.

WRITE 😕 v_text.

WRITE: / v_new_text.

Regards

Wiboon

Read only

0 Likes
930

Hi

use this .

write : '(',field,')'.

regards

prajwal

Read only

Former Member
0 Likes
931

try this it may help you


data : text(10) value '( 3 - 8 )',
       text1(10),
       text2(10),
       text3(10).

split text at '(' into text1 text2.
split text2 at ')' into text3 text1.

CALL FUNCTION 'STRING_REVERSE'
  EXPORTING
    STRING          = text3
    LANG            = sy-langu
 IMPORTING
   RSTRING         = text3
 EXCEPTIONS
   TOO_SMALL       = 1
   OTHERS          = 2
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

concatenate '(' text3 ')' into text separated by space.
write : / text.

regards

shiba dutta