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

How to set 'LOW-VALUE' , 'HIGH-VALUE' to a numeric type


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

Active User


Joined: 08 May 2008
Posts: 390
Location: China

PostPosted: Tue Aug 21, 2012 7:30 am
Reply with quote

In COBOL, for a string variable , let's say 'A', no matter what the length it has, we can use below statements to move the minimum and the maximum value to it:
Code:
MOVE LOW-VALUE TO A
MOVE HIGH-VALUE TO A
.

But for a numeric type variable, I want to use a common statement to move so called 'LOW-VALUE' and 'HIGH-VALUE' to it. how to achieve this?

For instance, let's say we have declared a variable 'B' with type S9(4) COMP-3:

Code:
01 B PIC S9(4) COMP-3.

Now,if I want to move the minimum value to it, I may use below statement:
Code:
MOVE -999999999 TO B

this may cause compiler to send a warning message, and furthermore, it's not a generic way of doing this. because if ‘B' is declared with S9(18) COMP-3, I may use blow statement instead:
Code:
MOVE -99999999999999999999 TO B


So, is there a generic way of doing this?

Thanks.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Aug 21, 2012 8:06 am
Reply with quote

Hello,

Did you try this (moving high/low-values)? What happened?
Back to top
View user's profile Send private message
dejunzhu

Active User


Joined: 08 May 2008
Posts: 390
Location: China

PostPosted: Tue Aug 21, 2012 10:12 am
Reply with quote

hi, dick,

Of course I tried.

It cannot be compiled.

I have forgotten the error message, but after I read the error message, I looked into 'LOW-VALUE' definition from IBM COBOL programming guide, and I know, LOW-VALUE cannot be assigned into numeric data directly.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Aug 21, 2012 10:28 am
Reply with quote

For COMP-3, redefine the field as Alphanumeric -

01 B PIC S9(18) COMP-3.

01 B-X REDEFINES B PIC X(10).

MOVE LOW-VALUES TO B-X.

MOVE HIGH-VALUES TO B-X.

For COMP, substitute ZERO for LOW-VALUES and -1 for HIGH-VALUES (field must be signed).

For DISPLAY-NUMERIC, use reference modification -

01 A PIC 9(18).

MOVE LOW-VALUES TO A (1:).
MOVE HIGH-VALUES TO A (1:).

Mr. Bill
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 21, 2012 12:16 pm
Reply with quote

dejunzhu,

Do you want the lowest and highest values a numeric field can contain? ie PIC S9(9) would contain either -999999999 (the lowest value) or 999999999 the highest value.

Or do you want the field to contain the values of the figurative contants LOW-VALUES and HIGH-VALUES?
Back to top
View user's profile Send private message
dejunzhu

Active User


Joined: 08 May 2008
Posts: 390
Location: China

PostPosted: Tue Aug 21, 2012 12:27 pm
Reply with quote

Bill Woodger wrote:
dejunzhu,

Do you want the lowest and highest values a numeric field can contain? ie PIC S9(9) would contain either -999999999 (the lowest value) or 999999999 the highest value.

Or do you want the field to contain the values of the figurative contants LOW-VALUES and HIGH-VALUES?

Sorry for misunderstanding ,
I want the lowest and highest values a numeric field can contain.
Back to top
View user's profile Send private message
dejunzhu

Active User


Joined: 08 May 2008
Posts: 390
Location: China

PostPosted: Tue Aug 21, 2012 12:31 pm
Reply with quote

Bill O'Boyle wrote:
For COMP-3, redefine the field as Alphanumeric -

01 B PIC S9(18) COMP-3.

01 B-X REDEFINES B PIC X(10).

MOVE LOW-VALUES TO B-X.

MOVE HIGH-VALUES TO B-X.


I'm afraid this method does not work. Because there is a sign indicator for S9(18) COMP-3, which cannot be assigned to digits. right?

Quote:
For COMP, substitute ZERO for LOW-VALUES and -1 for HIGH-VALUES (field must be signed).


Sorry for misunderstanding.
I don't mean move all ZEROS into these variable, but I want to move the lowest and the highest value to each...
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 21, 2012 1:53 pm
Reply with quote

If you have thoroughly confused everything in your question, please don't complain when suggestions don't work.

Try this:

Code:
           MOVE ALL '9'                 TO A-COMP-3
           DISPLAY ">" A-COMP-3 "<"
           SUBTRACT A-COMP-3            FROM ZERO
             GIVING                     A-COMP-3
           DISPLAY ">" A-COMP-3 "<"
                                                   
           MOVE ALL '9'                 TO A-COMP
           DISPLAY ">" A-COMP   "<"
           SUBTRACT A-COMP              FROM ZERO
             GIVING                     A-COMP
           DISPLAY ">" A-COMP   "<"


Note, to get the minimum, requires negation (so two lines of Cobol). Note also, this is not perfect when the field has decimal places (they will be zero). However, will work for fields of any size, without having to take account of the size explicitly when writing the code.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 21, 2012 3:20 pm
Reply with quote

For those unable to get out of bed in the morning without using INITIALIZE, the technique also works with INITIALIZE.

