IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

how to load an array with ODO declaration


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Wed Jul 07, 2010 10:04 am
Reply with quote

Hi

The requirement is i need to use an array with ODO clause for the following case.

There are 5 managers and the no. of area each manager handles varies from 3 to 6.

I need to know how to load this array with syntax and the declaration.
and how data would be present in the input file.Also how to load this array from the file.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Jul 07, 2010 11:21 am
Reply with quote

Ambili S wrote:
and how data would be present in the input file
Do you believe that somebody here knows better about YOUR input data? icon_eek.gif
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Wed Jul 07, 2010 11:24 am
Reply with quote

The input file contains the manager id ( 2 chars) and the no of area he handles ( pic 9(1)).
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Jul 07, 2010 11:27 am
Reply with quote

Is this a business requirement or some kind of case study? What do you mean by "ODO clause"? If you're referring to the COBOL OCCURS DEPENDING ON, why not read through the COBOL Manuals and try something on your own first.
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Wed Jul 07, 2010 1:40 pm
Reply with quote

Here's my requirement,please ignore the above posts.

I have a students file which contains student id(2 char) and the subjects ( 3 chars) they have opted for. The subjects opted by the students varies from 2 to 6. The input file is as follows :

01ENGHIN
02HINGEOCHESCIENGBIO
03SCIGEOPHYBIO

My query is how to declare this using occurs depending on clause and how do i load this array from the above file. After loading if i want to see the subjects opted by student id 02 , how can i do it.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Jul 07, 2010 2:31 pm
Reply with quote

you will miss the 'learning portion of this exercise'
without making any effort yourself.

so, without explanation, I will show you how to define your table.
Code:

05  student-count pic s9(7) comp-3 value zero.
05  student-table  occurs 0 to 5000 times depending on student-count indexed by student-idx.
  10  student-id  pic x(02).
  10  class pic x(03) occurs 6 times indexed by class-idx.
       88  no-class  value spaces.


with this as a start, I will leave it to you to try your hand at the code.
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Wed Jul 07, 2010 3:23 pm
Reply with quote

Thanks for the above code.If you could provide me some links which can throw more light on this , it would of great help.Meanwhile i"ll try with the piece of code you have provided.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Jul 07, 2010 3:34 pm
Reply with quote

you can start with the IBM Manuals link at the top of the page.

This is a link for All Cobol Manuals.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Wed Jul 07, 2010 3:41 pm
Reply with quote

1.4.5 Creating variable-length tables (DEPENDING ON)
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Thu Jul 08, 2010 9:29 am
Reply with quote

I tried using the following declaration. Please correct me what's gone wrong here.

Since in my i/p file i have 3 student records with varying subjects( Minimum 1 subject and maximum is 6 subject) , i use the following array declaration. sTUDENT ID ( 2 CHARS) SUBJECT( 3CHARS)

I/p file layout :

01 STUDENT-REC.
02 STU-ID PIC 9(2).
02 SUB1 PIC X(3).
02 SUB2 PIC X(3).
02 SUB3 PIC X(3).
02 SUB4 PIC X(3).
02 SUB5 PIC X(3).
02 SUB6 PIC X(3).


I/p file data:

01AAA
02BBBDDDEEEHHHJJJPPP
03TTTUUUOOO

01 CNT PIC 9(1).
01 STUDENT-REC.
02 STUD-DETAILS OCCURS 5 TIMES INDEXED BY I1.
03 STUDNT-ID PIC 9(2).
03 SUBJECT OCCURS 1 TO 6 TIMES DEPENDING ON CNT.
05 STU-SUB PIC X(3).

Now to load the array from file i used the below logic.

Read input file
Move STU-ID to STUDNT-ID(I1).
move SUB1 to STU-SUB(I1,CNT).
Add 1 to CNT.
move SUB2 to STU-SUB(I1,CNT).
Add 1 to CNT.
likewise till SUB6 ....
then SET I1 up by 1 ....and repeat the above.

