用于编写审计跟踪的源代码
模块 T1520IC3 中的函数 write_audit_trail 写入 ILE C 程序 T1520PG1的审计跟踪。 模块 T1520IC3 用于创建服务程序 T1520SP1,如 图 1中所示。
使用以下源:
/* This function writes an audit trail. To write the audit trail */
/* the file field structure is retrieved from the DDS file */
/* T1520DD1 and the taxrate data item is imported from service */
/* program T1520SP2. Retrieves the file field structure. */
#pragma mapinc("myinc", "MYLIB/T1520DD1(*all)", "both", "p z","")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <decimal.h>
#include <recio.h>
#include <xxcvt.h>
/* These includes are for the call to QWCCVTDT API to get */ 1
/* the system date to be used in the audit trail. */
#include <QSYSINC/H/QWCCVTDT>
#include <QSYSINC/H/QUSEC>
/* DDS mapping of the audit file, T1520DD1. */ 2
#include "myinc"
/* Tax rate is imported from service program T1520SP2. */ 3
const extern decimal (2,2) taxrate;
void write_audit_trail (char user_id[10],
char item_name[],
decimal (10,2) price,
short int quantity,
char formatted_cost[22])
{
char char_item_name[21];
char char_price[11];
char temp_char_price[11];
char char_quantity[4];
char char_date[6];
char char_taxrate[2];
/* Qus_EC_t is defined in QUSEC. */
Qus_EC_t errcode;
char get_date[16];
int i;
double d;
/* File field structure is generated by the #pragma */
/* mapinc directive. */
MYLIB_T1520DD1_T1520DD1R_both_t buf1;
_RFILE *fp;
/* Get the current date. */
errcode.Bytes_Provided = 0;
QWCCVTDT ("*CURRENT ", "", "*MDY ", get_date, &errcode);
memcpy (char_date, &(get_date[1]), 6);
/* Loop through the item_name and remove the null terminator. */
for (i=0; i<=20; i++)
{
if (item_name[i] == '\0') char_item_name[i] = ' ';
else char_item_name[i] = item_name[i];
}
/* Convert packed to zoned for audit file. */
d = price;
QXXDTOZ (char_price, 10, 2, d);
QXXITOZ (char_quantity, 4, 0, quantity);
d = taxrate;
QXXDTOZ (char_taxrate, 2, 2, d);
/* Set up buffer for write. */
memset(&buf1, ' ', sizeof(buf1));
memcpy(buf1.USER, user_id, 10);
memcpy(buf1.ITEM, char_item_name, 20);
memcpy(buf1.PRICE, char_price, 11);
memcpy(buf1.QTY, char_quantity, 4);
memcpy(buf1.TXRATE, char_taxrate, 2);
memcpy(buf1.TOTAL, formatted_cost, 21);
memcpy(buf1.DATE, char_date, 6);
if ((fp = _Ropen("MYLIB/T1520DD1", "ar+")) == NULL)
{
printf("Cannot open audit file\n");
}
_Rwrite(fp, (void *)&buf1, sizeof(buf1));
_Rclose(fp);
}注:
- 此源需要 QSYSINC/H 文件中的两个成员 QUSEC 和 QWCCVTDT。 只要在 CRTBNDC 或 CRTCMOD 命令上指定 OPTION (*STDINC) 参数 (缺省值) ,就会自动搜索 QSYSINC 库以查找系统包含文件。
- include 名称
myinc与编译器为 #pragma mapinc 伪指令生成类型定义时创建的临时源成员相关联。 有关如何使用 #pragma mapinc 伪指令的信息,请参阅 在程序中使用外部描述的文件 。 - 要编写审计跟踪,将从服务程序
T1520SP2导入税率。