pjs.char()

pjs.char()

Description

pjs.char() converts a value into its character representation and returns the result as a string.

Parameters

  1. Value or field - The value to convert. This is normally a field declared with pjs.define(), but a literal or an expression can also be passed.

  2. Format (optional) - The date or time format to apply, for example *ISO, *USA, *EUR, or *MDY. This is used when a date, time, or timestamp value is passed as the first parameter.

When the format is omitted for a date or time value, the format defined on the field is used. If the field does not define one, the format from the program’s control options is used, and *ISO is used if neither is set.

Examples

Example 1: Packed Decimal to Character

This example converts a packed decimal field into a character field, and shows where the padding in the result comes from.

// Purpose: convert a packed decimal quantity into its character form. // A 3-digit packed decimal field holding the value 4. pjs.define("s", { type: 'packed decimal', length: 3, decimals: 0, initValue: 4 }); // A fixed-length character field to receive the converted value. pjs.define("c", { type: 'char', length: 5 }); // pjs.char() returns the digits only, so it returns the string "4" here. c = pjs.char(s); return c; // "4 " // The four trailing blanks come from the char(5) target field, which pads // values on the right. They are not added by pjs.char() itself.

Example 2: Date to Character

This example converts a single date field into three different character formats, including a format with the separators removed.

// Purpose: render the same date field in three different formats. // A date field initialized from an ISO date string. pjs.define("datefld", { type: 'date', initValue: pjs.date('2016-06-13') }); pjs.define("out1", { type: 'char', length: 10 }); pjs.define("out2", { type: 'char', length: 10 }); pjs.define("out3", { type: 'char', length: 6 }); // No format is passed and the field does not define one, so *ISO is used. out1 = pjs.char(datefld); // "2016-06-13" // *USA renders the date as MM/DD/YYYY, separated by slashes. out2 = pjs.char(datefld, "*usa"); // "06/13/2016" // A trailing 0 on the format removes the separators, leaving 6 characters. out3 = pjs.char(datefld, "*mdy0"); // "061316"

RPG Equivalent

%CHAR()


Related Pages