HPlogo HP Data Entry and Forms Management System (VPLUS) Reference Manual: HP 3000 MPE/iX Computer Systems > Chapter 4 Advanced Forms Design

SET

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

Used to move data either by setting the current field to a value or by moving data between fields. Also performs automatic formatting.

Syntax

[SET {destination TO source
destination
TO source}]

Parameters

source

Can be a field name, save field name, constant, arithmetic expression, or an index retrieve operand within parenthesis. Refer to "Statement Syntax" earlier in this section for details.

destination

Can be a field name or save field name.

Discussion

When data is moved between constants, fields, and save fields, certain restrictions apply and certain conversions may take place. These depend entirely upon the data types of the source and destination. In general, any field, save field, or constant can be converted to a character type field, but numeric and date fields accept only data of a similar type. DIG fields accept only positive sources. If a source is $EMPTY, the destination is set to all blanks. Table 4-9 “Conversion During Data Movement” shows the conversion that is performed when data is moved between fields.

Assigning a Value to the Current Field

To set the current field to the value of another field, a save field, a constant, an arithmetic expression, or a value in a list located through an index, use the following SET statement:

Syntax

SET [fieldname] TO source

Parameters

fieldname

The current field name (default).

source

Can be a field name, save field name, constant, arithmetic expression, or an index retrieve operand within parenthesis. Refer to "Statement Syntax" earlier in this section for details.

Discussion

In general, any source value can be moved to a character type field. Numeric and date fields accept only data of similar type. If the field type is DIG, the source must be a positive value (see Table 4-7 “Automatic Formatting for Numeric Data”).

By default, all fields are initialized to blanks in the initialization phase (refer to "Phases" at end of this section for more information on phases.) You can specify a particular initial value for any field by including an initial value in the Field Menu field attributes. More elaborate initialization can be done with this subset of the SET statement.

When you assign an initial value to a field in the Field Menu, you can specify only a constant. The constant is entered exactly like user input at a terminal. (Remember that input in FORMSPEC is NATIVE-3000; if a native language is specified, data is converted at run-time. Refer to Section 8.) When you assign a value through the SET statement, you have more flexibility. The values assigned are dynamic in that they may depend on values in other fields or in save fields, or they may be derived from an arithmetic expression, or through an indexed retrieval. If you do assign a constant through the SET statement, it must follow the rules for constants described earlier in this section. That is, a character string must be surrounded by quotes, a date string by exclamation points. Also, a date constant must be in the order MDY regardless of its destination format.

If a source field is of date type (MDY, YMD, DMY), the current field must be defined to be 8 bytes long to allow for internal delimiters. Some examples using the SET TO source statement follow.

Example

  1. Assume a date field of the form MDY.

    SET TO $TODAY                \Sets the field to today's date in the
    \format dd/dd/dd in the order of
    \the field's date type.

    SET TO !FEB 10,1986! \Sets the field to the specified date.

    SET TO DAT1 \Sets the field to whatever value
    \is in the field DAT1 at run-time.
  2. Assume the current field is type DIG. The following statement sets this field to a digit selected from a list of digits by the index value, COUNT:

               SET TO COUNT OF 7,9,16,24,31,72,15,12

    If COUNT=5, the value assigned to the field is 31, if COUNT=3, the value 16 is assigned, and so forth.

  3. Values may be passed from one form to another through save fields. Assume that when FORMA is executed, the save field SF3 is set to the value of F1. Further assume you are designing FORMB and want to set the current field to the value of the field F1 in FORMA.

    SET TO SF3                   \Value passed from a field in a different
    \form through the save field SF3.

Moving Data Between Fields

To move data to a field or a save field from another field or save field, or to move a constant, an arithmetic expression, or a value retrieved from a list to a particular field, use the following versions of the SET statement:

Syntax

[SET {destination
destination ''TO'' source}]

Parameters

source

Can be a field name, save field name, constant, arithmetic expression, or an index retrieve operand within parenthesis. Refer to "Statement Syntax" earlier in this section for details.

destination

Can be a field name or save field name.

Discussion

When a source is not included, whatever value is in the current field is moved to the specified destination. (The current field is the field in which the SET statement appears.)

Example

  1. Move the value resulting from an arithmetic expression to a numeric data field AMOUNT:

    SET AMOUNT TO 6 %(3*COST)

    This statement multiplies the value of the field COST by 3 and then sets AMOUNT to 6 percent of the result.

  2. Set the save field SF3 to the current value of the field in which the SET statement appears:

    SET SF3

    Assume the current field is a character type with the value SMITH. The SET statement moves the value SMITH to the save field SF3. SF3 must be a character type save field.

Automatic Formatting

In general, automatic formatting performed during data movement is governed by the data type of the destination. The following discussion illustrates data movement for various data types. Refer to Table 4-9 “Conversion During Data Movement” for a summary of the conversion performed during data movement.

Character Type

If the destination is a character field, data moved to it does not change its relative position. If the source is too large for the destination, the data is truncated on the right when it is moved. If the source has fewer characters, the destination is padded with blanks on the right.

Table 4-6 Automatic Formatting for Character Data

Source

Destination

"ARMSTRONG" (9 characters)

"ARMSTRONGD" (10 characters)

"DDARMSTRONG" (11 characters)

