MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

linkage field and db2 command

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
jctgf
Beginner


Joined: 05 Nov 2006
Posts: 89
Topics: 36

PostPosted: Thu Mar 19, 2009 6:31 pm    Post subject: linkage field and db2 command Reply with quote

Code:

linkage section.
01 dfhcommarea.
03 lk-timestamp pic x(26).

procedure division using dfhcommarea.
exec sql
        set :lk-timestamp = current_timestamp
end-exec
goback.


hi,

in the program above i'm receiving the db2 current timestamp in a linkage section variable.

it works perfectly most of the times, but SOMETIMES it doesn't.

i replaced lk-timestamp for a ws variable (w-timestamp) and then moved it to lk-timestamp and it solved the problem. please, see below:

Code:

working-storage section.
01 w-timestamp pic x(26).

linkage section.
01 dfhcommarea.
03 lk-timestamp pic x(26).

procedure division using dfhcommarea.
exec sql
        set :w-timestamp = current_timestamp
end-exec
move w-timestamp to lk-timestamp.
goback.



can someone explain why SOMETIMES the linkage variable isn't properly filled with the result of a db2 sql command?

thanks.
Back to top
View user's profile Send private message Send e-mail
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Fri Mar 20, 2009 4:24 am    Post subject: made a few changes to original post Reply with quote

did you CALL this module from 2 different modules?

if you look at the compile listing, you will see inserted code (by db2) between your Procedure Division Using statement and
your exec sql set timestamp.

this code is executed once - by the first call to this module (notice SQL-INIT-END logic).

this code sets up the addressing for db2 for your host variables.

1st call, the linkage section comes from program A working storage. sql-init section addresses the host variable to program A.

2nd call, the linkage section comes from program B working storage, yet db2 has the host variable addressed to program A.
you will find when program B calls the db2 module,
the set timestamp will populate program A working storage.

that is why it works sometimes.

would suggest that you use linkage for host variables only if the db2 program is only called from one module and the linkage is to that one modules working storage.

if your db2 timestamp program is called from more than one module, you need to use working storage of the db2 program as the host variable - as you had to do to get everything to work.

you can also solve the problem by reseting the sql-init-flag each time you exit the db2 module, but I would not recommend this solution

I made the same mistake about 15 years ago.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
jctgf
Beginner


Joined: 05 Nov 2006
Posts: 89
Topics: 36

PostPosted: Fri Mar 20, 2009 6:06 am    Post subject: Reply with quote

thank you a lot, sir!
thank you very much indeed!
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group