This loaded the array but i am unable to do a SEARCH in the array.

Please do let me know what's going wrong.
Back to top
View user's profile Send private message
chavinash2004

New User


Joined: 30 Jun 2010
Posts: 37
Location: hyderabad

PostPosted: Thu Jul 08, 2010 10:48 am
Reply with quote

Hi all,
Please any of yuou explain me what is the difference between IF and IF NOT with example.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Jul 08, 2010 11:42 am
Reply with quote

chavinash2004,
If you start a new thread, as you should have,
you will receive an answer;
if not, you will not.


Ambili S,

Quote:
This loaded the array

no, that is untrue

there will only be one value of cnt - there is only one variable.
as a result, the value of count will dictate howmany classes there
are for each student.
based on your input, you will have 3 classes for each student.
you know by examining your input, that each student does not have the
same number of classes.

yet, by virtue of the way you decided to design the table,
you have no way to determine the actual number of classes each student has.

there are a variable number of students.
though each student can have between 1 and 6 classes, your design does not allow for anyway to determine howmany each student has.

suggest you go back an re-read (or read) the manual, specifically the programmers guide,
and learn about the restrictions of defining complex ODO's.
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Thu Jul 08, 2010 12:07 pm
Reply with quote

Sir is this declaration correct :

01 STUDENT-REC.
03 CNT PIC 9(1).
03 STUDENT-TABLE OCCURS 5 TIMES INDEXED BY I1.
05 STU-ID PIC X(02).
05 STU-SUB PIC X(03) OCCURS 1 TO 6 TIMES DEPENDING ON CNT
INDEXED BY I2.
07 STU-SUB PIC X(3).

If yes , then while loading the array how should the subjects be defined . Should it be :
MOVE SUB1 TO STU-SUB(I1,I2)
SET I2 UP BY 1
MOVE SUB2 TO STU-SUB(I1,I2) ...Likewise till SUB6

If it's this way then when should i increase the value of CNT ?

I read the complex ODO part in the guide . But couldn't understand how to load the complex ODO array and how to refer to the varying part in SEARCH . Could you please help me with it ?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Jul 08, 2010 1:51 pm
Reply with quote

Ambili S,

as Kolusu says: **Sigh**

1. my suggestion of table definition is posted about 6 posts back.

2. your definition means that the number of classes that the last student has,
will determine how many classes every student has.

3. I will help you with your procedural code,
when I think you have decided on a table definition that I think will work.
Item 2. above explains why I don't think your current definition is acceptable.

HINT:
Each student can have a varying number of classes,
but within a definite range of 1 and 6.
so,
IF class(student-index,class-index) = spaces
Then student(student-index) does not have a class.
IF class(student-index,class-index) > spaces,
then student(student-index) has a class.
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Thu Jul 08, 2010 2:07 pm
Reply with quote

Yes , according to my data the Number of Students is fixed , but the classes for each will vary from 1 to 6. So how do i declare this array , load and then do a SEARCH in the array. This is my question. Hope now it's clear. According to your declaration :

Quote:
05 student-count pic s9(7) comp-3 value zero.
05 student-table occurs 0 to 5000 times depending on student-count indexed by student-idx.
10 student-id pic x(02).
10 class pic x(03) occurs 6 times indexed by class-idx.
88 no-class value spaces.


student-id also varies along with class. But for mine student-id remains fixed i.e. 3 students but the classes opted by each of them varies form 1 to 6.

Please help me.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Jul 08, 2010 2:57 pm
Reply with quote

Ambili S,

The number of classes for each student is variable.
therefore if the class table defined for each student is to be an ODO,
then each student must have his/her own 'class-count'.

From the manual:
All data-names used in the OCCURS clause can be qualified; they cannot be subscripted or indexed

so, in order for your table definition to work,
you need the following modification:
Code:

01 CNT PIC S9(3) COMP-3.

01 STUDENT-TABLE.
   02 STUD-DETAILS             OCCURS 5 TIMES
                               INDEXED BY I1.
      03 STUDNT-ID             PIC 9(2).
      03 STUDNT-CLASS-CNT      PIC S9(3).
      03 SUBJECT               OCCURS 1 TO 6 TIMES
                               DEPENDING ON CNT
                               INDEXED BY I2.
         05 STU-SUB PIC X(3).


Code:

set i1 to 1
Read input file
Move STU-ID to STUDNT-ID(I1).
move SUB1 to STU-SUB(I1,1).
move SUB2 to STU-SUB(I1,2).
move SUB3 to STU-SUB(I1,3).
move SUB4 to STU-SUB(I1,4).
move SUB5 to STU-SUB(I1,5).
move SUB6 to STU-SUB(I1,6).
evaluate true
    when sub2 = spaces
         move 1 to cnt
    when sub3 = spaces
         move 2 to cnt
    when sub4 = spaces
         move 3 to cnt
    when sub5 = spaces
         move 4 to cnt
    when sub6 = spaces
         move 5 to cnt
    when other
         move 6 to cnt
end-evaluate
move cnt to STUDNT-CLASS-CNT(T1)
then SET I1 up by 1 ....and repeat the above.


to refer to a student, you set I1 to appropriate value.
to refer to a student's class,
after setting I1,
you move STUDNT-CLASS-CNT(T1) to CNT
then you can refer to a class as STU-SUB(I1,I2)
until I2 > cnt
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Thu Jul 08, 2010 3:28 pm
Reply with quote

Thanks a ton for this. It really helped me to understand the varying array portion. One more question , here i wanted to display all those student id's who have opted for class say 'BBB' . Say the 1st , 3rd and 5th student opt for class BBB. So how can i do this , as i tried with search and it's not working.

Here's my i/p file :

01AAABBB
02CCCDDDEEEFFFNNNHHH
03IIIJJJBBBLLL
04OOOYYYWWWRRR
05IIIJJJBBBLLL
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Jul 08, 2010 4:21 pm
Reply with quote

Using the following definition, (I like level 88's):
Code:

01 CNT PIC S9(3) COMP-3.

01 STUDENT-TABLE.
   02 STUD-DETAILS             OCCURS 5 TIMES
                               INDEXED BY I1.
      03 STUDNT-ID             PIC 9(2).
         88 NO-STUDNT          VALUE ZERO.
      03 STUDNT-CLASS-CNT      PIC S9(3).
      03 SUBJECT               OCCURS 1 TO 6 TIMES
                               DEPENDING ON CNT
                               INDEXED BY I2.
         05 STU-SUB PIC X(3).
            88  SUB-IS-BBB     VALUE 'BBB'.


before populating the table,
Code:
SET NO-STUDNT(1)
    NO-STUDNT(2)
    NO-STUDNT(3)
    NO-STUDNT(4)
    NO-STUDNT(5)  TO TRUE


now, to search the table,
because the true count of subjects is STUDNT-CLASS-CNT(I1)
and CNT is the odo object,
CNT must be populated before each search with STUDNT-CLASS-CNT(I1)

thus, to search for all students taking subject :BBB
Code:

PERFORM VARYING I1
           FROM 1
             BY 1
          UNTIL NO-STUDNT(I1)
             OR I1 > 5
   MOVE STUDNT-CLASS-CNT(I1) TO CNT
   SEARCH SUBJECT
     WHEN SUB-IS-BBB(I1,I2)
          DISPLAY STUDNT-ID(I1)
   END-SEARCH
END-PERFORM
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts How to load to DB2 with column level ... DB2 6
No new posts REASON 00D70014 in load utility DB2 6
No new posts COBOL Ascending and descending sort n... COBOL Programming 5
No new posts DB2 Load - Sort Or order BY DB2 1
Search our Forums:

Back to Top