Show TOC

Querying Data from Context InstancesLocate 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 .

Once you have supplied a context instance with key values, you can query its dependent values. You do this using the DEMAND statement:

Syntax

DEMAND val 1 = f 1 ... val n = f n FROM CONTEXT inst                             [MESSAGES INTO itab].

This statement fills the fields f 1 … f n with the derived values val 1 … val n from the context instance inst. The fields of the context are contained in the fields table.

In doing this, the system carries out the following steps:

  1. It checks to see whether the context instance already contains valid derived values. This is the case if the values have already been calculated in a previous DEMAND statement and the instance has not since been supplied with new key field values using the SUPPLY statement. In this case, these values are assigned to fields  f 1 … f n .
  2. If the context instance does not contain valid values, the system calculates new ones. It looks first in the context buffer (see Buffering Contexts ) for data records with the right key field values for the current context instance. If it finds the corresponding values, the system copies them as valid values into the context instance and assigns them to fields f 1 … f n .
  3. If there are no appropriate values in the context buffer, the system derives the values according to the context definition. The system also searches the context buffer during the derivation for intermediate results, which it uses if they are valid. When it has derived the values, the system saves all results in the context buffer, copies the values to the context instance and assigns them to fields f 1 … f n .
  4. If the system cannot determine the dependent values, it terminates the process, sets fields f 1 … f n to their initial values and outputs the user message stored in the Modules table. You can handle these messages in your programs by using the MESSAGES option (see Message Handling In Contexts ).
    Tip

    REPORT rsgcon01.

    DATA: c_from TYPE spfli-cityfrom,      c_to   TYPE spfli-cityto,      c_time TYPE spfli-fltime.

    CONTEXTS demo_travel.

    DATA: demo_travel_inst1 TYPE context_demo_travel,      demo_travel_inst2 TYPE context_demo_travel.

    SUPPLY carrid = 'LH'       connid = '400'       TO CONTEXT demo_travel_inst1.

    SUPPLY carrid = 'AA'       connid = '017'       TO CONTEXT demo_travel_inst2.

    DEMAND cityfrom = c_from       cityto   = c_to       fltime   = c_time       FROM CONTEXT demo_travel_inst1.

    WRITE: / c_from, c_to, c_time.

    DEMAND cityfrom = c_from       cityto   = c_to       fltime   = c_time       FROM CONTEXT demo_travel_inst2.

    WRITE: / c_from, c_to, c_time.

    This program creates two instances of context demo_travel, supplies them both with key values and reads three dependent values from each of them.