Writing Records Once à to Two Tables

by Dan Blank

Dan shares the solution to a nagging problem. You can get in touch with Dan at danblank@ticnet.com

The Obstacle

In my company we receive materials in the Receiving table (RX.dbf) and naturally want that quantity to be added to our main inventory table (MIF.dbf) through posting. But what happens when the main inventory file doesn’t have a record of the part number to post the quantity? If no matching inventory record is found, the receiving material information gets posted to cyberspace or nowhere!

Well, thanks to Dr. Wayne’s article on posting in Xbasic, a flag pops up and alerts us that a record does not exist. Therefore, no posting occurs. This is a nice feature, but who wants to go into the main inventory file and create the missing record, especially since all the main information is already entered in the Receiving table?

When we enter the record in the receiving table we enter the part number, the shelf location, the site code (warehouse or building the part goes to), and the quantity received. Our main inventory file has the same fields. Why enter the same information twice in two different tables? Wouldn’t it be nice to press a button and have that record automatically written in the main inventory file?

Have a problem of your own that you've worked out? Want to help out other Alpha-challenged readers? Share your solution with others. Write to Dr. Wayne for instructions on how to submit your own article.

The Solution

I played around with this for along time. I came up with the following Xbasic:

dim target as p
dim PN as c
dim Sitecode as c
dim Quant as n
dim Shelf as c
'open destination file
target=table.open ("MIF",FILE_RW_SHARED)
'begin entering new record
target.enter_begin()
target.PN=PN
target.Quant=Quant
target.SITECODE=Sitecode
target.SHELF=Shelf
'save the record
target.enter_end(.t.)
'close destination file
target.close()

Script 1. My first attempt.

Problem: all Script 1 did was to create empty records in MIF.dbf. After getting nowhere fast, I posted my problem on the Alpha 5 message board. I got some help from Tom Cone. Tom turned me onto a new Xbasic terminology: Source table. Source table made a lot of sense but was new to me. Tom looked at my script and helped me with the following Xbasic:

option strict
dim target as p 'pointer to destination
dim sourcetbl as p 'pointer to source table
'open destination file
target=table.open ("MIF",FILE_RW_SHARED)
'establish pointer to source table
sourcetbl=table.current()
 
'begin entering new record
target.enter_begin()
target.PN=sourcetbl.PN
target.Quant=sourcetbl.Quant
target.SITECODE=sourcetbl.Sitecode
target.SHELF=sourcetbl.Shelf
'save the record
target.enter_end(.t.)
'close destination file
target.close()

Script 2. Tom Cone's enhancement to my script.

That did the trick! Now when we receive materials and a warning pops up that a record does not exist, the data entry person pushes a button and bingo! the record is created in our Main Inventory File (MIF.dbf).

Dan Blank is a Material Program Control Manager for Qwest Commnications in Dallas, Texas. His main use of A5 is to keep track of Qwest's inventory at 170+ sites from South Texas to Eastern Pennsylvania. He started using Alpha Five version 1 in 1996 and, in his words, "is continually upgrading to the latest and greatest versions of Alpha 5 available." You can reach Dan at danblank@ticnet.com

8/30/99

Don't forget, we need your feedback to make this site better!

Return to home