[TRANSACTION] (define transaction)
[TRANSACTION] specifies the range to be handled as a transaction when an access definition file is being used to customize an operation window.
If the processing status is NORMAL when the processing defined in the transaction ends, the transaction is committed; if the processing status is not NORMAL, the transaction is rolled back.
Syntax
[TRANSACTION] . . . [BEGIN] . . . [END] [TRANSACTION_END]
Values
Codes the transaction processing.
Remarks
Whether or not transaction processing is complete is determined according to the status referenced by the transaction processing end tag [TRANSACTION_END] or by the embedded function $BREAK, which breaks out of the transaction processing. If the status is NORMAL, the transaction is committed; if the status is not NORMAL, it is not committed (it is rolled back).
The status of the access definition file is updated on an ongoing basis by execution of tags and embedded functions. If processing that updates the status is specified more than once in a transaction, whether to commit or roll back is based on the status that was last specified.
This means that if a transaction is committed immediately before a [TRANSACTION_END] tag or a $BREAK embedded function, we recommend that you use the $SETSTATUS embedded function to explicitly specify NORMAL as the status.
Note that transaction processing cannot be nested.
Example
The following shows an example of transaction processing:
[TRANSACTION] [APPEND] AssetInfo [DATA] AssetInfo.AssetID = '10000' AssetInfo.AssetNo = '10000' AssetInfo.AssetWorkKind = '001' AssetInfo.AssetKind = '001' AssetInfo.AssetBranchNo = '0' [SET_VALUE] STATUS = $GETSTATUS() [IF] STATUS = NORMAL [THEN] ##Process 1 [APPEND] InstalledInfo [DATA] InstalledInfo.InstalledID = '10000' InstalledInfo.AssetID = '10000' [SET_VALUE] STATUS = $GETSTATUS() [IF] STATUS = NORMAL [THEN] ##Process 2 [SET_VALUE] MSG = 'TRANSACTION : COMMIT' $ECHO(MSG) [ELSE] ##Process 3 [SET_VALUE] MSG = 'TRANSACTION : ROLLBACK' $ECHO(MSG) [IF_END] [ELSE] ##Process 4 [SET_VALUE] MSG = 'TRANSACTION : ROLLBACK' $ECHO(MSG) [IF_END] [TRANSACTION_END] |
In this processing, the following exception processing is performed.
-
If addition of asset ID 10000 fails:
Control is transferred to the processing indicated by comment ##Process 4. Because the termination status of [APPEND] is not NORMAL, the transaction processing between [TRANSACTION] and [TRANSACTION_END] is rolled back and processing terminates. This means that all requests to the database are invalidated.
-
If addition of asset ID 10000 is successful:
Control is transferred to the processing indicated by comment ##Process 1. Asset ID 10000 and installed software ID 10000 are registered in the installed software information.
-
If addition of asset ID 10000 succeeds, and addition of installed software ID 10000 fails:
Control is transferred to the processing indicated by comment ##Process 3.
Because the termination status of [APPEND] is not NORMAL, the transaction processing between [TRANSACTION] and [TRANSACTION_END] is rolled back and processing terminates. This means that all requests to the database are invalidated.
-
If addition of asset ID 10000 and of installed software ID 10000 is successful:
Control is transferred to the processing indicated by comment ##Process 2. Because the termination status of [APPEND] is NORMAL, all requests to the database are validated.