copyBytes()

The system function VGLib.copyBytes copies one field to another.

As is true in StrLib.copyStr, the source and target may be of a character type. In the current function, the source also may be any of the following types:
  StrLib.copyBytes(
    target a character type  inOut,
    targetSubIndex INT in,
    targetSubLength INT in,
    source BIN, DECIMAL, NUM, NUMC, PACF, or a character type in,
    sourceSubIndex INT in,
    sourcetSubLength INT in)
target
Field or literal from which a target substring is derived.
targetSubIndex
Identifies the starting byte in target, given that the first byte in target has the value 1. This index can be an integer literal. Alternatively, this index can be an item defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.
targetSubLength
Identifies the number of bytes in the value that is derived from target. The length can be an integer literal. Alternatively, the length can be a field defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.
source
Field or literal from which a source value is derived.
sourceSubIndex
Identifies the starting byte of the value in source, given that the first byte in source has the value 1. This index can be an integer literal. Alternatively, this index can be a field defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.
sourceSubLength
Identifies the number of bytes in the value that is derived from source. The length can be an integer literal. Alternatively, the length can be an item defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.

If the source is longer than the target, the source is truncated. If the source is shorter than the target, the source value is padded with blanks, even if that value is numeric.

Definition considerations

The following values are returned in sysVar.errorCode:
8
Index less than 1 or greater than value length.
12
Length less than 1.
20
Invalid double-byte index. Index for a DBCHAR or UNICODE string points to middle of double-byte character.
24
Invalid double-byte length. Length in bytes for a DBCS or UNICODE string is odd (double-byte lengths must always be even).

Example

  target = "120056";
  source = "34";
  StrLib.copyBytes(target,3,2,source,1,2);
  // target = "123456"

Related reference
copyStr()
EGL library VGLib

Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.