Quantcast
Viewing all articles
Browse latest Browse all 10

Understanding Peoplecode – Variables

Variables are storage places for text or numbers that you define and manipulate. In peoplecode, each variable type starts with special character.

Scope of a Variable

The scope of a variable is the part of the program over which the variable name can be referenced.

  • Global : It is valid for entire session. Once a global variable is assigned it be used in any component or page till user signs out.

    Syntax:
    Global data_type &var_name

    Description:
    The Global statement allows you to declare PeopleCode global variables. A global variable, once declared in any PeopleCode program, will remain in scope throughout the PeopleSoft session. The variable must be declared with the Global statement in any PeopleCode program in which it is used.

    Note that all PeopleCode data types can be declared as Global. For example, ApiObject data types can only be declared as Local.

  • Component: It is valid while any page in the component in which its defined stays active.
    Component variables act the same as global variables when an Application Engine program is called from a page (using CallAppEngine).
    Component variables remain defined after a TransferPage, DoModal, or DoModalComponent function. However, variables declared as Component do not remain defined after using the Transfer function, whether you’re transferring within the same component or not.
  • Local: Local variables declared at the top of a PeopleCode program (or within the main, that is, non-function, part of a program) remain in scope for the life of that PeopleCode program.

    Declaring a variable

    Specify the scope and datatype of a variable.

    Syntax

    <scope> <datatype> &<variablename>;
    

    Example

    Local Rowset &RS;
    Local Field &DATE;
    

    Things to Note

    • As in any programming lanuage Declare variables before you use them. If you do not declare a variable, it’s automatically declared with the scope Local and the data type Any. You receive a warning message in the Validation tab of the PeopleSoft Application Designer output window for every variable that is not declared when you save the PeopleCode program
    • Another reason to declare variables is for the design-time checking. If you declare a variable of one data type, then assign to it a value of a different type, the PeopleCode Editor catches that assignment as a design-time error when you try to save the program. With an undeclared variable, the assignment error does not appear until runtime.
    • In addition, if you declare variables, the Find Object Reference feature finds embedded definitions. For example, suppose you wanted to find all occurrences of the field DEPT_ID. If you have not declared &MyRecord as a record, Find Object References does not find the following reference of the field DEPT_ID:
      &MyRecord.DEPT_ID.Visible = False;
      

    The post Understanding Peoplecode – Variables appeared first on Everything Technical.


Viewing all articles
Browse latest Browse all 10

Trending Articles