(target: DataReference | FieldSymbol, options?: ICreateDataOptions)
| 24 | const tableOptions: ITableOptions = {withHeader: false, keyType: TableKeyType.default}; |
| 25 | |
| 26 | |
| 27 | /** CREATE DATA ... TYPE REF TO <name>, both the static and the dynamic spelling. |
| 28 | * "REF TO data" is the generic case: the created data object is itself an |
| 29 | * unbound data reference, so the target points at a DataReference. Anything |
| 30 | * else names a class or interface. */ |
| 31 | function createDataRefTo(target: DataReference, name: string) { |
| 32 | if (name.toUpperCase() === "DATA") { |
| 33 | // a DataReference pointing at a DataReference, same shape GET REFERENCE OF |
| 34 | // a "REF TO data" variable produces - the declared types do not model the |
| 35 | // nesting, so this mirrors get_reference's cast |
| 36 | target.assign(new DataReference(undefined) as any); |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | if (abap.Classes[name.toUpperCase()] === undefined) { |
| 41 | throwError("CX_SY_CREATE_DATA_ERROR"); |
| 42 | } |
| 43 | |
| 44 | target.assign(new abap.types.ABAPObject({qualifiedName: name, RTTIName: name})); |
| 45 | } |
| 46 | |
| 47 | /** CREATE DATA ... LIKE dobj takes the type of dobj, never its content: the |
| 48 | * created data object starts initial. A table is created empty right away |
| 49 | * instead of copying its rows first. */ |
| 50 | function initialLike(like: any) { |
| 51 | if (like instanceof Table || like instanceof HashedTable) { |
| 52 | const TableType = like.constructor as typeof Table; |
| 53 | return new TableType(like.getRowType(), like.getOptions(), like.getQualifiedName()); |
| 54 | } |
| 55 | const copy = like.clone(); |
| 56 | copy.clear(); |
| 57 | return copy; |
| 58 | } |
| 59 | |
| 60 | export function createData(target: DataReference | FieldSymbol, options?: ICreateDataOptions) { |
| 61 | // console.dir(options); |
| 62 | |
| 63 | if (target instanceof FieldSymbol) { |
| 64 | createData(target.getPointer(), options); |
| 65 | return; |
| 66 | } else if (!(target instanceof DataReference)) { |
| 67 | throw new Error("CREATE_DATA_REFERENCE_EXPECTED"); |
| 68 | } |
| 69 | if (options?.name && options?.table) { |
| 70 | if (abap.DDIC[options.name.trimEnd()] === undefined) { |
| 71 | throwError("CX_SY_CREATE_DATA_ERROR"); |
| 72 | } |
| 73 | target.assign(new abap.types.Table(abap.DDIC[options.name.trimEnd()].type(), tableOptions)); |
| 74 | } else if (options?.name !== undefined) { |
| 75 | if (abap.DDIC[options.name.trimEnd()]) { |
| 76 | target.assign(abap.DDIC[options.name.trimEnd()].type().clone()); |
| 77 | } else if (options.name.includes("=>")) { |
| 78 | const [className, typeName] = options.name.trimEnd().toUpperCase().split("=>"); |
| 79 | |
| 80 | if (abap.Classes[className] === undefined) { |
| 81 | throwError("CX_SY_CREATE_DATA_ERROR"); |
| 82 | } |
| 83 | if (abap.Classes[className][typeName.toLowerCase()] === undefined) { |
nothing calls this directly
no test coverage detected