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

Statement Right circular!!!

Former Member
0 Likes
2,360

Hi,

I had like to move the -ve sign of the number from rear to front

Ex: if the number is 2000- i want to have this value in the output as -2000.

for that i had used the ABAP key words shift right circular

This is working fine for the numbers as well. i had made the numbers as data types Chars and performed the coding.

But if the number is in the format 0.0001-, then even after applying the shift right circular it is not working-

But the decimal part has to be maintained as these decimal values are needed in the final output

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,135

Hi,

try this code will definitely work.

DATA: w_pack TYPE p DECIMALS 4 VALUE '-20.0021'.
DATA: w_amount(100) TYPE c.
w_amount = w_pack.
IF w_amount < 0.
  SHIFT w_amount RIGHT DELETING TRAILING '-'.
  SHIFT w_amount LEFT DELETING LEADING ' '.
  CONCATENATE '-' w_amount INTO w_amount.
  WRITE:/ w_amount.
ELSE.
  SHIFT w_amount LEFT DELETING LEADING ' '.
  WRITE:/ w_amount.
ENDIF.

regards

sarves

Edited by: Sarves Sombhatla on Feb 20, 2009 2:17 PM

4 REPLIES 4
Read only

Former Member
0 Likes
1,136

Hi,

try this code will definitely work.

DATA: w_pack TYPE p DECIMALS 4 VALUE '-20.0021'.
DATA: w_amount(100) TYPE c.
w_amount = w_pack.
IF w_amount < 0.
  SHIFT w_amount RIGHT DELETING TRAILING '-'.
  SHIFT w_amount LEFT DELETING LEADING ' '.
  CONCATENATE '-' w_amount INTO w_amount.
  WRITE:/ w_amount.
ELSE.
  SHIFT w_amount LEFT DELETING LEADING ' '.
  WRITE:/ w_amount.
ENDIF.

regards

sarves

Edited by: Sarves Sombhatla on Feb 20, 2009 2:17 PM

Read only

0 Likes
1,135

Hi,

check again

the code does not work that way

Read only

0 Likes
1,135

You could always use a regex:

DATA:  g_sub1(10)     TYPE c,
       g_sub2(10)     TYPE c,
       g_result(20)   TYPE c,
       g_in(10)       TYPE p DECIMALS 9 VALUE '000.0001-'.

g_result = g_in.

FIND all OCCURRENCEs OF REGEX '(\b\S+\b)(-?)' IN g_result SUBMATCHES g_sub1 g_sub2.


CONCATENATE g_sub2 g_sub1 INTO g_result.

WRITE:/ g_result.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,135

Hello Simran,

I am trying this code & it works fine for me:

PARAMETERS: p_amt TYPE menge_d.

DATA:
l_v_amt1 TYPE char16.

WRITE p_amt TO l_v_amt1.

SHIFT l_v_amt1 BY 1 PLACES RIGHT CIRCULAR.

CONDENSE l_v_amt1.

WRITE: l_v_amt1.

Hope this might be of some use to you.

BR,

Suhas