Step 2: Selecting Records

In this section:

Goal

To update customer records, you first must identify and retrieve the records. You use the NEXT command to select the records and copy the relevant information (customer ID, name, address, and phone number) into the CustInfo stack.


Top of page

x
Methods: NEXT and MATCH

To read data from a data source, you first must select the record where the data resides. In MODIFY, there were two ways of doing this:

For example, before MODIFY displays a record in a CRTFORM or writes it to the SPA, you must select it using MATCH or NEXT. You also must identify the record before MODIFY includes, updates, or deletes it. Thirdly, you can only identify one segment instance, in one record, at a time.

Maintain releases you from these restrictions. In Maintain, there are five ways of selecting records:


Top of page

x
Specifying Data Source Position With the REPOSITION Command

Each time you issue a NEXT command, Maintain begins searching for records from the current position in the data source. For example, if your first data source operation retrieved a set of records:

FOR ALL NEXT CustID INTO SmokeStack
WHERE ProdName EQ 'VCR DUST COVER';

Maintain has searched sequentially through the entire data source. The current position marker now points to the end of the data source. If you issue another NEXT command:

FOR ALL NEXT LastName FirstName INTO CandyStack
WHERE ProdName EQ 'CANDY';

Maintain searches from the current position to the end of the data source. Because the current position is the end of the data source, no records are found.

When you want a NEXT command to search through the entire data source (often the case when you wish to retrieve a set of records), you must first issue the REPOSITION command to move the current position marker to the beginning of the data source.

For example, the following REPOSITION command specifies the CustID field—which is in the root segment—and so moves the current position marker for the root segment chain and all of its descendant chains back to the beginning of the chain (in effect, back to the beginning of the data source):

REPOSITION CustID;
FOR ALL NEXT LastName FirstName INTO CandyStack
WHERE ProdName EQ 'CANDY';

REPOSITION is similar to the MODIFY command of the same name.


Top of page

x
Solution

You add a NEXT command to retrieve the desired records. Each part of the command plays a different role:

The procedure now looks like this:

MAINTAIN FILE VideoTrk 
FOR ALL NEXT CustID INTO CustInfo
WHERE ExpDate GE 920601 AND ExpDate LE 920621; 
END

Try it now: If you have created your own set of application files, enter these additional commands into your FOCEXEC file.


Information Builders