Sample program – SYCTSAA6
/* @(#) syctsaa6.c 11.3 10/14/96 */
/****** SYCTSAA6 - CLIENT LANGUAGE REQUEST APPL - C - CICS **********/
/* */
/* CICS TRANID: SYA6 */
/* */
/* PROGRAM: SYCTSAA6 */
/* */
/* PURPOSE: Demonstrates Open Client for CICS CALLs. */
/* */
/* FUNCTION: Illustrates how to send a language request with */
/* parameters to: */
/* */
/* - A SQL Server */
/* */
/* SQL Server: */
/* */
/* If the request is sent to a SQL Server it */
/* executes the SQL statement: */
/* */
/* SELECT FIRSTNME, EDUCLVL */
/* FROM SYBASE.SAMPLETB */
/* */
/* */
/* PREREQS: Before running SYCTSAA6, make sure that the server */
/* you wish to access has an entry in the Connection */
/* Router Table for that Server and the MCG(s) that */
/* you wish to use. */
/* */
/* */
/* INPUT: On the input screen, make sure to enter the Server */
/* name, user id, and password for the target */
/* TRAN NAME is not used for LAN servers. */
/* */
/* */
/* Open Client CALLs used in this sample: */
/* */
/* cs_convert convert a datatype from one value to another */
/* cs_ctx_alloc allocate a context */
/* cs_ctx_drop drop a context */
/* ct_bind bind a column variable */
/* ct_close close a server connection */
/* ct_config set or retrieve context properties */
/* ct_cmd_alloc allocate a command */
/* ct_cmd_drop drop a command */
/* ct_command initiate remote procedure call */
/* ct_con_alloc allocate a connection */
/* ct_con_drop drop a connection */
/* ct_con_props alter properties of a connection */
/* ct_connect open a server connection */
/* ct_describe return a description of result data */
/* ct diag retrieve SQLCODE messages */
/* ct_exit exit client library */
/* ct_fetch fetch result data */
/* ct_init init client library */
/* ct_results set up result data */
/* ct_res_info return result set info */
/* ct_send send a request to the server */
/* */
/* History: */
/* */
/* Date BTS# Descrition */
/* ======= ====== ================================================= */
/* Sept 96 Create */
/* */
/* */
/********************************************************************/
#pragma csect(code,"SYCTSAA6")
#pragma linkage(SYCVTD, OS)
/*------------------------------------------------------------------*/
/* CLIENT LIBRARY C COPY BOOK */
/*------------------------------------------------------------------*/
#include "ctpublic.h"
/*------------------------------------------------------------------*/
/* CICS BMS DEFINITIONS C COPY BOOK */
/*------------------------------------------------------------------*/
#include "syctba6.h"
/*------------------------------------------------------------------*/
/* DEFINES */
/*------------------------------------------------------------------*/
#define FALSE 0
#define TRUE 1
#define IN a6panel.a6paneli
#define OUT a6panel.a6panelo
#define RS a6panel.a6panelo.rsltne
/*------------------------------------------------------------------*/
/* GLOBALS - CLIENT COMMON WORK AREA */
/*------------------------------------------------------------------*/
/*
** Open Client variables
*/
CS_CONTEXT *context; /* pointer to context handle */
CS_CONNECTION *connection; /* pointer to connection handle */
CS_COMMAND *cmd; /* pointer to command proc */
CS_CHAR servname[30]; /* Server name */
CS_CHAR username[8]; /* User login name */
CS_CHAR pwd[8]; /* Password */
CS_CHAR tran[8]; /* Transaction name */
CS_CHAR driver[9]; /* Network driver */
CS_INT server_size;
CS_INT user_size;
CS_INT pwd_size;
CS_INT tran_size;
CS_CHAR msgstr[40]; /* message string */
CS_INT msg_size = 40; /* error message size */
CS_CHAR msgtext1[79];
CS_CHAR msgtext2[79];
CS_INT text_size = 79;
CS_INT page_cnt = 0;
CS_INT row_num = 0;
CS_INT version; /* CT version # */
CS_VARCHAR col_firstnme;
CS_SMALLINT col_edlevel;
CS_INT maxconnect = 0;
CS_INT results_type;
/*
** Variables to control program flow
*/
CS_SMALLINT no_input = 1;
CS_SMALLINT no_errors_sw = 1;
CS_SMALLINT no_more_results = 0;
CS_SMALLINT diag_msgs_initialized = 0;
CS_INT print_once = 1;
/*
** Variables for conversion to display
*/
CS_INT cvtleft;
CS_INT cvtright;
double cvtdbl;
char cvtwork[17];
/*
** CICS variables for
** System date and time
*/
char TMP_DATE[8] = " ";
char TMP_TIME[8] = " ";
char UTIME[8];
/*------------------------------------------------------------------*/
/* Standard CICS Attribute and Print Control Chararcter List */
/*------------------------------------------------------------------*/
#include <dfhbmsca.h> /* BMS definitions */
/*------------------------------------------------------------------*/
/* CICS Standard Attention Identifiers C Copy Book */
/*------------------------------------------------------------------*/
#include <dfhaid.h> /* PFK definitions */
/*------------------------------------------------------------------*/
/* Local Functions Prototypes */
/*------------------------------------------------------------------*/
void proces_input();
void bind_columns();
void send_command();
void proces_results();
void result_row_processing();
void fetch_row_processing();
void error_out();
void get_diag_messages();
void get_client_msgs();
void get_server_msgs();
void close_connection();
void quit_client_library();
void display_initial_screen();
void get_input_data();
void disp_data();
/********************************************************************/
/* Main routine */
/********************************************************************/
main ()
{
CS_INT rc;
CS_INT i;
EXEC CICS ADDRESS EIB(dfheiptr);
/*------------------------------------------------------------------*/
/* program initialization */
/*------------------------------------------------------------------*/
memset (msgtext1, ' ', text_size);
strncpy (msgtext2, "Press Clear To Exit", text_size);
page_cnt = page_cnt + 1;
memset(servname, ' ', 30);
memset(username, ' ', 8);
memset(tran, ' ', 8);
memset(pwd, ' ', 8);
memset(driver, ' ', 9);
for (i = 0; i < 14; ++i)
memset (RS[i].rsltno, ' ', text_size); /* init output
lines */
/* get system time */
EXEC CICS ASKTIME ABSTIME(UTIME);
EXEC CICS FORMATTIME
ABSTIME(UTIME)
DATESEP('/')
MMDDYY(TMP_DATE)
TIME(TMP_TIME)
TIMESEP ;
display_initial_screen ();
get_input_data ();
/*------------------------------------------------------------------*/
/* Allocate a context structure */
/*------------------------------------------------------------------*/
if (no_input == FALSE)
{
version = CS_VERSION_50;
rc = cs_ctx_alloc (version, &context);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CSCTXALLOC failed", msg_size);
no_errors_sw = FALSE ;
error_out (rc);
EXEC CICS RETURN ;
}
/*------------------------------------------------------------------*/
/* Initialize the Client-Library */
/*------------------------------------------------------------------*/
/* context allocated, it's now OK to use ct_diag for message
retrieving */
diag_msgs_initialized = 1;
rc = ct_init (context, version);
if (rc == CS_SUCCEED)
{
proces_input ();
}
else
{
strncpy (msgstr, "CT_INIT failed", msg_size);
no_errors_sw = FALSE ;
error_out (rc);
}
close_connection ();
quit_client_library ();
} /* process input data entered */
else /* no input data received */
EXEC CICS RETURN ;
} /* end main */
/********************************************************************/
/* */
/* Subroutine to display the initial screen */
/* */
/********************************************************************/
void display_initial_screen ()
{
strncpy (OUT.sdateo, TMP_DATE, 8);
strncpy (OUT.stimeo, TMP_TIME, 8);
strncpy (OUT.prognmo, "SYCTSAA6", 8);
strncpy (OUT.msg1o, msgtext1, text_size);
strncpy (OUT.msg2o, msgtext2, text_size);
strncpy (OUT.spageo, "0001", 4);
EXEC CICS SEND MAP("SYCTBA6")
FROM(a6panel)
CURSOR(252)
FRSET
ERASE
FREEKB ;
} /* end display_initial_screen */
/********************************************************************/
/* */
/* Subroutine to get input data */
/* */
/********************************************************************/
void get_input_data ()
{
CS_SMALLINT enter_data_sw = 0;
CS_CHAR blank30[30] = " ";
CS_CHAR blank8[8] = " ";
int i;
EXEC CICS RECEIVE MAP("a6panel")
MAPSET("SYCTBA6")
ASIS ;
if (IN.serverl == 0)
{
if (strncmp (servname, blank30, 30) == 0)
{
IN.serverl = -1 ; /* set the cursor position */
strncpy (msgtext1, "Please Enter Server Name",
text_size);
enter_data_sw = TRUE ;
}
}
else if (IN.serverl > 0)
{
server_size = IN.serverl ;
strncpy (servname, IN.serveri, server_size);
no_input = 0;
}
if (IN.userl == 0)
{
if (strncmp (username, blank8, 8) == 0)
{
IN.userl = -1 ; /* set the cursor position */
if (enter_data_sw == FALSE) /* not overlaid msgtext1 */
strncpy (msgtext1, "Please Enter User-ID", text_size);
enter_data_sw = TRUE ;
}
}
else
{
user_size = IN.userl ;
strncpy (username, IN.useri, user_size);
}
if (IN.pswdl != 0)
{
pwd_size = IN.pswdl ;
strncpy (pwd, IN.pswdi, pwd_size);
}
if (IN.tranl != 0)
{
tran_size = IN.tranl ;
strncpy (tran, IN.trani, tran_size);
}
if (IN.netdrvl != 0)
{
strncpy (driver, IN.netdrvi, 9);
for (i=0; i<9; ++i)
driver[i] = toupper (driver[i]);
}
if (enter_data_sw == TRUE) /* bad input data */
{
enter_data_sw = FALSE ;
display_initial_screen ();/* request for input again */
get_input_data ();
}
} /* end get_input_data */
/********************************************************************/
/* */
/* Subroutine to process input data */
/* */
/********************************************************************/
void proces_input ()
{
CS_INT rc;
CS_INT *outlen;
CS_INT buf_len;
CS_INT msglimit;
CS_INT netdriver;
/*------------------------------------------------------------*/
/* Allocate a connection to the server */
/*------------------------------------------------------------*/
rc = ct_con_alloc (context, &connection);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_CONALLOC failed", msg_size);
no_errors_sw = FALSE ;
error_out (rc);
}
/*------------------------------------------------------------*/
/* Alter properties of the connection for user-id */
/*------------------------------------------------------------*/
buf_len = user_size;
rc = ct_con_props (connection, (long)CS_SET,
(long)CS_USERNAME, username,
buf_len, outlen);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_CON_PROPS for user-id failed",
msg_size);
no_errors_sw = FALSE ;
error_out (rc);
}
/*------------------------------------------------------------*/
/* Alter properties of the connection for password */
/*------------------------------------------------------------*/
buf_len = pwd_size;
rc = ct_con_props (connection, (long)CS_SET,
(long)CS_PASSWORD, pwd, buf_len, outlen);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_CON_PROPS for password failed",
msg_size);
no_errors_sw = FALSE ;
error_out (rc);
}
/*------------------------------------------------------------*/
/* Alter properties of the connection for transaction */
/*------------------------------------------------------------*/
buf_len = tran_size;
rc = ct_con_props (connection, (long)CS_SET,
(long)CS_TRANSACTION_NAME,
tran, buf_len, outlen);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_CON_PROPS for transaction failed",
msg_size);
no_errors_sw = FALSE ;
error_out (rc);
}
/*------------------------------------------------------------*/
/* Alter properties of the connection for network driver */
/*------------------------------------------------------------*/
netdriver = 9999; /* default value for non-regconized
driver name */
/* if no netdriver entered, default is LU62 */
if (strncmp(driver," ",9) == 0 ??
strncmp(driver,"LU62",4) == 0)
netdriver = CS_LU62;
else if (strncmp(driver,"INTERLINK",8) == 0)
netdriver = CS_INTERLINK;
else if (strncmp(driver,"IBMTCPIP",8) == 0)
netdriver = CS_TCPIP;
else if (strncmp(driver,"CPIC",4) == 0)
netdriver = CS_NCPIC;
rc = ct_con_props (connection, (long)CS_SET,
(long)CS_NET_DRIVER, (long) netdriver,
CS_UNUSED, outlen);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_CON_PROPS for network driver failed",
msg_size);
no_errors_sw = FALSE ;
error_out (rc);
}
/*------------------------------------------------------------*/
/* Setup retrieval of All Messages */
/*------------------------------------------------------------*/
rc = ct_diag (connection, CS_INIT,
CS_UNUSED, CS_UNUSED, CS_NULL);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_DIAG CS_INIT failed", msg_size);
no_errors_sw = FALSE ;
error_out (rc);
}
/*------------------------------------------------------------*/
/* Set the upper limit of number of messages */
/*------------------------------------------------------------*/
msglimit = 5 ;
rc = ct_diag (connection, CS_MSGLIMIT, CS_ALLMSG_TYPE,
CS_UNUSED, &msglimit);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_DIAG CS_MSGLIMIT failed", msg_size);
no_errors_sw = FALSE ;
error_out (rc);
}
/*------------------------------------------------------------*/
/* Open connection to the server or CICS region */
/*------------------------------------------------------------*/
rc = ct_connect (connection, servname, server_size);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_CONNECT failed", msg_size);
no_errors_sw = FALSE ;
error_out (rc);
}
/*------------------------------------------------------------*/
/* Invokes SEND_COMMAND routine */
/*------------------------------------------------------------*/
if (no_errors_sw)
send_command ();
/*------------------------------------------------------------*/
/* Process the results of the command */
/*------------------------------------------------------------*/
if (no_errors_sw)
{
while (no_more_results == FALSE)
proces_results ();
}
} /* end proces_input */
/********************************************************************/
/* */
/* Subroutine to allocate, send, and process commands */
/* */
/********************************************************************/
void send_command ()
{
CS_INT rc;
CS_INT *outlen;
CS_INT buf_len;
CS_CHAR sql_cmd[45];
/*------------------------------------------------------------*/
/* Find out what the maximum number of connections is */
/*------------------------------------------------------------*/
rc = ct_config (context, CS_GET, CS_MAX_CONNECT,
&maxconnect, CS_FALSE, outlen);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_CONFIG failed", msg_size);
strncpy (msgtext2, "Please press return to continue!",
text_size);
error_out(rc);
/* reset program flags to move on with the task */
print_once = TRUE;
diag_msgs_initialized = TRUE;
strncpy(msgtext2, "Press Clear To Exit", text_size);
}
/*------------------------------------------------------------*/
/* Allocate a command handle */
/*------------------------------------------------------------*/
rc = ct_cmd_alloc (connection, &cmd);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_CMDALLOC failed", msg_size);
no_errors_sw = FALSE ;
error_out(rc);
}
/*------------------------------------------------------------*/
/* Prepare the language request */
/*------------------------------------------------------------*/
strcpy(sql_cmd,
"SELECT FIRSTNME, EDUCLVL FROM SYBASE.SAMPLETB");
buf_len = sizeof(sql_cmd);
rc = ct_command(cmd, (long) CS_LANG_CMD, sql_cmd,
buf_len, (long) CS_UNUSED);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_COMMAND failed", msg_size);
no_errors_sw = FALSE ;
error_out (rc);
}
/*------------------------------------------------------------*/
/* Send the language request */
/*------------------------------------------------------------*/
rc = ct_send (cmd);
if (rc != CS_SUCCEED)
{
strcpy (msgstr, "CT_SEND failed", msg_size);
no_errors_sw = FALSE ;
error_out (rc);
}
} /* end send_command */
/********************************************************************/
/* */
/* Subroutine to process the result */
/* */
/********************************************************************/
void proces_results ()
{
CS_INT rc;
/*------------------------------------------------------------*/
/* Set up the results data */
/*------------------------------------------------------------*/
rc = ct_results (cmd, &results_type);
/*------------------------------------------------------------*/
/* Determine the outcome of the comand execution */
/*------------------------------------------------------------*/
switch (rc)
{
case CS_SUCCEED:
/*--------------------------------------------------------------*/
/* Determine the type of result returned by the current request */
/*--------------------------------------------------------------*/
switch (results_type)
{
/*------------------------------------------------------------*/
/* Process row results */
/*------------------------------------------------------------*/
case CS_ROW_RESULT:
result_row_processing ();
fetch_row_processing ();
break;
/*------------------------------------------------------------*/
/* Process parameter results --- there should be no parameter */
/* to process */
/*------------------------------------------------------------*/
case CS_PARAM_RESULT:
no_more_results = FALSE;
break;
/*------------------------------------------------------------*/
/* process status results --- the stored procedure status */
/* result will not be processed in this example */
/*------------------------------------------------------------*/
case CS_STATUS_RESULT:
no_more_results = FALSE;
break;
/*------------------------------------------------------------*/
/* print an error message if the server encountered an error */
/* while executing the request */
/*------------------------------------------------------------*/
case CS_CMD_FAIL:
no_errors_sw = FALSE ;
strncpy (msgstr,
"CT_RESUL returned CS_CMD-FAIL restype",
msg_size);
error_out (rc);
break;
/*------------------------------------------------------------*/
/* print a message for successful commands that returned no */
/* data( optional ) */
/*------------------------------------------------------------*/
case CS_CMD_SUCCEED:
strncpy (msgstr,
"CT_RESUL returned CS_CMD_SUCCEED restype",
msg_size);
break;
/*------------------------------------------------------------*/
/* print a message for requests that have been processed */
/* successfully( optional ) */
/*------------------------------------------------------------*/
case CS_CMD_DONE:
strncpy (msgstr,
"CT_RESUL returned CS_CMD_DONE restype",
msg_size);
break;
default:
no_more_results = TRUE ;
no_errors_sw = FALSE ;
strncpy (msgstr,
"CT_RESUL returned UNKNOWN restype",
msg_size);
error_out (rc);
break;
} /* end of switch (result_type) */
break; /* case of CS_SUCCEED */
/*------------------------------------------------------------*/
/* print an error message if the CTBRESULTS call failed */
/*------------------------------------------------------------*/
case CS_FAIL:
no_more_results = TRUE ;
no_errors_sw = FALSE ;
strncpy (msgstr, "CT_RESULTS returned CS_FAIL ret_code",
msg_size);
error_out (rc);
break;
/*------------------------------------------------------------*/
/* drop out of the results loop if no more result sets are */
/* available for processing or if the results were cancelled */
/*------------------------------------------------------------*/
case CS_END_RESULTS:
case CS_CANCELLED:
no_more_results = TRUE ;
break;
default:
no_more_results = TRUE ;
no_errors_sw = FALSE ;
strncpy (msgstr, "CT_RESULTS returned unknown ret_code",
msg_size);
error_out (rc);
break;
} /* end of switch (rc) */
} /* end process_results */
/********************************************************************/
/* */
/* Subroutine to process result rows */
/* */
/********************************************************************/
void result_row_processing ()
{
CS_INT rc;
CS_INT col_len;
CS_INT numcol;
CS_INT parm_cnt;
char msg1[40] = "The maximum number of connections is ";
char msg2[25] = "The number of columns is ";
char wrk_str [4];
char period = '.';
/*------------------------------------------------------------*/
/* We need to bind the data to program variables. We don't */
/* care about the indicator variable so we'll pass NULL for */
/* that parameter in OC_BIND(). */
/*------------------------------------------------------------*/
rc =
ct_res_info(cmd,CS_NUMDATA,&numcol,sizeof(numcol),&col_len);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_RES_INFO failed", msg_size);
no_errors_sw = FALSE ;
error_out (rc);
}
/*------------------------------------------------------------*/
/* display the number of connections */
/*------------------------------------------------------------*/
row_num = row_num + 1;
strncpy (RS[row_num].rsltno, msg1, msg_size);
cvtleft = 4; /* Digits to the left */
cvtright = 0; /* Digits to the right */
SYCVTD(maxconnect, wrk_str,
cvtleft, cvtright, cvtwork, cvtdbl, CS_TRUE);
strncat (RS[row_num].rsltno, wrk_str, 4);
row_num = row_num + 2;
/*------------------------------------------------------------*/
/* display the number of columns */
/*------------------------------------------------------------*/
strncpy (RS[row_num].rsltno, msg2, sizeof(msg2));
cvtleft = 4; /* Digits to the left */
cvtright = 0; /* Digits to the right */
SYCVTD(numcol, wrk_str,
cvtleft, cvtright, cvtwork, cvtdbl, CS_TRUE);
strncat (RS[row_num].rsltno, wrk_str, 4);
row_num = row_num + 2;
if (numcol != 2)
{
strncpy (msgstr, "CT_RES_INFO returned wrong # of parms",
msg_size);
no_errors_sw = FALSE ;
error_out (rc);
}
/*------------------------------------------------------------*/
/* Setup column headings */
/*------------------------------------------------------------*/
strncpy (RS[row_num].rsltno,
"FirstName EducLvl", text_size);
row_num = row_num + 1;
strncpy (RS[row_num].rsltno,
"========== =======", text_size);
for (parm_cnt = 1; parm_cnt <= numcol; ++parm_cnt)
bind_columns (parm_cnt);
} /* end result_row_processing */
/********************************************************************/
/* */
/* Subroutine to bind each data */
/* */
/********************************************************************/
void bind_columns (parm_cnt)
CS_INT parm_cnt;
{
CS_INT rc;
CS_INT col_len;
CS_DATAFMT datafmt;
rc= ct_describe(cmd, parm_cnt, &datafmt);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_DESCRIBE failed", msg_size);
no_errors_sw = FALSE ;
error_out(rc);
}
/*------------------------------------------------------------*/
/* We need to bind the data to program variables. We don't */
/* care about the indicator variable so we'll pass NULL for */
/* that parameter in OC_BIND(). */
/*------------------------------------------------------------*/
/*------------------------------------------------------------*/
/* rows per fetch */
/*------------------------------------------------------------*/
switch (datafmt.datatype)
{
/*------------------------------------------------------------*/
/* bind the first column, FIRSTNME defined as VARCHAR(12) */
/*------------------------------------------------------------*/
case CS_VARCHAR_TYPE:
rc= ct_bind(cmd, parm_cnt, &datafmt, &col_firstnme,
&col_len, CS_NULL);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_BIND CS_VARCHAR_TYPE failed",
msg_size);
no_errors_sw = FALSE ;
error_out(rc);
}
break;
/*------------------------------------------------------------*/
/* bind the second column, EDLEVEL defined as SMALLINT */
/*------------------------------------------------------------*/
case CS_SMALLINT_TYPE:
rc= ct_bind(cmd, parm_cnt, &datafmt, &col_edlevel,
&col_len, CS_NULL);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_BIND CS_SMALLINT_TYPE failed",
msg_size);
no_errors_sw = FALSE ;
error_out(rc);
}
break;
default:
break;
} /* end of switch (datatype) */
} /* end bind_columns */
/********************************************************************/
/* */
/* Subroutine to fetch row processing */
/* */
/********************************************************************/
void fetch_row_processing ()
{
CS_INT rows_read;
CS_INT rc;
CS_INT col_len;
CS_INT max_screen_rows = 10;
CS_SMALLINT nomore_rows = 0;
CS_DATAFMT datafmt;
CS_DATAFMT datafmt2;
struct {
char first[12];
char space2[2];
char edlevel[4];
} output_row;
while (nomore_rows == FALSE)
{
strcpy(col_firstnme.str, " ");
memset (&output_row, ' ', sizeof(output_row));
rc = ct_fetch (cmd, (long) CS_UNUSED,
(long) CS_UNUSED,
(long) CS_UNUSED,
&rows_read);
switch (rc)
{
case CS_SUCCEED:
nomore_rows = FALSE ;
datafmt.datatype = CS_VARCHAR_TYPE;
datafmt.maxlength = sizeof(col_firstnme);
datafmt2.datatype = CS_CHAR_TYPE;
datafmt2.maxlength = 12;
/*------------------------------------------------------------*/
/* convert the first column from VARCHAR to CHAR for display */
/*------------------------------------------------------------*/
if (cs_convert(context, datafmt, col_firstnme, datafmt2,
&output_row.first, &col_len) !=
CS_SUCCEED)
{
strncpy (msgstr,
"CS_CONVERT CS_CHAR_TYPE failed", msg_size);
no_errors_sw = FALSE ;
error_out(rc);
}
/*------------------------------------------------------------*/
/* save ROW RESULTS for later display */
/*------------------------------------------------------------*/
cvtleft = 4; /* Digits to the left */
cvtright = 0; /* Digits to the right */
SYCVTD(col_edlevel, output_row.edlevel,
cvtleft, cvtright, cvtwork, cvtdbl, CS_TRUE);
if (row_num > max_screen_rows)
{
strncpy (msgtext1, "Please press return to
continue!", text_size);
memset (msgtext2, ' ', text_size);
disp_data ();
/* re-init output lines */
for (row_num = 0; row_num < 14; ++row_num)
memset (RS[row_num].rsltno, ' ', text_size);
row_num = 1;
page_cnt = page_cnt + 1 ;
/*------------------------------------------------------------*/
/* Setup column headings */
/*------------------------------------------------------------*/
strncpy (RS[row_num].rsltno, "FirstName EducLvl",
text_size);
row_num += 1;
strncpy (RS[row_num].rsltno, "========== =======",
text_size);
row_num += 1;
} /* if row_num > 10 */
row_num += 1;
memcpy (RS[row_num].rsltno, &output_row,
sizeof(output_row));
break; /* end of CS_SUCCEED */
case CS_END_DATA:
nomore_rows = TRUE ;
strncpy (msgtext1, "All rows processing completed!",
text_size);
strncpy (msgtext2, "Press Clear To Exit", text_size);
disp_data ();
break; /* end of CS_END_DATA */
case CS_FAIL:
nomore_rows = TRUE ;
no_errors_sw = FALSE ;
strncpy (msgstr, "CT_FETCH returned CS_FAIL ret_code");
error_out(rc);
break; /* end of CS_FAIL */
case CS_ROW_FAIL:
nomore_rows = TRUE ;
no_errors_sw = FALSE ;
strncpy (msgstr, "CT_FETCH returned CS_ROW_FAIL
ret_code");
error_out(rc);
break; /* end of CS_ROW_FAIL */
case CS_CANCELLED:
nomore_rows = TRUE ;
no_errors_sw = FALSE ;
strncpy (msgstr, "CT_FETCH returned CS_CANCELLED
ret_code");
error_out(rc);
break; /* end of CS_CANCELLED */
default:
nomore_rows = TRUE ;
no_errors_sw = FALSE ;
strncpy (msgstr, "CT_FETCH returned Unknown ret_code");
error_out(rc);
break; /* end of OTHERWISE */
} /* end of switch (rc) */
} /* end of while nomore_rows false */
} /* end fetch_row_processing */
/********************************************************************/
/* */
/* Subroutine to print output messages. */
/* */
/********************************************************************/
void error_out (rc)
CS_INT rc;
{
/*
** Display Message
*/
struct {
char test_case[9] ;
char samp_lit[5] ;
char samp_rc[4] ;
char rest_lit[15] ;
char rest_type[4] ;
char filler[2] ;
char msg[40];
} disp_msg;
memset(&disp_msg, ' ', sizeof(disp_msg));
strcpy(disp_msg.test_case, "SYCTSAA6");
strcpy(disp_msg.samp_lit, "rc = ");
strcpy(disp_msg.rest_lit, " Result Type: ");
cvtleft = 4; /* Digits to the left */
cvtright = 0; /* Digits to the right */
SYCVTD(rc, disp_msg.samp_rc,
cvtleft, cvtright, cvtwork, cvtdbl, CS_TRUE);
SYCVTD(results_type, disp_msg.rest_type,
cvtleft, cvtright, cvtwork, cvtdbl, CS_TRUE);
if (diag_msgs_initialized)
get_diag_messages ();
/*------------------------------------------------------------------*/
/* display error messages */
/*------------------------------------------------------------------*/
strncpy (disp_msg.msg, msgstr, msg_size);
memcpy (msgtext1, &disp_msg, sizeof(disp_msg));
if (print_once)
{
disp_data ();
print_once = FALSE ;
}
} /* end error_out */
/********************************************************************/
/* */
/* Subroutine to retrieve any diagnostic messages */
/* */
/********************************************************************/
void get_diag_messages()
{
CS_SMALLINT cnt;
CS_INT num_of_msgs = 0;
CS_INT rc;
/*------------------------------------------------------------------*/
/* Disable calls to this subroutine */
/*------------------------------------------------------------------*/
diag_msgs_initialized = FALSE ;
/*------------------------------------------------------------------*/
/* First, get client messages */
/*------------------------------------------------------------------*/
rc = ct_diag (connection, CS_STATUS, CS_CLIENTMSG_TYPE,
CS_UNUSED, #_of_msgs);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_DIAG CS_STATUS CLIENTMSG_TYPE failed",
msg_size);
error_out(rc) ;
}
else if (num_of_msgs > 0)
{
for (cnt = 1; cnt <= num_of_msgs; ++cnt)
get_client_msgs ();
}
/*------------------------------------------------------------------*/
/* Then, get server messages */
/*------------------------------------------------------------------*/
rc = ct_diag (connection, CS_STATUS, CS_SERVERMSG_TYPE,
CS_UNUSED, #_of_msgs);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_DIAG CS_STATUS SERVERMSG_TYPE failed",
msg_size);
error_out(rc) ;
}
else if (num_of_msgs > 0)
{
for (cnt = 1; cnt <= num_of_msgs; ++cnt)
get_server_msgs ();
}
} /* end get_diag_messages */
/********************************************************************/
/* */
/* Subroutine to retrieve diagnostic messages from client */
/* */
/********************************************************************/
void get_client_msgs()
{
CS_INT rc;
CS_INT i;
CS_CHAR *txtpos;
CS_INT textleft;
CS_INT msgno = 1;
CS_CHAR blank_13[13] = " ";
CS_CLIENTMSG clientmsg;
struct {
char msgno_hdr[13];
char msgno_data[8];
char severity_hdr[13];
char severity_data[6];
} client_msg;
rc = ct_diag (connection, CS_GET, CS_CLIENTMSG_TYPE,
msgno, &clientmsg);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_DIAG CS_GET CS_CLIENTMSG_TYPE failed",
msg_size);
error_out(rc) ;
}
/*------------------------------------------------------------------*/
/* display message text */
/*------------------------------------------------------------------*/
i = 1 ;
strncpy (RS[i].rsltno, "Client Message:");
i = 3 ;
memset(&client_msg, ' ', sizeof(client_msg));
strcpy (client_msg.msgno_hdr, " OC MsgNo: ");
strcpy (client_msg.severity_hdr, " Severity: ");
cvtleft = 8; /* Digits to the left */
cvtright = 0; /* Digits to the right */
SYCVTD(clientmsg.msgnumber, client_msg.msgno_data,
cvtleft, cvtright, cvtwork, cvtdbl, CS_TRUE);
cvtleft = 6; /* Digits to the left */
SYCVTD(clientmsg.severity, client_msg.severity_data,
cvtleft, cvtright, cvtwork, cvtdbl, CS_TRUE);
memcpy (RS[i].rsltno, &client_msg, sizeof(client_msg));
i += 1 ;
/* get number of Client msgs */
if (clientmsg.msgnumber != 0)
{
strcpy (RS[i].rsltno, " OC MsgTx: ");
strncat (RS[i].rsltno, clientmsg.msgstring, 66);
i += 1 ;
txtpos = clientmsg.msgstring + 66;
textleft = clientmsg.msgstringlen - 66;
while (textleft > 0)
{
strncpy (RS[i].rsltno, blank_13, 13);
strncat (RS[i].rsltno, txtpos, 66);
i += 1;
txtpos += 66;
textleft -= 66;
}
}
else
{
strncpy (RS[i].rsltno, " OC MsgTx: No Message!",
text_size);
i += 1 ;
}
/* get number of Server msgs */
memset(&client_msg, ' ', sizeof(client_msg));
strcpy (client_msg.msgno_hdr, " OS MsgNo: ");
cvtleft = 8; /* Digits to the left */
cvtright = 0; /* Digits to the right */
SYCVTD(clientmsg.osnumber, client_msg.msgno_data,
cvtleft, cvtright, cvtwork, cvtdbl, CS_TRUE);
memcpy (RS[i].rsltno, &client_msg, sizeof(client_msg));
i += 1 ;
if (clientmsg.osnumber != 0)
{
strcpy (RS[i].rsltno, " OS MsgTx: ");
strncat (RS[i].rsltno, clientmsg.osstring, 66);
i += 1 ;
txtpos = clientmsg.osstring + 66;
textleft = clientmsg.osstringlen - 66;
while (textleft > 0)
{
strncpy (RS[i].rsltno, blank_13, 13);
strncat (RS[i].rsltno, txtpos, 66);
i += 1;
txtpos += 66;
textleft -= 66;
}
}
else
{
strncpy (RS[i].rsltno, " OS MsgTx: No Message!",
text_size);
i += 1 ;
}
} /* end get_client_msgs */
/*------------------------------------------------------------------*/
/* */
/* Subroutine to retrieve diagnostic messages from server */
/* */
/*------------------------------------------------------------------*/
void get_server_msgs()
{
CS_INT rc;
CS_INT i;
CS_CHAR *txtpos;
CS_INT textleft;
CS_INT msgno = 1;
CS_CHAR blank_13[13] = " ";
CS_CHAR proc_id_data[66];
CS_CHAR svrname_data[66];
CS_SERVERMSG servermsg;
struct {
char msg_no_hdr[13];
char msg_no_data[6];
char severity_hdr[14];
char severity_data[6];
char state_hdr[14];
char state_data[4];
char line_no_hdr[13];
char line_no_data[4];
} serv_msg;
memset(&serv_msg, ' ', sizeof(serv_msg));
rc = ct_diag (connection, CS_GET, CS_SERVERMSG_TYPE,
msgno, &servermsg);
if (rc != CS_SUCCEED)
{
strncpy (msgstr, "CT_DIAG CS_GET CS_SERVERMSG_TYPE failed",
msg_size);
error_out (rc) ;
}
/*------------------------------------------------------------------*/
/* display message text */
/*------------------------------------------------------------------*/
strcpy (serv_msg.msg_no_hdr, " Message#: ");
strcpy (serv_msg.severity_hdr, ", Severity: ");
strcpy (serv_msg.state_hdr, ", State No: ");
strcpy (serv_msg.line_no_hdr, " Line No: ");
cvtleft = 6; /* Digits to the left */
cvtright = 0; /* Digits to the right */
SYCVTD(servermsg.msgnumber, serv_msg.msg_no_data,
cvtleft, cvtright, cvtwork, cvtdbl, CS_TRUE);
SYCVTD(servermsg.severity, serv_msg.severity_data,
cvtleft, cvtright, cvtwork, cvtdbl, CS_TRUE);
cvtleft = 4; /* Digits to the left */
SYCVTD(servermsg.state, serv_msg.state_data,
cvtleft, cvtright, cvtwork, cvtdbl, CS_TRUE);
SYCVTD(servermsg.line, serv_msg.line_no_data,
cvtleft, cvtright, cvtwork, cvtdbl, CS_TRUE);
if (servermsg.svrnlen > 66)
{
strncpy (svrname_data, servermsg.svrname, 63);
strcat (svrname_data, "...");
}
else
strncpy (svrname_data, servermsg.svrname, 66);
if (servermsg.proclen > 66)
{
strncpy (proc_id_data, servermsg.proc, 63);
strcat (proc_id_data, "...");
}
else
strncpy (proc_id_data, servermsg.proc, 66);
strncpy (RS[1].rsltno, "Server Message:", text_size);
memcpy (RS[3].rsltno, &serv_msg, sizeof(serv_msg));
strcpy (RS[5].rsltno, " Serv Nam: ");
strcat (RS[5].rsltno, svrname_data);
strcpy (RS[6].rsltno, " Proc ID : ");
strcat (RS[6].rsltno, proc_id_data);
strcpy (RS[7].rsltno, " Message : ");
strncat (RS[7].rsltno, servermsg.text, 66);
i = 8 ;
txtpos = servermsg.text + 66;
textleft = servermsg.textlen - 66;
while (textleft > 0)
{
strncpy (RS[i].rsltno, blank_13, 13);
strncat (RS[i].rsltno, txtpos, 66);
i += 1;
txtpos += 66;
textleft -= 66;
}
} /* end get_server_msgs */
/********************************************************************/
/* */
/* Subroutine to perform drop command handler, close server */
/* connection, and deallocate Connection Handler. */
/* */
/********************************************************************/
void close_connection ()
{
CS_INT rc;
/*------------------------------------------------------------------*/
/* drop the command handle */
/*------------------------------------------------------------------*/
rc = ct_cmd_drop (cmd);
if (rc == CS_FAIL)
{
strncpy (msgstr, "CT_CMD_DROP failed", msg_size);
error_out (rc) ;
}
/*------------------------------------------------------------------*/
/* close the server connection */
/*------------------------------------------------------------------*/
rc = ct_close (connection, (long) CS_UNUSED);
if (rc == CS_FAIL)
{
strncpy (msgstr, "CT_CLOSE failed", msg_size);
error_out (rc) ;
}
/*------------------------------------------------------------------*/
/* De_allocate the connection handle */
/*------------------------------------------------------------------*/
rc = ct_con_drop (connection);
if (rc == CS_FAIL)
{
strncpy (msgstr, "CT_CON_DROP failed", msg_size);
error_out (rc) ;
}
} /* end close_connection */
/********************************************************************/
/* */
/* Subroutine to perform exit client library and deallocate context */
/* structure. */
/* */
/********************************************************************/
void quit_client_library ()
{
CS_INT rc;
/*------------------------------------------------------------------*/
/* Exit the Client Library */
/*------------------------------------------------------------------*/
rc = ct_exit (context, (long) CS_UNUSED);
if (rc == CS_FAIL)
{
strncpy (msgstr, "CT_EXIT failed", msg_size);
error_out(rc) ;
}
/*------------------------------------------------------------------*/
/* De-allocate the context structure */
/*------------------------------------------------------------------*/
rc = cs_ctx_drop (context);
if (rc == CS_FAIL)
{
strncpy (msgstr, "CT_CTX_DROP failed", msg_size);
error_out(rc) ;
}
EXEC CICS RETURN ;
} /* end quit_client_library */
/********************************************************************/
/* */
/* Subroutine to display output */
/* */
/*****************************************************************-*/
void disp_data()
{
CS_SMALLINT QF_LEN;
CS_SMALLINT QF_MAXLEN;
CS_CHAR QF_ANSWER;
CS_SMALLINT CICS_RESPONSE;
strncpy (OUT.stimeo, TMP_TIME, 8);
strncpy (OUT.sdateo, TMP_DATE, 8);
strncpy (OUT.prognmo, "SYCTSAA6", 8);
switch (page_cnt)
{
case 1:
strcpy (OUT.spageo, "0001"); break;
case 2:
strcpy (OUT.spageo, "0002"); break;
case 3:
strcpy (OUT.spageo, "0003"); break;
case 4:
strcpy (OUT.spageo, "0004"); break;
case 5:
strcpy (OUT.spageo, "0005"); break;
case 6:
strcpy (OUT.spageo, "0006"); break;
case 7:
strcpy (OUT.spageo, "0007"); break;
case 8:
strcpy (OUT.spageo, "0008"); break;
case 9:
strcpy (OUT.spageo, "0009"); break;
default:
strcpy (OUT.spageo, "9999");
}
OUT.servera = DFHBMPRO;
strncpy (OUT.servero, servname, server_size);
OUT.usera = DFHBMPRO;
strncpy (OUT.usero, username, user_size);
OUT.pswda = DFHBMDAR;
strncpy (OUT.pswdo, pwd, pwd_size);
OUT.trana = DFHBMPRO;
strncpy (OUT.trano, tran, tran_size);
OUT.netdrva = DFHBMPRO;
strncpy (OUT.netdrvo, driver, 9);
memcpy (OUT.msg1o, msgtext1, text_size);
strncpy (OUT.msg2o, msgtext2, text_size);
/*------------------------------------------------------------------*/
/* DISPLAY THE DATA */
/*------------------------------------------------------------------*/
EXEC CICS SEND MAP("SYCTBA6")
FROM(a6panel)
CURSOR
FRSET
ERASE
FREEKB ;
EXEC CICS RECEIVE INTO(QF_ANSWER)
LENGTH(QF_LEN)
MAXLENGTH(QF_MAXLEN)
RESP(CICS_RESPONSE) ;
} /* end disp_data */