This example shows the SAA callable interface for IBM C language.
The following program, DSQABFC, is shipped with the QMF product. You can look at the sample source code listing here or you can access it online.
The sample program for the C language callable interface performs the following function:
QMF does not supply query Q1 or form F1, but the sample program uses these objects.
This section also shows how to compile, link-edit, and run a C language program that uses the callable interface. QMF does not ship the REXX EXEC, JCL, or CLIST in these examples, but you can copy them from here, altering them to suit your installation.
/******************************************************************/ /* Sample Program: DSQABFC */ /* C Version of the SAA Query Callable Interface */ /******************************************************************/ /******************************************************************/ /* Include standard and string "C" functions */ /******************************************************************/ #include <string.h> #include <stdlib.h> /******************************************************************/ /* Include and declare query interface communications area */ /******************************************************************/ #include <DSQCOMMC.H> int main() { struct dsqcomm communication_area; /* DSQCOMM from include */ /******************************************************************/ /* Query interface command length and commands */ /******************************************************************/ signed long command_length; static char start_query_interface[] = "START"; static char set_global_variables[] = "SET GLOBAL"; static char run_query[] = "RUN QUERY Q1"; static char print_report[] = "PRINT REPORT (FORM=F1"; static char end_query_interface[] = "EXIT"; /******************************************************************/ /* Query command extension, number of parameters and lengths */ /******************************************************************/ signed long number_of_parameters; /* number of variables */ signed long keyword_lengths[10]; /* lengths of keyword names */ signed long data_lengths[10]; /* lengths of variable data */
/******************************************************************/ /* Variable data type constants */ /******************************************************************/ static char char_data_type[] = DSQ_VARIABLE_CHAR; static char int_data_type[] = DSQ_VARIABLE_FINT; /******************************************************************/ /* Keyword parameter and value for START command */ /******************************************************************/ static char start_keywords[] = "DSQSMODE"; static char start_keyword_values[] = "INTERACTIVE"; /******************************************************************/ /* Keyword parameter and values for SET command */ /******************************************************************/ #define SIZE_VAL 8 char set_keywords [3][SIZE_VAL]; /* Parameter name array */ signed long set_values[3]; /* Parameter value array */ /******************************************************************/ /* MAIN PROGRAM */ /******************************************************************/ /******************************************************************/ /* Start a Query Interface Session */ /******************************************************************/ strncpy (communication_area.dsq_comm_level, DSQ_CURRENT_COMM_LEVEL, sizeof(communication_area.dsq_comm_level)); number_of_parameters = 1; command_length = sizeof(start_query_interface); keyword_lengths[0] = sizeof(start_keywords); data_lengths[0] = sizeof(start_keyword_values); dsqcice(&communication_area,; &command_length,; &start_query_interface[0], &number_of_parameters,; &keyword_lengths[0], &start_keywords[0], &data_lengths[0], &start_keyword_values[0], &char_data_type[0]);
/******************************************************************/ /* Set numeric values into query using SET command */ /******************************************************************/ number_of_parameters = 3; command_length = sizeof(set_global_variables); strcpy(set_keywords[0],"MYVAR01"); strcpy(set_keywords[1],"SHORT"); strcpy(set_keywords[2],"MYVAR03"); keyword_lengths[0] = SIZE_VAL; keyword_lengths[1] = SIZE_VAL; keyword_lengths[2] = SIZE_VAL; data_lengths[0] = sizeof(long); data_lengths[1] = sizeof(long); data_lengths[2] = sizeof(long); set_values[0] = 20; set_values[1] = 40; set_values[2] = 84; dsqcice(&communication_area,; &command_length,; &set_global_variables[0], &number_of_parameters,; &keyword_lengths[0], &set_keywords[0][0], &data_lengths[0], &set_values[0], &int_data_type[0]); /******************************************************************/ /* Run a Query */ /******************************************************************/ command_length = sizeof(run_query); dsqcic(&communication_area,&command_length,; &run_query[0]); /******************************************************************/ /* Print the results of the query */ /******************************************************************/ command_length = sizeof(print_report); dsqcic(&communication_area,&command_length,; &print_report[0]); /******************************************************************/ /* End the query interface session */ /******************************************************************/ command_length = sizeof(end_query_interface); dsqcic(&communication_area,&command_length,; &end_query_interface[0]); exit(0); }