Reading From a Data Source

In this section:

Most applications need to read data from a data source. The most common method is to read data from a data source into a data source stack. Before reading, you first need to select the record in which the data resides. There are five ways of selecting records:

You can read from individual data sources, and from those that have been joined. Maintain supports joins that are defined in a Master File. For information about defining joins in a Master File, see the Describing Data With WebFOCUS Language manual. Maintain can read from joined data sources, but cannot write to them.

You can evaluate the success of a command that reads from a data source by testing the FocError system variable, as described in Evaluating the Success of a Simple Data Source Command.

The NEXT and MATCH commands are described in detail in Command Reference in the Maintain Language Reference manual.

Top of page

Repositioning Your Location in a Data Source

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


then Maintain will have searched sequentially through the entire data source, so the current position marker will now point to the end of the data source. If you then 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. Since the current position is the end of the data source, no records are retrieved.

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

Example: Repositioning to the Beginning of the Data Source

The following REPOSITION command specifies the CustID field 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):

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