Just Enough SQL, With QMF and SPUFI
Just Enough SQL, With QMF and SPUFI
By Gabe Gargiulo
IBMMAINFRAMES.com
140 FRAYE 51 MGR 6 21150.00 --------150 WILLIAMS 51 SALES 6 19456.50 637.65 160 MOLINARE 10 MGR 7 22959.20 --------170 KERMISCH 15 CLERK 4 12258.50 110.10 180 ABRAHAMS 38 CLERK 3 12009.75 236.50 190 SNEIDER 20 CLERK 8 14252.75 126.50 200 SCOUTTEN 42 CLERK ------ 11508.60 84.20 210 LU 10 MGR 10 20010.00 --------220 SMITH 51 SALES 7 17654.50 992.80 230 LUNDQUIST 51 CLERK 3 13369.80 189.65 240 DANIELS 10 MGR 5 19260.25 --------250 WHEELER 51 CLERK 6 14460.00 513.30 260 JONES 10 MGR 12 21234.00 --------270 LEA 66 MGR 9 18555.50 --------280 WILSON 66 SALES 9 18674.50 811.50 290 QUILL 84 MGR 10 19818.00 --------300 DAVIS 84 SALES 5 15454.50 806.10 310 GRAHAM 66 SALES 13 21000.00 200.30 320 GONZALES 66 SALES 4 16858.20 844.00 330 BURKE 66 CLERK 1 10988.00 55.50 340 EDWARDS 84 SALES 7 17844.00 1285.00 350 GAFNEY 84 CLERK 5 13030.50 188.00
IBMMAINFRAMES.com
SELECT ID, NAME, SALARY, COMM FROM Q.STAFF WHERE ID = 10 OR ID = 15 Results ---------+---------+----ID NAME SALARY COMM ---------+---------+----10 SANDERS 18357.50 ---------
SQL Syntax no column rules, indent to taste in embedded SQL, must start in or after column 12 upper or lower case as desired except in data values for comparisons: match case specified to that of the data free format, 1 or more spaces between words no continuation character, just go to next line ; used only in SPUFI when > 1 SQL statement, as end of statement delimiter ; is not used in QMF ; is not used in embedded SQL multiple things (tables, columns) separated by commas SELECT NAME, SALARY ... --comment to end of line (in embedded SQL, use COBOL * in column 7)
IBMMAINFRAMES.com
Clauses: this order. Suggest one only per line SELECT required display, show a table; create a result table FROM required the desired table or tables WHERE optional select only rows that meet these criteria GROUP BY optional crunch data into groups HAVING optional limits which groups are selected ORDER BY optional sort the result table Optimize for 10 rows optional optimize for this number of rows With UR optional "uncommitted" Read also With CS, With RR
IBMMAINFRAMES.com
40 O'BRIEN 38 SALES 6 18006.00 846.55 50 HANES 15 MGR 10 20659.80 60 QUIGLEY 38 SALES - 16808.30 650.25 70 ROTHMAN 15 SALES 7 16502.83 1152.00 80 JAMES 20 CLERK - 13504.60 128.20 90 KOONITZ 42 SALES 6 18001.75 1386.70 100 PLOTZ 42 MGR 7 18352.80 110 NGAN 15 CLERK 5 12508.20 206.60 120 NAUGHTON 38 CLERK - 12954.75 180.00 130 YAMAGUCHI 42 CLERK 6 10505.90 75.60 More...
The columns are separated by commas --Example Show some columns, and all rows
SELECT ID, NAME FROM Q.STAFF ID NAME -------10 SANDERS 20 PERNAL 30 MARENGHI 40 O'BRIEN 50 HANES 60 QUIGLEY 70 ROTHMAN 80 JAMES 90 KOONITZ
IBMMAINFRAMES.com
<= less than or equal to / not greater than > less than or equal to / not greater than >= greater than or equal to / not less than < greater than or equal to / not less than Numeric data: doesn'need apostrophes in queries t WHERE SALARY = 19999 Character data: Apostrophes needed in query WHERE NAME = ' MARIA'
IBMMAINFRAMES.com
OR - only one needs to be true for the row to be selected --Example Show employees with 5, 6, or 7 years
SELECT * FROM Q.STAFF WHERE YEARS = 5 OR YEARS = 6 OR YEARS = 7 ---------+---------+---------+----ID NAME DEPT JOB YEARS SALARY COMM ---------+---------+---------+----10 SANDERS 20 MGR 7 18357.50 --------30 MARENGHI 38 MGR 5 17506.75 --------40 O'BRIEN 38 SALES 6 18006.00 846.55 70 ROTHMAN 15 SALES 7 16502.83 1152.00 90 KOONITZ 42 SALES 6 18001.75 1386.70 100 PLOTZ 42 MGR 7 18352.80 --------110 NGAN 15 CLERK 5 12508.20 206.60 130 YAMAGUCHI 42 CLERK 6 10505.90 75.60 140 FRAYE 51 MGR 6 21150.00 --------150 WILLIAMS 51 SALES 6 19456.50 637.65 160 MOLINARE 10 MGR 7 22959.20 --------220 SMITH 51 SALES 7 17654.50 992.80 240 DANIELS 10 MGR 5 19260.25 --------250 WHEELER 51 CLERK 6 14460.00 513.30 300 DAVIS 84 SALES 5 15454.50 806.10 340 EDWARDS 84 SALES 7 17844.00 1285.00 350 GAFNEY 84 CLERK 5 13030.50 188.00
IBMMAINFRAMES.com
---------------------------- DATA SET UTILITY OPTION ===> M A - Allocate new data set C - Catalog data set R - Rename entire data set U - Uncatalog data set D - Delete entire data set S - Data set information (short)
IBMMAINFRAMES.com
blank - Data set information M - Enhanced data set allocation ISPF LIBRARY: PROJECT ===> GROUP ===> TYPE ===> OTHER PARTITIONED OR SEQUENTIAL DATA SET: DATA SET NAME ===> userid.DB2.SQL VOLUME SERIAL ===> (If not cataloged, required for option "C") DATA SET PASSWORD ===> (If password protected)
PRESS ENTER Record length of 80 is needed Record format of FB Make it a library or PDS
------------------------ ALLOCATE NEW DATA SET COMMAND ===> DATA SET NAME: Userid.DB2.SQL MANAGEMENT CLASS ===> (Blank for default STORAGE CLASS ===> (Blank for default VOLUME SERIAL ===> (Blank for authorized default DATA CLASS ===> (Blank for default SPACE UNITS ===> TRKS (BLKS, TRKS, CYLS, PRIMARY QUANTITY ===> 5 (In above units) SECONDARY QUANTITY ===> 5 (In above units) DIRECTORY BLOCKS ===> 10 (Zero for sequential RECORD FORMAT ===> FB RECORD LENGTH ===> 80
IBMMAINFRAMES.com
BLOCK SIZE ===> DATA SET NAME TYPE ===> PDS (LIBRARY, PDS, or blank) EXPIRATION DATE ===> (YY/MM/DD, YYYY/MM/DD YY.DDD, YYYY.DDD in Julian DDDD for retention period
or blank) (* Specifying LIBRARY may override zero directory block) PRESS ENTER Get into SPUFI Different companies use different numbers for menu choices. Find out yours. Set up your screen like this SPUFI Enter the input data set name: (Can be sequential 1 DATA SET NAME ... ===> userid.DB2.SQL(TEST1) <- new or existing member name 2 VOLUME SERIAL ... ===> (Enter if not cataloged) 3 DATA SET PASSWORD ===> (Enter if password protected) Enter the output data set name: (Must be a sequential 4 DATA SET NAME ... ===> userid.SPUFI.LIST Note that SPUFI.LIST can be any name, and it does not have to be preallocated Specify processing options: 5 CHANGE DEFAULTS ===> NO (Y/N - Display SPUFI defaults 6 EDIT INPUT ...... ===> YES (Y/N - Enter SQL statements?) 7 EXECUTE ......... ===> YES (Y/N - Execute SQL statements?)
IBMMAINFRAMES.com
8 AUTOCOMMIT ...... ===> YES (Y/N - Commit after successful 9 BROWSE OUTPUT ... ===> YES (Y/N - Browse output data set?) For remote SQL processing: 10 CONNECT LOCATION ===> PRESS: ENTER to process END to exit HELP for more information PRESS ENTER This takes you into the editor. Type these commands on the command line, to set your preferences. These settings cant get you into trouble. Others might. Then type in your SQL in the large completely blank area.
EDIT ---- Userid.DB2.SQL(TEST1) - 01.00 --------------------- COLUMNS 001 072 COMMAND ===> recovery on;number off;nulls all;reset SCROLL ===> CSR ****** ***************************** TOP OF DATA ...... SELECT * ...... FROM Q.STAFF ...... ...... ...... ...... ...... ****** **************************** BOTTOM OF DATA
PRESS PF3
IBMMAINFRAMES.com
SPUFI
Enter the input data set name: (Can be sequential 1 DATA SET NAME ... ===> userid.DB2.SQL(TEST1) <- new or existing member name 2 VOLUME SERIAL ... ===> (Enter if not cataloged) 3 DATA SET PASSWORD ===> (Enter if password protected) Enter the output data set name: (Must be a sequential 4 DATA SET NAME ... ===> userid.SPUFI.LIST Note that SPUFI.LIST can be any name, and it does not have to be preallocated Specify processing options: 5 CHANGE DEFAULTS ===> NO (Y/N - Display SPUFI defaults 6 EDIT INPUT ...... ===> * (Y/N - Enter SQL statements?) the asterisk means that you have already performed this action 7 EXECUTE ......... ===> YES (Y/N - Execute SQL statements?) 8 AUTOCOMMIT ...... ===> YES (Y/N - Commit after successful 9 BROWSE OUTPUT ... ===> YES (Y/N - Browse output data set?) For remote SQL processing: 10 CONNECT LOCATION ===> PRESS: ENTER to process END to exit HELP for more information
PRESS ENTER
BROWSE -- Userid.SPUFI.LIST ------- LINE 00000000 COL 001 080 COMMAND ===> SCROLL ===> PAGE SELECT * FROM Q.STAFF --------+---------+---------+---------+---------+---------+--
IBMMAINFRAMES.com
ID NAME DEPT JOB YEARS SALARY COMM --------+---------+---------+---------+---------+---------+-10 SANDERS 20 MGR 7 18357.50 --------20 PERNAL 20 SALES 8 18171.25 612.45 30 MARENGHI 38 MGR 5 17506.75 --------40 O'BRIEN 38 SALES 6 18006.00 846.55 50 HANES 15 MGR 10 20659.80 --------60 QUIGLEY 38 SALES ------ 16808.30 650.25 70 ROTHMAN 15 SALES 7 16502.83 1152.00 80 JAMES 20 CLERK ------ 13504.60 128.20 90 KOONITZ 42 SALES 6 18001.75 1386.70 More...
PRESS PF3 Executing SQL with QMF Get into QMF ________________________________________________________________________ ______ IBM* Licensed Materials - Property of IBM 5706-254 5706-255 5648-061 (c) Copyright IBM Corp. 1982, 1995 All Rights Reserved. * Trademark of International Business Machines ________________________________________________________________________ ______ QMF HOME PANEL
IBMMAINFRAMES.com
Version 3 Release 2.0 B ****** ** ** ********* ** ** *** *** ** Query ** ** **** **** ******* Management ** ** ** ** ** ** ** Facility ** * ** ** **** ** ** ****** ** ** ** ** ________________________________________ Type command on command line or use PF keys. For help, press PF1 or type HELP. ________________________________________________________________________ ______ 1=Help 2=List 3=End 4=Show 5=Chart 6=Query 7=Retrieve 8=Edit Table 9=Form 10=Proc 11=Profile 12=Report Press PF6 to get into the query panel SQL QUERY LINE 1 *** END *** 1=Help 2=Run 3=End 4=Print 5=Chart 6=Draw 7=Backward 8=Forward 9=Form 10=Insert 11=Delete 12=Report QUERY is displayed. COMMAND SCROLL Tab twice Type in the SQL query SQL QUERY LINE 1 select * from q.staff IBMMAINFRAMES.com
*** END *** 1=Help 2=Run 3=End 4=Print 5=Chart 6=Draw 7=Backward 8=Forward 9=Form 10=Insert 11=Delete 12=Report OK, QUERY is displayed. COMMAND SCROLL ===> PAGE
REPORT LINE 1 POS 1 79 ID NAME DEPT JOB YEARS SALARY COMM ------ --------- ------ ----- ------ ---------- ---------10 SANDERS 20 MGR 7 18357.50 20 PERNAL 20 SALES 8 18171.25 612.45 30 MARENGHI 38 MGR 5 17506.75 40 O' BRIEN 38 SALES 6 18006.00 846.55 50 HANES 15 MGR 10 20659.80 60 QUIGLEY 38 SALES - 16808.30 650.25 70 ROTHMAN 15 SALES 7 16502.83 1152.00 80 JAMES 20 CLERK - 13504.60 128.20 90 KOONITZ 42 SALES 6 18001.75 1386.70 100 PLOTZ 42 MGR 7 18352.80 110 NGAN 15 CLERK 5 12508.20 206.60 120 NAUGHTON 38 CLERK - 12954.75 180.00
IBMMAINFRAMES.com
130 YAMAGUCHI 42 CLERK 6 10505.90 75.60 140 FRAYE 51 MGR 6 21150.00 1=Help 2= 3=End 4=Print 5=Chart 6=Query 7=Backward 8=Forward 9=Form 10=Left 11=Right 12= OK, this is the REPORT from your RUN command. COMMAND SCROLL ===> PAGE Press PF6 to get back into the query panel Useful things you can do with QMF Seeing how the table was defined Type HELP or press PF1 to get the HELP panel Choose SQL for explanations and examples of SQL syntax. ________________________________________________________________________ ______ IBM* Licensed Materials - Property of IBM 5706-254 5706-255 5648-061 (c) Copyright IBM Corp. 1982, 1995 All Rights Reserved. * Trademark of International Business Machines ________________________________________________________________________ ______ QMF HOME PANEL Version 3 Release 2.0 B ****** ** ** ********* ** ** *** *** ** Query ** ** **** **** *******
IBMMAINFRAMES.com
Management ** ** ** ** ** ** ** Facility ** * ** ** **** ** ** ****** ** ** ** ** ________________________________________ Type command on command line or use PF keys. For help, press PF1 or type HELP. ________________________________________________________________________ ______ 1=Help 2=List 3=End 4=Show 5=Chart 6=Query 7=Retrieve 8=Edit Table 9=Form 10=Proc 11=Profile 12=Report HELP
Press PF6 to get into the query panel Type the following on the COMMAND line RESET QUERY DRAW Q.STAFF (TYPE = INSERT) A ready-made INSERT type query will appear. In it you will find the datatype definitions of all the columns in the table. SQL QUERY LINE 1
INSERT INTO Q.STAFF (ID, NAME, DEPT, JOB, "YEARS", SALARY, COMM) VALUES ( -- ENTER VALUES BELOW COLUMN NAME DATA TYPE LENGTH NULLS , -- ID SMALLINT NO , -- NAME VARCHAR 9 YES
IBMMAINFRAMES.com
, -- DEPT SMALLINT YES , -- JOB CHAR 5 YES , -- YEARS SMALLINT YES , -- SALARY DECIMAL ( 7, 2) YES ) -- COMM DECIMAL ( 7, 2) YES 1=Help 2=Run 3=End 4=Print 5=Chart 6=Draw 7=Backward 8=Forward 9=Form 10=Insert 11=Delete 12=Report QUERY is displayed. COMMAND line SCROLL
Giving yourself a copy of a table that you can INSERT/UPDATE/DELETE (Not all companies will let you do this) SQL QUERY LINE 1 *** END *** 1=Help 2=Run 3=End 4=Print 5=Chart 6=Draw 7=Backward 8=Forward 9=Form 10=Insert 11=Delete 12=Report OK, QUERY is displayed. COMMAND SCROLL ===> PAGE Type on the command line: RESET QUERY DISPLAY table-name for example: Q.STAFF SAVE DATA AS table-name qualified with your Userid for example: Userid.STAFF ------------------------------------------------- Table of Contents ---------------------------------
IBMMAINFRAMES.com
SQL the Language, syntax 2 Displaying data: SELECT 3 Limiting what is selected: WHERE 5 Additional conditions on the WHERE 6 Using Spufi to Execute Your SQL 7
Executing SQL with QMF 11
IBMMAINFRAMES.com
//SYSEXEC DD DSN=xxxxxxxxxxxxxx,DISP=SHR //ISPPROF DD DSN=&ISPPROF,UNIT=SYSDA, // DCB=(DSORG=PO,RECFM=FB,LRECL=80,BLKSIZE=3120), // SPACE=(CYL,(2,2,45)),DISP=(NEW,DELETE) //ISPLOG DD DUMMY //SYSTSPRT DD SYSOUT=* //DSQUDUMP DD SYSOUT=* //SYSTSIN DD * ISPSTART PGM(DSQQMFE) PARM(S=name-of-db2-subsystem,M=B,I=name-of-qmf-proc-to-execute) NEWAPPL(DSQE) /*
IBMMAINFRAMES.com