DSN8ED6

Demonstrates how to use WLM_REFRESH, the sample stored procedure for refreshing a WLM environment .

 /********************************************************************* 00010000
 * Module name = DSN8ED6 (DB2 sample program)                         * 00020000
 *                                                                    * 00030000
 * DESCRIPTIVE NAME = Caller for sample WLM_REFRESH stored procedure  * 00040000
 *                                                                    * 00050000
 *    LICENSED MATERIALS - PROPERTY OF IBM                            * 00060000
 *    5675-DB2                                                        * 00070000
 *    (C) COPYRIGHT 1999, 2000 IBM CORP. ALL RIGHTS RESERVED.         * 00090000
 *                                                                    * 00120000
 *    STATUS = VERSION 7                                              * 00130000
 *                                                                    * 00160000
 * Function: Demonstrates how to use WLM_REFRESH, the sample stored   * 00220000
 *           procedure for refreshing a WLM environment               * 00230000
 *                                                                    * 00240000
 * Notes:                                                             * 00250000
 *   Dependencies: Requires IBM C/C++ for OS/390 V1R3 or higher       * 00260000
 *                                                                    * 00270000
 *   Restrictions:                                                    * 00280000
 *                                                                    * 00290000
 * Module type: C program                                             * 00300000
 *   Processor: IBM C/C++ for OS/390 V1R3 or higher                   * 00310000
 * Module size: See linkedit output                                   * 00320000
 *  Attributes: Re-entrant and re-usable                              * 00330000
 *                                                                    * 00340000
 * Entry Point: DSN8ED6                                               * 00350000
 *     Purpose: See Function                                          * 00360000
 *     Linkage: Standard OS/390 linkage                               * 00370000
 *                                                                    * 00380000
 *                                                                    * 00390000
 *  Parameters: DSN8ED6 uses the C "main" argument convention of      * 00400000
 *              argv (argument vector) and argc (argument count).     * 00410000
 *                                                                    * 00420000
 *              - ARGV[0]  = (input) pointer to a char[9], null-      * 00430000
 *                           terminated string having the name of     * 00440000
 *                           this program (DSN8ED6)                   * 00450000
 *              - ARGV[1]  = (input) pointer to a char[32] null-      * 00460000
 *                           terminated string having the name of     * 00470000
 *                           the WLM environment to be refreshed.     * 00480000
 *              - ARGV[2]  = (input) pointer to a char[4], null-      * 00490000
 *                           terminated string having the DB2 sub-    * 00500000
 *                           system id associated with the WLM        * 00510000
 *                           environment to be refreshed              * 00520000
 *              - ARGV[3]  = (input) pointer to a char[8], null-      * 00530000
 *                           terminated string having the name of a   * 00540000
 *                           secondary authorization id that has      * 00550000
 *                           access to the resource profile <ssid>.-  * 00560000
 *                           WLM_REFRESH.<wlm-environment-name>.      * 00570000
 *                           in resource class DSNR.  WLM_REFRESH     * 00580000
 *                           requires READ access on that profile     * 00590000
 *                           in order to fulfill a refresh request.   * 00600000
 *                                                                    * 00610000
 * Normal Exit: Return Code: 0000                                     * 00620000
 *              - Message: none                                       * 00630000
 *                                                                    * 00640000
 *  Error Exit: Return Code: 1999                                     * 00650000
 *              - Message: Error: Invalid call parameter count        * 00660000
 *                                Specify either 2 or 3 call para-    * 00670000
 *                                meters for DSN8ED6, as follows:     * 00680000
 *                                1. The name of a WLM environment    * 00690000
 *                                   to be refreshed (1-32 characters)* 00700000
 *                                2. The DB2 subsystem id (1-4 char-  * 00710000
 *                                   acters)                          * 00720000
 *                                3. A secondary authorization id for * 00730000
 *                                   submitting the refresh request   * 00740000
 *                                   (Optional.  1-8 characters)      * 00750000
 *                                                                    * 00760000
 *              - Message: <formatted SQL text from DSNTIAR>          * 00770000
 *                                                                    * 00780000
 *                                                                    * 00790000
 *    External References:                                            * 00800000
 *             - Routines/Services: DSNTIAR: DB2 msg text formatter   * 00810000
 *             - Data areas       : None                              * 00820000
 *             - Control blocks   : None                              * 00830000
 *                                                                    * 00840000
 *  Pseudocode:                                                       * 00850000
 *   DSN8ED6:                                                         * 00860000
 *   - Verify that number of input parameters passed is either:       * 00870000
 *     - 2 (WLM environment name and DB2 ssid); or                    * 00880000
 *     - 3 (WLM environment name, DB2 ssid, and secondary auth id     * 00890000
 *     - Other: issue diagnostic message and end with code 1999       * 00900000
 *   - Set current SQLID to secondary auth id, if one was passed in   * 00910000
 *   - Call sample stored procedure WLM_REFRESH                       * 00920000
 *     - if unsuccessful, call sql_error to issue a diagnostic mes-   * 00930000
 *       sage, then end with code 1999.                               * 00940000
 *   - Report the following parameters, passed back from WLM_REFRESH: * 00950000
 *     - Return code                                                  * 00960000
 *     - Return message                                               * 00970000
 *     - Set DSN8ED6 return code from WLM_REFRESH return code         * 00980000
 *   End DSN8ED6                                                      * 00990000
 *                                                                    * 01000000
 *   sql_error:                                                       * 01010000
 *   - call DSNTIAR to format the unexpected SQLCODE.                 * 01020000
 *   End sql_error                                                    * 01030000
 *                                                                    * 01032000
 * Change log:                                                        * 01034000
 * 01/15/04 PQ79759  - Increase authID to 9 bytes                     * 01036000
 *                                                                    * 01040000
 *********************************************************************/ 01050000
 /********************** C library definitions ***********************/ 01060000
 #include <stdio.h>                                                     01070000
 #include <stdlib.h>                                                    01080000
 #include <string.h>                                                    01090000
                                                                        01100000
 /***************************** Equates ******************************/ 01110000
 #define         OUTLEN        80      /* Length of output line      */ 01120000
 #define         DATA_DIM      10      /* Number of message lines    */ 01130000
                                                                        01140000
 #define         NOT_OK         0      /* Run status indicator: Error*/ 01150000
 #define         OK             1      /* Run status indicator: Good */ 01160000
                                                                        01170000
                                                                        01180000
 /******************** DB2 SQL Communication Area ********************/ 01190000
 EXEC SQL INCLUDE SQLCA;                                                01200000
                                                                        01210000
                                                                        01220000
 /************************ DB2 Host Variables ************************/ 01230000
 EXEC SQL BEGIN DECLARE SECTION;                                        01240000
   char          wlmEnvName[33];       /* WLM environment name       */ 01250000
   char          ssID[5];              /* Subsystem name             */ 01260000
                                                                        01270000
   char          authID[9];            /* Current authorization id   */ 01280000
                                                                        01290000
   char          message[123];         /* WLM_REFRESH return message */ 01300000
   long int      code;                 /* WLM_REFRESH return code    */ 01310000
 EXEC SQL END DECLARE SECTION;                                          01320000
                                                                        01330000
 /********************** DB2 Message Formatter ***********************/ 01340000
 struct          error_struct          /* DSNTIAR message structure  */ 01350000
 {                                                                      01360000
   short int     error_len;                                             01370000
   char          error_text[DATA_DIM][OUTLEN];                          01380000
 }               error_message = {DATA_DIM * (OUTLEN)};                 01390000
                                                                        01400000
 #pragma         linkage( dsntiar, OS )                                 01410000
                                                                        01420000
 extern short int dsntiar( struct      sqlca         *sqlca,            01430000
                           struct      error_struct  *msg,              01440000
                           int                       *len );            01450000
                                                                        01460000
 /********************* DSN8ED6 Global Variables *********************/ 01470000
 short int       status = OK;          /* DSN8ED6 run status         */ 01480000
 long int        completion_code = 0;  /* DSN8ED6 return code        */ 01490000
                                                                        01500000
 /******************** DSN8ED6 Function Prototypes *******************/ 01510000
 int main( int argc, char *argv[] );                                    01520000
 void sql_error( char locmsg[] );                                       01530000
                                                                        01540000
                                                                        01550000
 int main( int argc, char *argv[] )                                     01560000
 /********************************************************************* 01570000
 * Get input parms, pass them to DSNTWR, and process the results      * 01580000
 *********************************************************************/ 01590000
 { printf( "**** DSN8ED6: Sample caller of WLM_REFRESH stored "         01600000
                         "procedure (DSNTWR)\n" );                      01610000
   printf( "*\n" );                                                     01620000
                                                                        01630000
   if( argc < 3  ||  argc > 6 )                                         01640000
     { printf( "* Error: Invalid call parameter count\n" );             01650000
       printf( "*        Specify either 2 or 3 call parameters "        01660000
                        "for DSN8ED6, as follows:\n" );                 01670000
       printf( "*        1. The name of a WLM environment to be "       01680000
                           "refreshed (1-32 characters)\n" );           01690000
       printf( "*        2. The DB2 subsystem id (1-4 characters)\n" ); 01700000
       printf( "*        3. A secondary authorization id for "          01710000
                           "submitting the refresh request\n" );        01720000
       printf( "*           (Optional.  1-8 characters)\n" );           01730000
       status = NOT_OK;                                                 01740000
     }                                                                  01750000
   else if( strlen(argv[1]) < 1  ||  strlen(argv[1]) > 32 )             01760000
     { printf( "* Error: The WLM environment name must be 1-32 "        01770000
                        "characters in length\n" );                     01780000
       status = NOT_OK;                                                 01790000
     }                                                                  01800000
   else if( strlen(argv[2]) < 1  ||  strlen(argv[2]) > 4 )              01810000
     { printf( "* Error: The DB2 subsystem id must be 1-4 "             01820000
                        "characters in length\n" );                     01830000
       status = NOT_OK;                                                 01840000
     }                                                                  01850000
   else if( argc == 4 && (strlen(argv[3]) < 1 || strlen(argv[3]) > 8) ) 01860000
     { printf( "* Error: The secondary authorization id must be 1-8 "   01870000
                        "characters in length\n" );                     01880000
       status = NOT_OK;                                                 01890000
     }                                                                  01900000
   else                                                                 01910000
     { strcpy( wlmEnvName,argv[1] );                                    01920000
       strcpy( ssID,argv[2] );                                          01930000
     }                                                                  01940000
                                                                        01950000
   /******************************************************************* 01960000
   * Change authid if one was passed in                               * 01970000
   *******************************************************************/ 01980000
   if( status == OK  &&  argc == 4 )                                    01990000
     { strcpy( authID,argv[3] );                                        02000000
                                                                        02010000
       EXEC SQL SET CURRENT SQLID = :authID;                            02020000
       if( SQLCODE != 0 )                                               02030000
         sql_error( "Error setting SQLID" );                            02040000
     }                                                                  02050000
                                                                        02060000
   /******************************************************************* 02070000
   * Call WLM_REFRESH to refresh the specified WLM environment        * 02080000
   *******************************************************************/ 02090000
   if( status == OK )                                                   02100000
     { EXEC SQL CALL SYSPROC.WLM_REFRESH( :wlmEnvName,                  02110000
                                          :ssID,                        02120000
                                          :message,                     02130000
                                          :code );                      02140000
       if( SQLCODE != 0 )                                               02150000
         sql_error( "Error calling SYSPROC.WLM_REFRESH" );              02160000
       else                                                             02170000
         { printf( "* Results: WLM_REFRESH returned code %i "           02180000
                              "and the following message:\n",code );    02190000
           printf( "* %s\n",message );                                  02200000
         }                                                              02210000
     }                                                                  02220000
                                                                        02230000
   if( status != OK )                                                   02240000
     completion_code = 1999;                                            02250000
   else                                                                 02260000
     completion_code = code;                                            02270000
                                                                        02280000
   return( completion_code );                                           02290000
                                                                        02300000
 } /* end main */                                                       02310000
                                                                        02320000
                                                                        02330000
 void sql_error( char locmsg[] )       /* SQL message formatter      */ 02340000
 { short int   rc;                     /* DSNTIAR Return code        */ 02350000
   int         j,k;                    /* Loop control               */ 02360000
   static int  lrecl = OUTLEN;         /* Width of message lines     */ 02370000
                                                                        02380000
   /******************************************************************* 02390000
   * set status to prevent further processing                         * 02400000
   *******************************************************************/ 02410000
   status = NOT_OK;                                                     02420000
                                                                        02430000
   /******************************************************************* 02440000
   * print the locator message                                        * 02450000
   *******************************************************************/ 02460000
   printf( " %.80s\n", locmsg );                                        02470000
                                                                        02480000
   /******************************************************************* 02490000
   * format and print the SQL message                                 * 02500000
   *******************************************************************/ 02510000
   rc = dsntiar( &sqlca, &error_message, &lrecl );                      02520000
   if( rc == 0 )                                                        02530000
     for( j=0; j<DATA_DIM; j++ )                                        02540000
       {                                                                02550000
         for( k=0; k<OUTLEN; k++ )                                      02560000
           putchar(error_message.error_text[j][k] );                    02570000
         putchar('\n');                                                 02580000
       }                                                                02590000
   else                                                                 02600000
     {                                                                  02610000
       printf( " *** ERROR: DSNTIAR could not format the message\n" );  02620000
       printf( " ***        SQLCODE is %d\n",SQLCODE );                 02630000
       printf( " ***        SQLERRM is \n" );                           02640000
       for( j=0; j<sqlca.sqlerrml; j++ )                                02650000
         printf( "%c", sqlca.sqlerrmc[j] );                             02660000
       printf( "\n" );                                                  02670000
     }                                                                  02680000
                                                                        02690000
 } /* end of sql_error */                                               02700000