18
Thu, Apr
5 New Articles

The Display Trigger Description (DSPTRGD) Command

CL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

The new DB2/400 trigger function is a very useful addition to an already great database. Properly implemented, triggers can increase the intelligence of your database by causing it to automatically respond to database events such as adding, deleting, or updating records. For example, a trigger could be implemented to automatically fax an order confirmation whenever a record is added to the order file.

You define triggers for physical files; the definition of what causes the trigger to fire and the program that is called when the trigger fires is contained in the file description. The Display File Description (DSPFD) command will display or print this information, but the format is cluttered. If you want to view trigger information for multiple files, the information will be spread across numerous pages.

The Display Trigger Description (DSPTRGD) command provides a solution to this problem. DSPTRGD displays trigger descriptions in a subfile and uses one single line record to display each trigger description, as illustrated in 1. As you can see, the display includes the library and file the trigger is assigned to, trigger time, trigger event, update condition, and trigger program and library. (For more information, see "DB2/400 Trigger Implementation," MC, October 1995.)

The Display Trigger Description (DSPTRGD) command provides a solution to this problem. DSPTRGD displays trigger descriptions in a subfile and uses one single line record to display each trigger description, as illustrated in Figure 1. As you can see, the display includes the library and file the trigger is assigned to, trigger time, trigger event, update condition, and trigger program and library. (For more information, see "DB2/400 Trigger Implementation," MC, October 1995.)

You can run DSPTRGD for a specific file, a generic (GENERIC*) file name, or all (*ALL) files. You can qualify the file with a specific library or with these special library values: *ALL, *ALLUSR, *USRLIBL, *CURLIB, or *LIBL.

2 contains the source for the DSPTRGD command. 3 contains display file TRG002DF, 4 contains the command processing program (CPP) TRG002CL, and 5 contains program TRG003CL, which builds the subfile information.

Figure 2 contains the source for the DSPTRGD command. Figure 3 contains display file TRG002DF, Figure 4 contains the command processing program (CPP) TRG002CL, and Figure 5 contains program TRG003CL, which builds the subfile information.

How It Works

The DSPTRGD application uses a subfile technique described in "CL Subfiles," TechTalk, MC, August 1995. The unique thing about this technique is the fact that it uses a CL program to interact with a subfile. It's an ideal solution for simple subfile applications such as the DSPTRGD command.

This technique works by changing the display characteristics of a message subfile. Normally, message subfiles use a subfile page (SFLPAG) value of 1, a subfile size (SFLSIZ) value of 2, and a subfile message record (SFLMSGRCD) value of 24. Whenever you send a message to the message subfile, a single line message is displayed on line 24 of the display. If more than one message is sent to the message subfile, a '+' character displays at the end of the message indicating that you can place the cursor on the message and use the roll keys to display additional messages.

For this technique, you expand the number of records to be displayed at the same time (SFLPAG) to a value that is greater than 1; change the number of records in the subfile (SFLSIZ) to a value 1 greater than the SFLPAG value; and change the line number value of the subfile message record (SFLMSGRCD) to a value less than 24. The subfile for the DSPTRGD command uses a SFLPAG value of 18, a SFLSIZ value of 19, and the line number value of the SFLMSGRCD is 4 (see 3). This allows the message subfile to behave similarly to a normal subfile.

For this technique, you expand the number of records to be displayed at the same time (SFLPAG) to a value that is greater than 1; change the number of records in the subfile (SFLSIZ) to a value 1 greater than the SFLPAG value; and change the line number value of the subfile message record (SFLMSGRCD) to a value less than 24. The subfile for the DSPTRGD command uses a SFLPAG value of 18, a SFLSIZ value of 19, and the line number value of the SFLMSGRCD is 4 (see Figure 3). This allows the message subfile to behave similarly to a normal subfile.

