This example expects errors sent as escape messages.
Refer to Example in OPM RPG: Retrieving the HOLD parameter (exception message) for the original example.
/***********************************************************************/ /***********************************************************************/ /* */ /*Program Name: JOBDAPI */ /* */ /*Programming Language: ILE C */ /* */ /*Description: This example expects errors sent as */ /* escape messages. */ /* */ /*Header Files Included: SIGNAL - C Error Signalling Routines */ /* STDIO - Standard Input/Output */ /* STRING - String Functions */ /* QUSEC - Error Code Parameter */ /* QWDRJOBD - Retrieve Job Description API */ /* QLIEPT - Entry Point Table */ /* */ /***********************************************************************/ /***********************************************************************/ #include <signal.h> #include <stdio.h> #include <string.h> #include <qusec.h> /* Error Code Parameter Include for the APIs */ #include <qwdrjobd.h> (2) /* Retrieve Job Description API Include */ #include <qliept.h> char received[8]; /* Used to receive error msgs signaled */ /* from QWDRJOBD API. */ /***********************************************************************/ /* Function: error_handler */ /* Description: This function handles exceptions signalled from the */ /* QWDRJOBD API. The message identifier received is */ /* assigned to the variable 'received'. */ /***********************************************************************/ void error_handler(int dummy) { _INTRPT_Hndlr_Parms_T ExcDta = {0}; _GetExcData(&ExcDta); memcpy(received,ExcDta.Msg_Id,7); signal(SIGALL,error_handler); } /***********************************************************************/ /* 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[] (8) { 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 command_string[53]; /*********************************************************************/ /* Enable error handler. */ /*********************************************************************/ signal(SIGALL,error_handler); memset(hold_value, ' ', 10); memset(received, ' ', 7); /*********************************************************************/ /* 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 parameters passed into qual_job_desc. (9) */ /*********************************************************************/ memcpy(qual_job_ptr, argv[1], 10); qual_job_ptr += 10; memcpy(qual_job_ptr, argv[2], 10); (6) /*********************************************************************/ /* Set the error code parameter to 0. */ /*********************************************************************/ error_code.ec_fields.Bytes_Provided = 0; /*********************************************************************/ /* Call the QWDRJOBD API. */ /*********************************************************************/ QWDRJOBD(rec_var, /* Receiver Variable */ 390, (3) /* Receiver Length */ "JOBD0100", (5) /* Format Name */ qual_job_desc, /* Qualified Job Description */ &error_code); /* Error Code */ if(memcmp(received, " ", 7) == 0) memcpy(hold_value, ((Qwd_JOBD0100_t *)rec_var)->Hold_Job_Queue, 10); /*********************************************************************/ /* Let's tell everyone what the hold value was for this job. */ /*********************************************************************/ sprintf(command_string, "SNDMSG MSG('HOLD value is %.7s') TOUSR(QPGMR)", hold_value); system(command_string); } /* main */