All files / src/abap/2_statements/expressions type_table.ts

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

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 53 54 55 56 57 58 59 60 61 62 631x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x 1x  
import {seq, opt, alt, per, Expression, altPrio, optPrio, plusPrio, plus, ver, AlsoIn} from "../combi";
import {Constant, TypeName, Integer, EntityAssociation} from ".";
import {IStatementRunnable} from "../statement_runnable";
import {FieldChain} from "./field_chain";
import {TypeTableKey} from "./type_table_key";
import {Release} from "../../../version";
import {derivedTypesAlt} from "./_derived_types";
 
export class TypeTable extends Expression {
  public getRunnable(): IStatementRunnable {
    const header = "WITH HEADER LINE";
    const initial = seq("INITIAL SIZE", Constant);
 
    const generic = seq(opt(alt("STANDARD", "HASHED", "INDEX", "SORTED", "ANY")), "TABLE");
 
    const normal1 = seq(opt(alt("STANDARD", "HASHED", "INDEX", "SORTED", "ANY")),
                        "TABLE OF",
                        optPrio("REF TO"),
                        TypeName);
 
    const likeType = seq(opt(alt("STANDARD", "HASHED", "INDEX", "SORTED", "ANY")),
                         "TABLE OF",
                         optPrio("REF TO"),
                         opt(FieldChain),
                         opt(per(header, initial, plusPrio(TypeTableKey))));
 
    const rangeType = seq("RANGE OF", TypeName, optPrio(header), optPrio(initial), optPrio("VALUE IS INITIAL"));
    const rangeLike = seq("RANGE OF", FieldChain, optPrio(header), optPrio(initial), optPrio("VALUE IS INITIAL"));
 
    // a maximum of 15 secondary table keys can be defined
    // "WITH" is not allowed as a field name in keys
    const typetable = alt(generic, seq(normal1,
                                       alt(opt(per(header, initial, plusPrio(TypeTableKey))),
                                           seq(plus(TypeTableKey), optPrio(initial))), optPrio("VALUE IS INITIAL")));
 
    const occurs = seq("OCCURS", altPrio(Integer, FieldChain));
 
    const entity = alt(TypeName, EntityAssociation);
 
    const derivedTypes = derivedTypesAlt(
      ver(Release.v773, seq("ACTION IMPORT", entity)),
      ver(Release.v774, seq("READ LINK", entity)),
      ver(Release.v787, seq("EVENT", entity)),
    );
 
    const derived = ver(Release.v770, seq("TABLE FOR", derivedTypes, optPrio("VALUE IS INITIAL")),
                        {also: AlsoIn.OpenABAP});
 
    const oldType = seq(opt("REF TO"), TypeName, alt(seq(occurs, opt(header)), header));
    const oldLike = seq(opt("REF TO"), FieldChain, alt(seq(occurs, opt(header)), header));
 
    const typeLine = seq("LINE OF", TypeName, occurs, header);
 
    const ret = altPrio(
      seq(occurs, opt(header)),
      seq("LIKE", alt(oldLike, likeType, rangeLike, typeLine)),
      seq("TYPE", alt(oldType, typetable, rangeType, typeLine, derived)));
 
    return ret;
  }
 
}