SWAP
The SWAP instruction exchanges the contents of the source operand with the contents of the destination operand. The operands must be compatible for a swap operation. In general, this means that the operands must have the same variable type, physical size, and any required format or state attributes. The instruction uses the following format:
|
|
|
|
|
Where:
label
Optional. A Program Execution Label.
source
Required. A previously defined Character String Variable, National Character String Variable, or Numeric Variable. In addition, the source operand can be a RECORD or VARLIST that contains multiple variables to be used for multiple swap operations.
sep
Required. A comma or one of the following prepositions: BY, TO, OF, FROM, USING, WITH, IN, or INTO.
dest
Required. A previously defined Character String Variable, National Character String Variable, or Numeric Variable. In addition, the source operand can be a RECORD or VARLIST that contains multiple variables to be used for multiple swap operations.
Flags Affected: OVER
Note the following:
By default, the OVER flag is cleared. The OVER flag is set TRUE if a GUI object is encountered and skipped in a RECORD to RECORD swap operation. When this occurs, the GUI object member is no swapped, the operation continues with the next variable, and the OVER flag is set.
If the source and destination RECORD/VARLIST operands contain a different number of variables, SWAP processes matching variables in order until the shorter variable list is exhausted or until an error is encountered.
When the SWAP operation detects an error, an F18 error is generated and the subcode identifies the specific type of error encountered as follows:
|
Sub Code Value |
Source/destination variable mismatch because: |
|
1 |
The types are not the same. |
|
2 |
An operand variable with an unknown type is encountered. |
|
3 |
The variable behavior/state attributes required for the swap are not the same. |
|
5 |
The physical sizes are not the same. |
|
6 |
A DIM NULL variable is not allowed. |
|
7 |
Unable to allocate memory when creating a buffer for a variable larger than 8192 bytes. |
|
8 |
The form formats are not the same. |
|
9 |
The GUI object types are not the same. |
The following example demonstrates SWAP processing for individual variables, RECORD variables, and VARLIST variables:
See Also: Character String Instructions
![]() |