Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 24 Next »

The define API is used to declare fields with a strong data type that you will use in your Profound.js modules. All IBM i data types are available.

To declare fields that are loosely typed, use the var clause in JavaScript instead.

Parameters
  1. Field name (string)
  2. Config (object)
Config object

A config object is required when defining all fields. It what gives your field attributes, like length, decimal places, dimensions, etc. Available means the element is optional.

Element nameElement typeDescription
typeString

There are the following types available in Profound.js

  • packed decimal
  • decimal
  • integer
  • unsigned integer
  • char
  • boolean
  • date
  • time
  • timestamp
  • pointer
  • data structure

Some config elements only apply to certain types.

lengthNumber

Required on all types other than

  • date
  • time
  • timestamp
  • pointer
decimalsNumber

Required on types

  • Packed decimal
  • Decimal
varyingBooleanAvailable to char type.
initValueString/Number/BooleanAvailable to all data types.
dimNumberAvailable to all data types. Using dim makes your field into an array. Arrays are 1-indexed.
orderbyString

Available to all types when dim element is used. Either of these values are required:

  • "ASCEND"
  • "DESCEND"
elementsObjectRequired when using data-structure type. Read about data-structures below.
qualifiedBooleanAvailable when using data structure type.
specialString

Available to data-structure subfields. Acceptable values are:

PSDS

  • "*status"
  • "*proc"
  • "*parm"
  • "*routine"

INFDS

  • "*file"
  • "*record"
  • "*opcode"
  • "*status"
  •  "*routine" 
nullableBoolean / String

Available to all data types, except from the data-structure type. Only use this attribute if you this field to be null-capable.

  • Pass in "true" to make the field null-capable. This option also allows you to assign 'null' to the field.
  • Pass in a "string" which references an Boolean variable to use that as the null-indicator and making the field null-capable.
likerecObject

Available when using a data structure type. This object requires two elements.

  • intrecname - String, name of record format from previously defined table.
  • fields - optional String value of "*key". If "*key" is specified, only key fields will be defined.

When likerec is specified, the data structure becomes qualified automatically.

likedsStringOnly available to the data-structure type. Provide the name of the data-structure which will be copied into the current definition.
dataAreaString

Available to all data types, except from the pointer type. String pointing to data-area object. Example values:

  • MYDTAARA
  • PRODLIB/DTAATA
Examples
Example 1: packed decimal
pjs.define("Num", { type: 'packed decimal', length: 3, decimals: 2 });
Num = 5;
Example 2: date with initValue
pjs.define("loandate", { type: 'date', initValue: pjs.date('2000-01-01') });
Example 3: char field with pointer to that field
pjs.define("stg", { type: 'char', length: 4 });
pjs.define("ptr", { type: 'pointer', initValue: pjs.getBuffer("stg") });
Example 4: char field array with initValue

This does mean that every element in this array will be initilized with the initValue.

pjs.define("arr", { type: 'char', length: 10, dim: 3, initValue: '0123456789' });

 

Data structures

When you declare a field of data-structure type,  this means you need to provide an 'elements' object. Each key in this object will be the name of the subfield and the value of this key will be another config element. If a data-structure is qualified, the data-structure will act similar to a JavaScript object.

Example 5: Data structure with two subfields (non-qualified)
pjs.define("someDS", { type: 'data structure', elements: {
  "Field1": { type: 'char', length: 10, initValue: '1' },
  "Field2": { type: 'char', length: 10 }
}});
 
Field2 = '2';
Example 6: Data structure array, qualified and two subfields
pjs.define("dsarr", { type: 'data structure', qualified: true, dim: 2, elements: {
  "field1": { type: 'char', length: 1 },
  "field2": { type: 'char', length: 1 }
}});
 
dsarr[1].field1 = '1';
dsarr[1].field2 = '2';
dsarr[2].field1 = '3';
dsarr[2].field2 = '4';
Example 7: Null-capable field with null assignment
pjs.define("myNumber", { 
  type: 'packed decimal',
  length: 10,
  decimals: 0,
  nullable: true 
});

//Set value to 5
myNumber = 5;

//Set null-indicator to true
myNumber = null;

//Set value to 10, sets the null-indicator to false
myNumber = 10;

//Set null-indicator to true
pjs.nullInd(myNumber, true);
  • No labels