Problem solve Get help with specific problems with your technologies, process and projects.

Lists real connected ODBC users without C

A previous tip showed a method that required the C compiler. This version needs only CL.

A previous tip showed a method that required the C compiler. This version needs only CL.

The current job user and active job status are extracted from a variable structure at the end of the JOBL0200 format. As written, the variable structure is assumed always to be the same. To be perfectly correct, this CL should process that variable structure rather than extracting from fixed offsets into it.


	 pgm

/*                                                           */
/* *Usrspc variables...                                      */
/*                                                           */
   dcl   &usrspc        *char      20   /* Space name/lib    */

   dcl   &offslst       *char       4   /* Offset to list    */
   dcl   &sizlste       *char       4   /* Size list entries */
   dcl   &nbrlste       *dec   (  7 0 ) /* Number of entries */

   dcl   &us_hdr        *char     150   /* Space header      */

   dcl   &us_jobe       *char     512   /* A single entry    */

/*                                                           */
/* Job selection variables...                                */
/*                                                           */
   dcl   &jobname       *char      26   /* Select job name   */
   dcl   &dftuser       *char      10   value( 'QUSER     ' )
                                        /* Prestart user     */
/* Variable keys to select                                   */
   dcl   &nbrkeys       *char       4   value( x'00000002' )
                                        /* bin(   2 )        */
   dcl   &rtvcurusr     *char       4   value( x'00000131' )
                                        /* bin( 305 )        */
   dcl   &rtvsts        *char       4   value( x'00000065' )
                                        /* bin( 101 )        */
/* Variable key list...                                      */
   dcl   &varkeylst     *char     400

/*                                                           */
/* Retrieved values from job list...                         */
/*                                                           */
   dcl   &job           *char      10
   dcl   &user          *char      10
   dcl   &nbr           *char       6

   dcl   &curuser       *char      10   /* Current user      */
   dcl   &sts           *char       4   /* Job status        */


/*                                                           */
/* Global message monitor...                                 */
/*                                                           */

   monmsg   ( cpf0000 mch0000 )  exec( goto  Std_Err )

/*                                                           */
/* Create a *usrspc to work with...                          */
/*                                                           */

   chgvar    &usrspc       ( 'ODBCJOB   ' *cat 'QTEMP     ' )

   call  QUSCRTUS         ( +
                            &usrspc                 +
                            'TMPLST    '            +
                            x'00001000'             +
                            X'00'                   +
                            '*ALL      '            +
                            'Temp list ODBC jobs    ' +
                            '*YES      '            +
                            x'0000000000000000'     +
                          )


/*                                                           */
/* This sets up selection criteria for list jobs API...      */
/*                                                           */

/* The jobname we're after...                                */

   chgvar    &jobname      ( 'QZDASOINIT' *cat +
                             &dftuser     *cat +
                             '*ALL   '         +
                           )

/* Include current job user and active job status...         */

   chgvar    &varkeylst    ( &rtvcurusr *cat &rtvsts )

/*                                                           */
/* This lists active jobs with the job name specified.       */
/*                                                           */

   call  QUSLJOB          ( +
                            &usrspc                 +
                            'JOBL0200'              +
                            &jobname                +
                            '*ACTIVE   '            +
                            x'0000000000000000'     +
                            'B'                     +
                            &nbrkeys                +
                            &varkeylst              +
                          )



/*                                                           */
/* Get the *usrspc header for the list attributes...         */
/*                                                           */

   call  QUSRTVUS         ( +
                            &usrspc                 +
                            x'00000001'             +
                            x'00000096'             +
                            &us_hdr                 +
                          )

/*                                                           */
/* Get the offset to the list within the space, the number   */
/*   of list entries and size of each entry from the header. */
/*                                                           */
   chgvar    &offslst        %sst( &us_hdr    125 4 )
   chgvar    &nbrlste        %bin( &us_hdr    133 4 )
   chgvar    &sizlste        %sst( &us_hdr    137 4 )

/* If no entries, then get out of here...                    */

   if  ( &nbrlste *eq 0 )     do
      sndpgmmsg  msgid( CPF9898 ) msgf( QCPFMSG ) +
                   msgdta( 'No ODBC jobs found.' )
      goto   Clean_up
   enddo


/* Set the offset to the list within the space...            */

   chgvar    %bin( &offslst ) ( %bin( &offslst ) + 1 )


Nxt_JobE:

/* Get an entry from the list...                             */

   call  QUSRTVUS         ( +
                            &usrspc                 +
                            &offslst                +
                            &sizlste                +
                            &us_jobe                +
                          )

/* Extract job info from list entry...                       */

   chgvar    &job            %sst( &us_jobe     1  10 )
   chgvar    &user           %sst( &us_jobe    11  10 )
   chgvar    &nbr            %sst( &us_jobe    21   6 )

   chgvar    &curuser        %sst( &us_jobe    81  10 )
   if  ( &curuser *eq &dftuser )     do
      chgvar    &curuser        '*DEFAULT'
   enddo

   chgvar    &sts            %sst( &us_jobe   109   4 )


/* Display the result...                                     */

   sndpgmmsg  msgid( CPF9898 ) msgf( QCPFMSG ) +
                msgdta( 'Job<' *cat &nbr *tcat +
                '/' *cat &user *tcat +
                '/' *cat &job  *tcat +
                '> Current user<' *cat &curuser *tcat +
                '> Status<' *cat &sts *tcat '>')


/* Perform loop testing...                                   */

   chgvar    &nbrlste      ( &nbrlste - 1 )

   if  ( &nbrlste *gt 0 )     do

      chgvar    %bin( &offslst ) ( %bin( &offslst ) + +
                                   %bin( &sizlste ) )
      goto      Nxt_JobE

   enddo



/*                                                           */
/* Exit processing...                                        */
/*                                                           */


Clean_up:

   dltusrspc   %sst( &usrspc 11 10 )/%sst( &usrspc 1 10 )

   return

Std_Err:

   /* Move any *DIAG messages up the stack...        */

   Qsys/call  pgm( QSYS/QMHMOVPM ) parm( +
                                         '    '          +
                                         '*DIAG     '    +
                                         x'00000001'     +
                                         '*         '    +
                                         x'00000001'     +
                                         x'00000000'     +
                                       )
   Qsys/monmsg     ( CPF0000 MCH0000 )

   /* Resend any *ESCAPE messages up the stack...     */

   Qsys/call  pgm( QSYS/QMHRSNEM ) parm( +
                                         '    '          +
                                         x'00000000'     +
                                       )
   Qsys/monmsg     ( CPF0000 MCH0000 )

   return

endpgm 

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Ask your systems management questions--or help out your peers by answering them--in our live discussion forums.

Ask the Experts yourself: Our systems management gurus are waiting to answer your technical questions.

Dig Deeper on Performance

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close