Triton Db2 Geek

Confessions of a DB2 geek

IBM Gold Consultant Program and IBM Premier business Partner

Assembler : Getting Connected to DB2

May 7th, 2013 - by

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
ST     R0,ADSNALI
LOAD   EP=DSNWLI2   LOAD CAF IFI
ST     R0,ADSNWLI2

                 :
ADSNALI      DS     F            EP OF DB2 CAF (DSNALI)
ADSNWLI2     DS     F            EP OF DSNWLI2 (DB2 CAF IFI)

Connect
Driving the connection looks a bit like this:

      L        R15,ADSNALI
LA       R5,IFISSID
LA       R6,ENECB        DB2 TERMINATION ECB
LA       R7,STECB        DB2 STARTUP ECB
LA       R8,RIBPTR       DB2 RIB PTR
CALL    (15),(ALICONN,(5),(6),(7),(8)),VL,MF=(E,CALLBLK)
LTR      R15,R15
BE       DOCMD

           :
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′.

Disconnect
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
L R15,ADSNALI
CALL (15),(ALIDISC),VL,MF=(E,CALLBLK)
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.

Roar.

Follow James on Twitter @db2dinosaur

Comments

« »

Tag Archives