COPY
Syntax
![]()
Command
Mandatory parameter Optional parameter Mandatory keyword Optional keyword |
<Destination> := COPY (<Item>, <Position>[, <Length>])
Description
Copies a part of an item into another item. If no length is specified, the substring value is copied from the specified position until the end of the variable.
Diagram
Returned value type
Realstring
Parameters
Parameter | Description | |
<Destination> | Field into which the result value is copied. | |
<Item> | Variable from which the substring is copied. | |
<Position> | Expression giving the position of the substring. If an invalid position (e.g. a value higher than the <Item> length) is returned, the system item RESOK will be set to "FALSE". If a valid position is specified, RESOK will retain its current value. |
|
<Length> | Expression giving the length of the substring. |
Remarks
The copied substring will always be handled according to the type of the specified <Item>. This means that if the <Item> is a string and the substring contains trailing spaces, these spaces will be omitted.
A warning will be given when copying using a literal value as length and the length is greater than the length of the variable to assign the result to. |
When copying alphas to numerics the result will be right aligned. Note that the substring should contain only numbers or spaces. Spaces will be interpreted as zero's. |
Examples
A
str := 'abcdef'
str2 := copy (str, 4, 2)
// The value for str2 becomes "de"
B
str := 'abcdef'
str2 := copy (str, length(str) - 1)
// The value for str2 becomes the last two characters of str
// i.e. "ef"
C
var
sa-10 : alpha 10
sn-3 : numeric 3 value 23
routine main
str2 := copy (sa-10, sn-3, 1)
// The position in sn-3 (23) is invalid for
// the source item sa-10. ResOk will be set to False
D
var
sa-5 : alpha 5
sn-3 : numeric 3
routine main
begin_routine
sa-5 := '123'
sn-3 := copy (sa-5, 3, 3)
// The copy of an alpha will be right aligned
// When copying into a numeric, trailing spaces will translate into zeroes
// Result: sn-3 is '300'
str := 'abcdef'
str2 := copy (str, 4, 2)
// The value for str2 becomes "de"
B
str := 'abcdef'
str2 := copy (str, length(str) - 1)
// The value for str2 becomes the last two characters of str
// i.e. "ef"
C
var
sa-10 : alpha 10
sn-3 : numeric 3 value 23
routine main
str2 := copy (sa-10, sn-3, 1)
// The position in sn-3 (23) is invalid for
// the source item sa-10. ResOk will be set to False
D
var
sa-5 : alpha 5
sn-3 : numeric 3
routine main
begin_routine
sa-5 := '123'
sn-3 := copy (sa-5, 3, 3)
// The copy of an alpha will be right aligned
// When copying into a numeric, trailing spaces will translate into zeroes
// Result: sn-3 is '300'