All files / src/cds/expressions cds_define_hierarchy.ts

100% Statements 52/52
100% Branches 1/1
100% Functions 1/1
100% Lines 52/52

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 531x 1x 1x 1x 1x 1x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 1x  
import {CDSAnnotation, CDSAs, CDSCondition, CDSInteger, CDSName, CDSParametersSelect, CDSPrefixedName, CDSString, CDSWithParameters} from ".";
import {Expression, opt, optPrio, seq, star, altPrio} from "../../abap/2_statements/combi";
import {IStatementRunnable} from "../../abap/2_statements/statement_runnable";
 
export class CDSDefineHierarchy extends Expression {
  public getRunnable(): IStatementRunnable {
    const field = seq(star(CDSAnnotation), optPrio("KEY"), CDSPrefixedName, optPrio(CDSAs));
    const sortDirection = altPrio("ASCENDING", "DESCENDING");
    const siblingsOrderField = seq(CDSPrefixedName, optPrio(sortDirection));
    const siblingsOrder = seq("SIBLINGS", "ORDER", "BY", siblingsOrderField, star(seq(",", siblingsOrderField)));
 
    const directory = seq("DIRECTORY", CDSName, "FILTER", "BY", CDSCondition);
 
    // DATE PERIOD: period from <field> to <field> [valid from :p to :p]
    const datePeriod = seq(
      "PERIOD", "FROM", CDSName, "TO", CDSName,
      opt(seq("VALID", "FROM", altPrio(CDSString, CDSPrefixedName), "TO", altPrio(CDSString, CDSPrefixedName))),
    );
 
    const depthValue = altPrio(CDSString, CDSInteger, CDSPrefixedName);
    const loadMode = altPrio("BULK", "INCREMENTAL", CDSPrefixedName);
 
    const hierarchyBody = seq(
      "SOURCE", CDSName, opt(CDSParametersSelect),
      "CHILD", "TO", "PARENT", "ASSOCIATION", CDSName,
      opt(altPrio(
        seq(opt(directory), datePeriod, opt(directory)),
        seq(datePeriod, opt(directory)),
        directory,
      )),
      opt(seq("START", "WHERE", CDSCondition)),
      opt(siblingsOrder),
      opt(seq("DEPTH", depthValue)),
      opt(seq("NODETYPE", CDSName)),
      opt(seq("LOAD", loadMode)),
      opt(seq("MULTIPLE", "PARENTS", altPrio("NOT ALLOWED", "ALLOWED", seq("LEAVES", optPrio("ONLY"))))),
      opt(seq("ORPHANS", altPrio("IGNORE", "ROOT", "ERROR"))),
      opt(seq("CYCLES", altPrio("BREAKUP", "ERROR"))),
      opt(seq("GENERATE", "SPANTREE")),
      opt(seq("CACHE", altPrio("ON", "OFF", "FORCE"))),
    );
 
    return seq(
      star(CDSAnnotation),
      opt("DEFINE"), "HIERARCHY", CDSName,
      opt(CDSWithParameters),
      "AS", "PARENT", "CHILD", "HIERARCHY", "(", hierarchyBody, ")",
      "{", seq(field, star(seq(",", field))), "}",
      opt(";"),
    );
  }
}