Programming a BEA Tuxedo ATMI Application Using FML

     Previous  Next    Open TOC in new window  Open Index in new window  View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

FML and VIEWS Examples

This topic includes the following sections:

 


VIEWS Examples

The VIEWS examples provided in this section are unrelated to the example FML program that appears later in this section.

Sample Viewfile

The following listing is a sample of a viewfile containing a source view description, custdb.

Listing 6-1 Sample Viewfile
# BEGINNING OF VIEWFILE
VIEW custdb
# /* This is a comment */
# /* This is another comment */
#TYPE CNAME FBNAME COUNT FLAG SIZE NULL
carray bug BUG_CURS 4 - 12 "no bugs"
long custid CUSTID 2 - - -1
short super SUPER_NUM 1 - - 999
long youid ID 1 - - -1
float tape TAPE_SENT 1 - - -.001
char ch CHR 1 - - "0"
string action ACTION 4 - 20 "no action"
END
#END OF VIEWFILE

Sample Field Table

The following listing is a sample of a field table needed to compile the view in the last section.

Listing 6-2 Sample Field Table
# name          number  type    flags   comments
CUSTID 2048 long - -
VERSION_RUN 2055 string - -
ID 2056 long - -
CHR 2057 char - -
TAPE_SENT 2058 float - -
SUPER_NUM 2066 short - -
ACTION 2074 string - -
BUG_CURS 2085 carray - -

Sample Header File Produced by viewc

The following listing shows a header file produced by the view compiler. Assume that the viewfile in the earlier section was used as input to viewc.

Listing 6-3 Sample Header File Produced by viewc
struct custdb {
char bug[4][12]; /* null="no bugs" */
long custid[2]; /* null=-1 */
short super; /* null=999 */
long youid; /* null=-1 */
float tape; /* null=-0.001000 */
char ch; /* null="0" */
char action[4][20]; /* null="no action" */
};

Sample Header File Produced by mkfldhdr

The following listing shows a header file produced from a field table file by mkfldhdr. Assume that a field table file containing the definitions of the fields shown in the previous examples was used as input to mkfldhdr.

Listing 6-4 Sample Header File Produced by mkfldhdr(1)
/* custdb.flds.h as generated by mkfldhdr from a field table:      */
/* fname fldid */
/* ----- ----- */
#define ACTION ((FLDID)43034) /* number: 2074 type: string */
#define BUG_CURS ((FLDID)51237) /* number: 2085 type: carray */
#define CUSTID ((FLDID)10240) /* number: 2048 type: long */
#define SUPER_NUM ((FLDID)2066) /* number: 2066 type: short */
#define TAPE_SENT ((FLDID)26634) /* number: 2058 type: float */
#define VERSION_RUN ((FLDID)43015) /* number: 2055 type: string */
#define ID ((FLDID)10248) /* number: 2056 type: long */
#define CHR ((FLDID)18441) /* number: 2057 type: char */

Sample COBOL COPY File

The following listing shows the COBOL COPY file, CUSTDB.cbl, produced by viewc with the -C option.

Listing 6-5 Sample COBOL COPY File
*       VIEWFILE: "t.v"
* VIEWNAME: "custdb"
05 BUG OCCURS 4 TIMES PIC X(12).
* NULL="no bugs"
05 CUSTID OCCURS 2 TIMES PIC S9(9) USAGE IS COMP-5.
* NULL=-1
05 SUPER PIC S9(4) USAGE IS COMP-5.
* NULL=999
05 FILLER PIC X(02).
05 YOUID PIC S9(9) USAGE IS COMP-5.
* NULL=-1
05 TAPE USAGE IS COMP-1.
* NULL=-0.001000
05 CH PIC X(01).
* NULL='0'
05 ACTION OCCURS 4 TIMES PIC X(20).
* NULL="no action"
05 FILLER PIC X(03).

For a sample COBOL program that includes a COBOL COPY file produced by viewc -C, see Programming a BEA Tuxedo ATMI Application Using COBOL.

Sample VIEWS Program

The following program is an example of the use of VIEWS to map a structure to a fielded buffer. The environment variables discussed in Setting Up Your Environment for FML and VIEWS must be properly set for this program to work.

Information on compiling FML programs can be found on the compilation(5) reference page in BEA Tuxedo File Formats, Data Descriptions, MIBs, and System Processes Reference.

