Upload
tamsin-underwood
View
215
Download
0
Embed Size (px)
Citation preview
Thirteen Tricks ©2002 Tom Shriver, DataVisor 3
Everyday Problem and a Suggested Solution
Problem: Starting a New PQL Program We need another new PQL Retrieval We start writing the same 20 lines of code We add a few Variations
Solution: Make a Menu Option or Button That writes the skeleton That has the bells and whistles you conveniently forgot
Thirteen Tricks ©2002 Tom Shriver, DataVisor 4
What do we want the button to do?
1. Create Starter PQL Code That is Efficient That has the tricky code already written
Commonly Used User Prompts Date Booleans Tabulate Structure
2. Give us some options Filename or Member name Output (Report) Filename Prompt for Common Parameters Post Processing Options (e.g. Print, Display)
Thirteen Tricks ©2002 Tom Shriver, DataVisor 5
13 Tricks at a Glance
Thirteen Tricks ©2002 Tom Shriver, DataVisor 6
The Baker's Dozen Tricks
1. Generate PQL Program2. Automatically Edit PQL &
make it SIR Default File3. Run Many Programs in
one Procedure4. Prompt for Date Range
(allow human formats)5. Abort Complex Procedure
Midstream6. Disconnect & Reconnect
Master for Speed7. 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
Thirteen Tricks ©2002 Tom Shriver, DataVisor 7
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
Thirteen Tricks ©2002 Tom Shriver, DataVisor 8
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)
Thirteen Tricks ©2002 Tom Shriver, DataVisor 9
3. Put Many Programs and Procedures in a Single Command Set
All DBMS commands & command sets allowedo PQLo DBMS Anytime Commandso Utilitieso Schema Definitiono Compiler Controls (CIF)
Later Commands Use Results of Earlier Ones
Have to Make Sure all Possibilities are handled
Thirteen Tricks ©2002 Tom Shriver, DataVisor 10
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)
Since Y2K we've formatted our dates with 4 digits for the year – makes for lots of typing
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)
Thirteen Tricks ©2002 Tom Shriver, DataVisor 11
5. Abort Procedures Midstream
In Complex Procedures, user may request an abort 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 PROGRAMc this comment is very importantCIF EQ "<ABORT>" , "YES"FINISHCIF END
Thirteen Tricks ©2002 Tom Shriver, DataVisor 12
6. Disconnect & ReConnect Master to Speed Up Retrievals (NoUpdate)
Check if Master is Connected with SYSTEM(38) 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
ReConnect with:
PROGRAM | TRICKS.MSTSET
. COMPUTE MST_STAT = <MSTSTAT>
. IF(MST_STAT = 1)EXECUTE DBMS 'SET MASTER'
END PROGRAM
Thirteen Tricks ©2002 Tom Shriver, DataVisor 13
7. Use Template Code for PQL Procedures
Figure out Tricky Procedures Once
Have the Program Generator Insert Needed Code
You modify the Template, e.g. change variables
Thirteen Tricks ©2002 Tom Shriver, DataVisor 14
8. Post Process PQL Output (only if PQL Program ran Successfully)
Anything you typically do after you run a PQL program is a candidate for Post Processing Options
o Edit, Print, Modify, Use with other Software
But you Only want to Post Process if PQL was OKo TERROR system global has count of errors
o Conditionally Compile the Post Processing Code
Thirteen Tricks ©2002 Tom Shriver, DataVisor 15
9. Edit the PQL Output File 10. Print the PQL Output File
Set Filenames in a Standard Global (e.g. REPFILE) Use Global in Procedure Definitions Use DBMS EDITFILE command to Edit Use DBMS PRINT FILE command to Print
GLOBAL REPFILE = GENDER.REPPROGRAM. PROCESS REC 1. GET VARS GENDER. PERFORM PROCS. END RECFREQUENCIES INTEGER = GENDER(1,2) / FILENAME="<REPFILE>"END PROGRAMcEDITFILE "<REPFILE>"PRINT FILE "<REPFILE>"
Thirteen Tricks ©2002 Tom Shriver, DataVisor 16
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 )
Thirteen Tricks ©2002 Tom Shriver, DataVisor 17
12. Start other Software Using Output
SIR Interface Procedures: SPSS, SAS, etc
GLOBAL REPFILE = GENDER.REPPROGRAM. PROCESS REC EMPLOYEE. GET VARS ALL. PERFORM PROCS. END RECSPSS SAVE FILE FILENAME="<REPFILE>" / VARIABLES = ALLEND PROGRAMcPROGRAM. DISPLAY YESNOBOX 'Start SPSS?' RESPONSE YN. IFNOT(YN=1)STOP. PQL ESCAPE ' "C:\Program Files\SPSS\SPSSWIN.EXE" <repfile>'. END PROGRAM
Thirteen Tricks ©2002 Tom Shriver, DataVisor 18
13. Pull it All Together with a Custom Tool Bar Button
Several Methods to Add a Button (or Menu Item)o Copy, Edit & ReCompile SYSPROC.SYSTEM.MAINMENUo Use DVMenu Dialog Tool
To Edit MainMenuo Declare Integer Variable as a Menu Item Alias
o Assign a Value not Given to Other Menu Item Aliases
o Define Button:TBARITEM MKPQL , "MKPQLPIC","PQL Starter",0
o Define what to do if item is selectedIF(ID=MKPQL)execute dbms "CALL TRICKS.PQLSTART"
o Save, Run, Exit SIR, Start SIR again to see changes