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
 

 

group variable not working in IF clause.

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

New User


Joined: 17 Feb 2014
Posts: 19
Location: India

PostPosted: Mon Feb 17, 2014 8:19 pm    Post subject: group variable not working in IF clause.
Reply with quote

hi,

my declaration is as below.

01 WS-VIRT-VND.
05 WS-VNDR-A PIC 9(06) VALUE ZEROS.
05 WS-VNDR-B PIC 9(02) VALUE ZEROS.
05 WS-VNDR-C PIC 9(01) VALUE ZEROS.
01 WS-VIRT-VNDR REDEFINES WS-VIRT-VND PIC 9(09).

after moving 123456789 to WS-VIRT-VND if i use WS-VIRT-VND in IF clause it is not working. That is

IF WS-VIRT-VND > 999999 is resulting as false where as WS-VIRT-VNDR >999999 is resulting as true.

What is the reason?
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Mon Feb 17, 2014 8:33 pm    Post subject: Reply to: group variable not working in IF clause.
Reply with quote

Why do you want to do this?

One is comparing a numeric field to a numeric literal, the other is comparing a group item to a numeric literal which is shorter than the group item.

I'm sure if you consult the manual it will reveal why it is doing a character compare.

Can't say I ever have done such a thing, or would ever consider doing it. Even if it "worked" (if the literal was the same length as the field) would the next person along realise the danger of shortening the literal?
Back to top
View user's profile Send private message
vinuseba

New User


Joined: 17 Feb 2014
Posts: 19
Location: India

PostPosted: Mon Feb 17, 2014 8:39 pm    Post subject:
Reply with quote

hi Bill,

The variable WS-VIRT-VND is rading a number and the IF clause is to make sure the read number is greater than 999999 for further processing.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Mon Feb 17, 2014 9:11 pm    Post subject:
Reply with quote

As you were told, using the group name in the IF statement may give you erroneous results. Do NOT use the group variable name in your IF statement.
Back to top
View user's profile Send private message
pongi

New User


Joined: 21 Aug 2006
Posts: 4
Location: US

PostPosted: Tue Feb 18, 2014 1:40 am    Post subject:
Reply with quote

Please follow the Robert Insturctions. But, thought to post my thoughts.

WS-VIRT-VND > 999999 ==> This will be the Alpha Numeric Comparision. So, First 6 chracters will be compared 123456789 > 999999. - So, it is gave False, since char by char will be compared.

WS-VIRT-VNDR >999999 == Numeric comparison which will work as arithmatic comparison.
Back to top
View user's profile Send private message
vinuseba

New User


Joined: 17 Feb 2014
Posts: 19
Location: India

PostPosted: Tue Feb 18, 2014 9:18 am    Post subject:
Reply with quote

Thanks everyone for the explanation
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Tue Feb 18, 2014 7:53 pm    Post subject:
Reply with quote

Displaying the values of WS-VIRT-VND and WS-VIRT-VNDR before executing your IF statement would have shown you why. It's handy to keep a short test program around for researching problems like this.
Back to top
View user's profile Send private message
vinuseba

New User


Joined: 17 Feb 2014
Posts: 19
Location: India

PostPosted: Wed Feb 19, 2014 9:12 am    Post subject:
Reply with quote

thats cool Terry.... Thank you
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
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts find RACF group for access to spooled... jzhardy JCL & VSAM 1 Mon May 08, 2017 11:46 am
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Group Data based on a key Arun Raj DFSORT/ICETOOL 7 Thu Apr 27, 2017 11:29 pm
No new posts Need Help with : IFTHEN(WHEN=GROUP) Sumanta_89 DFSORT/ICETOOL 1 Wed Apr 19, 2017 5:23 pm


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