Example in ILE C: Accessing the HOLD attribute

This example shows how to print messages to spool files.

Note: Read the Code license and disclaimer information for important legal information.

Refer to Example in OPM RPG: Accessing the HOLD attribute for the original example.

/***********************************************************************/
/***********************************************************************/
/*                                                                     */
/*Program Name:          JOBDAPI                                       */
/*                                                                     */
/*Programming Language:  ILE C                                         */
/*                                                                     */
/*Description:           This example shows how to print messages      */
/*                       to spool files.                               */
/*                                                                     */
/*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;

main(int argc, char *argv[])
{
  error_code_t  error_code;
  char          qual_job_desc[20];
  char          *qual_job_ptr = qual_job_desc;
  char          rec_var[390];
  char          hold_value[10];
  char          message_id[7];
  char          command_string[25];
  char          message_string[29];
  FILE          *stream;

  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;

  /*********************************************************************/
  /* Open QPRINT file so that data can be written to it.  If the file  */
  /* cannot be opened, print a message and exit.                       */
  /*********************************************************************/
  if((stream = fopen("QPRINT", "wb")) == NULL)
  {
    printf("File could not be opened\n");
    exit(1);
  }

  /*********************************************************************/
  /* Call the QWDRJOBD API.                                            */
  /*********************************************************************/
  QWDRJOBD(rec_var,               /* Receiver Variable                 */
           390,                   /* Receiver Length                   */
           "JOBD0100",            /* Format Name                       */
           qual_job_desc,         /* Qualified Job Description         */
           &error_code);          /* Error Code                        */

  /*********************************************************************/
  /* If an error was returned, print the error message to the QPRINT   */
  /* spool file.                                                       */
  /*********************************************************************/
  if(error_code.ec_fields.Bytes_Available > 0)
  {
    memcpy(message_id, error_code.ec_fields.Exception_Id, 7);
    sprintf(message_string,
            "Failed.  Error ID - %.7s",
            message_id);
    fprintf(stream, message_string);
  }
  /*********************************************************************/
  /* Let's tell everyone what the hold value was for this job.         */
  /* The result will be printed in the QPRINT spool file.              */
  /*********************************************************************/
  else
  {
    memcpy(hold_value, ((Qwd_JOBD0100_t *)rec_var)->Hold_Job_Queue, 10);
    sprintf(command_string,
            "HOLD value - %.10s",
            hold_value);
    fprintf(stream, command_string);
  }

  fclose(stream);

} /* main */
Related reference
Example in OPM RPG: Accessing the HOLD attribute