INFIELD()

INFIELD() operator tests whether its operand is the identifier of the current form field.

This operator can only be used within CONSTRUCT, INPUT, and INPUT ARRAY statements to take field-dependent actions.

Description: INFIELD%20Operator

field

the name of the current field in the form

screen-array

the name of a screen array

screen-record

the name of a screen record

table- reference

the unqualified name, alias, synonym, or the FORMONLY keyword used to refer to the table

INFIELD() returns TRUE if field is the name of the current screen field.

Otherwise, INFIELD() returns FALSE.

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

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

Here is a simple example of using the INFIELD() operator.

4gl source code

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

.per form

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 "[]"

This program will display a form with four fields of which the third field is the ‘correct’ one where you must place your cursor. If you place your cursor in any other field, an error message is displayed telling you that your cursor is not in the 3rd field.

This is a piece of 4gl code 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 this example, the INPUT statement uses INFIELD() 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

 

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.