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

Host variables declared in File descriptor of FILE SECTION


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rakesh17684

New User


Joined: 08 Oct 2006
Posts: 61
Location: San Diego

PostPosted: Mon Feb 20, 2012 12:08 pm
Reply with quote

Hi,
I am trying to use a host variable in a query for a COBOL DB2 program.
The variable is declared in the file section

Code:
DATA DIVISION.                 
FILE SECTION.                   
FD INPT-FILE                   
    RECORDING MODE IS F         
    BLOCK  CONTAINS   0 RECORDS.
 01 INPT-DATA.
      05 INPT-FR-CODE               PIC S9(04) USAGE COMP.       


--------------
when the variable is used as host variable for the queries inside the program . the query fails.
When the same variable is moved to a working section/DCLGEN variable it works fine.
What is the reason this happens .can we avoid this ?I am trying to reduce the number of variables declared.

Thanks in advance for any explanation or solution given.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Feb 20, 2012 12:41 pm
Reply with quote

What does your manual say?

How do you feel this "reduces the number of variables" and why would you want to do that?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Feb 20, 2012 12:59 pm
Reply with quote

Quote:
the query fails.


only thing that failed was the TS providing enough info......

what is the data definition of the variable in W-S (dclgen)

and as Bill mentioned, why are you so worried about number of variables in your program?

do you have some idiot at your site that says the number of variables must be keep to a minimum?

the biggest problem with using the FD, is that it must be open before it can be addressed.
and since all the addresses for the host variables are passed to db2 prior to your first instruction after PROCEDURE DIVISION,
i can understand why you are having problems...........
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Feb 27, 2012 8:10 pm
Reply with quote

If I recall correctly : addresses within file section vary within a block
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Feb 27, 2012 10:17 pm
Reply with quote

Generally, yes. Read a record, new address. Write a record, new address.

So, no address before the first program instruction, and then a changing address.

I'd even suspect it tellls you in some manual somewhere not to even try this.
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Mon Feb 27, 2012 11:05 pm
Reply with quote

Yes, I am pretty sure it is documented, but in IBM-speak. Years ago, when I first read that section my reaction was "WTF?" After some research, I figured out what they meant and boiled it down to a simple rule of thumb: Always define DB2 Host Variables in Working Storage. Never use the FD area, never use Linkage. (Local Storage is okay too, but who uses that?).

My other rule of thumb: Where possible, always use the host variables defined in the DCLGEN. You can't go wrong that way.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Feb 27, 2012 11:29 pm
Reply with quote

quoting from the manual
Quote:
You must explicitly declare
all host variables and host
variable arrays that are used
in SQL statements in the
WORKING-STORAGE SECTION or
LINKAGE SECTION of your
program's DATA DIVISION.


the must applies also to the where
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Feb 27, 2012 11:39 pm
Reply with quote

for linkage section, you need to add a line of code to your program to move '1'
(or space, i forget which,
but you can tell how to turn the switch back on for each call
by looking at the compiler listing)
to INIT-FLAG as the first instruction in your program.
that way, each time the program is CALLed,
db2, again, goes thru the code which passes the addresses to db2.

because one needs to know what is going on in the computer,
it is generally safer to tell everyone only to use working/local storage.

linkage requires resetting of the INIT-FLAG,
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Feb 27, 2012 11:55 pm
Reply with quote

And presumably don't get clever with SET ADDRESS, just because it is allowed in the Linkage Section.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Feb 28, 2012 1:02 am
Reply with quote

a little further clarification.

you have a db2 module that is CALLed by everybody to select some rows.
first time it is CALLed by prg-1 USING PGM-1 WORKING-STORAGE.
db2 module provides the addresses linkage section variables to db2, which are prg-1 working-storage.

then prg-2 CALLs db2 module with prg-2 WORKING-STORAGE.

if the db2 module does not have the INIT-FLAG reset logic,
which would cause db2 to be CALLed for addressing,
all the sql would use pgm-1 data areas for host-variables.
even though pgm-2 CALLed the db2 module (with pgm-2 using pgm-2 working-storage)

sad but true.
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Tue Feb 28, 2012 1:46 am
Reply with quote

In an IMS online environment, it can get even worse because the subroutine may remain in storage between transactions. Even if only one program calls the subroutine, that calling program may not be loaded in the same area of storage from one transaction to the next. It *usually* works okay, but there are no guarantees. I have had some very interesting debugging sessions caused by this issue.

Rather than try to explain all this to, er, less technically minded developers, I usually just trot out the rule of thumb. The smarter ones will ask why; there's no point in trying to explain it to the others.
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 -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top