"DDARMSTRON" (10 characters)

"ARMSTRONGDDDDD" (14 characters)

"ARMSTRONG" (9 characters)

 

Numeric Type

When data is moved between numeric fields, the following formatting is performed:

Sign

Any plus sign is stripped from the source before the number is moved to its destination. If the source is negative, a minus sign is inserted to the left of the first digit in the destination.

Decimal Point

If the source has an implied or actual decimal point (IMPn or NUM[n] data type), the fractional part is rounded and/or truncated or zero filled to conform to the number of decimal places specified for the destination.

If the destination has no decimal position (NUMO, IMPO, or DIG), any fractional part is rounded and/or truncated. If the destination is NUM (floating decimal point), the number is right justified after being stripped of trailing zeros following the decimal point.

If the source specifies no decimal places (type is NUMO, IMPO, or DIG) and if the destination has an implied or actual decimal point, the fractional part is zero filled.

Note that if the length of the destination is too small, any decimal places are rounded and truncated until the source fits.

Commas

All commas in the source are removed.

Leading Zeros

Leading zeros are stripped in all cases.

The result is then placed, right justified, as shown in Table 4-8 “Automatic Formatting for Dates”, in the destination field.

With Native Language Support, decimal and thousands indicators are language-dependent in the NUM[n] and IMP[n] fields. When data is moved between fields and automatic formatting occurs for data entered in any field, recognition, removal or insertion of these decimal and thousands indicators also depends upon the local custom for the native language specified for the forms file. The optional decimal symbols in constants will be local custom-dependent. For more information on Native Language Support, see Section 8.

Table 4-7 Automatic Formatting for Numeric Data

Source

Destination

123 (DIG)

123 (DIGIT,length is 5)

123 (IMP2)

1.23 (NUM2,length is 4)

12.3 (NUM1)

12.3 (NUM,length is 6)

12.3 (NUM1)

12.30 (NUM2)length is 5)

12.3 (NUM1)

12. (NUM2,length is 3)

12.3 (NUM1)

1230 (IMP2,length is 4)

12.3 (NUM1)

123 (IMP1,length is 3)

+3357 (NUM)

335700 (IMP2,length is 6)

-3357 (IMP3)

-3.4 (NUM1,length is 4)

001,000 (NUM)

1000.00 (NUM2,length is 7)

 

Date Type

Any date, regardless of the format of the source, is moved to the destination as dd/dd/dd, as shown in Table 4-8 “Automatic Formatting for Dates” Thus, if a date is going to be placed into a field using a SET command, the field must be at least eight characters long. The order depends on whether the destination is specified as MDY, DMY, or YMD. With Native Language Support, conversion from alphabetic months to the numeric destination month is language dependent. For more information on Native Language Support, see Section 8.

Table 4-8 Automatic Formatting for Dates

Source

Destination

FEB 5, 1986

02/05/86 (defined as MDY)

2/5/86

86/02/05 (defined as YMD)

2,5,86

02/05/86 (defined as MDY)

February 5, 1986

05/02/86 (defined as DMY)

September 16, 1986

09/16/86 (defined as MDY)

Oct. 23. 1986

86/10/23 (defined as YMD)

October 23, 1986

23/10/86 (defined as DMY)

 

Table 4-9 Conversion During Data Movement


From
To
CHARNUMNUMnIMPnDIGDATE
CHARTruncate or Pad with blanks on rightillegalillegalillegalillegalillegal
NUMTruncate or Pad with blanks on rightRight justify; Strip leading zeroes; Pad leading blanks; try to fit 9 decimal places, rounding truncating, inserting a decimal point as neededRight justify; Strip leading zeroes; Pad leading blanks; Round or truncate fractions, insert decimal point as neededRight justify; Strip leading zeroes even if fractional; Pad leading blanks remove any decimal point.Right justify; Strip leading zeroes; Pad leading blanks. Value must be positive)illegal
NUMnillegal
IMPnillegal
DIGillegal
DATETruncate or Pad with blanks on rightillegalillegalillegalillegalConvert to dd/dd/dd in order of destination; Left justify; Pad trailing blanks

 

Default Formatting

Besides the explicit formatting described below, data is formatted whenever it is moved between fields according to the rules for automatic formatting. If you want data entered by the user to be formatted automatically, you can specify the following version of the SET statement.

SET TO thisfield

Parameters

thisfield

is the name of the field in which SET appears. Essentially, you set the field to itself.

For example, you may want to ensure that a monetary value is always right justified with a decimal point inserted preceding two decimal positions. To do this, define the field as type NUM2 and then use the SET statement to force data entered in this field to be formatted. The Field Menu in Figure 4-3 “Field Menu with a SET Statement” illustrates this use of SET.

Figure 4-3 Field Menu with a SET Statement

Field Menu with a SET Statement

Example

  1. Suppose the user enters a price in the field as follows:

    [123.5DDDD]

    The SET statement causes it to be formatted as:

    [DDD123.50]
  2. In another situation, this version of SET TO can be used to format a date. Suppose the date field, DATE1, is type MDY and the user enters a date in the form:

    [FEB 12, 86]

    A SET statement of the form SET TO DATE1 in the Field Menu describing DATE1 formats the user entered data as:

    [02/12/86DD]
Feedback to webmaster