Have a Question?
Print

01222: Trigger Code to Determine and Log Programs Used to Access Data

Title:

Trigger Code to Determine and Log Programs Used to Access Data

Description:

A trigger consists of a block of BBj code that executes when a particular type of operation occurs on a particular data table. In BBj, triggers belong to individual physical files. This means that a WRITE RECORD operation on a file and an SQL UPDATE or INSERT statement on a table defined in the Data Dictionary both cause write triggers to fire. 

This functionality makes the trigger an ideal tool for runtime analysis. Use the following trigger code to log the various programs that are accessing any given data file. Possible use-cases include Analysysis for modernization of legacy code and debugging for file corruption.

Resolution:


td! = BBjAPI().getFileSystem().getTriggerData() 
id$ = td!.getIDString() 

logfile$=”/path/to/log.txt” 


if len(id$)>4 then 
if id$(1,4)=”BBJ:” then 

id=num(id$(5)) 
sesinfos!=BBjAPI().getSessionInfos() 

for i=0 to sesinfos!.size()-1 

sesinfo!=sesinfos!.get(i) 
if sesinfo!.getSessionID()=id then 

ch=unt 
open (ch,MODE=”O_CREATE,O_APPEND”)logfile$ 
write (ch) “Timestamp: “+date(0:”%Dz.%Mz.%Yl %Hz:%mz:%sz”)+” 
File: “+td!.getFilename()+” Pgm: “+sesinfo!.getProgramName()+” Line: 
“+str(sesinfo!.getProgramLine())+” User: “+sesinfo!.getUser()+” Terminal: 
“+sesinfo!.getTerminalID()+” IP: “+sesinfo!.getIPAddress()+” Type: 
“+td!.getTriggerType() 
close (ch) 
break 
fi 

next i 

else 

ch=unt 
open (ch,MODE=”O_CREATE,O_APPEND”)logfile$ 
write (ch) “Timestamp: “+date(0:”%Dz.%Mz.%Yl %Hz:%mz:%sz”)+” 
File: “+td!.getFilename()+” Pgm: (“+id$+”) Line: – User: – Terminal: – IP: – 
Type: “+td!.getTriggerType() 
close (ch) 

fi 
fi



Last Modified: 01/14/2011 Product: BBj Operating System: N/A

BASIS structures five components of their technology into the BBx Generations.

Table of Contents
Scroll to Top