Entering content frameQuerying Data from Context Instances Locate the document in its SAP Library structure

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 <val1> = <f 1> ... <val n> = <f n> FROM CONTEXT <inst>
[MESSAGES INTO <itab>].

This statement fills the fields <fn> with the derived values <val n> from 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 <fn>.
  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 <fn>.
  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 <fn>.
  4. If the system cannot determine the dependent values, it terminates the process, sets fields <fn> 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 ).

Example

REPORT RSGCON01.

DATA: C_FROM LIKE SPFLI-CITYFROM,
      C_TO   LIKE SPFLI-CITYTO,
      C_TIME LIKE 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