Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
fundu

New User

Joined: 05 Oct 2005
Posts: 2

 Posted: Tue Mar 21, 2006 12:15 am    Post subject: How to change the sign of a packed decimal 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

DavidatK

Active Member

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

Posted: Tue Mar 21, 2006 2:04 am    Post subject: Re: How to change the sign of a packed decimal

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
cheryala

New User

Joined: 20 Mar 2006
Posts: 46

 Posted: Tue Mar 21, 2006 11:52 am    Post subject: Re: How to change the sign of a packed decimal 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

Active User

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

Posted: Wed Mar 22, 2006 5:49 pm    Post subject:

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.
mmwife

Super Moderator

Joined: 30 May 2003
Posts: 1592

 Posted: Thu Mar 23, 2006 6:53 am    Post subject: 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.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Cannot change DATACLAS on DFSMSdss re... Alan Playford JCL & VSAM 10 Tue May 01, 2018 6:43 pm Repeat Sequence Number Until change i... rahulabvp DFSORT/ICETOOL 6 Thu Mar 29, 2018 12:51 pm How to group and sum the decimal value sakrat DFSORT/ICETOOL 2 Tue Mar 06, 2018 9:13 pm How to change the logon screen info o... sakthikumarT TSO/ISPF 4 Fri Dec 29, 2017 6:44 pm Change NULL indicator in UNLOAD utility Khadhar Basha DB2 2 Fri Dec 15, 2017 3:01 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us