Show TOC

What are Contexts?Locate this document in the navigation structure

 Contexts are obsolete and should not be used. Contexts were introduced in Release 4.0 for high-performance access to frequently required data. Since the introduction of ABAP Objects for Release 4.5, contexts have not been developed further. Since Release 6.40, contexts can be replaced by shared objects .

Within the large quantities of data in the SAPsystem database, there are always smaller sets of basic data that you can use to derive further information. In a relational database model, for example, these are the key fields of database tables.

When an application program requires further information in order to continue, this is often found in these small amounts of basic data. The relational links in the database are often used to read further data on the basis of this basic data, or further values are calculated from it using ABAP statements.

It is often the case that certain relationships between data are always used in the same form to get further data, either within a single program or in a whole range of programs. This means that a particular set of database accesses or calculations is repeatedly executed, despite the fact that the result already exists in the system. This causes unnecessary system load, which can be alleviated by using contexts.

Contexts are objects within ABAP Workbench, consisting of key input fields, the relationships between these fields, and other fields which can be derived from them. Contexts can associate these derived fields by foreign key relationships between tables, by function modules, or by other contexts.

You define contexts abstractly in ABAP Workbench (transaction SE33), and use instances of them as runtime objects in your ABAP programs. You define contexts in Context Builder, which is part of ABAP Workbench. They consist of key input fields, the relationships between the fields, and the other fields and values that you can derive from them. Contexts can associate these derived fields by foreign key relationships between tables, by function modules, or by other contexts.

In ABAP Workbench, contexts consist of fields and modules. Their fields are divided into key fields and derived fields. The modules describe the relationship between the fields.

Technically, contexts are special ABAP programs. The context can be saved in one of two places:

  • in a non-executable program, with the name CONTEXT_S_<context name>.For the example context DEMO_TRAVEL, this would be CONTEXT_S_DEMO_TRAVEL).
  • in a generated executable program, with the name CONTEXT_X_<context name>.For the example context DEMO_TRAVEL, this would be CONTEXT_X_DEMO_TRAVEL).

In application programs, you work with instances of a context. You can use more than one instance of the same context. The application program supplies input values for the key fields in the context using the SUPPLY statement, and can query the derived fields from the instance using the DEMAND statement.

Each context has a cross-transaction buffer on the application server. When you query an instance for values, the context program searches first of all for a data record containing the corresponding key fields in the appropriate buffer. If one exists, the data is copied to the instance. If one does not exist, the context program derives the data from the key field values supplied and writes the resulting data record to the buffer.

Whenever, in a program, new key fields are entered into an instance that has already been previously supplied with them, the system invalidates all affected values that have already been derived. These values are only supplied again the next time they are queried.