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
 

 

Host variables declared in File descriptor of FILE SECTION

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
rakesh17684

New User


Joined: 08 Oct 2006
Posts: 59
Location: Atlanta

PostPosted: Mon Feb 20, 2012 12:08 pm    Post subject: Host variables declared in File descriptor of FILE SECTION
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7240

PostPosted: Mon Feb 20, 2012 12:41 pm    Post subject: Reply to: Host variables declared in File descriptor of FILE
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    Post subject:
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: 1278
Location: Belgium

PostPosted: Mon Feb 27, 2012 8:10 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7240

PostPosted: Mon Feb 27, 2012 10:17 pm    Post subject: Reply to: Host variables declared in File descriptor of FILE
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: 641
Location: Whitby, ON, Canada

PostPosted: Mon Feb 27, 2012 11:05 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Feb 27, 2012 11:29 pm    Post subject: Reply to: Host variables declared in File descriptor of FILE
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7240

PostPosted: Mon Feb 27, 2012 11:55 pm    Post subject: Reply to: Host variables declared in File descriptor of FILE
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    Post subject:
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: 641
Location: Whitby, ON, Canada

PostPosted: Tue Feb 28, 2012 1:46 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm


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