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
 

 

Help for OCCURS DEPENDING ON

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

New User


Joined: 12 Jun 2008
Posts: 12
Location: Pune

PostPosted: Thu Oct 16, 2008 5:00 pm    Post subject: Help for OCCURS DEPENDING ON
Reply with quote

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

Robert Sample

Global Moderator


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

PostPosted: Thu Oct 16, 2008 5:08 pm    Post subject:
Reply with quote

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

Active User


Joined: 23 Jul 2008
Posts: 106
Location: USA

PostPosted: Thu Oct 16, 2008 5:24 pm    Post subject:
Reply with quote

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

Global Moderator


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

PostPosted: Thu Oct 16, 2008 5:39 pm    Post subject:
Reply with quote

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

Active User


Joined: 23 Jul 2008
Posts: 106
Location: USA

PostPosted: Thu Oct 16, 2008 5:41 pm    Post subject:
Reply with quote

I am pretty much clear now.

Thanks for your clarification Bob!
Back to top
View user's profile Send private message
udaysnimje

New User


Joined: 12 Jun 2008
Posts: 12
Location: Pune

PostPosted: Thu Oct 16, 2008 5:58 pm    Post subject:
Reply with quote

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

New User


Joined: 14 Nov 2008
Posts: 1
Location: Pune

PostPosted: Fri Nov 14, 2008 2:54 pm    Post subject: Occurs variable
Reply with quote

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.. icon_rolleyes.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Fri Nov 14, 2008 6:10 pm    Post subject:
Reply with quote

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

New User


Joined: 28 Feb 2005
Posts: 4
Location: chennai

PostPosted: Sun Dec 14, 2008 9:15 pm    Post subject: Occurs depending on
Reply with quote

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

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sun Dec 14, 2008 10:05 pm    Post subject:
Reply with quote

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

New User


Joined: 28 Feb 2005
Posts: 4
Location: chennai

PostPosted: Tue Dec 16, 2008 5:43 pm    Post subject:
Reply with quote

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

Global Moderator


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

PostPosted: Tue Dec 16, 2008 6:32 pm    Post subject:
Reply with quote

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

New User


Joined: 28 Feb 2005
Posts: 4
Location: chennai

PostPosted: Tue Dec 16, 2008 6:53 pm    Post subject:
Reply with quote

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

New User


Joined: 28 Feb 2005
Posts: 4
Location: chennai

PostPosted: Tue Dec 16, 2008 7:07 pm    Post subject:
Reply with quote

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

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Dec 16, 2008 11:16 pm    Post subject:
Reply with quote

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

Global Moderator


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

PostPosted: Tue Dec 16, 2008 11:29 pm    Post subject:
Reply with quote

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
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 Add Trailing Zeroes depending upon th... Rohit Umarjikar DFSORT/ICETOOL 3 Fri Oct 23, 2015 1:47 am
No new posts Multiple OCCURS depending on in same ... muralirajansm COBOL Programming 6 Fri Aug 21, 2015 4:23 pm
No new posts 3-D Table with nested DEPENDING ON Cl... VivekKhanna COBOL Programming 5 Sat Aug 08, 2015 11:18 pm
No new posts Repeating input records for variable ... ksouren007 DFSORT/ICETOOL 1 Fri Jul 31, 2015 4:16 pm
No new posts Syncsort - help needed with ICETOOL O... ramas.kamal SYNCSORT 2 Wed Apr 16, 2014 4:17 pm


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