Example in ILE C: Accessing a field value (initial library list)
This ILE C program accesses a variable-length array. The variable-length array is the initial library list for a job description.
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
/***********************************************************************/
/***********************************************************************/
/* */
/*Program Name: JOBDAPI */
/* */
/*Programming Language: ILE C */
/* */
/*Description: This example shows how to access a field */
/* value returned from a retrieve API. */
/* */
/*Header Files Included: STDIO - Standard Input/Output */
/* STRING - String Functions */
/* QUSEC - Error Code Parameter */
/* QWDRJOBD - Retrieve Job Description API */
/* QLIEPT - Entry Point Table */
/* */
/***********************************************************************/
/***********************************************************************/
#include <stdio.h>
#include <string.h>
#include <qusec.h> /* Error Code Parameter Include for the APIs */
#include <qwdrjobd.h> /* Retrieve Job Description API Include */
#include <qliept.h> /* Entry Point Table Include */
/***********************************************************************/
/* Error Code Structure */
/* */
/* This shows how the user can define the variable-length portion of */
/* error code for the exception data. */
/* */
/***********************************************************************/
typedef struct {
Qus_EC_t ec_fields;
char Exception_Data[100];
} error_code_t;
/***********************************************************************/
/* JOBD0100 Structure */
/* */
/* This shows how the user can define the variable-length portion of */
/* the JOBD0100 format. */
/* */
/***********************************************************************/
typedef struct {
Qwd_JOBD0100_t data;
char Lib_Data[5000]; (1) (2)
} JOBD0100;
main(int argc, char *argv[])
{
error_code_t error_code;
char library[10];
char qual_job_desc[20];
char *qual_job_ptr = qual_job_desc;
char rec_var[1000];
char *rec_ptr = rec_var;
char hold_value[10];
char message_id[7];
char command_string[49];
int i;
int num_libs;
int offset;
int rec_len = 5000;
memset(hold_value, ' ', 10);
/*********************************************************************/
/* Make sure we received the correct number of parameters. The argc */
/* parameter will contain the number of parameters that was passed */
/* to this program. This number also includes the program itself, */
/* so we need to evaluate argc-1. */
/*********************************************************************/
if (((argc - 1) < 2) || ((argc - 1 > 2)))
/*********************************************************************/
/* We did not receive all of the required parameters so exit the */
/* program. */
/*********************************************************************/
{
exit(1);
}
/*********************************************************************/
/* Move the two parameter passed into qual_job_desc. */
/*********************************************************************/
memcpy(qual_job_ptr, argv[1], 10);
qual_job_ptr += 10;
memcpy(qual_job_ptr, argv[2], 10);
/*********************************************************************/
/* Set the error code parameter to 16. */
/*********************************************************************/
error_code.ec_fields.Bytes_Provided = 16;
/*********************************************************************/
/* Call the QWDRJOBD API. */
/*********************************************************************/
QWDRJOBD(rec_var, /* Receiver Variable */
rec_len, /* Receiver Length */
"JOBD0100", /* Format Name */
qual_job_desc, /* Qualified Job Description */
&error_code); /* Error Code */
/*********************************************************************/
/* If an error was returned, send an error message. */
/*********************************************************************/
if(error_code.ec_fields.Bytes_Available > 0)
{
/* In this example, nothing was done for the error condition. */
}
/*********************************************************************/
/* Let's tell everyone what the library value was for this job. */
/*********************************************************************/
else
{
num_libs = ((JOBD0100 *)rec_var)->data.Number_Libs_In_Lib_list;
offset = ((JOBD0100 *)rec_var)->data.Offset_Initial_Lib_List;
/*******************************************************************/
/* Advance receiver variable pointer to the location where the */
/* library list begins. */
/*******************************************************************/
rec_ptr += offset;
for(i=0; i<num_libs; i++)
{
memcpy(library, rec_ptr, 10);
sprintf(command_string,
"SNDMSG MSG('LIBRARY %.10s') TOUSR(QPGMR)",
library);
system(command_string);
rec_ptr += 11;
if((offset + 10) >= rec_len)
break;
offset += 11;
}
}
} /* main */