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
 

 

Alphanumeric variable in a numeric check

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
chowdhrykapildev

New User


Joined: 05 Aug 2009
Posts: 44
Location: Hyderabad

PostPosted: Mon Mar 12, 2012 7:31 pm    Post subject: Alphanumeric variable in a numeric check
Reply with quote

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
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7912
Location: Bellevue, IA

PostPosted: Mon Mar 12, 2012 7:35 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Mon Mar 12, 2012 7:45 pm    Post subject: Reply to: Alphanumeric variable in a numeric check
Reply with quote

What are the possibilities for the data in the PIC X(20)?
Back to top
View user's profile Send private message
chowdhrykapildev

New User


Joined: 05 Aug 2009
Posts: 44
Location: Hyderabad

PostPosted: Mon Mar 12, 2012 8:18 pm    Post subject:
Reply with quote

@Robert: Compile option is ARITH(COMPAT)...
@Bill: Numeric values and blanks
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Mar 12, 2012 8:25 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7912
Location: Bellevue, IA

PostPosted: Mon Mar 12, 2012 8:41 pm    Post subject:
Reply with quote

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 packed-decimal, external-decimal, and numeric-edited data items is raised from 18 to 31.

The maximum number of digits that you can specify in a fixed-point 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 large-precision PICTURE)

Condition-name values (on numeric data items with large-precision PICTURE)

The maximum number of digits that you can specify in the arguments to NUMVAL and NUMVAL-C 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
| packed-decimal, external-decimal, and numeric-edited data items is 18.

The maximum number of digits in a fixed-point numeric literal is 18.

The maximum number of digits in the arguments to NUMVAL and NUMVAL-C 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 20-digit 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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Mon Mar 12, 2012 8:43 pm    Post subject: Reply to: Alphanumeric variable in a numeric check
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Mar 12, 2012 8:48 pm    Post subject:
Reply with quote

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
View user's profile Send private message
chowdhrykapildev

New User


Joined: 05 Aug 2009
Posts: 44
Location: Hyderabad

PostPosted: Mon Mar 12, 2012 10:19 pm    Post subject:
Reply with quote

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 .......
END-IF
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
View user's profile Send private message
chowdhrykapildev

New User


Joined: 05 Aug 2009
Posts: 44
Location: Hyderabad

PostPosted: Mon Mar 12, 2012 10:24 pm    Post subject:
Reply with quote

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 .......
END-IF
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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7912
Location: Bellevue, IA

PostPosted: Mon Mar 12, 2012 10:38 pm    Post subject:
Reply with quote

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 left-justified and blank-filled? 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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Tue Mar 13, 2012 12:39 am    Post subject: Reply to: Alphanumeric variable in a numeric check
Reply with quote

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 right-most 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
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
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm
No new posts What is the command to check MODE of ... rohanthengal CLIST & REXX 6 Fri Nov 18, 2016 1:48 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm


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