Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Baker's Dozen Tricks in a Button Thirteen Tricks of the SIR Trade Rolled into a Single Useful Application © Tom Shriver, DataVisor 2002.

Similar presentations


Presentation on theme: "A Baker's Dozen Tricks in a Button Thirteen Tricks of the SIR Trade Rolled into a Single Useful Application © Tom Shriver, DataVisor 2002."— Presentation transcript:

1 A Baker's Dozen Tricks in a Button Thirteen Tricks of the SIR Trade Rolled into a Single Useful Application © Tom Shriver, DataVisor 2002

2 For Web Based Viewers of this Presentation This presentation demonstrates several SIR and PQL programming techniques by explaining a single application. A working version of the COMPANY database available from DataVisor demostrates this application and contains all the PQL code. This code is easily adapted to any SIR database (SIR2000 or SIR2002). A CD containing these (and other) demonstration materials was distributed at the SIR UK Conference in Aberdeen, Scotland, June 2002. For a free copy of these materials, contact DataVisor by email at: datavisor@insightbb.com

3 Thirteen Tricks ©2002 Tom Shriver, DataVisor3 Everyday Problem and a Suggested Solution u Problem: Starting a New PQL Program n We need another new PQL Retrieval n We start writing the same 20 lines of code n We add a few Variations u Solution: Make a Menu Option or Button n That writes the skeleton n That has the bells and whistles you conveniently forgot

4 Thirteen Tricks ©2002 Tom Shriver, DataVisor4 What do we want the button to do? 1. Create Starter PQL Code uThat is Efficient uThat has the tricky code already written u Commonly Used User Prompts u Date Booleans u Tabulate Structure 2. Give us some options uFilename or Member name uOutput (Report) Filename uPrompt for Common Parameters uPost Processing Options (e.g. Print, Display)

5 Thirteen Tricks ©2002 Tom Shriver, DataVisor5 13 Tricks at a Glance

6 Thirteen Tricks ©2002 Tom Shriver, DataVisor6 The Baker's Dozen Tricks 1. Generate PQL Program 2. Automatically Edit PQL & make it SIR Default File 3. Run Many Programs in one Procedure 4. Prompt for Date Range (allow human formats) 5. Abort Complex Procedure Midstream 6. Disconnect & Reconnect Master for Speed 7. Use "Template Code" for PQL Procedures 8. Post Process PQL Output (only if PQL Runs OK) 9. EDIT Output File 10. Print Output File 11. Display as Web Page 12. Start other Software that uses PQL Output (e.g. SPSS) 13. Do it all with a Customized Button

7 Thirteen Tricks ©2002 Tom Shriver, DataVisor7 1. Generate a PQL Program 1. Create a Template of the PQL (TRICKS.BASE_PQL) 2. Write a PQL Program, a VisualPQL Dialog (TRICKS.RUNPMT) that: 1.Prompts for Output File Name 2.Prompts for Other Customizations 3.Reads PQL Template 4.Inserts Customizations where Necessary 5.Writes all to the New File when Done

8 Thirteen Tricks ©2002 Tom Shriver, DataVisor8 2. Automatically Edit Generated PQL & Make it the SIR Default Edit File 1. After the " END PROGRAM " of Generator Program, use the DBMS Any-Time Command: EDITFILE "file_name" PROGRAM. WRITE(NEW.PQL)"c This is my New PQL Program" END PROGRAM EDITFILE "NEW.PQL" 2. In the Generator Program, set Global FILENAME with name of PQL File. SIR uses this global when you invoke the File Editor. COMPUTE FNAME="NEW.PQL" COMPUTE N = GLOBALS("FILENAME",FNAME)

9 Thirteen Tricks ©2002 Tom Shriver, DataVisor9 3. Put Many Programs and Procedures in a Single Command Set u All DBMS commands & command sets allowed oPQL oDBMS Anytime Commands oUtilities oSchema Definition oCompiler Controls (CIF) u Later Commands Use Results of Earlier Ones u Have to Make Sure all Possibilities are handled

10 Thirteen Tricks ©2002 Tom Shriver, DataVisor10 4. Prompt for Dates & Date Ranges (allow human date formats and variations)  Single most frequently used booleans are to limit retrievals by date or date ranges. Create a standard way to do this (TRICKS.DATERANG) u Since Y2K we've formatted our dates with 4 digits for the year – makes for lots of typing u Users would prefer to enter strings like "1 1 2" for "Jan 1 2002"  A PQL program can interpret these, expand them and put them in globals for later use (TRICKS.DATEEDIT)

