无常笔记ABAP Cheat Sheets中文导读全站搜索

英文原文:SAP-samples · 上游版本 d43eb13c4c7c · 原始 Markdown

SAP LUW

Introduction

[!NOTE] The concept is relevant to both ABAP Cloud and classic ABAP, but some of the statements covered in the cheat sheet and the executable example are only relevant to classic ABAP.

This cheat sheet provides a high-level overview of the SAP LUW concept that deals with data consistency with a focus on SAP LUW-related statements, supported by an executable example to check the syntax in action.

When you run an application, you typically change data in a transaction, which may be temporarily stored in transactional buffers. This data may be temporarily inconsistent in the buffers, but it is important that the data be in a consistent state at the end of the transaction so that it can be saved to the database.

Consider the following example of transactional consistency:

[!NOTE]

Terms

The following terms are related to the concept of the SAP LUW and try to give you some context about it:

⬆️ back to top

SAP LUW Overview

For an SAP LUW, the following aspects come into play:

Using the above bank transfer as an example:

⬆️ back to top

Bundling Techniques

The following bundling techniques are available in Standard ABAP. This means that programming units are registered in different work processes, but are executed by a single work process. All database changes are put into one database LUW, and all changes are committed in one final database commit.

Using update function modules

[!NOTE] If a runtime error occurs during the update, the update work process executes a database rollback, and notifies the user whose program created the entries.

Using remote-enabled function modules

Using subroutines

⬆️ back to top

An SAP LUW is usually started by opening a new internal session. The statements to end an SAP LUW have already been mentioned above: COMMIT WORK [AND WAIT] and ROLLBACK WORK.

COMMIT WORK [AND WAIT]

ROLLBACK WORK

[!NOTE]

⬆️ back to top

The following concepts are related to the SAP LUW to ensure transactional consistency. They are not discussed in detail here. For more information, see the links.

Authorization concept

Lock concept

[!NOTE] For more information about related topics in RAP, see the sections Authorization Control and Concurrency Control in the Development guide for the ABAP RESTful Application Programming Model.

⬆️ back to top

The SAP LUW in ABAP Cloud and RAP

A limited set of ABAP language features is available in ABAP for Cloud Development (restricted ABAP language version). The limitations include the fact that the above bundling techniques are not available. Note that the local update is enabled by default in ABAP Cloud.

In fact, RAP is the transactional programming model for ABAP Cloud. And RAP comes with a well-defined transactional model and follows the rules of the SAP LUW. At the end of an SAP LUW in RAP, database modification operations should be performed in a final step in the RAP late save phase by persisting the consistent data in the RAP transactional buffer to the database.

There are RAP-specific ABAP EML statements for commit and rollback:

⬆️ back to top

Controlled SAP LUW

Example using CL_ABAP_TX:

...

*&---------------------------------------------------------------------*
*& Activating the modify transactional phase
*&---------------------------------------------------------------------*

cl_abap_tx=>modify( ).

"The following database modification statement is not allowed in the
"modify transactional phase. In certain contexts, e.g. in ABAP Cloud,
"the runtime error BEHAVIOR_ILLEGAL_STMT_IN_CALL occurs.
MODIFY zdemo_abap_carr FROM TABLE @( VALUE #(
    ( carrid = 'XY'
      carrname = 'XY Airlines'
      currcode = 'EUR'
      url =  'some_url' ) ) ).

...

*&---------------------------------------------------------------------*
*& Activating the save transactional phase
*&---------------------------------------------------------------------*

cl_abap_tx=>save( ).

"In this phase, database modifications are allowed.
MODIFY zdemo_abap_carr FROM TABLE @( VALUE #(
    ( carrid = 'XY'
      carrname = 'XY Airlines'
      currcode = 'EUR'
      url =  'some_url' ) ) ).
...

⬆️ back to top

More Information

⬆️ back to top

Executable Example

After the import of the repository, proceed as follows:

[!NOTE]


🟢 Click to expand for more information
The example demonstrates the SAP LUW using dynpros and bundling techniques with update function modules and subroutines. In the dynpros, you can select various options that determine how the program runs. It covers the following aspects:

The selection options follow this pattern:

First dynpro:

Second dynpro:

Third dynpro:

During program execution, logs are collected and eventually written to a database table (also using an update function module or subroutine). These logs document the progress of the transaction with various pieces of information. These include work process information, SAP LUW key retrieval, and transaction state retrieval (using methods of the CL_SYSTEM_TRANSACTION_STATE class).

If the program is not terminated immediately and the SAP LUW has ended, another program is called that displays a dynpro.

Fourth dynpro (part of a new program that is started):

Notes on the various options for checking out the SAP LUW: