View previous topic :: :: View next topic

Author 
Message 
chowdhrykapildev
New User
Joined: 05 Aug 2009 Posts: 44 Location: Hyderabad




Hi everyone,
I have a requirement wherein i need to use a alphanumeric variable (variable2) of length X(20) in a numeric condition say...
IF variable1 < +0.05 AND variable2 >= 10
I tried different methods like using redefines, NUMVAL, Unstring but unable to come at a final solution.
Can someone help me how can I achieve this?
Thanks, 

Back to top 




Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8280 Location: Dubuque, Iowa, USA




1. Verify you have compile option ARITH(EXTEND) turned on.
2. Move VARIABLE2 to a numeric value defined PIC 9(20).
3. use the numeric variable in your IF statement. 

Back to top 


Bill Woodger
DFSORT Moderator
Joined: 09 Mar 2011 Posts: 7314




What are the possibilities for the data in the PIC X(20)? 

Back to top 


chowdhrykapildev
New User
Joined: 05 Aug 2009 Posts: 44 Location: Hyderabad




@Robert: Compile option is ARITH(COMPAT)...
@Bill: Numeric values and blanks 

Back to top 


dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6970 Location: porcelain throne




NUMVAL
why does that not work.
and provide examples of data values that can be in the 20 char field.
cut and paste.
not that we don't believe you, we know that you are not lying.
it is because based on what you have said, NUMVAL should work.
so we know that you don't know,
so cut and paste examples of what the 20 char field can contain. 

Back to top 


Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8280 Location: Dubuque, Iowa, USA




chowdhrykapildev, from the Enterprise COBOL Programming Guide manual, section 2.4.5 on the ARITH compile option:
Quote: 
Default is: ARITH(COMPAT)
Abbreviations are: AR(C), AR(E)
When you specify ARITH(EXTEND):
The maximum number of digit positions that you can specify in the
 PICTURE clause for packeddecimal, externaldecimal, and numericedited data items is raised from 18 to 31.
The maximum number of digits that you can specify in a fixedpoint numeric literal is raised from 18 to 31. You can use numeric literals with large precision anywhere that numeric literals are currently allowed, including:
Operands of PROCEDURE DIVISION statements
VALUE clauses (for numeric data items with largeprecision PICTURE)
Conditionname values (on numeric data items with largeprecision PICTURE)
The maximum number of digits that you can specify in the arguments to NUMVAL and NUMVALC is raised from 18 to 31.
The maximum value of the integer argument to the FACTORIAL function is 29.
Intermediate results in arithmetic statements use extended mode.
When you specify ARITH(COMPAT):
The maximum number of digit positions in the PICTURE clause for
 packeddecimal, externaldecimal, and numericedited data items is 18.
The maximum number of digits in a fixedpoint numeric literal is 18.
The maximum number of digits in the arguments to NUMVAL and NUMVALC is 18.
The maximum value of the integer argument to the FACTORIAL function is 28.
Intermediate results in arithmetic statements use compatibility mode. 
In other words, if you continue to use ARITH(COMPAT), then there is ABSOLUTELY no way your program can handle a 20digit number  hence what you are asking will be IMPOSSIBLE. Either change the compiler option, or forget what you want to do, or cut the number from 20 digits to 18 digits  your choice. 

Back to top 


Bill Woodger
DFSORT Moderator
Joined: 09 Mar 2011 Posts: 7314




I was hoping for a little more detail, and like dbz some examples would be nice.
As long as you are using it in COMPUTE, NUMVAL is only going to fail (U4038) with what you have so far describe, if there are embedded blanks. Leading blanks, followed by numbers, numbers followed by trailing blanks, mix of the two, decimal point, sign (+ or , CR or DB) and NUMVAL will work. 

Back to top 


dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6970 Location: porcelain throne




no, it can not handle a 20 digit number, but it can handle a 18 digit number,
the TS needs to provide us with a picture clause for VAR1.
also,
Quote: 
IF variable1 < +0.05 AND variable2 >= 10 
is just plain stupid.
VARIABLE 2 CAN NOT BE USED IN A NUMERIC COMPARE STATEMENT 

Back to top 


chowdhrykapildev
New User
Joined: 05 Aug 2009 Posts: 44 Location: Hyderabad




I tried moving variable2 which is X(20) into a numeric variable (say variable3) which is 9(15) as below:
MOVE variable2 (1:15) TO variable3 and used variable3 in the if logic.
For few scenarios, the below condition is getting satisfied eventhough variable3 is <=10
IF variable1 < +0.05 AND variable3 >= 10
DISPLAY 'ENTERED 2ND IF'
Compute .......
ENDIF
For ex: when variable2 is 6, below are the displays:
variable2 : 3
variable3 : 3BBBBBBBBBBBBB0
ENTERED 2ND IF
I'm surprised how 0 (zero) is getting displayed for variable3 where B denotes blanks. 

Back to top 


chowdhrykapildev
New User
Joined: 05 Aug 2009 Posts: 44 Location: Hyderabad




I tried moving variable2 which is X(20) into a numeric variable (say variable3) which is 9(15) as below:
MOVE variable2 (1:15) TO variable3 and used variable3 in the if logic.
For few scenarios, the below condition is getting satisfied eventhough variable3 is <=10
IF variable1 < +0.05 AND variable3 >= 10
DISPLAY 'ENTERED 2ND IF'
Compute .......
ENDIF
For ex: when variable2 is 6, below are the displays:
variable2 : 3
variable3 : 3BBBBBBBBBBBBB0
ENTERED 2ND IF
I'm surprised how 0 (zero) is getting displayed for variable3 where B denotes blanks. 

Back to top 


Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8280 Location: Dubuque, Iowa, USA




Quote: 
I'm surprised how 0 (zero) is getting displayed for variable3 where B denotes blanks. 
Why are you surprised? This is normal and expected behavior  as you would know if you'd searched this forum. COBOL will ensure the final byte of the zoned decimal variable is unsigned by forcing an OR with x'F0'  which WILL change a blank to a zero.
You would be better served on the Beginner's and Students Forum instead of this one  your lack of COBOL understanding is such that there's not much chance you're going to get your program working successfully. Do you understand why you're getting your numeric VARIABLE3 leftjustified and blankfilled? If not, you have some manual reading to do  try reading the COBOL Language Reference manual cover to cover, then follow it with the Programming Guide manual cover to cover. 

Back to top 


Bill Woodger
DFSORT Moderator
Joined: 09 Mar 2011 Posts: 7314




Your latest came as a bit of a surprise. I thing we were expecting a few more digits.
Can you explain what you tried with NUMVAL, and how you think that didn't work for you?
Can you show what you did for the UNSTRING attempt, including data definitions?
Robert has explained how your rightmost blank becomes a zero, but even if it didn't, you'd still have a three, followed by 14 trailing blanks, which is very far from being a number three for comparison purposes. Three followed by 14 blanks is bigger than nine followed by 13 nines. It is huge.
You need it right justified. If you search for "JUST RIGHT", correctly, in this forum you'll find an UNSTRING example from last week. NUMVAL should be straightforward, though a bit "sledgehammer vs nut". 

Back to top 


