The function write_audit_trail in module T1520IC3 writes the audit trail for the ILE C program T1520PG1. Module T1520IC3 is used to create service program T1520SP1, shown in Figure 52.
Use the following source:
Figure 58. ILE C Source to Write an Audit Trail
/* 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 the system */(1)
/* 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);
}
|
Notes:
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.