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

Converting negative values in internal table

Former Member
0 Likes
2,491

Hi Friends,

I have some negative and positive values in the internal table I want to make all the values to be positive. Following field has all the values dfkkop-betrw.

Pls tell me how to convert only negative values to positive values.

Thanx and Regards,

Line

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
1,374

Hi Line,

if you want it to be done fast:

field-symbols: <itab> like line of itab.
loop at itab assigning <itab> where betrw < 0.
 <itab>-betrw = - <itab>-betrw.
endloop.

Regards,

Clemens

6 REPLIES 6
Read only

Former Member
0 Likes
1,374

read the records from internal table if value is negative multiply with -1

check the code below,

REPORT ZEX33 .

data : begin of itab occurs 0,

vbeln like likp-vbeln,

netwr like likp-netwr,

end of itab.

itab-vbeln = '0005002035'.

itab-netwr = '5.78'.

append itab.

clear itab.

itab-vbeln = '0005002035'.

itab-netwr = '-3.25'.

append itab.

clear itab.

itab-vbeln = '0005002035'.

itab-netwr = '-8.47'.

append itab.

clear itab.

itab-vbeln = '0005002035'.

itab-netwr = '1.98'.

append itab.

clear itab.

<b>loop at itab.

if itab-netwr < 0.

itab-netwr = itab-netwr * -1.

modify itab index sy-tabix.

else.

continue.

endif.

endloop.</b>

loop at itab.

write : / itab-vbeln , itab-netwr .

endloop.

Read only

Former Member
0 Likes
1,374

multiply negative values with -1 to make it positive .

loop at itab.

if itab-f1 is < 0.
itab-f1 = itab-f1 * -1.
modify itab index sy-tabix transporitng f1." use this
endif.

endloop.

BTW check the boundaries of your requirement .

regards,

vijay

Read only

Former Member
0 Likes
1,374

Hello,

U can do like this:

LOOP AT G_T_VBAP.

<b> IF G_T_VBAP-betrw lt -1.

MULTIPLY G_T_VBAP-betrw BY -1.

MODIFY G_T_VBAP.

ENDIF.</b>

ENDLOOP.

If useful reward.

Vasanth

Read only

Former Member
0 Likes
1,374

Hi

hi use

loop at itab.

abs

endloop.

Thanks

Shiva

Read only

Clemenss
Active Contributor
0 Likes
1,375

Hi Line,

if you want it to be done fast:

field-symbols: <itab> like line of itab.
loop at itab assigning <itab> where betrw < 0.
 <itab>-betrw = - <itab>-betrw.
endloop.

Regards,

Clemens

Read only

Former Member
0 Likes
1,374

hi

jst chek whether the value is less than 0.. then multiply with -1. use the field symbols so u no need to modify the table again.. it directly works on the body of the table.

field-symbols: <dfkkop> type xxxxx.
loo at dfkkop assigning <dfkkop> where betrw <= 0.
<dfkkop>-betrw = <dfkkop>-betrw * -1.
endloop.

Please Close this thread.. when u r problem is solved

Reward if Helpful

Regards

Naresh Reddy K