#Dexterity Future Proof Range Setting


David Meego - Click for blog homepageThis is another one of those “Musgravian” principles.

When I train people on Dexterity I show them a better method to set indexed ranges than the style you will often see in older code or by developers who have not yet been “converted”.

There are two types of ranges in Dexterity and this method applies to indexed ranges where you are applying a range against a key. The other type of range is using a where clause and only works on SQL tables.

Before we begin, here is a quick refresher on how indexed ranges work. You need to set all the key fields (i.e. the fields that make up the segments of the index) in the table’s table buffer to the desired values for the start of the range, set the start, then change the key fields to the values for the end of the range and set the end. Note that only the values of the key fields are of interest and the values of any other fields are irrelevant.

The steps to define and use a range are:

  1. Clear any existing ranges.
  2. Set the key fields for the start of the range
  3. Start the range using the index
  4. Set the key fields for the end of the range
  5. End the range using the index
  6. Perform desired actions using the index
  7. Clear the range when finished.

Notes:

  • If using a scrolling window limited by a range, you must not clear the range while the window is still being used otherwise it will start to show data from outside the range.
  • If you use an index other than the one the range has been defined on, the data will not be limited by the range.

Below is the traditional method for defining a range:

range clear table SOP_LINE_WORK;

'SOP Type' of table SOP_LINE_WORK = 'SOP Type';
'SOP Number' of table SOP_LINE_WORK = 'SOP Number';
clear 'Line Item Sequence' of table SOP_LINE_WORK;
clear 'Component Sequence' of table SOP_LINE_WORK;

range start table SOP_LINE_WORK;

fill 'Line Item Sequence' of table SOP_LINE_WORK;
fill 'Component Sequence' of table SOP_LINE_WORK;

range end table SOP_LINE_WORK;

Here is the future proof method of defining the same range:

range clear table SOP_LINE_WORK;

clear table SOP_LINE_WORK;
'SOP Type' of table SOP_LINE_WORK = 'SOP Type';
'SOP Number' of table SOP_LINE_WORK = 'SOP Number';

range start table SOP_LINE_WORK by number 1;

fill table SOP_LINE_WORK;
'SOP Type' of table SOP_LINE_WORK = 'SOP Type';
'SOP Number' of table SOP_LINE_WORK = 'SOP Number';

range end table SOP_LINE_WORK by number 1;

What are the differences and why are they important?

Here is a list of why this method is better:

  • Use the clear table and fill table commands to clear and fill all the fields in the table. This will ensure that fields not manually set will have the appropriate values.
  • You only need to mention the fields that have defined values. You don’t need to mention any other fields as they are handled by the clear table and fill table commands.
  • If additional fields are added to the index in the future, there is no need to revisit the code to add them with manual clear and fill commands, they will be handled by the clear table and fill table commands.
  • I can guarantee that you will not remember to change every location a range is defined when a field is added to the index, so using a method that works regardless is safer and “future proof”.
  • Adding the index number or name clarifies the index being used. If no index is defined, it will use the first index, but specifying it is safer.
  • The fill table command was not added until Dexterity version 4.0, or the older code could not use this method.

Keep developing.

David

This article was originally posted on http://www.winthropdc.com/blog.

2 thoughts on “#Dexterity Future Proof Range Setting

Please post feedback or comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.