FMLを使用したOracle Tuxedo ATMIアプリケーションのプログラミング

     前  次    新規ウィンドウで目次を開く  新規ウィンドウで索引を開く  PDFとして表示 - 新規ウィンドウ  Adobe Readerを取得 - 新規ウィンドウ
コンテンツはここから始まります

FMLおよびVIEWSの例

ここでは、以下の内容について説明します。

 


VIEWSの使用例

この項で示すVIEWSの使用例は、この章の後半にあるFMLプログラムの使用例とは無関係です。

VIEWファイルの例

リスト6-1は、ソースVIEW記述custdbを含むVIEWファイルの例です。

リスト6-1 VIEWファイルの例
# 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

フィールド表の例

リスト6-2は、前の項で示したVIEWのコンパイルに必要なフィールド表の例です。

リスト6-2 フィールド表の例
# 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 - -

viewcによって生成されるヘッダー・ファイルの例

リスト6-3は、VIEWコンパイラによって生成されたヘッダー・ファイルです。viewcに対する入力として、前の項のVIEWファイルを使用しています。

リスト6-3 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" */
};

mkfldhdrによって生成されるヘッダー・ファイルの例

リスト6-4は、mkfldhdrによってフィールド表ファイルから生成されたヘッダー・ファイルです。mkfldhdrに対する入力として、前の例のフィールド定義を格納したフィールド表ファイルを使用しています。

リスト6-4 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 */

COBOL COPYファイルの例

リスト6-5は、viewc-Cコマンドライン・オプションを指定して作成されたCOBOL COPYファイル、CUSTDB.cblです。

リスト6-5 COBOL COPYファイルの例
*       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).

viewc -Cを使用して作成したCOBOL COPYファイルを含むCOBOLプログラムの例については、『COBOLを使用したOracle Tuxedo ATMIアプリケーションのプログラミング』を参照してください。

VIEWSプログラムの例

リスト6-6は、VIEWを使用して構造体とフィールド化バッファをマッピングするプログラムの例です。このプログラムが正しく動作するには、「FMLおよびVIEWSの環境設定」で説明した環境変数を正しく設定する必要があります。

FMLプログラムのコンパイル方法については、『Oracle Tuxedoファイル形式、データ記述、MIBおよびシステム・プロセス・リファレンス』「compilation(5)」リファレンス・ページを参照してください。

リスト6-6 VIEWSプログラムの例
/* 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);

}

bankappでのVIEWSの使用例

bankappは、Oracle Tuxedoシステムに同梱されるサンプル・アプリケーションです。このアプリケーション・プログラムには、VIEWS構造を使用した2つのファイルが組み込まれています。サンプル内の構造体は、FMLバッファにマッピングされない構造体なので、構造体メンバーへのデータの入出力にFML関数は使用されていません。

$TUXDIR/apps/bankapp/audit.cは、コマンドライン・オプションを使って、型付きバッファVIEWにサービス・リクエストを設定する方法を決定するクライアント・プログラムです。

サーバー$TUXDIR/apps/bankapp/BAL.ecのコードは、サービス・リクエストを受け付け、ESQL文の公式化に使用されるVIEWバッファからのフィールドを示します。

関連項目

 


bankappでのFMLの使用例

bankappは、Oracle Tuxedoシステムに同梱されるサンプル・アプリケーションです。サーバーでは、

ACCT.ec
BTADD.ec
TLR.ec

上記のサーバーでは、FML型付きバッファ(bankappクライアントであるbankcltからサーバーに渡される)のデータを操作するためのFML関数が使用されています。

これらのサーバーでは、FML関数のFalloc、Falloc32(3fml)およびFrealloc、Frealloc32(3fml)のかわりに、ATMI関数のtpalloc(3c)およびtprealloc(3c)を使用してメッセージ・バッファを割り当てます。


  先頭に戻る       前  次