pjs.move()
Description
pjs.move() moves a value from one field into another, left or right adjusted, without any type checking. By default the value is right adjusted in the target field.
Parameters
Source - The field or value the data is taken from.
Target - The field the data is moved into.
Source date/time/timestamp format (optional) - The format used to render a date, time, or timestamp source before it is moved, for example
*ISOor*USA.Pad (optional) - If passed as
true, the target field is cleared before the move.Adjust left (optional) - Pass
trueto left adjust the value; otherwise the value is right adjusted. Use pjs.moveLeft() to always left adjust.
Because pjs.move() performs no type checking, the source and target do not have to be the same type. Review the examples below to confirm how the data lands in the target before using a conversion in production code.
Examples
Example 1: Character to Character
This example shows the default right-adjusted move between two character fields.
// Purpose: show the default MOVE behavior -- the source is right adjusted
// into the target and the target's remaining left bytes are left untouched.
pjs.define("source", { type: 'char', length: 5, initValue: 'bbbbb' });
pjs.define("unpadded", { type: 'char', length: 10, initValue: 'aaaaaaaaaa' });
// The 5 source bytes overwrite the 5 rightmost bytes of the target.
pjs.move(source, unpadded);
return unpadded;
// "aaaaabbbbb" -- the first 5 'a' bytes of the target are preserved.Example 2: Character to Character With Padding
This example repeats Example 1 with the pad option enabled, so the target is cleared first.
// Purpose: show the pad option, which clears the target before the move.
pjs.define("source", { type: 'char', length: 5, initValue: 'bbbbb' });
pjs.define("padded", { type: 'char', length: 10, initValue: 'aaaaaaaaaa' });
// The 3rd parameter is the date/time format (not needed here, so '').
// The 4th parameter is pad: true clears the target first.
pjs.move(source, padded, '', true);
return padded;
// " bbbbb" -- the target's 'a' bytes were cleared to blanks by the pad.Example 3: Packed Decimal to Character
This example moves a packed decimal value into a character field, showing that the decimal point is not carried over.
// Purpose: move a numeric value into a character field.
pjs.define("char1", { type: 'char', length: 10, initValue: 'abcdefgh' });
pjs.define("pkd1", { type: 'packed decimal', length: 5, decimals: 2, initValue: 123.45 });
// The numeric digits are moved without the decimal point, right adjusted.
pjs.move(pkd1, char1);
return char1;
// "abcde12345" -- "12345" occupies the 5 rightmost bytes.Example 4: Date to Integer
This example converts a date field into an integer field using an explicit date format.
// Purpose: convert a date field into a numeric field using a date format.
pjs.define("int1", { type: 'integer' });
pjs.define("ResYMD", { type: 'date', dateFormat: '*ymd', initValue: pjs.date('2014-01-28') });
// The 3rd parameter tells pjs.move() which format to render the date in
// before moving it. The format separators are dropped for a numeric target.
pjs.move(ResYMD, int1, '*usa');
return int1;
// 1282014 -- *USA gives 01/28/2014, which becomes the digits 01282014.Example 5: Constant to Boolean
This example moves a constant into a boolean (indicator) field.
// Purpose: move a constant into a boolean (indicator) field.
pjs.define("ind1", { type: 'boolean', initValue: false });
// The constant true is moved into the indicator field.
pjs.move(true, ind1);
return ind1;
// trueExample 6: Date to Numeric in Four Formats
This example moves the same date into four numeric fields, one per format, so the resulting digit order can be compared side by side.
// Purpose: compare how the four common date formats land in a numeric field.
// Note the target lengths: *ISO and *JIS produce 8 digits, *USA produces 8
// digits with a leading zero (shown as 7 when read back as a number), and
// *EUR produces 8 digits.
pjs.define("zoned1", { type: 'decimal', length: 10, decimals: 0 });
pjs.define("zoned2", { type: 'decimal', length: 10, decimals: 0 });
pjs.define("zoned3", { type: 'decimal', length: 8, decimals: 0 });
pjs.define("zoned4", { type: 'decimal', length: 8, decimals: 0 });
pjs.define("Date1", { type: 'date', initValue: pjs.date('2016-01-16') });
pjs.define("Date2", { type: 'date', initValue: pjs.date('2016-01-16') });
pjs.define("Date3", { type: 'date', initValue: pjs.date('2016-01-16') });
pjs.define("Date4", { type: 'date', initValue: pjs.date('2016-01-16') });
pjs.move(Date1, zoned1, '*iso'); // YYYYMMDD
pjs.move(Date2, zoned2, '*usa'); // MMDDYYYY
pjs.move(Date3, zoned3, '*eur'); // DDMMYYYY
pjs.move(Date4, zoned4, '*jis'); // YYYYMMDD
// zoned1 = 20160116 (*ISO)
// zoned2 = 1162016 (*USA)
// zoned3 = 16012016 (*EUR)
// zoned4 = 20160116 (*JIS)RPG Equivalent
MOVE