Get Example source ABAP code based on a different SAP table
• DEFINE JOIN DEPENDENCY RULE ABAP_DDIC_STATEMENT
ABAP_DDIC_DDL - DEFINE JOIN DEPENDENCY RULE>
ABAP_SYNTAX DEFINE JOIN DEPENDENCY RULE drul ON dbtab1, dbtab2 IF { cond_pattern } THEN { derived_cond }>
What does it do? Variant of the Dictionary DDL> statement DEFINE DEPENDENCY RULE>> used to define a join dependency rule >. A join dependency rule can be defined for exactly two database tables dbtab1> and dbtab2>, separated by a comma. It derives an additional join condition derived_cond> from the pattern cond_pattern>. When two DDIC database tables joined by a join expression are read, the SAP HANA database optimizer finds the pattern in the ON> condition of the expression and, if necessary, adds the additional join condition AND> to this condition. If any further additional conditions are defined by filter dependency rules> for one of the two database tables, these rules are also applied to the other DDIC database table, if they apply to the columns specified in the join condition. <(>cond_pattern<)>> In cond_pattern>, a pattern from a relational expression can be specified in the curly brackets after IF> as follows: lhs = rhs $[AND lhs = rhs ...$]> Comparisons with the operator => joined using AND> are possible. Joins using OR> or negations using NOT> are not possible.
The following can be specified as the left side lhs> of the comparison:
dbtab1.column> or dbtab2.column> for a column column> of the DDIC database tables dbtab1> or dbtab2>.
The following can be specified as the right side rhs> of the comparison:
dbtab1.column> or dbtab2.column> for a column column> of the DDIC database tables dbtab1> or dbtab2>.
An untyped character literal or an untyped numeric literal. This syntax is the same as in untyped literals in ABAP CDS>.
A numbered placeholder $1>, $2>, ... <(>derived_cond<)>> In derived_cond>, a template for a relational expression can be specified in the curly brackets after THEN> as follows: lhs =$| < $|>$| < =$|>= rhs $[OR lhs =$| < $|>$|<(> <<)>=$|>= rhs ...$]> Single comparisons can be placed in parentheses ( )>. Negations using NOT> are not possible.
The following can be specified as the left side lhs> of a comparison:
dbtab1.column> or dbtab2.column> for a column column> of the database table dbtab1> or dbtab2>.
The following can be specified as the right side rhs> of a comparison:
dbtab1.column> or dbtab2.column> for a column column> of the database table dbtab1> or dbtab2>.
An untyped character literal or an untyped numeric literal. This syntax is the same as in untyped literals in ABAP CDS >.
A numbered placeholder $1>, $2>, ..., which must also be specified in cond_pattern>. When the condition is added, the operand for the condition is inserted into this placeholder. The same placeholder for the same operand value must exist in the pattern cond_pattern>.
Built-in functions in ABAP Dictionary> in ABAP CDS> syntax.
Simple case distinctions> in ABAP CDS syntax.
Latest notes:
It cannot be guaranteed that the SAP HANA database optimizer finds the pattern cond_pattern>. This is why the additional condition derived_cond> must not modify the result set of the original query. It is technically possible to modify the result set with a dependency rule, but should be avoided since it produces undefined behavior in cases where the SAP HANA database optimizer finds the pattern cond_pattern > in some reads but not in others.
The additional condition for a query can be viewed in the SQL Trace> tool (transaction ST05>>) by choosing Display Execution Plan> . ABAP_HINT_END
Example ABAP Coding
The following dependency rules are defined: DEFINE FILTER DEPENDENCY RULE demo_drul_3 ON demo_parts_3 IF { demo_parts_3.value >= 30 } THEN { demo_parts_3.area >= 3 } DEFINE FILTER DEPENDENCY RULE demo_drul_4 ON demo_parts_3 IF { demo_parts_3.value < 40 } THEN { demo_parts_3.area < 4 } DEFINE JOIN DEPENDENCY RULE demo_drul_5 ON demo_parts_3, demo_parts_4 IF { demo_parts_3.client = demo_parts_4.client AND demo_parts_3.id = demo_parts_4.id AND demo_parts_3.value = demo_parts_4.value } THEN { demo_parts_3.area = demo_parts_4.area }> The program DEMO_DEPENDENCY_RULE_3>> uses the following SELECT> statement to access DEMO_PARTS_3> and DEMO_PARTS_4>: SELECT demo_parts_3~id, demo_parts_3~value, demo_parts_4~text FROM demo_parts_3 INNER JOIN demo_parts_4 ON demo_parts_3~id = demo_parts_4~id AND demo_parts_3~value = demo_parts_4~value WHERE demo_parts_3~value >= 30 AND demo_parts_3~value < 40 ORDER BY demo_parts_3~id INTO TABLE @DATA(result).> The SAP HANA database optimizer adds the following condition to the ON> condition implicitly: AND demo_parts_3~area = demo_parts_4~area> It also adds the following filter conditions to the WHERE> condition implicitly: AND demo_parts_3~area >= 3 AND demo_parts_3~area < 4 AND demo_parts_4~area >= 3 AND demo_parts_4~area < 4> If the data in the DDIC database tables is structured correctly, the dependency rules do not modify the result set. ABAP_EXAMPLE_END