Assembler : Getting Connected to DB2
At the end of another week of chasing my tail and trying not to get in too much trouble with Mrs DB2 Dinosaur, I’ve resolved to write a quick post about getting the assembler component of the DB2 monitor connected to DB2.
Whilst this is fairly well documented in the manuals, we have a slightly different set of requirements, as:
a) We aren’t running application code / allocating a plan or package, and
b) We are running commands and talking to the IFI
Probably you already looked at this in the DB2 V9 Application Programming and SQL Guide and you’re wondering why this warrants a post. Well, go find the same information in the V10 manuals, little warm blooded squishy. You’ll find that Chapter 30 (Programming for the Call Attach Facility) has disappeared. As I may have mentioned before, I am a bit lazy, so it may be that this is still in the documentation set somewhere else. Then again…
Anyway, I like the CAF as it’s fairly simple and we can get to issue commands, drive the IFI and run dynamic SQL from it without having to write an encyclopedia of code.
Loading the Interface
The interface entry point that we use for CAF is DSNALI, so we make this available to our code with the LOAD macro, and save the entry point that’s returned to us. Note that I generally get all of my loading done early on in the code so that I don’t do all the work, for example, and then find I can’t write the report, so in this example, I’ve loaded the IFI interface DSNWLI2 as well:
LOAD EP=DSNALI LOAD CAF
LOAD EP=DSNWLI2 LOAD CAF IFI
ADSNALI DS F EP OF DB2 CAF (DSNALI)
ADSNWLI2 DS F EP OF DSNWLI2 (DB2 CAF IFI)
Driving the connection looks a bit like this:
LA R6,ENECB DB2 TERMINATION ECB
LA R7,STECB DB2 STARTUP ECB
LA R8,RIBPTR DB2 RIB PTR
ALICONN DC CL12’CONNECT ‘
RIBPTR DS F RELEASE INFORMATION BLOCK
STECB DS F SUBSYSTEM START ECB
ENECB DS F SUBSYSTEM SHUTDOWN ECB
IFISSID DS CL4 DB2 SUBSYSTEM ID
This is about as simple as anything gets in DB2! The ENECB gets posted if DB2 is running and gets a shutdown request, and STECB is posted if DB2 is down and gets a start request. RIBPTR is set following a successful connect request and points to the DB2 Release Information Block (RIB) – see xxxx.SDSNMACS(DSNDRIB) for the mapping.
On return, R15 is the return code (0 = okay), and R0 is the reason code – e.g. x’00F30002′.
Once you’ve finished doing all of the things that you want to do with DB2 over CAF, please remember to close up shop nicely – i.e. stop the traces you started, close the plan you opened, and disconnect:
* CALL DSNALI TO DISCONNECT
DISCDB2 DS 0H
B THEEND AND SHUTDOWN
ALIDISC DC CL12’DISCONNECT ‘
So, now that we know how to get connected, next time we’ll see how to get our traces started and allocate an OPn trace buffer.
Follow James on Twitter @db2dinosaur« Previous | Next »