pjs.createDataArea()



This API creates a data area on IBM i and optionally initializes it.

Parameters

This API can accept an optional database connection definition object to select between multiple database connections. To select the database connection, call pjs.getDB() and pass the result as the first parameter, followed by the parameters documented below. If a database connection definition object is not passed, the default database connection is used.

  1. An object with the following key/value pairs: 

    1. name - A string containing the data area name, in LIBRARY/OBJECT_NAME notation. If the library is omitted, the data area will be created in the job's current library or QGPL

    2. type -  A string containing either "*CHAR", "*DEC", or "*LGL". This API cannot be used to create a *DDM (remote) data area.

    3. length - The desired length for the data area. See the IBM i command help for CRTDTAARA for limitations/restrictions.

    4. decimals (optional) - Number of decimal positions for *DEC data areas. Defaults to zero if not specified.

    5. initValue (optional) - Initialization value. Use a string for *CHAR data areas, a number for *DEC, and a Boolean for *LGL.

    6. Replace (optional) - If set to Boolean true, an existing data area will be replaced and re-created. If not specified, an exception will be thrown if the given data area already exists.

Return Value

None.

Exception Handling

If there is a problem creating the data area, an Error will be thrown with the following properties:

  • message - The IBM i message text.

  • error - The message id.

  • help - The message help text.

Examples



Create a 10-byte character data area and initialize
try { pjs.createDataArea({ name: "mylib/mydtaara", type: "*char", length: 10, initValue: "my_text" });   // Data area is created/initialized. } catch (error) { // Problem! Data area not created. }



Create a 5,2 decimal data area, initialize, and replace existing object
try { pjs.createDataArea({ name: "mylib/mydtaara", type: "*dec", length: 5, decimals: 2, initValue: 999.99, replace: true });   // Data area is created/initialized. } catch (error) { // Problem! Data area not created. }



Requirements

This API requires the Profound.js Connector module.