/* @(#) syctsar6.c 1.1 10/14/96 */ /****** SYCTSAR6 - Client RPC Request APPL - C - CICS ***************/ /* */ /* CICS TRANID: SYR6 */ /* */ /* PROGRAM: SYCTSAR6 */ /* */ /* PURPOSE: Demonstrates Open Client for CICS CALLs. */ /* */ /* FUNCTION: Illustrates how to send an RPC request with */ /* parameters to: */ /* */ /* - A SQL Server */ /* - An Open Server running in a CICS/IMS region. */ /* */ /* SQL Server: */ /* */ /* If the request is sent to a SQL Server it */ /* intitiates the stored procedure "SYR2". */ /* */ /* Note: The Net-Gateway/MCG product includes a script*/ /* that creates this procedure in a target SQL */ /* server. */ /* */ /* Open Server/CICS or Open Server/IMS: */ /* */ /* If the request is sent to an Open Server/CICS or */ /* IMS region, it invokes the transaction SYR2. */ /* */ /* Note: The Open Server/CICS and IMS products include */ /* the sample transaction SYR2. This is the */ /* server side transaction invoked by this */ /* program. */ /* */ /* PREREQS: Before running SYCTSAR6, 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 server */ /* TRAN NAME is not used for LAN servers. */ /* Enter SYR2 in the TRAN NAME field if the server is */ /* in a CICS or IMS region. */ /* */ /* Open Client CALLs used in this sample: */ /* */ /* 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_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_param define a command parameter */ /* ct_results sets up result data */ /* ct_send send a request to the server */ /* */ /* History: */ /* */ /* Date BTS# Descrition */ /* ======= ====== ================================================= */ /* Sept 96 Create */ /* */ /* */ /********************************************************************/ #pragma csect(code,"SYCTSAR6") #pragma linkage(SYCVTD, OS) #pragma runopts(env(IMS),plist(IMS)) #pragma runopts(NOSPIE,NOSTAE) /*------------------------------------------------------------------*/ /* 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_INT version; /* CT version # */ 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 results_type; /* ** Column variables for returned data */ CS_VARCHAR col_firstnme; CS_VARCHAR col_lastname; CS_SMALLINT col_educlvl; CS_CHAR col_jobcode[8]; CS_CHAR col_salary[12]; CS_INT ret_parm1; /* ** 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 convertion 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 result_param_processing (); void fetch_param_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); /*------------------------------------------------------------------*/ /* CICS Aid Handler -- not support in C language */ /*------------------------------------------------------------------*/ /* EXEC CICS HANDLE AID ANYKEY(NO_INPUT) CLEAR(GETOUT) ; */ /*------------------------------------------------------------------*/ /* Program initialization */ /*------------------------------------------------------------------*/ strncpy(msgtext1, " ", text_size); strncpy(msgtext2, "Press Clear To Exit", text_size); page_cnt = page_cnt + 1; memset(servname, ' ', 30); memset(username, ' ', 8); memset(pwd, ' ', 8); memset(tran, ' ', 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 */ else /* no input data */ 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, "SYCTSAR6", 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_SMALLINT nullind = 0; CS_CHAR rpc_cmd[4] = "SYR2"; CS_INT param1 = 0; CS_CHAR param2[3] = "D11"; CS_DATAFMT datafmt; /*------------------------------------------------------------*/ /* 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 command (an RPC request) */ /*------------------------------------------------------------*/ buf_len = 4; rc = ct_command(cmd, (long) CS_RPC_CMD, rpc_cmd, buf_len, (long) CS_UNUSED); if (rc != CS_SUCCEED) { strncpy (msgstr, "CT_COMMAND failed", msg_size); no_errors_sw = FALSE ; error_out (rc); } /*------------------------------------------------------------*/ /* */ /* Setup a return parameter for NUM_OF_ROWS */ /* */ /* Describe the first parameter (NUM_OF_ROWS) */ /* */ /*------------------------------------------------------------*/ strcpy (datafmt.name, "@parm1"); datafmt.namelen = 6; datafmt.datatype = CS_INT_TYPE; datafmt.format = CS_FMT_UNUSED; datafmt.maxlength = CS_UNUSED; datafmt.status = CS_RETURN; datafmt.usertype = CS_UNUSED; buf_len = sizeof(param1); rc = ct_param (cmd, datafmt, param1, buf_len, nullind); if (rc != CS_SUCCEED) { strncpy (msgstr, "CT_PARAM CS_INT_TYPE parm1 failed", msg_size) ; no_errors_sw = FALSE ; error_out (rc); } /*------------------------------------------------------------*/ /* */ /* Describe the second parameter (DEPTNO) */ /* */ /*------------------------------------------------------------*/ strcpy (datafmt.name, "@parm2"); datafmt.namelen = 6; datafmt.datatype = CS_VARCHAR_TYPE; datafmt.format = CS_FMT_UNUSED; datafmt.maxlength = CS_UNUSED; datafmt.status = CS_INPUTVALUE; datafmt.usertype = CS_UNUSED; buf_len = sizeof(param2); rc = ct_param (cmd, datafmt, param2, buf_len, nullind); if (rc != CS_SUCCEED) { strncpy (msgstr, "CT_PARAM CS_VARCHAR_TYPE parm2 failed", msg_size) ; no_errors_sw = FALSE ; error_out (rc); } /*------------------------------------------------------------*/ /* Send the command */ /*------------------------------------------------------------*/ rc = ct_send (cmd); if (rc != CS_SUCCEED) { strncpy (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; result_param_processing (); fetch_param_processing (); 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); } /* end of switch (result_type) */ break; /*------------------------------------------------------------*/ /* 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 numcol = 5; CS_INT parm_cnt; 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; /*------------------------------------------------------------*/ /* bind the first column, FIRSTNME defined as VARCHAR(12) */ /* and the second column, LASTNAME defined as VARCHAR(15) */ /*------------------------------------------------------------*/ memset (&datafmt, '\0', sizeof(datafmt)); switch (parm_cnt) { case 1: case 2: datafmt.datatype = CS_VARCHAR_TYPE; datafmt.format = CS_FMT_PADBLANK; if (parm_cnt == 1) { datafmt.maxlength = 12; rc= ct_bind(cmd, parm_cnt, &datafmt, &col_firstnme, &col_len, CS_NULL); } else { datafmt.maxlength = 15; rc= ct_bind(cmd, parm_cnt, &datafmt, &col_lastname, &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 third column, EDUCLVL defined as SMALLINT */ /*------------------------------------------------------------*/ case 3: datafmt.datatype = CS_SMALLINT_TYPE; datafmt.maxlength = 2; rc= ct_bind(cmd, parm_cnt, &datafmt, &col_educlvl, &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; /*------------------------------------------------------------*/ /* bind the fourth column, JOBCODE as CHAR */ /* bind the fifth column, SALARY as CHAR. It will be */ /* converted from float8 or money. */ /*------------------------------------------------------------*/ case 4: case 5: datafmt.datatype = CS_CHAR_TYPE; datafmt.format = CS_FMT_UNUSED; datafmt.scale = CS_SRC_VALUE; datafmt.precision = CS_SRC_VALUE; if (parm_cnt == 4) { datafmt.maxlength = sizeof(col_jobcode); rc= ct_bind(cmd, parm_cnt, &datafmt, &col_jobcode, &col_len, CS_NULL); } else { datafmt.maxlength = sizeof(col_salary); rc= ct_bind(cmd, parm_cnt, &datafmt, &col_salary, &col_len, CS_NULL); } if (rc != CS_SUCCEED) { strncpy (msgstr,"CT_BIND CS_CHAR failed", msg_size); no_errors_sw = FALSE ; error_out (rc); } break; default: break; } /* end of switch (parm_cnt) */ } /* 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; struct { char first[14]; char last[17]; char educ[10]; char jobcode[8]; char salary[12]; } output_row; while (nomore_rows == FALSE) { rc = ct_fetch (cmd, (long) CS_UNUSED, (long) CS_UNUSED, (long) CS_UNUSED, &rows_read); switch (rc) { case CS_SUCCEED: nomore_rows = FALSE ; if (row_num == 0) { /*------------------------------------------------------------*/ /* Setup column headings for the 1st screen */ /*------------------------------------------------------------*/ row_num += 1; strcpy (RS[row_num].rsltno, "FirstName "); strcat (RS[row_num].rsltno, "LastName "); strcat (RS[row_num].rsltno, "EducLvl "); strcat (RS[row_num].rsltno, "JobCode "); strcat (RS[row_num].rsltno, "Salary "); row_num += 1; strcpy (RS[row_num].rsltno, "========== "); strcat (RS[row_num].rsltno, "============= "); strcat (RS[row_num].rsltno, "======== "); strcat (RS[row_num].rsltno, "======== "); strcat (RS[row_num].rsltno, "========= "); } row_num += 1; 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) strncpy (RS[row_num].rsltno, " ", text_size); row_num = 1; page_cnt = page_cnt + 1 ; strcpy (RS[row_num].rsltno, "FirstName "); strcat (RS[row_num].rsltno, "LastName "); strcat (RS[row_num].rsltno, "EducLvl "); strcat (RS[row_num].rsltno, "JobCode "); strcat (RS[row_num].rsltno, "Salary "); row_num += 1; strcpy (RS[row_num].rsltno, "========== "); strcat (RS[row_num].rsltno, "============= "); strcat (RS[row_num].rsltno, "======== "); strcat (RS[row_num].rsltno, "======== "); strcat (RS[row_num].rsltno, "========= "); row_num += 1; } /*------------------------------------------------------------*/ /* Display results */ /*------------------------------------------------------------*/ memset (&output_row, ' ', sizeof(output_row)); strcpy (output_row.first, col_firstnme.str); strcpy (output_row.last, col_lastname.str); cvtleft = 4; /* Digits to the left */ cvtright = 0; /* Digits to the right */ SYCVTD(col_educlvl, output_row.educ, cvtleft, cvtright, cvtwork, cvtdbl, CS_TRUE); strcpy (output_row.jobcode, col_jobcode); strcpy (output_row.salary, col_salary); 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"); 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 describe the returned parameters */ /* */ /********************************************************************/ void result_param_processing () { CS_INT rc; CS_INT parm = 1; CS_INT col_len; CS_DATAFMT datafmt; /*------------------------------------------------------------*/ /* Get desription of return parameter */ /*------------------------------------------------------------*/ rc= ct_describe(cmd, parm, &datafmt); if (rc != CS_SUCCEED) { strncpy (msgstr, "CT_DESCRIBE failed", msg_size); no_errors_sw = FALSE ; error_out (rc); } /*------------------------------------------------------------*/ /* bind the return parameter, NUM_OF_ROWS defined as INTEGER */ /*------------------------------------------------------------*/ datafmt.datatype = CS_INT_TYPE; datafmt.format = CS_FMT_UNUSED; datafmt.maxlength = CS_UNUSED; rc= ct_bind(cmd, parm, &datafmt, &ret_parm1, &col_len, CS_NULL); if (rc != CS_SUCCEED) { strncpy (msgstr, "CT_BIND return parameter failed", msg_size); no_errors_sw = FALSE ; error_out (rc); } } /* end result_param_processing */ /********************************************************************/ /* */ /* Subroutine to fetch return parameter */ /* */ /********************************************************************/ void fetch_param_processing () { CS_INT rc; CS_INT rows_read; struct { char paren; char col_ret[4]; char or2_msg[17]; } output_row; memset (&output_row, ' ', sizeof(output_row)); strcpy (output_row.or2_msg, " row(s) affected)"); output_row.paren = '('; rc = ct_fetch (cmd, (long) CS_UNUSED, (long) CS_UNUSED, (long) CS_UNUSED, &rows_read); if (rc != CS_SUCCEED) { strncpy (msgstr, "CT_FETCH return parameter failed", msg_size); no_errors_sw = FALSE ; error_out(rc); } if (ret_parm1 > 0) { cvtleft = 4; /* Digits to the left */ cvtright = 0; /* Digits to the right */ SYCVTD(ret_parm1, output_row.col_ret, cvtleft, cvtright, cvtwork, cvtdbl, CS_TRUE); row_num += 2; memcpy (RS[row_num].rsltno, &output_row, sizeof(output_row)); disp_data (); } } /* end fetch_param_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, "SYCTSAR6"); 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 */ /*------------------------------------------------------------------*/ strcpy (disp_msg.msg, msgstr); 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.sdateo, TMP_DATE, 8); strncpy (OUT.stimeo, TMP_TIME, 8); strncpy (OUT.prognmo, "SYCTSAR6", 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 */