The CPP for the DSPTRGD command, TRG002CL (see 4), starts by calling program TRG003CL (see 5), which executes the Display File Description (DSPFD) command and creates an outfile containing the trigger descriptions for the files you've specified. TRG003CL reads the outfile, concatenates the information from a record, and sends the data to the program message queue of the caller (TRG002CL) through the Send Program Message (SNDPGMMSG) command.

The CPP for the DSPTRGD command, TRG002CL (see Figure 4), starts by calling program TRG003CL (see Figure 5), which executes the Display File Description (DSPFD) command and creates an outfile containing the trigger descriptions for the files you've specified. TRG003CL reads the outfile, concatenates the information from a record, and sends the data to the program message queue of the caller (TRG002CL) through the Send Program Message (SNDPGMMSG) command.

Since all messages sent to a program message queue are automatically loaded into the message subfile, you don't need to explicitly load the subfile. After TRG003CL finishes reading all the records in the outfile, TRG002CL displays the subfile through a series of SNDF and SNDRCVF commands, very similar to RPG WRITE and EXTFMT operations.

Check It Out

If you're using triggers and you want a way to view multiple trigger descriptions in an efficient format, check out the DSPTRGD utility. Even if you're not using triggers yet, you should look at the code for this utility to learn more about the CL subfile technique. Although this command could have been written using RPG, I wanted to write it in CL to show you how easy it is to use subfiles in CL programs-something most of us thought was impossible. For simple applications such as the DSPTRGD command, CL and a message subfile may be all you need. I'm sure you can find many other ways to employ this useful technique.

Richard Shaler is a senior technical editor for Midrange Computing.

The Display Trigger Description (DSPTRGD) Command

Figure 1: Output from the DSPTRGD Command



The Display Trigger Description (DSPTRGD) Command

Figure 2: DSPTRGD Command

 /*==================================================================*/ /* To compile: */ /* */ /* CRTCMD CMD(XXX/DSPTRGD) (XXX/TRG002CL) + */ /* SRCFILE(XXX/QCMDSRC) */ /* */ /*==================================================================*/ DSPTRGD: CMD PROMPT('Display Trigger Description') PARM KWD(FILE) TYPE(FILE) MIN(1) PROMPT('File') FILE: QUAL TYPE(*GENERIC) LEN(10) SPCVAL((*ALL)) QUAL TYPE(*NAME) LEN(10) DFT(*CURLIB) + SPCVAL((*LIBL) (*CURLIB) (*USRLIBL) + (*ALLUSR) (*ALL)) PROMPT('Library') 
The Display Trigger Description (DSPTRGD) Command

Figure 3: Display File TRG002DF

 *=============================================================== * To compile: * * CRTDSPF FILE(XXX/TRG002DF) SRCFILE(XXX/QDDSSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 A DSPSIZ(24 80 *DS3) A CA03(03) A CA12(03) A PRINT A R TRGDSP OVERLAY A 1 27'Display Trigger Description' A DSPATR(HI) A 3 2'Library' A 3 13'File' A 3 27'Time' A 3 37'Event' A 3 47'Cond' A 3 57'Library' A 3 68'Program' A R MSGSFL SFL A SFLMSGRCD(04) A MSGKEY SFLMSGKEY A PGMQ SFLPGMQ A R MSGCTL SFLCTL(MSGSFL) A SFLDSP A SFLDSPCTL A N03 SFLEND(*MORE) A SFLINZ A SFLSIZ(0019) A SFLPAG(0018) A PGMQ SFLPGMQ A R FKEYS OVERLAY A 23 2'F3=Exit' COLOR(BLU) *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
The Display Trigger Description (DSPTRGD) Command

Figure 4: CPP CL Program TRG002CL

 /*==================================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/TRG002CL) SRCFILE(XXX/QCLSRC) */ /* */ /*==================================================================*/ PGM PARM(&FILE) DCL VAR(&FILE) TYPE(*CHAR) LEN(20) DCL VAR(&MSG) TYPE(*CHAR) LEN(80) DCL VAR(&MSGID) TYPE(*CHAR) LEN(7) DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(80) DCLF FILE(TRG002DF) MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR)) CHGVAR VAR(&PGMQ) VALUE(TRG002CL) CALL PGM(TRG003CL) PARM(&FILE) SNDF RCDFMT(MSGCTL) SNDF RCDFMT(FKEYS) SNDRCVF RCDFMT(TRGDSP) GOTO CMDLBL(ENDPGM) ERROR: RCVMSG MSGTYPE(*EXCP) MSGDTA(&MSGDTA) MSGID(&MSGID) SNDPGMMSG MSGID(&MSGID) MSGF(QCPFMSG) MSGDTA(&MSGDTA) + MSGTYPE(*ESCAPE) ENDPGM: ENDPGM 
