Syntax
MOVE expression [ POSITION source_variable ] [ LENGTH variable ] target_variable [ POSITION target_variable |SORTA | SORTD] [ GS status ]
Parameters
Move can be abbreviated as MV.
expression
The source value.
POSITION source_variable
POSITION can be abbreviated as POS or PO. The position of the first character of the source substring.
The expression is restricted to a number-primitive variable, date, or literal. It must be unsigned, and it cannot have decimals. It cannot be specified as the Glb.Spaces, Glb.Zeros, Glb.High, or Glb.Low built-in segment attributes.
Use of this command parameter implies the complex variant of the Move logic command. Refer to Complex Variant below for more information. If a complex variant of the Move logic command does not specify this command option, the position of the first character of the source substring is assumed to be 1.
LENGTH variable
LENGTH can be abbreviated as LE. The length of the source substring.
The expression is restricted to a number-primitive variable, date, or literal. It must not be a signed number, and it cannot have decimals.
Use of this command parameter implies the complex variant of the Move logic command. Refer to Complex Variant below for more information. If a complex variant of the Move logic command does not specify this command option, the length of the source substring is assumed to be 1.
target_variable
The receiving variable.
If the length of the source substring is less than the length of the existing value of this variable, the characters of this existing value that are not overwritten are retained.
SORTA
Specifies ascending sort order of substring tokens. Refer to Sorted Variant below for more information.
Use of this command option implies the complex variant of the Move logic command. Refer to Complex Variant below for more information.
SORTD
Specifies descending sort order of substring tokens. Refer to Sorted Variant below for more information.
Use of this command option implies the complex variant of the Move logic command. Refer to Complex Variant below for more information.
POSITION variable
The position of the first character of the receiving substring to replace.
The expression is restricted to a number-primitive variable, date, or literal. It must not be a signed number, and it cannot have decimals. It cannot be specified as the Glb.Spaces, Glb.Zeros, Glb.High, or Glb.Low built-in segment attributes.
Use of this command parameter implies the complex variant of the Move logic command. Refer to Complex Variant below for more information. If a complex variant of the Move logic command does not specify this command option, the position of the first character of the receiving substring is assumed to be 1.
GS status
Indicates an invalid move specification using the specified variable.
Use of this command option implies the complex variant of the Move logic command.
Description
The Move logic command is used for data manipulation of primitive objects. You cannot Move a non-primitive other than a Group to another non-primitive. It can be used to simply copy a source value directly over the value of the receiving variable (simple variant), or to manipulate both, to give a new value in the receiving variable (complex variant). None, either, or both the source value and receiving variables can be an array.
Note: For MCP-based systems, COBOL85 requires numeric data to be large enough to contain a value equal to one plus the size of the item being moved by the command. For example, if the item being moved is 99 characters long, numeric data must have a length of at least 3.
The sorted variant is a sub-variant of the complex variant.
Note: It is possible to specify Move logic statements that produce inconsistent or unexpected results. These are known as overlapping moves.
The behavior of the Move logic command can be replicated using the ':=' assignment operator. Use of the assignment operator, where possible, rather than the Move logic command, is the LDL+ preferred format. Groups are pseudo-primitive objects and special consideration must be used when assigning values. To assign a string value to a member of a group, use the Move command. To assign a value to a primitive member of a group, use assignment operator (:=).
Simple variant
If the only command parameter specified is the receiving variable, it implies that the simple variant is used.
The simple variant of the Move logic command copies a source value directly over the value of a receiving variable.
The behavior of the simple variant of the Move logic command can be replicated using the ':=' assignment operator. Use of the assignment operator, where possible, rather than the Move logic command, is the LDL+ preferred format.
Complex variant
If any of the optional command options and parameters are specified, it implies that the complex variant is used.
The complex variant of the Move logic command manipulates both a source value and the value of a receiving variable to give a new value in the receiving variable. It does not alter the source value.
Values of different primitive types can be mixed, although the sign of the source value is not moved.
Sorted variant
If either the SortA or SortD command options are specfied, it implies the sorted variant is used.
The sorted variant of the Move logic command tokenizes both the source and receiving substrings. Each time this specific Move logic statement is invoked (for example, if it is specified within a Loop logic statement), the next token from the source is moved to the receiving substring, at a position determined by comparing the value of this token with the tokens in the receiving substring, and sorting them in the order specified by SortA or SortD. Spaces are not sorted.
The length of the value of the receiving variable increases with each invocation of the Move logic statement. Consequently, truncation might occur if this length exceeds the length of the receiving variable. If the rightmost significant token does not change position, truncation does not occur.
Refer to Example 5 below for an example of the sorted variant of the Move logic command.
Data truncation
If a national string value is input to a national string-primitive variable, the value is moved character-by-character, and truncated to the length of the variable.
If a national string value is input to a string-primitive variable, the value is moved byte-by-byte, and truncated to the length of the variable. This truncation might occur after the first byte of a double-byte character, resulting in an invalid character.
The following data truncation issues apply specifically to use of the simple variant:
String-primitive source values are left-aligned when moved to the receiving variable. The result is right-padded with spaces or truncated as necessary. Truncation occurs without warning.
Number-primitive source values are right-aligned, according to the position of the decimal point, when moved to the receiving variable. Extra decimals are truncated, rather than rounded, and the result is left-padded with zeros or truncated from the leftmost significant digit as necessary. Truncation occurs without warning.
Group variables are left-aligned when moved to the receiving variable.
Restrictions
The following restrictions apply to the use of the Move logic command:
Specifying a large number of Move logic statements might cause the code segment size limit to be exceeded during compilation. If this occurs, split the Move logic statements into smaller blocks using Label logic statements.
String values cannot be moved to a number-primitive variable as the result can be meaningless, depending on the platform the application is deployed to. The result might be inconsistent if truncation occurs.
The following restriction applies specifically to the use of Move logic statements involving one or more array values:
The definition of source and receiving arrays must be similar if values are to be preserved.
The Move command is valid with primitive/literals and instances of only a Group. Move has the ability to assign unlike types. Both Group/literal/primitive to Group; primitive/literal to primitive; Group to primitive(String only).
Primitives/literals which are Boolean or have Decimals cannot be Moved to a Group. These produce a semantic error on validation.
The assignment operator “:=” is valid for primitive/literals and instances of all other class instances. Unlike Move; assignment can only work with like types. The assignment operator cannot be used with instances of a Group and will produce a semantic error.
The following restriction applies to the use of simple and complex variants:
String values or String-primitive cannot be moved to a NationalString-primitive. NationalString-primitive cannot be moved to a String primitive.
Failure behavior
The Move logic command is validated if one of the following situations applies:
The segment's Def Bounds Checking property is set.
If this property is not set, error checking code is not generated, and error checking does not occur. Consequently, if the result of a complex variant of the Move logic command is outside the bounds of the receiving variable, the value of that variable might be inconsistent.
The GS command option is specified.
The SortA or SortD command options are specified.
If a Move logic statement is validated:
If an invalid Move logic statement is invoked, the Glb.Status built-in segment attribute (or the variable specified by the GS command option) is set to "*****", and the move does not occur.
If truncation occurs, the Glb.Status built-in segment attribute (or the variable specified by the GS command option) is generally not set to "*****".
However, if a sorted variant of the Move logic command truncates a character token when appending it to (rather than inserting it in) the receiving variable, the Glb.Status built-in segment attribute (or the variable specified by the GS command option) is set to "*****", and the move does not occur.
Examples
Example 1
This example uses the simple variant of the Move logic command.
LookUp Every Cust Determine Total CustBal (Cust.Customer) Amount Move Glb.TOTAL Frame01.Balance Frame01.Print() End
Note: An assignment statement can be used instead of a “Move” command for simple variants.
Example 2
This example uses the simple variant of the Move logic command. It moves a TimeW group variable, that has members HourW, MinW, and SecW, all of which are number-primitive variables of length 2. The ReceptW variable is a number-primitive variable of length 8.
Move 20 TimeW.HourW Move 04 TimeW.MinW Move 02 TimeW.SecW Move TimeW ReceptW : TimeW is 200402, ReceptW is 20040200
Notes:
In the MCP platform, ReceptW displays 200402 as the result is right-padded with spaces. To right-pad the result with zero, use the Complex Variant of the Move logic command.
In all other platforms, ReceptW displays 20040200 as the result is right-padded with zeros.
Example 3
This example uses the complex variant of the Move logic command. MyMonth is a number-primitive variable of length 2 and MyDate is a number-primitive variable of length 6.
Move ActMth Pos 3 Length 2 MyMonth : For example, if ActMth = 1503, then Move MyMonth MyDate Pos 3 : MyMonth = 03, MyDate = 000300
Example 4
This example uses the sorted variant of the Move logic command. Two characters are moved each time the Move logic statement is invoked in the loop. First, "QW" is moved, followed by "ER". "ER" comes before "QW" when sorted in ascending order, so the result is "ERQW". "TY" is moved next, giving "ERQWTY". The final result is "ASDFERGHJKLZNMOPQWTYUIVBXC", where each token of two characters is sorted in ascending order.
Quest := "QWERTYUIOPASDFGHJKLZXCVBNM" Posn := 1 Loop Move Quest Pos Posn Length 2 Answer SortA Posn := Posn + 2 If Posn >= 26 Break End End
Example 5
This example copies the string contained in the variable NewComment (starting from the fourth character and continuing to the end) to Cust.Comments and places it in the position indicated by the variable PreviousEnd. The value of NewComment is unchanged.
If NewComment contains "123Miscalculation in Cost", and Cust.Comments contains "Errors:" with PreviousEnd set to 8, at the end of the Move Cust.Comments becomes "Errors:Miscalculation in Cost".
Move NewComment Pos (TheStart + 3) Length (TheLength - 3) Cust.Comments Pos PreviousEnd