If, for some reason, you did want the value of the figurative constants in packed or binary fields, something like this:

Code:
       01  A-COMP-3-X.
           05  A-COMP-3                  COMP-3 PIC S9(7).
       01  A-COMP-X.
           05  A-COMP                    COMP   PIC S9(8).


And this:
Code:
          MOVE HIGH-VALUES             TO A-COMP-3-X
          DISPLAY ">" A-COMP-3-X "<"
          MOVE LOW-VALUES              TO A-COMP-3-X
          DISPLAY ">" A-COMP-3-X "<"
                                                     
          MOVE HIGH-VALUES             TO A-COMP-X
          DISPLAY ">" A-COMP-X "<"
          MOVE LOW-VALUES              TO A-COMP-X
          DISPLAY ">" A-COMP-X "<"


will get you there with only having one length definition per field, by making the numeric a subordinate data-item, rather than a REDEFINES.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Aug 21, 2012 5:43 pm
Reply with quote

Quote:
So, is there a generic way of doing this?
The answer is no. Unlike alphanumeric variables, which have the only possibility of being PICTURE X(?), numeric variables can be signed or unsigned, COMP, COMP-1, COMP-2, COMP-3 or DISPLAY (COMP-4 and COMP-5 can be treated as COMP for what you want to do) so there are too many possbile outcomes for there to be a generic solution.

For the upper end,
Code:
MOVE ALL 9 TO NUMERIC-VARIABLE
will set the numeric variable to the highest possible value -- although this is NOT an infallible method. Of course, if the numeric variable represents a date then it is NOT a valid date. And this does not work for COMP-1 or COMP-2 varaibles, where the value consists of the decimal as well as an exponent.

However, on the lower end, the value required depends on whether or not the varaible is signed. Unsigned, MOVE ZERO or MOVE ALL ZERO will work. Signed, probably the easiest way is
Code:
MOVE ALL 9 TO NUMERIC-SIGNED-VARIABLE
COMPUTE NUMERIC-SIGNED-VARAIBLE = -1 * NUMERIC-SIGNED-VARIABLE
And again, this fails for COMP-1 or COMP-2 variables.

To further complicate the situation, compiler options can impact the result as well. A PIC S9(04) COMP variable, for example, may have a maximum value of 9999 or 32767 -- depending upon how the compiler option TRUNC is set. So to reiterate my initial comment -- there is ABSOLUTELY no way a generic approach will work for numeric variables.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Aug 21, 2012 6:44 pm
Reply with quote

Update: testing indicates MOVE ALL 9 is not valid and won't compile under Enterrprise COBOL. ALL works only with alphanumeric literals, DBCS literals, national literals, and figurative constants (see 1.3.7 in the Enterprise COBOL Language Reference manual to what these include).
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 21, 2012 7:21 pm
Reply with quote

COMP-1 and COMP-2 are fixed-length, the the same move for maximum and minimum would always work (two MOVEs for COMP-1, two for COMP-2).

With unsigned fields, it is MOVE ZERO and MOVE ALL '9'.

The interesting one is the COMP-5.

Two 16-byte PIC X fields. One value X'8000' with '00' repeating to length. One with X'7FFF' with 'FF' repeating to length. Move appropriate one to group-level above the subordinate item. If "unsigned" it is the HIGH-VALUES method from my previous.

As Robert says, can't be generic across all numeric types, signed and unsigned, but you can have code of each combination which will work irrespective of the size of the field.

For unsigned COMP-3

MOVE ZERO and MOVE ALL '9'

For signed COMP-3

MOVE MOVE ALL '9' amd MOVE ALL '9' with SUBTRACT FROM ZERO GIVING

For unsigned- and signed-binary, PICture-limited value, as for COMP-3

DISPLAY numerics, as for COMP-3

MOVE COMP-1, COMP-2, MOVE the maximum and minimum values, fixed length for each.

For "native" binary (COMP-5 or compiler option), see the start of this post.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Aug 21, 2012 8:12 pm
Reply with quote

Thanks Bill, this sure confused me as well....
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Aug 21, 2012 8:20 pm
Reply with quote

i get the feeling that IF NUMERIC is actually the solution for anything except binary elements.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Aug 21, 2012 8:35 pm
Reply with quote

or another perspective:

high-values and low-values are a system (hexadecimal) limitation.

where as minimum/maximum value allowed
for a field of the various numeric data-types
is a compiler limitation.

the question posed by the TS should have been challenged
at the onset of this thread.
the comparison is that of apples to oranges.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Aug 21, 2012 8:38 pm
Reply with quote

I think we've beat this topic to death with Nerf bats. Now we can wait for the next topic to pop up!
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 21, 2012 9:29 pm
Reply with quote

dbzTHEdinosauer wrote:
[...]

high-values and low-values are a system (hexadecimal) limitation.

[...]


Not actually. Check the manual, you can set your own value for those figurative constants. Can't say I've done it, but it is possible :-)

Also, although not yet available in Enterprise Cobol, this can be done with an intrinsic function.

I sure hope it is not testing for numeric. It won't work, even on the occasions abends are avoided :-)

What are you hoping to achieve with this dejunzhu?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Aug 21, 2012 10:40 pm
Reply with quote

Bill Woodger wrote:
Not actually. Check the manual, you can set your own value for those figurative constants. Can't say I've done it, but it is possible :-)


sorry, I am in dumb-guy mode today, can't find a way to change the specific constant values referred to by a figurative constant (reserved word),
other than the quote and decimal point phrases.

could you provide a link to a method which will effect a change, please?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 21, 2012 11:14 pm
Reply with quote

SPECIAL-NAMES paragraph
[...]
Relates alphabet-names to character sets or collating sequences
[...]

ALPHABET clause
The ALPHABET clause provides a means of relating an alphabet-name to a
specified character code set or collating sequence.

[...]

The character that has the highest ordinal position in this
collating sequence is associated with the figurative constant
HIGH-VALUE. If more than one character has the highest
position because of specification of the ALSO phrase, the last
character specified (or defaulted to when any characters are not
explicitly specified) is considered to be the HIGH-VALUE
character for procedural statements such as DISPLAY and as the
sending field in a MOVE statement. (If the ALSO phrase
example given above were specified as the high-order characters
of this collating sequence, the HIGH-VALUE character would be
%.)
The character that has the lowest ordinal position in this
collating sequence is associated with the figurative constant
LOW-VALUE. If more than one character has the lowest position
because of specification of the ALSO phrase, the first character
specified is the LOW-VALUE character. (If the ALSO phrase
example given above were specified as the low-order characters
of the collating sequence, the LOW-VALUE character would be
D.)
[...]

Also refer to definitions of HIGH- and LOW-VALUES.

I worded it badly, making it look like there was something like SET VALUE OF HIGH-VALUES TO BANANAS. Sorry about that.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Aug 21, 2012 11:35 pm
Reply with quote

ah yes, i worded my comment badly.

comparing high-/low-values (which relates to collating sequence)
to
min/max values of numeric fields constrained by compiler limits
is an invalid comparison.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 21, 2012 11:43 pm
Reply with quote

Bill Woodger wrote:
dbzTHEdinosauer wrote:
[...]

high-values and low-values are a system (hexadecimal) limitation.

[...]


Not actually. Check the manual, you can set your own value for those figurative constants. Can't say I've done it, but it is possible :-)

Also, although not yet available in Enterprise Cobol, this can be done with an intrinsic function.

I sure hope it is not testing for numeric. It won't work, even on the occasions abends are avoided :-)

What are you hoping to achieve with this dejunzhu?


I claim "tops" for confusion.

Also, although not yet available in Enterprise Cobol, the maximum/minimum logical value can be done with an intrinsic function.

The functions we can't use yet are LOWEST-ALGEBRAIC and HIGHEST-ALGEBRAIC. I'm assured they work :-)
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 22, 2012 12:12 am
Reply with quote

Bill Woodger wrote:
Bill Woodger wrote:
dbzTHEdinosauer wrote:
[...]

high-values and low-values are a system (hexadecimal) limitation.

[...]


Not actually. Check the manual, you can set your own value for those figurative constants. Can't say I've done it, but it is possible :-)

Also, although not yet available in Enterprise Cobol, this can be done with an intrinsic function.

I sure hope it is not testing for numeric. It won't work, even on the occasions abends are avoided :-)

What are you hoping to achieve with this dejunzhu?


I claim "tops" for confusion.

Also, although not yet available in Enterprise Cobol, the maximum/minimum logical value can be done with an intrinsic function.

The functions we can't use yet are LOWEST-ALGEBRAIC and HIGHEST-ALGEBRAIC. I'm assured they work :-)


ok, you win, you are the most confused.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Aug 22, 2012 12:18 am
Reply with quote

Thanks.

And the last post in the thread.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Wed Aug 22, 2012 12:39 am
Reply with quote

Bill Woodger wrote:
Also, although not yet available in Enterprise Cobol, the maximum/minimum logical value can be done with an intrinsic function.

The functions we can't use yet are LOWEST-ALGEBRAIC and HIGHEST-ALGEBRAIC. I'm assured they work :-)

Isn't that a bit like saying, "The unicorn that I describe in my short story is ridable"? icon_confused.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Aug 22, 2012 1:38 am
Reply with quote

Hello,

I'm probably having a brain fade, but i do recall with COBOL some time ago (don't remember which year or which platform) that the compiler was able to appropriately generate the values used depending on the "picture" of the receiving field.

Does anyone else have a similar memory?

I do know we incorporated this into the COBOL-like compiler my team wrote in the mid-70's. We also gave the coders a compare-and-swap-high (CSWAPHI) and a compare-and-swap-low (CSWAPLO), and of course a non-conditional SWAP to get fields "reversed" with only one instruction. . .
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 Goto page 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts SMF record type 30 JCL & VSAM 8
No new posts ISRSUPC search utility - using high l... TSO/ISPF 2
No new posts Convert HEX to Numeric DB2 3
No new posts Find a record count/numeric is multip... COBOL Programming 1
No new posts Handling the numeric data in unstring... COBOL Programming 18
Search our Forums:

Back to Top