Using API's to gather Information QUSRJOBI

We have been usin API’s to gather information for sometime in our products so we have had to work out how to use quite a number with some interesting results! To say the manuals are hard to understand is only part of the problem, even reading through the header files trying to determin exactly how to address the resturned information can be difficult! So as we write test code for our systems which we feel could be of interst we will post it here. Its obviously not production code and is written with a lot of information gathered from the systems before we run the request and will not be able to recover from errors as we would hope the production code will! But if its helps others its not a bad thing to put it up (is it?).

Here is the code we have used to gather the library lists from the API QUSRJOBI, we wrote 2 samples because the first one didnt seem to work (long days make for stupid mistakes). Both sets of code now work aainst the test system and produce the expected results. This code is for info only and we cannot be responsible for it use.

First sample uses the JOBI0700 format which returns only the library names.

#include 
#include 
#include 
#include 
#include 

typedef _Packed struct Job_Inf_x {
                Qwc_JOBI0700_t JobInf;
                Qwc_Lib_List_t Lib[25];
                }Job_Inf_t;

int main(int argc, char **argv) {
int i = 0;
int Num_Libs = 0;
int JobInf_Len = 0;
char *ptr;
char JFmt[8] = "JOBI0700";                  /* Job Inf Fmt  */
char IntJobId[16];

Job_Inf_t JobDets;
Qus_EC_t Error_Code = {0};

Error_Code.Bytes_Provided = sizeof(Error_Code);

JobInf_Len = sizeof(struct Job_Inf_x);
memset(IntJobId,' ',16);

QUSRJOBI(&JobDets,
         JobInf_Len,
         JFmt,
         argv[1],
         IntJobId,
         &Error_Code);
if(Error_Code.Bytes_Available) {
   printf("%.7sn",Error_Code.Exception_Id);
   exit(-1);
   }
printf("Buffer size = %dn",sizeof(JobDets));
printf("Bytes returned %dn",JobDets.JobInf.Bytes_Return);
printf("Job Status %.10sn",JobDets.JobInf.Job_Status);
printf("Bytes Available %dn",JobDets.JobInf.Bytes_Avail);
printf("Number of System Libs %dn",JobDets.JobInf.Libs_In_Syslibl);
printf("Number of Product Libs %dn",JobDets.JobInf.Prod_Libs);
printf("Number of Current Libs %dn",JobDets.JobInf.Curr_Libs);
printf("Number of User Libs %dn",JobDets.JobInf.Libs_In_Usrlibl);
Num_Libs += JobDets.JobInf.Libs_In_Syslibl;
Num_Libs += JobDets.JobInf.Prod_Libs;
Num_Libs += JobDets.JobInf.Curr_Libs;
Num_Libs += JobDets.JobInf.Libs_In_Usrlibl;
for(i = 0; i < Num_Libs; i++) {
   printf(" Library[%d] = %.11sn",i,JobDets.Lib[i].Lib_Name);
   }
exit(0);

}

This is a sample of the output

Buffer size = 355
Bytes returned 135
Job Status *ACTIVE
Bytes Available 135
Number of System Libs 4
Number of Product Libs 0
Number of Current Libs 0
Number of User Libs 1
Library[0] = QSYS
Library[1] = QSYS2
Library[2] = QHLPSYS
Library[3] = QUSRSYS
Library[4] = JQG400
Press ENTER to end terminal session.

The next sample used the JOBI0750 format which returns more information about the libraries.

#include 
#include 
#include 
#include 
#include 

typedef _Packed struct Lib_Info{
     char Lib_Name[10];
     char Lib_Text_Description[50];
     int  Lib_ASP_Number;
     char Lib_ASP_Name[10];
     char Reserved[2];
     } Lib_Info_t;


