DSN8DLPV

Prompts the user to choose an employee, then retrieves the PSEG photo image for that employee from the PSEG_- PHOTO column of the EMP_PHOTO_RESUME table and passes it to GDDM for formatting and display.

 /*********************************************************************         
 * Module name = DSN8DLPV (DB2 sample program)                        *         
 *                                                                    *         
 * DESCRIPTIVE NAME = Display PSEG photo image of a specified employee*         
 *                                                                    *         
 *                                                                    *         
 *  LICENSED MATERIALS - PROPERTY OF IBM                              *         
 *  5655-DB2                                                          *         
 *  (C) COPYRIGHT 1997 IBM CORP.  ALL RIGHTS RESERVED.                *         
 *                                                                    *         
 *  STATUS = VERSION 6                                                *         
 *                                                                    *         
 * Function: Prompts the user to choose an employee, then retrieves   *         
 *           the PSEG photo image for that employee from the PSEG_-   *         
 *           PHOTO column of the EMP_PHOTO_RESUME table and passes it *         
 *           to GDDM for formatting and display.                      *         
 *                                                                    *         
 * Notes:                                                             *         
 *   Dependencies: Requires IBM C/C++ for OS/390 V1R3 or higher       *         
 *                 Requires IBM Graphical Data Display Manager (GDDM) *         
 *                 V3R1 or higher                                     *         
 *                                                                    *         
 *   Restrictions:                                                    *         
 *                                                                    *         
 * Module type: C program                                             *         
 *   Processor: IBM C/C++ for OS/390 V1R3 or subsequent release       *         
 * Module size: See linkedit output                                   *         
 *  Attributes: Re-entrant and re-usable                              *         
 *                                                                    *         
 * Entry Point: CEESTART (Language Environment entry point)           *         
 *     Purpose: See Function                                          *         
 *     Linkage: Standard MVS program invocation, no parameters        *         
 *                                                                    *         
 * Normal Exit: Return Code = 0000                                    *         
 *              - Message: none                                       *         
 *                                                                    *         
 *  Error Exit: Return Code = 0008                                    *         
 *              - Message: *** ERROR: DSN8DLPV DB2 Sample Program     *         
 *                                    Unexpected SQLCODE encountered  *         
 *                                    at location xxx                 *         
 *                                    Error detailed below            *         
 *                                    Processing terminated           *         
 *                                    (DSNTIAR-formatted message here)*         
 *                                                                    *         
 *              - Message: *** ERROR: DSN8DLPV DB2 Sample Program     *         
 *                                    No entry in the Employee Photo/ *         
 *                                    Resume table for employee with  *         
 *                                    empno = xxxxxx                  *         
 *                                    Processing terminated           *         
 *                                                                    *         
 *              - Message: *** ERROR: DSN8DLPV DB2 Sample Program     *         
 *                                    No PSEG photo image exists in   *         
 *                                    the Employee Photo/Resume table *         
 *                                    for the employee with empno =   *         
 *                                    xxxxxx.                         *         
 *                                    Processing terminated           *         
 *                                                                    *         
 *    External References:                                            *         
 *             - Routines/Services: DSNTIAR, GDDM, ISPF               *         
 *             - Data areas       : DSNTIAR error_message             *         
 *             - Control blocks   : None                              *         
 *                                                                    *         
 *                                                                    *         
 *  Pseudocode:                                                       *         
 *   DSN8DLPV:                                                        *         
 *   - Do until the user indicates termination                        *         
 *     - Call getEmplNum to request an employee id                    *         
 *     - Call getEmplPhoto to retrieve the PSEG photo image           *         
 *     - Call showEmplPhoto to display the photo                      *         
 *   End DSN8DLRV                                                     *         
 *                                                                    *         
 *   getEmplNum:                                                      *         
 *   - prompt user to select an employee whose photo is to be viewed  *         
 *                                                                    *         
 *   getEmplPhoto:                                                    *         
 *   - Fetch the specified employee's PSEG photo image from DB2       *         
 *     - call sql_error for unexpected SQLCODEs                       *         
 *   End getEmplPhoto:                                                *         
 *                                                                    *         
 *   showEmplPhoto:                                                   *         
 *   - Use GDDM calls to format and display the PSEG photo image      *         
 *                                                                    *         
 *   sql_error:                                                       *         
 *   - call DSNTIAR to format the unexpected SQLCODE.                 *         
 *                                                                    *         
 *********************************************************************/         
                                                                                
 /******************* C Program Product Libraries ********************/         
 #include <stdlib.h>                                                            
 #include <stdio.h>                                                             
 #include <string.h>                                                            
                                                                                
                                                                                
 /******* GDDM Program Product Libraries (Reentrant Versions) ********/         
 #include <ADMUCIRA>                                                            
 #include <ADMTSTRC>                                                            
 #include <ADMUCIRF>                                                            
 #include <ADMUCIRG>                                                            
 #include <ADMUCIRI>                                                            
                                                                                
                                                                                
 /***************************** Equates ******************************/         
 #define     NO                  0     /* Boolean: False             */         
 #define     YES                 1     /* Boolean: True              */         
                                                                                
 #define     NOT_OK              0     /* Run status indicator: Error*/         
 #define     OK                  1     /* Run status indicator: Good */         
                                                                                
 #define     TIAR_DIM           10     /* Max no. of DSNTIAR msgs    */         
 #define     TIAR_LEN           80     /* Length of DSNTIAR messages */         
                                                                                
                                                                                
 /************************** Global Storage **************************/         
 int         keepViewing     = YES;    /*                            */         
 int         status          = OK;     /* run status                 */         
                                                                                
 short int   ISPFrc;                   /* For ISPF return code       */         
                                                                                
                                                                                
 /******************** DB2 SQL Communication Area ********************/         
 EXEC SQL INCLUDE SQLCA;                                                        
                                                                                
                                                                                
 /********************** DB2 Message Formatter ***********************/         
 struct      error_struct {            /* DSNTIAR message structure  */         
   short int   error_len;                                                       
   char        error_text[TIAR_DIM][TIAR_LEN];                                  
   }         error_message = {TIAR_DIM * (TIAR_LEN)};                           
                                                                                
 #pragma linkage(dsntiar, OS)                                                   
                                                                                
 extern short int dsntiar( struct      sqlca         *sqlca,                    
                           struct      error_struct  *msg,                      
                           int                       *len );                    
                                                                                
                                                                                
 /**************************** DB2 Tables ****************************/         
 EXEC SQL DECLARE  EMP_PHOTO_RESUME  TABLE                                      
   (        EMPNO  CHAR(06)     NOT NULL,                                       
        EMP_ROWID  ROWID,                                                       
       PSEG_PHOTO  BLOB( 500K ),                                                
        BMP_PHOTO  BLOB( 100K ),                                                
           RESUME  CLOB(   5K )         );                                      
                                                                                
                                                                                
 /************** DB2 Host and Null Indicator Variables ***************/         
 EXEC SQL BEGIN DECLARE SECTION;                                                
   char        hvEMPNO[7];             /*                            */         
                                                                                
   SQL TYPE IS BLOB(500K) hvPSEG_PHOTO;/*                            */         
   short int   niPSEG_PHOTO = 0;       /*                            */         
 EXEC SQL END DECLARE SECTION;                                                  
                                                                                
                                                                                
 /************************** GDDM Variables **************************/         
 union{ Admaab      AABtag;                                                     
        char        AABstr[8];                                                  
      } AAB;                                                                    
 int         appl_id;                  /* id for application image   */         
                                                                                
                                       /* appl. image vars follow    */         
 int         ih_pixels       = 800;    /* -horiz size in # of pixels */         
 int         iv_pixels       = 750;    /* -vert size in # of pixels  */         
 int         iim_type        =   1;    /* -pixel type   (1=bi-level) */         
 int         ires_type       =   1;    /* -defined resolution indic. */         
 int         ires_unit       =   0;    /* -resolut'n units (0=inches)*/         
 float       ih_res          = 100.00; /* -horizontal resolution     */         
 float       iv_res          = 100.00; /* -vertical resolution       */         
                                                                                
                                       /* PSEG/GDDM convers'n factors*/         
 int         PSEGformat      =  -3;    /* indicates PSEG format      */         
 int         PSEGcompression =   4;    /* indicates IBM 3800 compresn*/         
                                                                                
 int         attype;                   /* type of attn/interrupt key */         
 int         attval;                   /* value of attn/interrupt key*/         
 int         count;                    /* number of fields modified  */         
                                                                                
                                                                                
 /*************************** ISPF Linkage ***************************/         
 #pragma linkage(isplink,OS)                                                    
                                                                                
                                                                                
 /*************************** ISPF Syntax ****************************/         
 char        CHAR[9]      = "CHAR    ";                                         
 char        CONTROL[9]   = "CONTROL ";                                         
 char        DISPLAY[9]   = "DISPLAY ";                                         
 char        LINE[9]      = "LINE    ";                                         
 char        VDEFINE[9]   = "VDEFINE ";                                         
 char        VGET[9]      = "VGET    ";                                         
 char        VRESET[9]    = "VRESET  ";                                         
                                                                                
                                                                                
 /********************** ISPF Shared Variables ***********************/         
 char        D8EMNUMB[7];              /*                            */         
                                                                                
                                                                                
 /************************* Global Functions *************************/         
 int  main( void );                    /*                            */         
 void getEmplNum( void );              /*                            */         
 void getEmplPhoto( void );            /*                            */         
 void showEmplPhoto( void );           /*                            */         
 void sql_error( char *locmsg );       /*                            */         
                                                                                
                                                                                
 /********************************************************************/         
 /*************************** main routine ***************************/         
 /********************************************************************/         
 int  main( void )                                                              
 {                                                                              
   /*******************************************************************         
   * Display employee photos until user indicates completion          *         
   *******************************************************************/         
   keepViewing = YES;                                                           
   while( keepViewing == YES )                                                  
     {                                                                          
       /***************************************************************         
       * prompt user to select an employee whose photo is to be viewed*         
       ***************************************************************/         
       getEmplNum();                                                            
                                                                                
       if( keepViewing == YES  &&  status == OK )                               
         {                                                                      
           /***********************************************************         
           * extract the employee's PSEG photo image from BLOB storage*         
           ***********************************************************/         
           getEmplPhoto();                                                      
           /***********************************************************         
           * if okay, convert PSEG image to GDDM format and display it*         
           ***********************************************************/         
           if( status == OK )                                                   
              showEmplPhoto();                                                  
           /***********************************************************         
           * otherwise, exit this program                             *         
           ***********************************************************/         
           else                                                                 
             keepViewing = NO;                                                  
         }                                                                      
     }                                                                          
                                                                                
 } /* end main */                                                               
                                                                                
                                                                                
 void getEmplNum( void )                                                        
 /*********************************************************************         
 * Called by the main routine.  Displays an ISPF panels to prompt the *         
 * user to select an employee whose photo image is to be displayed.   *         
 *********************************************************************/         
 {                                                                              
   /*******************************************************************         
   * Share the ISPF var having the employee number                    *         
   *******************************************************************/         
   ISPFrc = isplink( VDEFINE, "D8EMNUMB", D8EMNUMB, CHAR, 6 );                  
   strcpy( D8EMNUMB,"      " );                                                 
                                                                                
   /*******************************************************************         
   * Display the prompt panel                                         *         
   *******************************************************************/         
   ISPFrc = isplink( DISPLAY,"DSN8SSE " );                                      
   if( ISPFrc != 0 )                                                            
     keepViewing = NO;                                                          
                                                                                
   /*******************************************************************         
   * Save off the value of the ISPF shared variable                   *         
   *******************************************************************/         
   strcpy( hvEMPNO,D8EMNUMB );                                                  
                                                                                
   /*******************************************************************         
   * And release it                                                   *         
   *******************************************************************/         
   ISPFrc = isplink( VRESET );                                                  
 } /* end getEmplNum */                                                         
                                                                                
                                                                                
 void getEmplPhoto( void )                                                      
 /*********************************************************************         
 * Called by the main routine. Extracts a specified employee's PSEG   *         
 * photo image from a BLOB column in the sample EMP_PHOTO_RESUME.     *         
 * This image will be converted to GDDM format and displayed by the   *         
 * rotuien showEmplPhoto.                                             *         
 *********************************************************************/         
 {                                                                              
   EXEC SQL SELECT  PSEG_PHOTO                                                  
              INTO :hvPSEG_PHOTO                                                
              FROM  EMP_PHOTO_RESUME                                            
             WHERE  EMPNO = :hvEMPNO;                                           
                                                                                
                                                                                
   if( SQLCODE == 0 )                                                           
     hvPSEG_PHOTO.data[hvPSEG_PHOTO.length] = '\n';                             
   else if( SQLCODE == 100 )                                                    
     {                                                                          
       status = NOT_OK;                                                         
       printf( "*************************************************\n" );         
       printf( "*** ERROR: DSN8DLPV DB2 Sample Program\n"            );         
       printf( "***        No entry in the Employee Photo/Resume\n"  );         
       printf( "***        table for employee with empno = %s\n",               
                           hvEMPNO                                   );         
       printf( "***        Processing terminated\n"                  );         
       printf( "*************************************************\n" );         
     }                                                                          
   else if( SQLCODE == -305 )                                                   
     {                                                                          
       status = NOT_OK;                                                         
       printf( "*************************************************\n" );         
       printf( "*** ERROR: DSN8DLPV DB2 Sample Program\n"            );         
       printf( "***        No PSEG photo image exists in the\n"      );         
       printf( "***        Employee Photo/Resume table for the\n"    );         
       printf( "***        employee with empno = %s\n",                         
                           hvEMPNO                                   );         
       printf( "***        Processing terminated\n"                  );         
       printf( "*************************************************\n" );         
     }                                                                          
   else                                                                         
     {                                                                          
       status = NOT_OK;                                                         
       sql_error( "getEmplPhoto @1" );                                          
     }                                                                          
                                                                                
 } /* end getEmplPhoto */                                                       
                                                                                
                                                                                
 void showEmplPhoto( void )                                                     
 /*********************************************************************         
 * Called by the main routine.  Converts the employee's photo from    *         
 * PSEG format to a GDDM image and then displays it until the user    *         
 * depresses any PF key or the <enter> key.                           *         
 *********************************************************************/         
 {                                                                              
   /*******************************************************************         
   * Signal ISPF to full-screen refresh when GDDM session terminates  *         
   *******************************************************************/         
   isplink( CONTROL,DISPLAY,LINE );                                             
                                                                                
   /*******************************************************************         
   * Initialize GDDM                                                  *         
   *******************************************************************/         
   fsinit( AAB.AABstr );               /* GDDM anchor block          */         
                                                                                
   /*******************************************************************         
   * Obtain a GDDM application image id                               *         
   *******************************************************************/         
   imagid( AAB.AABstr,                 /* GDDM anchor block          */         
           &appl_id );                 /* application id for image   */         
                                                                                
   /*******************************************************************         
   * Create a GDDM application image to receive the employee photo    *         
   *******************************************************************/         
   imacrt( AAB.AABstr,                 /* GDDM anchor block          */         
           appl_id,                    /* target: application image  */         
           ih_pixels,                  /* horiz size in # of pixels  */         
           iv_pixels,                  /* vert size in # of pixels   */         
           iim_type,                   /* pixel type   (1=bi-level)  */         
           ires_type,                  /* defined resolution indic.  */         
           ires_unit,                  /* resolut'n units (0=inches) */         
           ih_res,                     /* horizontal resolution      */         
           iv_res );                   /* vertical resolution        */         
                                                                                
   /*******************************************************************         
   * Set up conversion of photo from PSEG format to GDDM format       *         
   *******************************************************************/         
   imapts( AAB.AABstr,                 /* GDDM anchor block          */         
           appl_id,                    /* target: application image  */         
           0,                          /* GDDM proj. id (0=identity) */         
           PSEGformat,                 /* source format (PSEG)       */         
           PSEGcompression );          /* source compression (3800)  */         
                                                                                
   /*******************************************************************         
   * Perform conversion                                               *         
   *******************************************************************/         
   imapt( AAB.AABstr,                  /* GDDM anchor block          */         
          appl_id,                     /* target: application image  */         
          hvPSEG_PHOTO.length,         /* source length              */         
          hvPSEG_PHOTO.data );         /* source: employee PSEG photo*/         
                                                                                
   /*******************************************************************         
   * Terminate conversion                                             *         
   *******************************************************************/         
   imapte( AAB.AABstr,                 /* GDDM anchor block          */         
           appl_id );                  /* target: application image  */         
                                                                                
   /*******************************************************************         
   * Transfer the GDDM application image to the display               *         
   *******************************************************************/         
   imxfer( AAB.AABstr,                 /* GDDM anchor block          */         
           appl_id,                    /* source: application image  */         
           0,                          /* target: 0=display          */         
           0 );                        /* GDDM proj. id (0=identity) */         
                                                                                
   /*******************************************************************         
   * Disable user updates to the image on the display                 *         
   *******************************************************************/         
   fsenab( AAB.AABstr,                 /* GDDM anchor block          */         
           1,                          /* type of input (1=alphanum) */         
           0 );                        /* type of control (0=disable)*/         
                                                                                
   fsenab( AAB.AABstr,                 /* GDDM anchor block          */         
           2,                          /* type of input (2=graphic)  */         
           0 );                        /* type of control (0=disable)*/         
                                                                                
   fsenab( AAB.AABstr,                 /* GDDM anchor block          */         
           3,                          /* type of input (3=image)    */         
           0 );                        /* type of control (0=disable)*/         
                                                                                
   /*******************************************************************         
   * Display the image until attn or interrupt key depressed          *         
   *******************************************************************/         
   asread( AAB.AABstr,                 /* GDDM anchor block          */         
           &attype,                    /* type of attn/interrupt key */         
           &attval,                    /* value of attn/interrupt key*/         
           &count );                   /* number of fields modified  */         
                                                                                
   /*******************************************************************         
   * Delete the GDDM application image                                *         
   *******************************************************************/         
   imadel( AAB.AABstr,                 /* GDDM anchor block          */         
           appl_id );                  /* target: application image  */         
                                                                                
   /*******************************************************************         
   * Terminate GDDM                                                   *         
   *******************************************************************/         
   fsterm( AAB.AABstr );               /* GDDM anchor block          */         
                                                                                
 } /* end showEmplPhoto */                                                      
                                                                                
                                                                                
 void sql_error( char *locmsg )                                                 
 /*********************************************************************         
 * SQL error handler                                                  *         
 *********************************************************************/         
 {                                                                              
   short int   rc;                     /* DSNTIAR Return code        */         
   int         j,k;                    /* Loop control               */         
   static int  lrecl = TIAR_LEN;       /* Width of message lines     */         
                                                                                
   /*******************************************************************         
   * print the location message                                       *         
   *******************************************************************/         
   printf( "*****************************************************\n" );         
   printf( "*** ERROR: DSN8DLPV DB2 Sample Program\n"                );         
   printf( "***        Unexpected SQLCODE encountered at location\n" );         
   printf( "***         %.68s\n", locmsg                             );         
   printf( "***        Error detailed below\n"                       );         
   printf( "***        Processing terminated\n"                      );         
   printf( "*****************************************************\n" );         
                                                                                
   /*******************************************************************         
   * format and print the SQL message                                 *         
   *******************************************************************/         
   rc = dsntiar( &sqlca, &error_message, &lrecl );                              
   if( rc == 0 )                                                                
     for( j=0; j<TIAR_DIM; j++ )                                                
       {                                                                        
         for( k=0; k<TIAR_LEN; k++ )                                            
           putchar(error_message.error_text[j][k] );                            
         putchar('\n');                                                         
       }                                                                        
   else                                                                         
     {                                                                          
       printf( " *** ERROR: DSNTIAR could not format the message\n" );          
       printf( " ***        SQLCODE is %d\n",SQLCODE );                         
       printf( " ***        SQLERRM is \n" );                                   
       for( j=0; j<sqlca.sqlerrml; j++ )                                        
         printf( "%c", sqlca.sqlerrmc[j] );                                     
       printf( "\n" );                                                          
     }                                                                          
                                                                                
 } /* end sql_error */