The Company
Products
Solutions
Services and Support
Customers
Partners
News
Events
Home >> News >> WebFOCUS Newsletter >> July 2003 >> Stack Notation and Field Descriptions

Stack Notation and Field Descriptions

By Mark Derwin

Lately I’ve seen applications in which the data appearing on the screen, or being used in calculations, is not what the developer is expecting. This is because of the way that the field is populated on the screen or the notation used in the calculations. So here is a short refresher on how to reference fields in a stack and how to populate fields on a form.

Stack Fields

When data is loaded into a stack, columns and rows are created. The columns are the names of the fields (either from the database or computed) and the rows are instances of the data. So, the following command:

FOR ALL NEXT MOVIECODE INTO MOVSTK

Creates a stack with nine columns (Moviecode, Title, Category, etc.) and 60 rows because that’s how many rows are in the database. To reference any cell in the stack you use the notation: StackName(Row).Field. If you wanted to reference the fifth title in the stack you would use:

MOVSTK(5).TITLE

Here, I explicitly used the row number. However, you can use any variable or expression that evaluates to an integer. You could use:

MOVSTK(MOVSTK.FOCCOUNT).TITLE

This is the last row.

There are two other notations of which you need to be aware:

STACK.FIELD and STACK().FIELD

The first, STACK.FIELD, is the same as using STACK(1).FIELD or the first row of the stack. If you want to operate on the current or selected stack row, then you should not use this notation. If your stack never has more than one row, or you are only interested in the data in the first row, then this is fine. Otherwise you should not use this.

The second, STACK().FIELD, is the same as STACK(Stack.FocIndex).FIELD, or the currently displayed or selected field. If a user makes a selection from a list box, combo box, or radio group, and that object is populated from a stack, then STACK().FIELD contains the selected value. If you are scrolling through a stack and displaying one record at a time, the currently displayed record is STACK().FIELD. If you wanted to display the selected record in a new stack you could use this:
Copy From Stack() Into Stack2

Field Descriptions

Fields displayed on a screen can come from three places: a stack, the database or a computed variable. Most of the time, you will want the data to come from a stack. This makes it easier to manipulate.

When you place the object on the form, the field name is prefaced by either the stack name or the database name. If when running your application you see the last record in the stack, instead of the selected one, it means that you dragged the database segment onto the form instead of the stack. You will have to remove those fields, then drag the stack onto the form and redisplay the fields.

I am not going to go into computed fields on forms because these don’t come from the database and can only have one value at a time.

So, be careful when displaying and manipulating your data and stacks. Make sure you’re seeing what you expect to see and using the correct data.