Entering content frame

Querying Data from Context Instances Locate the document in its SAP Library structure

Caution Contexts are obsolete and should not be used. Contexts were introduced for 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 Structure linkshared objects.


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


DEMAND val1 = f1 ... valn = fn FROM CONTEXT inst
                             [MESSAGES INTO itab].

This statement fills the fields f1fn with the derived values val1valn 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  f1fn .

       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 f1fn.

       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 f1fn.

       4.      If the system cannot determine the dependent values, it terminates the process, sets fields f1fn 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 ).


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 generates two instances of context demo_travel, supplies them both with key values and reads three dependent values from each of them.




Leaving content frame