Count down field to count negative numbers



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Count down field to count negative numbers

Postby harishcv » Wed Dec 29, 2010 2:09 pm

Hello,

I have a countdown field in my cobol program which counts the number of days left to reach a particular date(always fixed - say X date) from today. Currently, the counter counts till that X date is reached, that is counter = 000 when today = X date; and will remain as 000 eventhough X date is passed.

My requirement is to add negative numbers to counter processing, that is if the X date is passed, then counter shoud display -1, -2 etc. Please advice how cobol stores and process negative numbers. In reading a cobol book, found an option "PIC S9(03) SIGN IS LEADING SEPARATE" to process negative numbers - but not sure how to use this. or if there is a more simple work around.

If anyone came across such scenarios, please help me out.

Thanks,
Harish
harishcv
 
Posts: 11
Joined: Wed Dec 29, 2010 1:09 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Count down field to count negative numbers

Postby Robert Sample » Wed Dec 29, 2010 3:59 pm

The requirement is not difficult to meet: add an S to the PICTURE clause of the count variable. COBOL does not require SIGN LEADING SEPARATE for handling signed numbers -- it can deal with them in any USAGE clause.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Count down field to count negative numbers

Postby harishcv » Wed Dec 29, 2010 4:49 pm

Thanks Robert.

The file(where counter field is) which I am trying to update using cobol code is used by many REXX routines as well. I couldnt figure out how REXX codes can read negative counter values if we use "S" in the PICTURE clause.

So I was trying to understand if we can populate the counter field as -1, -2 etc or any other format which the REXX routines can also read.

Please let know your thoughts.
harishcv
 
Posts: 11
Joined: Wed Dec 29, 2010 1:09 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Count down field to count negative numbers

Postby Robert Sample » Wed Dec 29, 2010 5:36 pm

You posted in the COBOL forum. Your original post did not mention REXX. If you do not bother to completely AND CLEARLY specify the exact problem you are trying to solve, why do you think we can help you? We are not mind readers and cannot guess that you are using something other than COBOL when you post in the COBOL forum.

What is the current definition for the variable being used to pass the count back to REXX?
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Count down field to count negative numbers

Postby harishcv » Wed Dec 29, 2010 5:44 pm

I guess, I posted the original output I wish to achieve using COBOL program - "that is if the X date is passed, then counter shoud display -1, -2 etc"

And using S in PIC clause we cannot achieve this output. I am sorry if i confused anyone by mentioning REXX. Using cobol can we make the counter output to display like -1, -2 etc....

Note: The rexx routine used is not having any variable definition. I am just parsing the counter value to a variable.
harishcv
 
Posts: 11
Joined: Wed Dec 29, 2010 1:09 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Count down field to count negative numbers

Postby Robert Sample » Wed Dec 29, 2010 6:16 pm

Here is a link to the IBM COBOL library (which you should have had bookmarked a LONG, LONG time ago): http://www-01.ibm.com/software/awdtools/cobol/zos/library/

Find the COBOL Language Reference guide and read up on numeric edited variables (hint: the flashlight is the search function). You will be able to generate whatever format of display data you care to with a numeric edited variable.

It is not clear from your posts whether or not you have any idea about what you want to achieve. If you have a question about how REXX can handle a particular format, I recommend a post in the REXX forum.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Count down field to count negative numbers

Postby harishcv » Wed Dec 29, 2010 6:30 pm

Thank you very much!
harishcv
 
Posts: 11
Joined: Wed Dec 29, 2010 1:09 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Count down field to count negative numbers

Postby harishcv » Thu Dec 30, 2010 3:45 pm

Finally, achieved my result using " SIGN IS LEADING SEPARATE " logic. Had to define counter variables and all work counter variables as " SIGN IS LEADING SEPARATE ".

Got the counter output in desired format, that is with +/- sign before them.

-068 -054 -034 -006
+001 +015 +029 +050
+028 +042 +050 +063

Thanks a lot for support guyz.
harishcv
 
Posts: 11
Joined: Wed Dec 29, 2010 1:09 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post