11 Thirteen Tricks ©2002 Tom Shriver, DataVisor11 5. Abort Procedures Midstream u In Complex Procedures, user may request an abort u How to Stop things Midstream? 1. In First Program, set an "Abort" global 2. After Program, use Conditional Compilation ( CIF ) 3. FINISH command stops everything PROGRAM. compute n = globals("ABORT","YES") END PROGRAM c this comment is very important CIF EQ " ", "YES" FINISH CIF END

12 Thirteen Tricks ©2002 Tom Shriver, DataVisor12 6. Disconnect & ReConnect Master to Speed Up Retrievals (NoUpdate) Check if Master is Connected with SYSTEM(38) n Set a Global Variable to Remember Setting DBMS Command CLEAR MASTER Disconnects PROGRAM | TRICKS.MSTCLEAR. COMPUTE MST_STAT = SYSTEM(38). COMPUTE X=GLOBALN('MSTSTAT',MST_STAT). IF(MST_STAT = 1)EXECUTE DBMS 'CLEAR MASTER' END PROGRAM n ReConnect with: PROGRAM | TRICKS.MSTSET. COMPUTE MST_STAT =. IF(MST_STAT = 1)EXECUTE DBMS 'SET MASTER' END PROGRAM

13 Thirteen Tricks ©2002 Tom Shriver, DataVisor13 7. Use Template Code for PQL Procedures u Figure out Tricky Procedures Once u Have the Program Generator Insert Needed Code u You modify the Template, e.g. change variables

14 Thirteen Tricks ©2002 Tom Shriver, DataVisor14 8. Post Process PQL Output (only if PQL Program ran Successfully) n Anything you typically do after you run a PQL program is a candidate for Post Processing Options oEdit, Print, Modify, Use with other Software n But you Only want to Post Process if PQL was OK oTERROR system global has count of errors oConditionally Compile the Post Processing Code

15 Thirteen Tricks ©2002 Tom Shriver, DataVisor15 9. Edit the PQL Output File 10. Print the PQL Output File Set Filenames in a Standard Global (e.g. REPFILE ) n Use Global in Procedure Definitions Use DBMS EDITFILE command to Edit Use DBMS PRINT FILE command to Print GLOBAL REPFILE = GENDER.REP PROGRAM. PROCESS REC 1. GET VARS GENDER. PERFORM PROCS. END REC FREQUENCIES INTEGER = GENDER(1,2) / FILENAME=" " END PROGRAM c EDITFILE " " PRINT FILE " "

16 Thirteen Tricks ©2002 Tom Shriver, DataVisor16 11. Format & Display as a Web Page (HTML)  Use HTML Option on some Commands like TABULATE  Post Process Output and Add HTML commands ( DVPROCF.DVTOOLS.MKHTMTX, DVPROCF.DVTOOLS.MKHTMTAB )

17 Thirteen Tricks ©2002 Tom Shriver, DataVisor17 12. Start other Software Using Output u SIR Interface Procedures: SPSS, SAS, etc GLOBAL REPFILE = GENDER.REP PROGRAM. PROCESS REC EMPLOYEE. GET VARS ALL. PERFORM PROCS. END REC SPSS SAVE FILE FILENAME=" " / VARIABLES = ALL END PROGRAM c PROGRAM. DISPLAY YESNOBOX 'Start SPSS?' RESPONSE YN. IFNOT(YN=1)STOP. PQL ESCAPE ' "C:\Program Files\SPSS\SPSSWIN.EXE" '. END PROGRAM

18 Thirteen Tricks ©2002 Tom Shriver, DataVisor18 13. Pull it All Together with a Custom Tool Bar Button n Several Methods to Add a Button (or Menu Item) oCopy, Edit & ReCompile SYSPROC.SYSTEM.MAINMENU oUse DVMenu Dialog Tool n To Edit MainMenu oDeclare Integer Variable as a Menu Item Alias oAssign a Value not Given to Other Menu Item Aliases oDefine Button: TBARITEM MKPQL, "MKPQLPIC","PQL Starter",0 oDefine what to do if item is selected IF(ID=MKPQL)execute dbms "CALL TRICKS.PQLSTART" oSave, Run, Exit SIR, Start SIR again to see changes


Download ppt "A Baker's Dozen Tricks in a Button Thirteen Tricks of the SIR Trade Rolled into a Single Useful Application © Tom Shriver, DataVisor 2002."

Similar presentations


Ads by Google