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

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

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 63 641x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x
import {seq, per, altPrio, ver, Expression, AlsoIn} from "../combi";
import {Source} from ".";
import {IStatementRunnable} from "../statement_runnable";
import {Release} from "../../../version";
import {Dynamic} from "./dynamic";
 
export class StringTemplateFormatting extends Expression {
 
  public getRunnable(): IStatementRunnable {
 
    // https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-us/abapcompute_string_format_options.html
    const alphaOptions = altPrio("OUT", "RAW", "IN", Source, Dynamic);
 
    const alignOptions = altPrio("LEFT", "RIGHT", "CENTER", Source, Dynamic);
 
    const dateTimeOptions = altPrio("RAW", "ISO", "USER", "ENVIRONMENT", Source, Dynamic);
 
    const timeStampOptions = altPrio("SPACE", "ISO", "USER", "ENVIRONMENT", Source, Dynamic);
 
    const numberOptions = altPrio("RAW", "USER", "ENVIRONMENT", Source, Dynamic);
 
    const signOptions = altPrio("LEFT", "LEFTPLUS", "LEFTSPACE", "RIGHT", "RIGHTPLUS", "RIGHTSPACE", Source, Dynamic);
 
    const caseOptions = altPrio("RAW", "UPPER", "LOWER", Source, Dynamic);
 
    const zeroXSDOptions = altPrio("YES", "NO", Source, Dynamic);
 
    const styleOptions = altPrio("SIMPLE",
                                 "SIGN_AS_POSTFIX",
                                 "SCALE_PRESERVING",
                                 "SCIENTIFIC",
                                 "SCIENTIFIC_WITH_LEADING_ZERO",
                                 "SCALE_PRESERVING_SCIENTIFIC",
                                 "ENGINEERING",
                                 Source,
                                 Dynamic);
 
    const width = seq("WIDTH =", Source);
    const align = seq("ALIGN =", alignOptions);
    const timezone = seq("TIMEZONE =", Source);
    const timestamp = seq("TIMESTAMP =", timeStampOptions);
    const pad = seq("PAD =", Source);
    const number = seq("NUMBER =", numberOptions);
    const sign = seq("SIGN =", signOptions);
    const decimals = seq("DECIMALS =", Source);
    const alpha = ver(Release.v740sp02, seq("ALPHA =", alphaOptions), {also: AlsoIn.OpenABAP});
    const xsd = ver(Release.v740sp02, seq("XSD =", zeroXSDOptions));
    const country = seq("COUNTRY =", Source);
    const currency = seq("CURRENCY =", Source);
    const style = seq("STYLE =", styleOptions);
 
    const exponent = seq("EXPONENT =", Source);
    const casing = seq("CASE =", caseOptions);
    const zero = seq("ZERO =", zeroXSDOptions);
    const date = seq("DATE =", dateTimeOptions);
    const time = seq("TIME =", dateTimeOptions);
 
    // options which exclude each other are not distinguished here
    const formatting = per(sign, number, decimals, width, pad, alpha, align, country, currency, style, exponent,
                           casing, zero, xsd, date, time, timezone, timestamp);
 
    return formatting;
  }
}