PL/I programming example

The following sample program, DSQABFP, is shipped with QMF and uses IBM PL/I.

You can look at the sample source code listing here or you can access it online.

The sample program for the PL/I callable interface performs the following function:

QMF does not supply query Q1 or form F1, but the sample program uses these objects.

This section also shows how to compile, link-edit, and run a PL/I program using the callable interface. QMF does not ship the REXX EXEC, JCL, or CLIST in these examples, but you can copy them from here, altering them to suit your installation.

Figure 58. DSQABFP, sample PL/I program
 DSQABFP: PROCEDURE OPTIONS(MAIN REENTRANT) REORDER;                    00001000
 /********************************************************************/ 00002000
 /* Sample Program:  DSQABFP                                         */ 00003000
 /* PL/I Version of the SAA Query Callable Interface                 */ 00004000
 /********************************************************************/ 00005000
                                                                        00006000
 /********************************************************************/ 00007000
 /* Include and declare query interface communications area          */ 00008000
 /********************************************************************/ 00009000
 %INCLUDE SYSLIB(DSQCOMML);                                             00010000
                                                                        00011000
 /********************************************************************/ 00012000
 /* Builtin function                                                 */ 00013000
 /********************************************************************/ 00014000
 DCL LENGTH BUILTIN;                                                    00015000
                                                                        00016000
 /********************************************************************/ 00017000
 /* Query interface command length and commands                      */ 00018000
 /********************************************************************/ 00019000
 DCL COMMAND_LENGTH         FIXED BIN(31);                              00020000
 DCL START_QUERY_INTERFACE  CHAR(5)  INIT('START');                     00021000
 DCL SET_GLOBAL_VARIABLES   CHAR(10) INIT('SET GLOBAL');                00022000
 DCL RUN_QUERY              CHAR(12) INIT('RUN QUERY Q1');              00023000
 DCL PRINT_REPORT           CHAR(22) INIT('PRINT REPORT (FORM=F1)');    00024000
 DCL END_QUERY_INTERFACE    CHAR(4)  INIT('EXIT');                      00025000
                                                                        00026000
 /********************************************************************/ 00027000
 /* Query command extension, number of parameters and lengths        */ 00028000
 /********************************************************************/ 00029000
 DCL NUMBER_OF_PARAMETERS   FIXED BIN(31);/* number of variables     */ 00030000
 DCL KEYWORD_LENGTHS(10)    FIXED BIN(31);/* lengths of keyword names*/ 00031000
 DCL DATA_LENGTHS(10)       FIXED BIN(31);/* lengths of variable data*/ 00032000
                                                                        00033000
 /********************************************************************/ 00034000
 /* Keyword parameter and value for START command                    */ 00035000
 /********************************************************************/ 00036000
 DCL START_KEYWORDS         CHAR(8)  INIT('DSQSMODE');                  00037000
 DCL START_KEYWORD_VALUES   CHAR(11) INIT('INTERACTIVE');               00038000
                                                                        00039000
 /********************************************************************/ 00040000
 /* Keyword parameter and value for SET command                      */ 00041000
 /********************************************************************/ 00042000
 DCL 1 SET_KEYWORDS,                                                    00043000
       3  SET_KEYWORDS_1    CHAR(7) INIT('MYVAR01'),                    00044000
       3  SET_KEYWORDS_2    CHAR(5) INIT('SHORT'),                      00045000
       3  SET_KEYWORDS_3    CHAR(7) INIT('MYVAR03');                    00046000
                                                                        00047000
 DCL 1 SET_VALUES,                                                      00048000
       3  SET_VALUES_1      FIXED BIN(31),                              00049000
       3  SET_VALUES_2      FIXED BIN(31),                              00050000
       3  SET_VALUES_3      FIXED BIN(31);                              00051000
                                                                        00052000
 /********************************************************************/ 00053000
 /* Main program                                                     */ 00054000
 /********************************************************************/ 00055000
 DSQCOMM = '';                                                          00056000
 DSQ_COMM_LEVEL = DSQ_CURRENT_COMM_LEVEL;                               00057000
                                                                        00058000
 /********************************************************************/ 00059000
 /* Start a query interface session                                  */ 00060000
 /********************************************************************/ 00061000
 NUMBER_OF_PARAMETERS = 1;                                              00062000
 COMMAND_LENGTH = LENGTH(START_QUERY_INTERFACE);                        00063000
 KEYWORD_LENGTHS(1) = LENGTH(START_KEYWORDS);                           00064000
 DATA_LENGTHS(1) = LENGTH(START_KEYWORD_VALUES);                        00065000
                                                                        00066000
 CALL DSQCIPX(DSQCOMM,                                                  00067000
              COMMAND_LENGTH,                                           00068000
              START_QUERY_INTERFACE,                                    00069000
              NUMBER_OF_PARAMETERS,                                     00070000
              KEYWORD_LENGTHS,                                          00071000
              START_KEYWORDS,                                           00072000
              DATA_LENGTHS,                                             00073000
              START_KEYWORD_VALUES,                                     00074000
              DSQ_VARIABLE_CHAR);                                       00075000
                                                                        00076000
 /********************************************************************/ 00077000
 /* Set numeric values into query using SET command                  */ 00078000
 /********************************************************************/ 00079000
 NUMBER_OF_PARAMETERS = 3;                                              00080000
 COMMAND_LENGTH = LENGTH(SET_GLOBAL_VARIABLES);                         00081000
 KEYWORD_LENGTHS(1) = LENGTH(SET_KEYWORDS_1);                           00082000
 KEYWORD_LENGTHS(2) = LENGTH(SET_KEYWORDS_2);                           00083000
 KEYWORD_LENGTHS(3) = LENGTH(SET_KEYWORDS_3);                           00084000
 DATA_LENGTHS(1) = 4;                                                   00085000
 DATA_LENGTHS(2) = 4;                                                   00086000
 DATA_LENGTHS(3) = 4;                                                   00087000
 SET_VALUES_1 = 20;                                                     00088000
 SET_VALUES_2 = 40;                                                     00089000
 SET_VALUES_3 = 84;                                                     00090000
                                                                        00091000
 CALL DSQCIPX(DSQCOMM,                                                  00092000
              COMMAND_LENGTH,                                           00093000
              SET_GLOBAL_VARIABLES,                                     00094000
              NUMBER_OF_PARAMETERS,                                     00095000
              KEYWORD_LENGTHS,                                          00096000
              SET_KEYWORDS,                                             00097000
              DATA_LENGTHS,                                             00098000
              SET_VALUES,                                               00099000
              DSQ_VARIABLE_FINT);                                       00100000
                                                                        00101000
 /********************************************************************/ 00102000
 /* Run a Query                                                      */ 00103000
 /********************************************************************/ 00104000
 COMMAND_LENGTH = LENGTH(RUN_QUERY);                                    00105000
                                                                        00106000
 CALL DSQCIPL(DSQCOMM,                                                  00107000
             COMMAND_LENGTH,                                            00108000
             RUN_QUERY);                                                00109000
                                                                        00110000
 /********************************************************************/ 00111000
 /* Print the results of the query                                   */ 00112000
 /********************************************************************/ 00113000
 COMMAND_LENGTH = LENGTH(PRINT_REPORT);                                 00114000
                                                                        00115000
 CALL DSQCIPL(DSQCOMM,                                                  00116000
             COMMAND_LENGTH,                                            00117000
             PRINT_REPORT);                                             00118000
                                                                        00119000
 /********************************************************************/ 00120000
 /* End the query interface session                                  */ 00121000
 /********************************************************************/ 00122000
 COMMAND_LENGTH = LENGTH(END_QUERY_INTERFACE);                          00123000
                                                                        00124000
 CALL DSQCIPL(DSQCOMM,                                                  00125000
             COMMAND_LENGTH,                                            00126000
             END_QUERY_INTERFACE);                                      00127000
                                                                        00128000
 END       DSQABFP;                                                     00129000
[ Previous Page | Next Page | Contents | Index ]