Example in ILE C: Registering exit points and adding exit programs
This ILE C program registers an exit point with the registration facility. After the successful completion of the registration, the program adds an exit program to the exit point.
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
/********************************************************************/
/* PROGRAM: Register an Exit Point */
/* Add an Exit Program */
/* */
/* LANGUAGE: ILE C */
/* */
/* DESCRIPTION: This program registers an exit point with the */
/* registration facility. After the successful */
/* completion of the registration of the exit point, */
/* an exit program is added to the exit point. */
/* */
/* APIs USED: QusRegisterExitPoint - Register Exit Point */
/* QusAddExitProgram - Add Exit Program */
/* */
/********************************************************************/
/* NOTE: This example uses APIs that are shipped with *EXCLUDE */
/* authority. The user needs *USE authority to the service */
/* program QUSRGFA1 to use these APIs. */
/********************************************************************/
/********************************************************************/
/* Includes */
/********************************************************************/
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <qusrgfa1.h>
#include <qusec.h>
#include <qliept.h>
/********************************************************************/
/* Structures */
/********************************************************************/
typedef struct { /* Error code */
Qus_EC_t ec_fields;
char exception_data[100];
} error_code_struct;
typedef struct { /* Exit point control keys */
int num_rec;
Qus_Vlen_Rec_4_t max_pgms_rec;
int max_pgms;
Qus_Vlen_Rec_4_t descrip_rec;
char text_desc[50];
} rgpt_controls;
typedef struct { /* Exit program attribute keys*/
int num_rec;
Qus_Vlen_Rec_4_t replace_rec;
char replace;
char Reserved[3];
Qus_Vlen_Rec_4_t CCSID_rec;
int CCSID;
} addep_attributes;
/********************************************************************/
/* */
/* main */
/* */
/********************************************************************/
int main()
{
int ccsid,
pgm_num,
num_of_attrs,
epgm_num,
len_epgm_data,
add_epgm_num,
*ccsid_ptr,
*pgm_num_ptr;
error_code_struct error_code;
rgpt_controls control_keys;
addep_attributes attrib_keys;
/******************************************************************/
/* Register the exit point with the registration facility. If the */
/* registration of the exit point is successful, add an exit */
/* program to the exit point. */
/******************************************************************/
/******************************************************************/
/* Initialize the error code parameter. To signal exceptions to */
/* this program by the API, you need to set the bytes provided */
/* field of the error code to zero. Because this program has */
/* exceptions sent back through the error code parameter, it sets */
/* the bytes provided field to the number of bytes that it gives */
/* the API for the parameter. */
/******************************************************************/
error_code.ec_fields.Bytes_Provided=sizeof(error_code_struct);
/******************************************************************/
/* Set the exit point controls. Each control field is passed to */
/* the API using a variable length record. Each record must */
/* start on a 4-byte boundary. */
/******************************************************************/
/******************************************************************/
/* Set the total number of controls that are being specified on */
/* the call. This program lets the API take the default for the */
/* controls that are not specified. */
/******************************************************************/
control_keys.num_rec=2;
/******************************************************************/
/* Set the values for the two controls that are specified: */
/* Maximum number of exit programs = 10 */
/* Exit point text description = "EXIT POINT EXAMPLE" */
/******************************************************************/
control_keys.max_pgms_rec.Length_Vlen_Record=16;
control_keys.max_pgms_rec.Control_Key=3;
control_keys.max_pgms_rec.Length_Data=4;
control_keys.max_pgms=10;
control_keys.descrip_rec.Length_Vlen_Record=62;
control_keys.descrip_rec.Control_Key=8;
control_keys.descrip_rec.Length_Data=50;
memcpy(control_keys.text_desc,
"EXIT POINT EXAMPLE ",50);
/******************************************************************/
/* Call the API to register the exit point. */
/******************************************************************/
QusRegisterExitPoint("EXAMPLE_EXIT_POINT ",
"EXMP0100",
&control_keys,
&error_code);
/******************************************************************/
/* If an exception occurs, the API returns the exception in the */
/* error code parameter. The bytes available field is set to */
/* zero if no exception occurs and nonzero if an exception does */
/* occur. */
/******************************************************************/
if (error_code.ec_fields.Bytes_Available != 0)
{
printf("ATTEMPT TO REGISTER EXIT POINT FAILED WITH EXCEPTION: %.7s",
error_code.ec_fields.Exception_Id);
exit(1);
}
/******************************************************************/
/* If the call to register an exit point is successful, add */
/* an exit program to the exit point. */
/******************************************************************/
/******************************************************************/
/* Set the total number of exit program attributes that are being */
/* specified on the call. This program lets the API take the */
/* default for the attributes that are not specified. Each */
/* attribute record must be 4-byte aligned. */
/******************************************************************/
attrib_keys.num_rec=2;
/******************************************************************/
/* Set the values for the two attributes that are being */
/* specified: */
/* Replace exit program = 1 */
/* Exit program data CCSID = 37 */
/******************************************************************/
attrib_keys.replace_rec.Length_Vlen_Record=16;
attrib_keys.replace_rec.Control_Key=4;
attrib_keys.replace_rec.Length_Data=1;
attrib_keys.replace='1';
attrib_keys.CCSID_rec.Length_Vlen_Record=16;
attrib_keys.CCSID_rec.Control_Key=3;
attrib_keys.CCSID_rec.Length_Data=4;
attrib_keys.CCSID=37;
/******************************************************************/
/* Call the API to add the exit program. */
/******************************************************************/
QusAddExitProgram("EXAMPLE_EXIT_POINT ",
"EXMP0100",
1,
"EXAMPLEPGMEXAMPLELIB",
"EXAMPLE EXIT PROGRAM DATA",
25,
&attrib_keys,
&error_code);
/******************************************************************/
/* If an exception occurs, the API returns the exception in the */
/* error code parameter. The bytes available field is set to */
/* zero if no exception occurs and nonzero if an exception does */
/* occur. */
/******************************************************************/
if (error_code.ec_fields.Bytes_Available != 0)
{
printf("ATTEMPT TO ADD AN EXIT PROGRAM FAILED WITH EXCEPTION: %.7s",
error_code.ec_fields.Exception_Id);
exit(1);
}
} /* End program */