Move

Syntax

MOVE expression [ POSITION source_variable ] [ LENGTH variable ] target_variable 
[ POSITION target_variable |SORTA | SORTD] [ GS status ]

Parameters

Move can be abbreviated as MV.

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:

Restrictions

The following restrictions apply to the use of the Move logic command:

The following restriction applies to the use of simple and complex variants:

Failure behavior

The Move logic command is validated if one of the following situations applies:

If a Move logic statement is validated:

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