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

Make type P negative

Former Member
0 Likes
1,441

Hi Experts,

I must make negative a P type variable, how can I do it? I tried to multiplying by -1 but it doesn't work, when i run the program there is a runtime error.

Thankyou.

Cris.

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
1,111

I don't see the problem. Try this.


data: val type p VALUE '-2',   
      val2 type p VALUE -2.    
      res type p.

res = val2 - val.

write: res.

The result is 0 = -2 - (-2)

8 REPLIES 8
Read only

Former Member
0 Likes
1,111

check this..

data: a type p decimals 2.

a = '10.00'.

a = a * -1.

write a .

it is working for me.

Read only

former_member156446
Active Contributor
0 Likes
1,111

I tried this code: it works fine

data: lv_p type p DECIMALS 2 value '3.44'.

lv_p = lv_p * ( -1 ).  "space between ( and - 

WRITE:/ 'lv_p:', lv_p.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,111

Yep, that is how you would make it negative. You should be able to see this in debug mode. I guess you may be getting this error when your screen is thrown? If so, you need to make sure to modify your screen field to handle the - sign. So go to screen painter. Click on the "element list" tab, then click on the "Texts/ I/O Templates" Tab. FInd your field in the list, now in the column labeled as "Text or I/O Field, you should see underscores, simply add a "V" at the end of this. So you should have something like this _______________V in that field. Save and activate, and try your program again. The "V" is a placeholder for the sign.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,111

Post the statement where the error is happening

Read only

MarcinPciak
Active Contributor
0 Likes
1,112

I don't see the problem. Try this.


data: val type p VALUE '-2',   
      val2 type p VALUE -2.    
      res type p.

res = val2 - val.

write: res.

The result is 0 = -2 - (-2)

Read only

0 Likes
1,111

Hi,

Firs of all, thank you for all your quick answers. Well, really I am working with BW, and I have a program to extract data from a table to another table making some transformations in the fields of the source table and save it in the fields of the target table. One of this transformations is to make negative a field with type QUAN that has a lenght of 17 and 3 decimals. I read somewhere that in a program the type QUAN is treated like the type P. I have this (more or less )

"Internal table and work area for the source table.

DATA: it_dm TYPE STANDARD TABLE /bic/ohcfm_r_dm,

wa_dm LIKE LINE OF it_dm.

"Internal table and work area for the target table

DATA: it_ext_dm TYPE STANDARD TABLE ycfm_t_dm,

wa_ext_dm LIKE LINE OF it_ext_dm

"select of the source table

SELECT * FROM /bic/ohcfm_r_dm into table it_dm.

"loop the internal table

LOOP AT it_dm INTO wa_dm.

wa_ext_dm-dias_decalaje = wa_dm-/dias_decalaje * ( -1 ).

...

ENDLOOP.

...

The field dias_decalaje has QUAN type.

Thank you.

Cris.

Read only

0 Likes
1,111
wa_ext_dm-dias_decalaje = wa_dm-/dias_decalaje * ( -1 ).

create a temp variable and move the temp to final wa_ext_dm-dias_decalaje


data: lv_temp type p decimal 3.
lv_temp = wa_dm-/dias_decalaje * ( -1 ) 
move lv_temp to wa_ext_dm-dias_decalaje.

Read only

0 Likes
1,111

Hello,

I'd seen that the problem is the type of the field in the target table, it is a INT1, and the result of multiply the field by -1 is bigger than the type INT1, of course.

I must talk about this with my technical designer.

Thank you all.