Listing 6-6 Sample VIEWS Program
/* sample VIEWS program */
#include stdio.h>
#include "fml.h"
#include "custdb.flds.h" /* field header file shown in */
/* "Sample Header File Produced by viewc" listing */
#include "custdb.h" /* C structure header file produced by */
/* viewc shown in "Sample Field Table" listing */
#define NF 800
#define NV 400
extern Ferror;
main()
{
/* declare needed program variables and FML functions */
FBFR *fbfr,*Falloc();
void F_error();
char *str, *cstruct, buff[100];
struct custdb cust;

/* allocate a fielded buffer */
if ((fbfr = Falloc(NF,NV)) == NULL) {
F_error("sample.program");
exit(1);
}

/* initialize str pointer to point to buff */
/* copy string values into buff, and */
/* Fadd values into some of the fields in fbfr */

str = &buff;
strcpy(str,"13579");
if (Fadd(fbfr,ACTION,str,(FLDLEN)6) < 0)
F_error("Fadd");
strcpy(str,"act11");
if (Fadd(fbfr,ACTION,str,(FLDLEN)6) < 0)
F_error("Fadd");
strcpy(str,"This is a one test.");
if (Fadd(fbfr,BUG_CURS,str,(FLDLEN)19) < 0)
F_error("Fadd");
strcpy(str,"This is a two test.");
if (Fadd(fbfr,BUG_CURS,str,(FLDLEN)19) < 0)
F_error("Fadd");
strcpy(str,"This is a three test.");
if (Fadd(fbfr,BUG_CURS,str,(FLDLEN)21) < 0)
F_error("Fadd");

/* Print out the current contents of the fbfr */

printf("fielded buffer before:\n"); Fprint(fbfr);

/* Put values in the C structure */

cust.tape = 12345;
cust.super = 999;
cust.youid = 80;
cust.custid[0] = -1; cust.custid[1] = 75;
str = cust.bug[0][0];
strncpy(str,"no bugs12345",12);
str = cust.bug[1][0];
strncpy(str,"yesbugs01234",12);
str = cust.bug[2][0];
strncpy(str,"no bugsights",12);
str = cust.bug[3][0];
strncpy(str,"no bugsysabc",12);
str = cust.action[0][0];
strcpy(str,"yesaction");
str = cust.action[1][0];
strcpy(str,"no action");
str = cust.action[2][0];
strcpy(str,"222action");
str = cust.action[3][0];
strcpy(str,"no action");
cust.ch = '0';
cstruct = (char *)&cust;

/* Update the fbfr with the values in the C structure */
/* using the custdb view description. */

if (Fvstof(fbfr,cstruct,FUPDATE,"custdb") < 0) {
F_error("custdb");
Ffree(fbfr);
exit(1);
}

/* Note that the following would transfer */
/* data from fbfr to cstruct */
/*
if (Fvftos(fbfr,cstruct,"custdb") < 0) {
F_error("custdb");
Ffree(fbfr);
exit(1);
} */

/* print out the values in the C structure and */
/* the values in the fbfr */

printf("cstruct contains:\en");
printf("action=:%s:\n",cust.action[0][0]);
printf("action=:%s:\n",cust.action[1][0]);
printf("action=:%s:\n",cust.action[2][0]);
printf("action=:%s:\n",cust.action[3][0]);
printf("custid=%ld\n",cust.custid[0]);
printf("custid=%ld\n",cust.custid[1]);
printf("youid=%ld\n",cust.youid);
printf("tape=%f\n",cust.tape);
printf("super=%d\n",cust.super);
printf("bug=:%.12s:\n",cust.bug[0][0]);
printf("bug=:%.12s:\n",cust.bug[1][0]);
printf("bug=:%.12s:\n",cust.bug[2][0]);
printf("bug=:%.12s:\en",cust.bug[3][0]);
printf("ch=:%c:\n\n",cust.ch);

printf("fielded buffer after:\n");
Fprint(fbfr);
Ffree(fbfr);
exit(0);

}

Example of VIEWS in bankapp

bankapp is a sample application distributed with the BEA Tuxedo system. It includes two files in which a VIEWS structure is used. The structure in the example is one that does not map to an FML buffer, so FML functions are not used to get data into or out of the structure members.

$TUXDIR/apps/bankapp/audit.c is a client program that uses command-line options to determine how to set up a service request in a VIEW typed buffer.

The code in the server $TUXDIR/apps/bankapp/BAL.ec accepts the service request and shows the fields from a VIEW buffer being used to formulate ESQL statements.

See Also

 


FML Examples in bankapp

bankapp is a sample application distributed with the BEA Tuxedo system. The servers

ACCT.ec
BTADD.ec
TLR.ec

show FML functions being used to manipulate data in FML typed buffers that have been passed to the servers from bankclt, the bankapp client.

Note that in these servers the ATMI functions tpalloc(3c) and tprealloc(3c)—rather than the FML functions Falloc, Falloc32(3fml) and Frealloc, Frealloc32(3fml)—are used to allocate message buffers.


  Back to Top       Previous  Next