home *** CD-ROM | disk | FTP | other *** search
- How to add records to a transaction file:--
-
- 1) Define the "TRAN" transaction database using DataBoss. You would have
- fields like :--
-
- TRANS_NO -- 6# Numeric [key no. 1, (Unique)]
- TRANS_MODE -- U Character
- TRANS_DATE -- ##/##/#### Character
- TRANS_DESCR -- 40X Character
- TRANS_AMOUNT -- 8#.2# Numeric
-
- 2) Generate and compiler the "TRAN" application.
-
- 3) Define the main application from which the transactions will arise. This
- could be something like and "INV" invoice application. A very simple
- invoice application could have a single file with fields like :--
-
- INV_NO -- 10# Numeric [key no. 1, (Unique)]
- INV_DATE -- ##/##/#### Character
- CUSTOMER_ACCT_NO -- 10U Character
- CUSTOMER_NAME -- 20X Character
- CUSTOMER_ADDRESS1 -- 25X Character
- CUSTOMER_ADDRESS2 -- 25X Character
- CUSTOMER_ADDRESS3 -- 25X Character
- GOODS_DESCR -- 40X Character
- COST_OF_GOODS -- 4#.2# Numeric
-
- 4) Migrate file 1 of the TRAN application to file 2 of the INV application.
- It can be associated with window 1, and does not need to be linked to any
- file. When TRAN is later generated it will automatically have the code
- to open existing TRAN files and indexes.
-
- 5) Write a function to add a record and its indexes to the transaction file.
- Put this code into a function file, (like ADDTRAN.FUN), so that it can be
- included in the main application.
-
- void addTransaction(char mode)
- {
- int fno, kno;
- long rno, tl;
- keystr tkey;
- bool savok;
-
- savok = ok; /* Save the current value of ok */
- fno := 2; /* We want to work with file 2, the TRAN file */
- clear_rec(fno); /* Initialise the data buffer for file 2 "TRAN1" */
-
- /* Calculate the next unique Transaction Number */
- kno = 1; /* Key 1 is the unique transaction number */
- clearkey(idxkey[fno][kno]);
- prevkey(idxkey[fno][kno],&rno,tkey);
- if (!ok) tl = 1; else tl = ival(tkey) + 1;
-
- /* Initialise fields, be sure to pad or truncate to the correct length for
- character fields, and the correct length & decimal places for numerics */
-
- istr(TRAN1.TRANS_NO,tl,6);
- TRAN1.TRANS_MODE[0] = mode;
- sysdate(TRAN1.TRANS_DATE);
- strconcat(_tts,INV1.INV_NO," ",
- INV1.CUSTOMER_ACCT_NO," "
- INV1.GOODS_DESCR,NULL);
- strcopy(TRAN1.TRANS_DESCR,_tts,0,40);
- fstr(TRAN1.TRANS_AMOUNT,valu(INV1.COST_OF_GOODS),11,2);
-
- /* Add the record and keys */
- addrec(datf[fno],&rno,&TRAN1);
- for (kno=1; kno <= maxkeyno; kno++) {
- if (keylen[fno][kno] > 0) {
- getakey(tkey,fno,kno);
- addkey(idxkey[fno][kno],&rno,tkey);
- if (!ok)
- dberrm("Attempt To Add Bad Key - Rewrite Procedure Code !!");
- }
- }
-
- ok = savok; /* Restore value of OK */
- }
-
- 6) Create a custom skeleton file file that includes ADDTRAN.FUN, and calls
- addTransaction() whenever you want to want another transaction record
- added to the database.
-
- This could be at the end of the "edit_record()", "add_record()" and
- "delete_record()" functions :--
-
- /* Just after the DisplayRec at the end of "edit_record()" */
- if (exitcode != QitKey) addTransaction('E');
-
- /* Just after the DisplayRec at the end of "Add_Record" */
- if (exitcode != QitKey) addTransaction('A');
-
- /* Just before the call to DelARec in "Delete_Record" */
- if (exitCode != QitKey) addTransaction('D');
-
- 7) Generate and compile INV, but remember to change the skeleton
- specification on the generate screen from DBC.SKL to INV.SKL
-
- 8) Run TRAN.EXE. This will create the empty TRAN1.DAT and TRAN1.K1 files
-
- 9) Run INV.EXE. Add, Copy, Edit and Delete records.
-
- 10) Run TRAN to look at the transactions that have been created.