=============================================== SEARCH400.COM EXPERT DEVELOPER TIP August 15, 2001 More developer tips at http://search400.techtarget.com/tipsIndex/0,289482,sid3_tax2f9,00.html =============================================== SPONSORED BY: The 400 Group =============================================== iSeries DevCon The world's leading iSeries-AS/400 development experts come together at iSeries DevCon in Miami on Oct. 9-12, 2001. Get one-on-one access to the biggest names in iSeries development. Enhance your skills and professional value with instructor-led, hands-on training. Master the latest skills, tools, and technologies with expert guidance and field-tested advice. For a complete list of experts presenting at the conference and to save $200 on registration, visit http://www.the400group.com/devcon today. ================================================== CONGRATS TO OUR NEW TIPS CONTEST WINNERS ================================================== Congratulations to Raymond Johnson, winner of July's tip prize, a Seiko Secret Agent Man Watch! Ray will be inducted into our Hall of Fame for his winning tip: Copy from Client Access green screen without mouse http://www.search400.com/tip/1,289483,sid3_gci754601,00.html Kudos to our runner-up winners: Tom Gargano, Francis Lapeyre and Jim Townsend. NEW AUGUST PRIZE! Submit a tip and let the votes determine the winner of this month's prize, an Olympus Stylus Camera! http://search400.techtarget.com/tipsPrize/0,289492,sid3_prz757255_cts757251,00.html ========================================================= Use trigger programs to track record changes By John Kohan, search400 expert One of the issues programmers have to deal with is recording when a record was changed. Since we now have users accessing data from RPG programs, Cobol programs, DFU, Microsoft Access, Java, etc., it's getting harder to keep track of all the changes and who actually performed them. Trigger programs are one way for you to track these changes. Trigger programs are also useful in starting a process without user intervention. As an example, orders are now received from our customers many ways. These may include an order-entry program, EDI, a Java application, Web- based shopping carts and the like. You can write a trigger program to alert someone that an order has been received and to begin processing the order-fulfillment process. Before we begin to understand and write a simple trigger program, the example below uses only 11 lines of source code (RPG/400) to process the data. This process IS easy and with practice is also practical. When you create a trigger program, you need to bring two parameters into your program. The first parameter is Database file information much like the INFDS. It contains the trigger information, along with the record information. The second parameter is a 4-byte binary field that contains the length of the trigger buffer. IBM's DB2 Web site has a table that defines the trigger buffer I used -- http://publib.boulder.ibm.com/pubs/html/as400/v5r1/ic2924/index.htm Since the records in our databases have different lengths, the value in the "New record offset" field contains the beginning position within the first parameter that the new record data begins. This record matches the record buffer, so if you have three 10-byte alpha fields, the "New Record" section of parameter 1 is 30 bytes containing the contents of the record that was just added. Now lets put this together and write TRGPGM to call PGM passing the order number when a record is added to the file ORDERS. Create TRGPGM and allow two parameters in. The first parameter is a data structure that is 2000 bytes long and has the following sub fields: IPARM1 DS 2000 I B 65 680NEWOFS I B 69 720NEWLNG IPARM2 DS I B 1 40NWLGTH Now bring in the database file as an externally described data structure. IDATA EIDSORDERS And then get the starting position of the new record and move the contents into our ORDERS file. C Z-ADDNEWOFS X 30 C ADD 1 X C NEWLNG SUBSTPARM1:X DATA P All of the data is now loaded into the database fields, and we access the data just as if we read a file. Call program PGM and pass the order number. C CALL 'PGM' C PARM ORDNUM The last thing to do is add TRGPGM to the ORDERS file. You do this by running the following command: ADDPFTRG FILE(ORDERS) TRGTIME(*AFTER) TRGEVENT(*INSERT) PGM(TRGPGM) The following are recommended for a trigger program: (Copied from the above IBM Web site) * Create the trigger program so that it runs under the user profile of the user who created it. Then users who do not have the same level of authority to the program will not encounter errors. * Create the program with USRPRF(*OWNER) and *EXCLUDE public authority, and do not grant authorities to the trigger program to USER(*PUBLIC). Avoid having the trigger program altered or replaced by other users. The database invokes the trigger program whether or not the user causing the trigger program to run has authority to the trigger program. * Create the program as ACTGRP(*CALLER) if the program is running in an ILE environment. This allows the trigger program to run under the same commitment definition as the application. * Open the file with a commit lock level the same as the application's commit lock level. This allows the trigger program to run under the same commit lock level as the application. * Create the program in the physical file's library. * Use commit or rollback in the trigger program if the trigger program runs under a different activation group than the application. * Signal an exception if an error occurs or is detected in the trigger program. If an error message is not signaled from the trigger program, the database assumes that the trigger ran successfully. This may cause the user data to end up in an inconsistent state. ----------------------------------------- About the author: John Kohan is a senior programmer analyst at CT Codeworks (http://www.ctcodeworks.com/). He is also an adjunct instructor teaching AS/400 classes at his local state collage. As one of search400's site expert John also participates in our Ask the Expert feature. If you have a question for him, you may submit it here: http://search400.techtarget.com/ateQuestion/0,289624,sid3_tax285217,00.html ============================ MEMBER-SUBMITTED TIPS ============================ Search400 members submitted the following developer tips recently. Check them out and rate them to let us know what you think of them. And if you have a tip of your own you'd like to share send it in. You could win some great prizes. http://search400.techtarget.com/tipsSubmit/1,289485,sid3,00.html Find a message ID based on the message text Submitted by Victor Shumat http://search400.techtarget.com/tip/1,289483,sid3_gci759149,00.html Determine the external call to programs Submitted by Azmat Bhatti http://search400.techtarget.com/tip/1,289483,sid3_gci758145,00.html Who am I signed on as? Submitted by Juanita Pinto http://search400.techtarget.com/tip/1,289483,sid3_gci757370,00.html Adding security to FTP and the QUOTE RCMD command Submitted by Jim Townsend http://search400.techtarget.com/tip/1,289483,sid3_gci756088,00.html =============================================== SPONSORED BY: ARCAD Software =============================================== How up to date is your AS/400 technical DOCUMENTATION? ARCAD Observer is a unique and powerful AS/400 solution offering a completely automated technical documentation process of your AS/400 applications. This highly configurable and graphical software instantly generates technical documentation directly on your PC. The FREE, fully functional NEW AS/400 Source Code Analyzer for RPG, Cobol & ILE is available to the first 500 ARCAD Site visitors at http://www.arcadsoftware.com/. Contact Eric at (978) 927-2931 in the U.S. and Canada. ------------------------------------- FEATURED COURSE ------------------------------------- JavaScript Fundamentals This course describes the features of JavaScript and compares JavaScript with other technologies, such as Java. The course also covers the fundamentals of JavaScript programming, JavaScript variables, operators, loops, and conditional statements. http://as400.gofcs.com/products/by_product/IP0450/index.html ================================ SEARCH400 DAILY NEWS E-MAIL ================================ "Storage Solutions" "IBM takes aim at B2B's big 6" Did you see these headlines yesterday? You would have if you received search400's Daily News e-mail. Not only do we give you the latest IBM and iSeries news, but we also link you to choice articles and Web sites specific to the iSeries in our Daily Best Web Links. Sign up to receive search400's free news e-mail at http://search400.techtarget.com/register/1,,sid3,00.html ======================================================== If you would like to sponsor this or any techtarget newsletter, please contact Gabrielle DeRussy at mailto:[EMAIL PROTECTED]. ======================================================== If you no longer wish to receive this newsletter simply reply to this message with "REMOVE" in the subject line. Or, visit http://search400.techtarget.com/register and adjust your subscriptions accordingly. If you choose to unsubscribe using our automated processing, you must send the "REMOVE" request from the email account to which this newsletter was delivered. Please allow 24 hours for your "REMOVE" request to be processed.
