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
 

 

Declaring a cobol table with respect to a DB2 Table

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

New User


Joined: 25 Sep 2006
Posts: 3

PostPosted: Wed Jan 03, 2007 5:01 pm    Post subject: Declaring a cobol table with respect to a DB2 Table
Reply with quote

Hi,

I have one DB2 table...i want load the data from DB2 table to cobol table. i dont know how many rows are there in the db2 table.. while declaring the cobol table i have mention the size of the table... could you please let me know how can i do it.
Back to top
View user's profile Send private message

guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Wed Jan 03, 2007 6:07 pm    Post subject:
Reply with quote

Hi Esudhakar,

Quote:
while declaring the COBOL table i have mention the size of the table... could you please let me know how can i do it.


Would u please elaborate ur query?
Do u want to know how we can load COBOL table from db2 table? Or u want to know how to give occurrences for COBOL table without knowing number of records?
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Wed Jan 03, 2007 6:15 pm    Post subject: Re: declaring a cobol table
Reply with quote

esudhakar wrote:
I have one DB2 table...i want load the data from DB2 table to cobol table. i dont know how many rows are there in the db2 table.. while declaring the cobol table i have mention the size of the table... could you please let me know how can i do it.
Do you want to know how many rows you will need in the cobol table at the time of compile?
Or do you want to know how many rows you will need at the time of the select (runtime)?
Back to top
View user's profile Send private message
esudhakar

New User


Joined: 25 Sep 2006
Posts: 3

PostPosted: Thu Jan 04, 2007 11:50 am    Post subject:
Reply with quote

Do u want to know how we can load COBOL table from db2 table? Or u want to know how to give occurrences for COBOL table without knowing number of records?

I want to know both ways...
Back to top
View user's profile Send private message
kgumraj

Active User


Joined: 01 May 2006
Posts: 151
Location: Hyderabad

PostPosted: Fri Jan 05, 2007 11:02 am    Post subject: Re: declaring a cobol table
Reply with quote

Hi,

Use this query in your program before fetching the information from the table

Select count(*) into :WS-VAR from tablea;

you can then declare the variable table as

01 tablea.
02 rowa occurs 1 to 100000 depending on ws-var
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 962
Location: Richmond, Virginia

PostPosted: Fri Jan 05, 2007 7:00 pm    Post subject:
Reply with quote

This still limits you to 100000 rows. COBOL, unlike PL/I and other languages, does not support dynamic array allocation.

If that's what you need in COBOL, try this multi-step process:

1. in program1, do the count as above, and then generate your actual program, perhaps from a template file, replacing the OCCURS upper bound with your count, writing the generated program2 to a dataset
2. feed program2 into a compile/link step
3. execute program2, which is assured of having the correct table size assuming that in this very short time no table changes would have increased the count

Note that certain installations frown on generating production code as it has not passed through change-control procedures.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Fri Jan 05, 2007 7:10 pm    Post subject:
Reply with quote

Phrzby Phil wrote:
This still limits you to 100000 rows. COBOL, unlike PL/I and other languages, does not support dynamic array allocation.
IIRC, not natively, but GETMAINs could be called on behalf of the COBOL program, couldn't they? That should allow for than 100000 rows, wouldn't it?
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Fri Jan 05, 2007 11:18 pm    Post subject: Re: declaring a cobol table
Reply with quote

Calling getmain is a method that will allow for far greater memory allocations than native Cobol will allow, however then you may have to get into maintaining a ?linked list?, calculating subscript offsets and running the linked list chain to find the record your looking for. The overhead of doing this usually offsets the pluses; however, there is a place for it.
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: Sat Jan 06, 2007 12:48 am    Post subject:
Reply with quote

Hello,

When the data is loaded from the database to the COBOL table, what wil the next process(es) be?

Depending on your requirements, you may be able to create a temporary database table that is customized (situation specific keys and only the columns you need for the "table") to meet you needs.

Also, depending on your requirements, you may be able to process directly against the original database table.

If you post some more info, we will be better able to help.
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 Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm


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