IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to change the sign of a packed decimal


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
fundu

New User


Joined: 05 Oct 2005
Posts: 2

PostPosted: Tue Mar 21, 2006 12:15 am
Reply with quote

Hi,

How to change the sign of a packed decimal.

i have a variable like

05 a-var pic s9(3)v99 defined in a copybook

Suppose user entered negative value, I want to change the sign to positive for specific calculations. How can i do that, how can i check that the variable contains Positive value.

Thanks in advance,
Vijay KS
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Tue Mar 21, 2006 2:04 am
Reply with quote

Vijay KS,

I think the old fashion way is the most readable and simple.

Code:

    05  ABS-A-VAR PIC S9(3)V9(2)   COMP-3.

*---compute absolute value of A-VAR
    IF A-VAR < 0
    THEN
        COMPUTE ABS-A-VAR = A-VAR * -1
    ELSE
        MOVE A-VAR   TO ABS-A-VAR
    END-IF.

    COMPUTE ?????? = ?????? ABS-A-VAR ??????



There are other ways, and I?m sure some will chime in with others.

Dave
Back to top
View user's profile Send private message
cheryala

New User


Joined: 20 Mar 2006
Posts: 46

PostPosted: Tue Mar 21, 2006 11:52 am
Reply with quote

Hi,
I think one more working storage variable
05 ABS-OF-A PIC 9(3)V9(2) COMP-3.
After moving data from A to ABS-OF-A use it in the expressions..

Let me know if i'm wrong..

Cheers
RSC
Back to top
View user's profile Send private message
radhakrishnan82

Active User


Joined: 31 Mar 2005
Posts: 435
Location: chennai, India

PostPosted: Wed Mar 22, 2006 5:49 pm
Reply with quote

I agree that there are other ways to do the same.

I do agree that mulitipying a -ve number with -1 can result a positive value of the same number .Thinking about performance perspective,mulitiplication is a result of repeated addition.So whenever we perform multiplication, it performs addition process,internally.
While holding huge data,this may be a important factor considering its performance.(converting +ve to -ve or vice-versa)

Instead of multiplying a -ve number with -1 to convert it
as a postive value, its better to subtract the -ve number with 0.

Code:
IF A-VAR < 0
    THEN
        COMPUTE ABS-A-VAR = 0- A-VAR
    ELSE
        MOVE A-VAR   TO ABS-A-VAR
    END-IF.


Its an optimisation technique.

Hope it helps.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Mar 23, 2006 6:53 am
Reply with quote

If you will always need a positive value in the field and it comes to you as part of a record, the most efficient way to assure it's positive is to redefine it as PIC 9.. (without the S), then move it to itself. E.g.:

move unsigned-fld to unsigned-fld

This strips the sign whether it's pos or neg. No compare is required.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts PD not working for unsigned packed JO... DFSORT/ICETOOL 5
No new posts Def PD not working for unsigned packe... JCL & VSAM 3
No new posts 3270 personal communications. Can't c... TSO/ISPF 2
No new posts SELECT from data change table DB2 5
Search our Forums:

Back to Top