Table of Contents Previous Next PDF


RECORD Examples

RECORD Examples
This topic includes the following sections:
RECORD Example: COBOL Copybook File
Listing 8‑1 is a sample of COBOL copybook.
Listing 8‑1 Sample of COBOL Copybook File
* customer.cpy
01 CUSTOMER.
05 name PIC X(10).
05 balance PIC S9(9) COMP-5.
05 address PIC X(80).
 
Use cpy2record customer.cpy to generate RECORD description file customer.R in binary format. This RECORD description file is generated from COBOL copybook file through cpy2record and used by application program at run time.
RECORD Example: RECORD Programs
Listing 8‑2 and Listing 8‑3 are examples of using RECORD to map COBOL record to RECORD buffer. The environment variables discussed in Setting up Your Environment for RECORD must be properly set.
Listing 8‑2 Sample of RECORD Client Program
#include <stdio.h>
#include <atmi.h>
#include <fml32.h>
 
int main()
{
/* declare needed program variables */
struct RECORD *pRec;
int bal = 0;
int rtn;
long len;
 
/* attach to System/T as a client process */
if (tpinit((TPINIT *) NULL) == -1) {
(void) fprintf(stderr, "Tpinit failed\n");
exit(1);
}
 
/* allocate memory to store the RECORD data buffer */
len = Frneeded("CUSTOMER");
pRec = (struct RECORD *)tpalloc("RECORD", "CUSTOMER", len);
 
/* initialize buffer */
Rinit(pRec, NULL, 0, 0);
 
/* set the value in the RECORD */
Rset(pRec, "name", "Michael", C_STRING, 0, 0);
 
/* call service */
tpcall("CUSTSVC", (char *)pRec, 0, (char **)&pRec, &len, (long)0);
 
/* get item from reply */
rtn = Rget(pRec, "balance", &bal, C_INT, NULL, 0);
if( rtn < 0) {
userlog("Rget failed. %d %s\n",Ferror32, Fstrerror32(Ferror32));
}
userlog("The balance is %d\n", bal);
 
return 0;
}
 
Listing 8‑3 Sample of RECORD Server Program
#include <stdio.h>
#include <atmi.h>
 
void CUSTSVC(TPSVCINFO *rqst)
{
/* declare needed program variables */
struct RECORD *pRec;
char name[20];
int balance = 12345;
int len = sizeof(name);
int rtn;
 
/* retrieve RECORD buffer */
pRec = (struct RECORD *)rqst->data;
 
/* get data from RECORD buffer */
rtn = Rget(pRec, "name", name, C_STRING, &len, 0);
if( rtn < 0) {
userlog("Rget failed. %d %s\n",Ferror32, Fstrerror32(Ferror32));
}
userlog("customer name: %s", name);
 
/* set data to RECORD buffer */
Rset(pRec, "balance", &balance, C_INT, 0, 0);
if( rtn < 0) {
userlog("Rset failed. %d %s\n",Ferror32, Fstrerror32(Ferror32));
}
 
tpreturn(TPSUCCESS, 0, (char *)pRec, 0L, 0);
}
 
See Also
cpy2record in Oracle Tuxedo Command Reference.

Copyright © 1994, 2017, Oracle and/or its affiliates. All rights reserved.