INFIELD()

 

INFIELD() operator in CONSTRUCT, INPUT, and INPUT ARRAY statements tests whether its operand is the identifier of the current screen field .

 

Description: INFIELD%20Operator

 

Element

Description

field

This is the name of a field in the current screen form.

screen-array

This is the name of a screen array that was defined in the INSTRUCTIONS section of the form specification file.

screen-record

This is the name of a screen record that is defined, either explicitly or by implication, in the form specification file.

table reference

This is the unqualified name, alias, or synonym of a table or view; or it is the keyword FORMONLY.

 

Usage

 

INFIELD( ) is a Boolean operator that returns the value TRUE if field is the name of the current screen field. Otherwise, INFIELD( ) returns the value FALSE.

 

You must specify a field name rather than a field tag as the operand.

 

 

 

You can use INFIELD( ) during a CONSTRUCT, INPUT, or INPUT ARRAY statement to take field-dependent actions.

The INFIELD( ) operator is typically part of an ON KEY clause, often with the built-in function SHOWHELP( ) to display help messages to the user.

 

DATABASE formonly

 

SCREEN

{

[f1        ]

[f2        ]

[f3        ]

[f4        ]

 

Press (F1) when you are in the third field.

}

 

ATTRIBUTES

f1 = formonly.f1, COMMENTS="This is the first field";

f2 = formonly.f2, COMMENTS="This is the second field";

f3 = formonly.f3, COMMENTS="This is the third field";

f4 = formonly.f4, COMMENTS="This is the fourth field";

 

INSTRUCTIONS

 

DELIMITERS "[]"

 

MAIN

  DEFINE input_rec RECORD

    f1 CHAR(10),

    f2 CHAR(10),

    f3 CHAR(10),

    f4 CHAR(10)

  END RECORD

 

  OPTIONS INPUT WRAP

 

  LET input_rec.f1 = "Field 1"

  LET input_rec.f2 = "Field 2"

  LET input_rec.f3 = "Field 3"

  LET input_rec.f4 = "Field 4"

 

  OPEN WINDOW w_test

    AT 2, 2

    WITH FORM "infield_operator"

 

  INPUT BY NAME input_rec.* WITHOUT DEFAULTS

    ON KEY (F1)

      IF INFIELD(f3) THEN

        ERROR "CORRECT! You are in the third field!"

      ELSE

        ERROR "WRONG! You are not in the third field, try again!"

      END IF

  END INPUT

 

  CLOSE WINDOW w_test

END MAIN

 

These source files display a form with four fields, of which the third is the ‘correct’ field in which to place your cursor.  If you place your cursor in any of the other fields an error message is displayed, telling you your cursor is not in Field 3.  The following screenshot shows the message displayed when you have your cursor in Field 3.

 

Description: C:\Users\user\Desktop\Screenshots\infield2.jpg

 

The next code example is from a program that uses INFIELD( ) to determine whether to call a function:

 

ON KEY (F5)

      IF INFIELD(ind_type) THEN

            CALL select_industry_type()

 

When a user presses F5 during the INPUT, the select_industry_type( ) function is invoked if the screen cursor is in the ind_type field.

In the following example, the INPUT statement uses the INFIELD( ) operator with the SHOWHELP( ) function to display field-dependent help messages.

 

INPUT l_contact_rec.* FROM sc_cont.*

      ON KEY(F1)

            CASE

                   WHEN INFIELD(cont_name)

                          CALL SHOWHELP(301)

                   WHEN INFIELD(cont_comp)

                          CALL SHOWHELP(302)

                   WHEN INFIELD(ind_type)

                          CALL SHOWHELP(303)

                   ...

            END CASE

END INPUT

 

 

References

SCR_LINE( ), SHOWHELP( ), FIELD_TOUCHED( ), GET_FLDBUF( )