View previous topic :: View next topic
|
Author |
Message |
udaysnimje
New User
Joined: 12 Jun 2008 Posts: 12 Location: Pune
|
|
|
|
This query is regarding OCCURS DEPENDING ON
I have copybook declaration as follows
Code: |
01 WS-MAIN-RECORD
05 WS-RECORD1.
10 WS-R1S1 PIC X(10) VALUE 'TITLE1 '.
10 WS-R1S2 PIC X(05).
05 WS-RECORD2.
10 WS-R2S1 PIC X(10) VALUE 'TITLE2 '.
10 WS-R2S2-COUNTER PIC 9(04).
10 WS-R2S3-DATA OCCURS
1 TO 50 TIMES
DEPENDING ON WS-R2S2-COUNTER.
15 WS-R2S3L1 PIC X(07).
15 WS-R2S3L2 PIC X(12).
05 WS-RECORD3.
10 WS-R3S1 PIC X(10) VALUE 'TITLE3 '.
10 WS-R3S2-COUNTER PIC 9(04).
10 WS-R3S3-DATA OCCURS
1 TO 50 TIMES
DEPENDING ON WS-R3S2-COUNTER.
15 WS-R3S3L1 PIC X(07).
15 WS-R3S3L2 PIC X(12). |
When I compile the code in ECOBOL I am getting saviour error as
1>>> A "VALUE" clause was specified for variably located item
"WS-R3S1". The "VALUE" clause was discarded.
2>>> "OCCURS DEPENDING ON" object " WS-R3S2-COUNTER" was defined in a
variably located area. Execution results are unpredictable.
Please explain how to remove this error. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
The COBOL Language Reference in section 5.3.17.1 says:
Quote: |
A data item cannot contain a VALUE clause if the prior data item contains an OCCURS clause with the DEPENDING ON phrase. |
So either take the VALUE clause off WS-R351, or move it before the OCCURS DEPENDING ON variable. |
|
Back to top |
|
|
Mathiv Anan
Active User
Joined: 23 Jul 2008 Posts: 106 Location: USA
|
|
|
|
I think you cannot have another variable data WS-RECORD3 after a variable data WS-RECORD2 under the layout WS-MAIN-RECORD .
Normally, under a 01 level, we would need to have fixed record at the beginning of the layout and variable record at the end of the layout.
But, two set of variable records under a 01 class is not allowed.
Please correct me if i am wrong. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Actually, Mathi, you can have multiple OCCURS DEPENDING ON variables in an 01 structure. However, what the second compiler message is complaining about is that the object of the OCCURS DEPENDING ON (the number of occurrences variable) must be located in fixed storage (i.e., cannot occur in or after an OCCURS DEPENDING ON variable). Coded this way, the 01 would be acceptable:
Code: |
01 WS-MAIN-RECORD
05 WS-RECORD1.
10 WS-R1S1 PIC X(10) VALUE 'TITLE1 '.
10 WS-R1S2 PIC X(05).
05 WS-RECORD2.
10 WS-R2S1 PIC X(10) VALUE 'TITLE2 '.
10 WS-R3S1 PIC X(10) VALUE 'TITLE3 '.
10 WS-R2S2-COUNTER PIC 9(04).
10 WS-R3S2-COUNTER PIC 9(04).
10 WS-R2S3-DATA OCCURS
1 TO 50 TIMES
DEPENDING ON WS-R2S2-COUNTER.
15 WS-R2S3L1 PIC X(07).
15 WS-R2S3L2 PIC X(12).
05 WS-RECORD3.
10 WS-R3S3-DATA OCCURS
1 TO 50 TIMES
DEPENDING ON WS-R3S2-COUNTER.
15 WS-R3S3L1 PIC X(07).
15 WS-R3S3L2 PIC X(12). |
|
|
Back to top |
|
|
Mathiv Anan
Active User
Joined: 23 Jul 2008 Posts: 106 Location: USA
|
|
|
|
I am pretty much clear now.
Thanks for your clarification Bob! |
|
Back to top |
|
|
udaysnimje
New User
Joined: 12 Jun 2008 Posts: 12 Location: Pune
|
|
|
|
Thank you very much Robart and Mathi. It's new learning for me.
I have two options now :-
1>>>>I think I need to chnage record layout as per the positions of counters and VALUE clause
2>>>> Declear each 05 level record as 01 level. |
|
Back to top |
|
|
Shalabh Rastogi
New User
Joined: 14 Nov 2008 Posts: 1 Location: Pune
|
|
|
|
Hi robert,
I have the same query as OCCURS clause DEPENDING ON in a variably located area..
I have 1 more question like, inur resolution you have moved all the counters before Occurs clause, But what If I cannot change the Layout of my Copybook, is there ny other way out.. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Take the value clause off WS-R3S1 That's the only way to resolve it if you can't rearrange the variables. |
|
Back to top |
|
|
v_jaay
New User
Joined: 28 Feb 2005 Posts: 4 Location: chennai
|
|
|
|
hi, I have a query on occurs depending on. Its giving me unpredictable result when i run my program.
my record layout is this
working storage declaration.
Code: |
01 rec.
02 no-of-months pic 9(03).
02 employee-rec occurs 5 times.
05 employee-details occurs 1 to 100 times.
10 employee-sal pic s9(04) comp-3.
10 payslip-month pic x(03).
10 payslip-year pic x(04). |
here when i try to run the program the position of my record are getting changed in my output file.
array storage
record 1
no-of-months - 002
employee sal - 112345
payslip month - jun
payslip year - 2004
employee sal - 112345
payslip month - jul
payslip year - 2004
record 2
no-of-months - 001
employee sal - 134567
payslip month - jun
payslip year - 2004
This above records will be stored in a working storage and after doing some validations i will write this to a output file.
in my output file (record format - FB) when i write the above records after validation
112567jun2004
it seems like i'm having some overlay problem in the array that built
can anyone send a sample program for the above scenario.
main table with occurs and internal table with occurs depending on
Thanks in advance
vijay |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
You need to do a much more thorough job describing what you want to do.
Why is the array 2 dimensional?
Will "employee-rec" always occur 5 times? With no value associated with the 5 occurrences, how does the code know which one to use?
Should "employee-details" have an "occurs depending on"?
You need to post a representative sample of the input that will be processed and the output you want from that sample input. Once the requirement is understood, the "how to get there" can be worked on. With no defined target, it is hard to work on code. |
|
Back to top |
|
|
v_jaay
New User
Joined: 28 Feb 2005 Posts: 4 Location: chennai
|
|
|
|
dick scherrer,
you are right my friend. my previous example was not detailed because i thought the concept is more concerned then the example
cause i'm getting a overlay problem. i haven't a clue where its going wrong.
01 rec.
02 department-rec occurs 5 times
indexed by emp-idx.
05 month-count pic 9(03).
The month and the salary details will be coming from different file. where the above working storage will count the no-of-months in the month-count field.
as you all know that the depending on clause cannot use the work-variable declare in the array.
so we need to have two layouts for this and the 5 occurence is just an example. it can be any value which denotes the restriction of how many employee is allowed and index given in the above example is nothing but the employee number.
as per the below working storage the no of records per employee is
100 at maxium and 1 at the minium.
the employee sal is a calculated field which we will be calculating based on the breakups such as HRA, PF, BASIC etc...
This is the working storage declare to create the output file with independent record for each month.
01 rec.
02 no-of-months pic 9(03).
02 employee-rec occurs 5 times.
05 employee-details occurs 1 to 100 times
depending on no-of-months
indexed by det-indx
10 employee-sal pic s9(04) comp-3.
10 payslip-month pic x(03).
10 payslip-year pic x(04). |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
What do your MOVE and/or COMPUTE statements look like? If you think you're having an overlay problem, we need to see how your program is using the data structure to provide feedback. |
|
Back to top |
|
|
v_jaay
New User
Joined: 28 Feb 2005 Posts: 4 Location: chennai
|
|
|
|
robert,
whenever i get a record i do the following things.
1) set the index to the employee number
2) check the month-counter (employee indx). If counter greater than zero add 1 to the month counter. else set the counter to 1.
01 rec.
02 department-rec occurs 5 times
indexed by emp-idx.
05 month-count pic 9(03).
ex.
set emp-idx to valid-emp (which will be a subscript).
if month-counter (emp-idx) > 0 then
compute month-counter (emp-idx) = month-counter (emp-idx) + 1
else
compute month-counter (emp-idx) = 1
end-if
3) before writing the output file. I read the following table using perform where the index value will be incremented.
working storage
01 rec.
02 no-of-months pic 9(03).
02 employee-rec occurs 5 times.
05 employee-details occurs 1 to 100 times
depending on no-of-months
indexed by det-indx
10 employee-sal pic s9(04) comp-3.
10 payslip-month pic x(03).
10 payslip-year pic x(04).
procedure division.
perform varying emp-idx from 1 by 1 until emp-idx > 5
perform varying i from 1 by 1 until i > no-of-months
set det-indx to I.
move employee-sal (emp-idx, det-indx) to the output
move ---------------
move -------------
end-perform
end-perform |
|
Back to top |
|
|
v_jaay
New User
Joined: 28 Feb 2005 Posts: 4 Location: chennai
|
|
|
|
There seems to be a overlay problem. The same program when i ran without depending on gives me the proper output that i expect. But when using depending on it gives unpredictable results.
Sample input.
Employee number - 001
no-of-months - 2
Employee number - 002
no-of-months - 1
output i expect is
record 1
no-of-months - 002
employee sal - 112345
payslip month - jun
payslip year - 2004
employee sal - 112345
payslip month - jul
payslip year - 2004
output file will have employee number (first 3 bytes), sal (6bytes), month(3bytes) and year (4 bytes).
001 112345jun2004
001 112345jul2004
record 2
no-of-months - 001
employee sal - 134567
payslip month - jun
payslip year - 2004
output file will have employee number (first 3 bytes), sal (6bytes), month(3bytes) and year (4 bytes).
002 134567jun2004
The second record seems to be overlaying while using depending on clause. In the output file the next sequence of records are also getting overlayed. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Please practice using the "Code" tag. . . Data Division entries should be indented for readability as well as Procedure Division entries. . .
This "employee-rec occurs 5 times. " has no index defined. Suggest you define one and use it rather than the index from the "other" array.
I'll be gone for a while, but wanted to drop a quick reply in case it might help. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
What's the difference between index and subscript? Anybody?
An index is defined with INDEXED BY and is a 4-byte address pointer that is set to the address of the desired record of an array. A subscript is a variable (working storage usually but not always) that is numeric and can be set to a value. This value, when used with an array, is converted by COBOL into the address of the corresponding record in the array.
Indexes therefore cannot be used with any array except the one they are defined for -- or side effects (usually unpredictable and frequently nasty) will occur. Subscripts are an element number and can be used with any array. Change your code so each array has its own unique index and your overlay problem will go away, I bet. |
|
Back to top |
|
|
|