copyBytes()
The vgLib.copyBytes() system function copies the contents of one substring to another, byte by byte, without regard for the format of that content.
vgLib.copyBytes() is one of a number of functions maintained for compatibility with earlier versions. New code should use standard EGL operators for these purposes.
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.
Syntax
vgLib.copyBytes(
target HEX inOut,
targetSubstrIndex INT in,
targetSubstrLength INT in,
source HEX inOut,
sourceSubstrIndex INT in,
sourcetSubstrLength INT in)
- target
- Value from which a target substring is derived. Can be any value that is reference compatible with HEX.
- targetSubstrIndex
- Identifies the starting byte of the substring in target, given that the index value of the first byte is 1. This index can be an integer literal or variable (INT or BIN(9)).
- targetSubstrLength
- Identifies the number of bytes in the substring that is derived from target. The length can be an integer literal or variable (INT or BIN(9)).
- source
- Field or literal from which a source value is derived.
- sourceSubstrIndex
- Identifies the starting byte of the substring in source, given that the value of the first byte is 1. The index can be an integer literal or variable (INT or BIN(9)).
- sourceSubstrLength
- Identifies the number of bytes in the substring that is derived from source. The length can be an integer literal or variable (INT or BIN(9)).
Error considerations
If you use V6 exception compatibility (see Using V6 exception compatibility), the following values are
returned in sysVar.errorCode:
- 8
- Index less than 1 or greater than value length.
- 12
- Length less than 1.
- 20
- Index for a DBCHAR or UNICODE string points to the middle of a double-byte character.
- 24
- Length in bytes for a DBCS or UNICODE string is odd (double-byte lengths must always be even).
Example
The following example copies the source string
into the middle of target:
target HEX (8) = "1200567"; // target = "12005670"
source HEX (4)= "3478"; // index must be multiple of 2
vgLib.copyBytes(target,2,1,source,1,1); // target = "12345670"