View previous topic :: View next topic
|
Author |
Message |
amitc23
New User
Joined: 05 Nov 2014 Posts: 95 Location: India
|
|
|
|
Hi
I am having a problem checking for end of elements in an array. The Fixed file record is defined as
01 AB-RECORD-PRC redefines AI-record.
05 filler pic x(12).
05 record-num pic 9(08) comp.
05 AB-centre pic 9(2) comp-3.
05 filler pic x(4).
05 AB-date pic 9(7) comp-3.
05 filler pic x(3).
05 AB-volume pic 9(9) comp-3.
05 filler pic x(22).
05 AB-detail.
10 AB-detail-data occurs 600 times.
15 AB-detail-date pic 9(7) comp-3.
15 AB-detail-vol pic x(4).
15 filler pic x(22).
05 filler pic x(378).
The 600 items array is populated for only about 10 occurrences and then it contains all X'FFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
I am doing a search on this array as follows:
Perform varying wscount from 1 by 1 until
(AB-detail-date(wscount) = ws-mst-date) or
(AB-detail-date(wscount) = High-Values)
end-perform.
This code is giving error:
AB-DETAIL-DATE (PACKED INTEGER)" WAS COMPARED WITH "HIGH-VALUES". Comparison was discarded.
Please suggest how can I resolve ?
Regards
Amit |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
OMG...
You cannot compare COMP-3 variables with character values.
Code: |
Perform varying wscount from 1 by 1 until
(AB-detail-vol(wscount) = High-Values) or
(AB-detail-date(wscount) = ws-mst-date)
end-perform. |
This of course assumes that AB-detail-vol is also initialized with High values.
And if the compiler decides that the order of the compares needs to be reversed for efficiency reasons, you will still end in shit creek without a paddle. |
|
Back to top |
|
|
amitc23
New User
Joined: 05 Nov 2014 Posts: 95 Location: India
|
|
|
|
Hi
So is there any way I can find the end of elements on array ?
Regards |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
How can you possibly not know how many entries you stuffed in the table? So you use that to limit your search.
And yes, you "protect" your comparison of the packed-decimal by testing the limit first. No COBOL compiler is ever going to swap the comparisons for optimisation. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
A packed decimal variable with HIGH-VALUES will be non-numeric. So you now have at least 3 good ways to resolve your issue:
1. AB-DETAIL-DATE (WSCOUNT) NOT NUMERIC
2. AB-DETAIL-VOL (WSCOUNT) = HIGH-VALUES
3. Track the number of entries in the array and compare WSCOUNT to that value |
|
Back to top |
|
|
amitc23
New User
Joined: 05 Nov 2014 Posts: 95 Location: India
|
|
|
|
Hi Bill
The code section I pasted above is File Definition of the input file. I am reading directly from the file. Each record in itself contains array of 30 characters. The array starts at position 57, first element 57-86 , second element 87-116 , third element 117-146 and so on. Record is 18437 bytes long. This 30 byte array is repeated 600 times.So actually at processing time I do not know how many array elements would be populated.
I hope I am not missing anything and am able to explain. Please let me know if I am not. |
|
Back to top |
|
|
amitc23
New User
Joined: 05 Nov 2014 Posts: 95 Location: India
|
|
|
|
Thanks Robert, Not numeric works. It is giving a 0c7 at later point, but I can take care of that. |
|
Back to top |
|
|
amitc23
New User
Joined: 05 Nov 2014 Posts: 95 Location: India
|
|
|
|
It was a code fall through. I fixed it.
Thanks again Robert, Bill and prino.
Best Regards
Amit |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
"Traditionally", something in the record prior to the table would tell how many entries were actually active in the table.
If you don't have that, both Prino and Robert have suggested testing an alpha-numeric field for high-values.
There are other ways of arranging the same thing.
The problem with Robert's NUMERIC test is that there may be non-numeric (and non-HIGH-VALUES) data :-)
You also need to use the OCCURS limit, otherwise if all entries are full you may "fall of the end" of the table. |
|
Back to top |
|
|
jerryte
Active User
Joined: 29 Oct 2010 Posts: 202 Location: Toronto, ON, Canada
|
|
|
|
I suggest to define the table
Code: |
10 AB-detail-data occurs 600 times.
15 AB-detail-entry.
20 AB-detail-date pic 9(7) comp-3.
20 AB-detail-vol pic x(4).
20 filler pic x(22).
|
Then do your check check
Code: |
Perform varying wscount from 1 by 1 until
AB-detail-entry (wscount) = high-values or
AB-detail-date(wscount) = ws-mst-date
do something
end-perform.
|
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
That'll fall off the end when the table is full and a match is not found :-)
You could make the test an 88. Should. |
|
Back to top |
|
|
|