int main(int argc, char **argv) {
int i = 0;
int JobInf_Len = 0;
char *tmp;
char *ptr;
char JFmt[8] = "JOBI0750";                  /* Job Inf Fmt  */
char IntJobId[16];
char Buf[2500];
Qwc_JOBI0750_t *JobDets;
Lib_Info_t *Libptr;
Qus_EC_t Error_Code = {0};

Error_Code.Bytes_Provided = sizeof(Error_Code);

JobInf_Len = 2500;
memset(IntJobId,' ',16);

QUSRJOBI(Buf,
         JobInf_Len,
         JFmt,
         argv[1],
         IntJobId,
         &Error_Code);
if(Error_Code.Bytes_Available) {
   printf("%.7sn",Error_Code.Exception_Id);
   exit(-1);
   }

JobDets = (Qwc_JOBI0750_t *)Buf;
tmp = Buf;

printf("Bytes returned %dn",JobDets->Bytes_Return);
printf("Job Status %.10sn",JobDets->Job_Status);
printf("Bytes Available %dn",JobDets->Bytes_Avail);
printf("Number of System Libs %dn",JobDets->Number_Sys_Libs);
printf("Number of Product Libs %dn",JobDets->Number_Prod_Libs);
printf("Number of Current Libs %dn",JobDets->Number_Curr_Libs);
printf("Number of User Libs %dn",JobDets->Number_User_Libs);
printf("Offset Sys %dn",JobDets->Offset_Sys_Libs);
printf("Offset Prod %dn",JobDets->Offset_Prod_Libs);
printf("Offset Curr %dn",JobDets->Offset_Curr_Libs);
printf("Offset User %dn",JobDets->Offset_User_Libs);
if(JobDets->Number_Sys_Libs > 0) {
   ptr = tmp + JobDets->Offset_Sys_Libs;
   Libptr = (Lib_Info_t *)ptr;
   for(i = 0; i < JobDets->Number_Sys_Libs; i++) {
      printf("Sys Library[%d] = %.10sn",i,Libptr->Lib_Name);
      printf("Text %.50sn",Libptr->Lib_Text_Description);
      printf("ASP Number %dn",Libptr->Lib_ASP_Number);
      printf("ASP Name %.10sn",Libptr->Lib_ASP_Name);
      Libptr++;
      }
   }
if(JobDets->Number_Prod_Libs > 0) {
   ptr = tmp + JobDets->Offset_Prod_Libs;
   Libptr = (Lib_Info_t *)ptr;
   for(i = 0; i < JobDets->Number_Prod_Libs; i++) {
      printf("Prod Library[%d] = %.10sn",i,Libptr->Lib_Name);
      printf("Text %.50sn",Libptr->Lib_Text_Description);
      printf("ASP Number %dn",Libptr->Lib_ASP_Number);
      printf("ASP Name %.10sn",Libptr->Lib_ASP_Name);
      Libptr++;
      }
   }
if(JobDets->Number_Curr_Libs > 0) {
   ptr = tmp + JobDets->Offset_Curr_Libs;
   Libptr = (Lib_Info_t *)ptr;
   for(i = 0; i < JobDets->Number_Curr_Libs; i++) {
      printf("Curr Library[%d] = %.10sn",i,Libptr->Lib_Name);
      printf("Text %.50sn",Libptr->Lib_Text_Description);
      printf("ASP Number %dn",Libptr->Lib_ASP_Number);
      printf("ASP Name %.10sn",Libptr->Lib_ASP_Name);
      Libptr++;
      }
   }
if(JobDets->Number_User_Libs > 0) {
   ptr = tmp + JobDets->Offset_User_Libs;
   Libptr = (Lib_Info_t *)ptr;
   for(i = 0; i < JobDets->Number_User_Libs; i++) {
      printf("User Library[%d] = %.10sn",i,Libptr->Lib_Name);
      printf("Text %.50sn",Libptr->Lib_Text_Description);
      printf("ASP Number %dn",Libptr->Lib_ASP_Number);
      printf("ASP Name %.10sn",Libptr->Lib_ASP_Name);
      Libptr++;
      }
   }
exit(0);

}

The output from this code is much longer so we have just provided a shortened version.

Bytes returned 480
Job Status *ACTIVE
Bytes Available 480
Number of System Libs 4
Number of Product Libs 0
Number of Current Libs 0
Number of User Libs 1
Offset Sys 100
Offset Prod 0
Offset Curr 0
Offset User 404
Sys Library[0] = QSYS
Text System Library
ASP Number 1
ASP Name *SYSBAS
Sys Library[1] = QSYS2
Text System Library for CPI's
ASP Number 1
ASP Name *SYSBAS
Sys Library[2] = QHLPSYS
Text
ASP Number 1
ASP Name *SYSBAS
Sys Library[3] = QUSRSYS
Text System Library for Users
ASP Number 1
ASP Name *SYSBAS
User Library[0] = JQG400
Text
ASP Number 1
ASP Name *SYSBAS

We hope the code is useful to others.

Chris...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.