View previous topic :: View next topic |
Author |
Message |
jctgf Beginner
Joined: 05 Nov 2006 Posts: 89 Topics: 36
|
Posted: Thu Mar 19, 2009 6:31 pm Post subject: linkage field and db2 command |
|
|
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 |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Fri Mar 20, 2009 4:24 am Post subject: made a few changes to original post |
|
|
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 |
|
|
jctgf Beginner
Joined: 05 Nov 2006 Posts: 89 Topics: 36
|
Posted: Fri Mar 20, 2009 6:06 am Post subject: |
|
|
thank you a lot, sir!
thank you very much indeed! |
|
Back to top |
|
|
|
|