The Display Trigger Description (DSPTRGD) Command

Figure 5: CL Program TRG003CL

 /*==================================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/TRG003CL) SRCFILE(XXX/QCLSRC) */ /* */ /*==================================================================*/ PGM PARM(&FILE) DCL VAR(&FILE) TYPE(*CHAR) LEN(20) DCL VAR(&TTM) TYPE(*CHAR) LEN(6) DCL VAR(&TEV) TYPE(*CHAR) LEN(6) DCL VAR(&TCN) TYPE(*CHAR) LEN(6) DCL VAR(&RCDSFND) TYPE(*LGL) DCL VAR(&MSG) TYPE(*CHAR) LEN(80) DCL VAR(&MSGID) TYPE(*CHAR) LEN(7) DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(80) DCLF FILE(QAFDTRG) MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR)) OVRDBF FILE(QAFDTRG) TOFILE(QTEMP/DSPFD) DSPFD FILE(%SST(&FILE 11 10)/%SST(&FILE 1 10)) + TYPE(*TRG) OUTPUT(*OUTFILE) FILEATR(*PF) + OUTFILE(QTEMP/DSPFD) OUTMBR(*FIRST *REPLACE) LOOP: RCVF MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(DONE)) CHGVAR VAR(&TTM) VALUE(' ') CHGVAR VAR(&TEV) VALUE(' ') CHGVAR VAR(&TCN) VALUE(' ') IF COND(&TRTRTM = 'B') THEN(CHGVAR VAR(&TTM) + VALUE('Before')) IF COND(&TRTRTM = 'A') THEN(CHGVAR VAR(&TTM) + VALUE('After ')) IF COND(&TRTREV = 'D') THEN(CHGVAR VAR(&TEV) + VALUE('Delete')) IF COND(&TRTREV = 'I') THEN(CHGVAR VAR(&TEV) + VALUE('Insert')) IF COND(&TRTREV = 'U') THEN(CHGVAR VAR(&TEV) + VALUE('Update')) IF COND(&TRTRCN = 'A') THEN(CHGVAR VAR(&TCN) + VALUE('Always')) IF COND(&TRTRCN = 'C') THEN(CHGVAR VAR(&TCN) + VALUE('Change')) CHGVAR VAR(&RCDSFND) VALUE('1') CHGVAR VAR(&MSG) VALUE(&TRLIB *CAT ' ' *CAT + &TRFILE *CAT ' ' *CAT &TTM *CAT + ' ' *CAT &TEV *CAT ' ' + *CAT &TCN *CAT ' ' *CAT + &TRTRLB *CAT ' ' *CAT &TRTRIG) SNDPGMMSG MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA(&MSG) GOTO CMDLBL(LOOP) DONE: IF COND(*NOT &RCDSFND) THEN(DO) CHGVAR VAR(&MSG) VALUE('No files found with + triggers.') SNDPGMMSG MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA(&MSG) ENDDO GOTO CMDLBL(ENDPGM) ERROR: RCVMSG MSGTYPE(*EXCP) MSGDTA(&MSGDTA) MSGID(&MSGID) SNDPGMMSG MSGID(&MSGID) MSGF(QCPFMSG) MSGDTA(&MSGDTA) + MSGTYPE(*ESCAPE) ENDPGM: ENDPGM 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: