Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to change the sign of a packed decimal

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to change the sign of a packed decimal
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    Post subject: Re: How to change the sign of a packed decimal
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    Post subject: Re: How to change the sign of a packed decimal
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: 436
Location: chennai, India

PostPosted: Wed Mar 22, 2006 5:49 pm    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Fail to change physical VSAM filename... jacobdng CICS 7 Fri Jan 20, 2017 12:36 pm
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am
No new posts Change date (DD/MM/YY) in 2nd record ... uday kiran DFSORT/ICETOOL 12 Wed Sep 07, 2016 10:57 pm
No new posts How to change dataset attributes of m... ignich7 JCL & VSAM 3 Thu Jul 21, 2016 9:17 pm
No new posts GDG vsersion number change Raghu navaikulam JCL & VSAM 5 Fri May 27, 2016 4:49 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us