How to use abap-adt-api - 10 common examples

To help you get started, we’ve selected a few abap-adt-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sbcgua / sap-nw-abap-vagrant / abapdeploy.js / abapdeploy.js View on Github external
async function fetchTmpObj(objName) { // eslint-disable-line no-unused-vars
    const client      = create();
    const nodes       = await client.nodeContents('DEVC/K', '$TMP');
    const node        = nodes.nodes.find(i => i.OBJECT_NAME === objName);
    const structure   = await client.objectStructure(node.OBJECT_URI);
    const mainInclude = ADTClient.mainInclude(structure);
    const code        = await client.getObjectSource(mainInclude);
    // console.log(structure, mainInclude);
    console.log(code);
}
github sbcgua / sap-nw-abap-vagrant / abapdeploy.js / abapdeploy.js View on Github external
async function installProg(name, source) {
    const client = create();
    const path   = '/sap/bc/adt/programs/programs/' + name;
    const main   = path + '/source/main';

    try {
        await client.createObject({
            description: name,
            name,
            objtype: 'PROG/P',
            parentName: '$TMP',
            parentPath: '/sap/bc/adt/packages/$TMP'
        });

        client.stateful = session_types.stateful;
        const handle = await client.lock(path);
        await client.setObjectSource(main, source, handle.LOCK_HANDLE); // write the program
        console.log(`Program ${name} was successfully created`);
        await client.unLock(path, handle.LOCK_HANDLE);

        // read it for verification
        // const newsource = await c.getObjectSource(main)
        // console.log(newsource);

        const result = await client.activate( name, path );
        console.log(`Program ${name} was activated`);
        console.log(result);
    } finally {
        client.dropSession();
    }
}
github marcellourbani / vscode_abap_remote_fs / client / src / adt / abap / AbapClass.ts View on Github external
public async getChildren(
    client: ADTClient
  ): Promise {
    if (this.isLeaf()) throw FileSystemError.FileNotADirectory(this.vsName)
    if (!this.structure) await this.loadMetadata(client)
    if (!this.structure) throw FileSystemError.FileNotFound(this.vsName)

    const ns: NodeStructureMapped = {
      categories: new Map(),
      objectTypes: new Map(),
      nodes: []
    }
    const main = this.selfLeafNode()
    main.OBJECT_URI = ADTClient.mainInclude(this.structure)
    const sources = ADTClient.classIncludes(this.structure)
    this.structure.includes.forEach(i => {
      const node = {
        EXPANDABLE: "",
        OBJECT_NAME: this.name + "." + i["class:includeType"],
        OBJECT_TYPE: i["adtcore:type"],
        OBJECT_URI: sources.get(i["class:includeType"] as classIncludes) || "",
        OBJECT_VIT_URI: "",
        TECH_NAME: i["class:includeType"] // bit of a hack, used to match include metadata
      }
      if (node.OBJECT_URI) {
        if (i["abapsource:sourceUri"] === "source/main") ns.nodes.unshift(node)
        else ns.nodes.push(node)
      }
    })
github marcellourbani / vscode_abap_remote_fs / client / src / adt / AdtServer.ts View on Github external
public async relogin() {
    this.currentCancel.cancel()
    this.currentCancel = new CancellationTokenSource()
    this.currentCall = Promise.resolve()
    if (this.mainClient.stateful === session_types.stateful) {
      try {
        this.mainClient.stateful = session_types.stateless
        // juts in case I have pending locks...
        await this.mainClient.logout()
      } catch (error) {
        // ignore
      }
      await this.mainClient.login()
    }
  }
github marcellourbani / vscode_abap_remote_fs / client / src / adt / operations / AdtObjectCreator.ts View on Github external
const base = hierarchy[0]
    // if I picked the root node,a direct descendent or a package just ask the user to select any object type
    // if not, for abap nodes pick child objetc types (if any)
    // for non-abap nodes if it's an object type guess the type from the children
    if (hierarchy.length > 2)
      if (isAbapNode(base) && base.abapObject.type.match(/FUGR\/F/))
        return selectObjectType(base.abapObject.type)
      else {
        const child = base.isFolder
          ? [...base]
              .map(c => c[1])
              .find(c => isAbapNode(c) && c.abapObject.type !== PACKAGE)
          : base
        if (child && isAbapNode(child)) {
          const typeid = child.abapObject.type as CreatableTypeIds
          const guessed = CreatableTypes.get(typeid)
          if (guessed) return guessed
        }
      }
    // default...
    return selectObjectType()
  }
github marcellourbani / vscode_abap_remote_fs / client / src / adt / operations / AdtObjectCreator.ts View on Github external
private async getObjectDetails(uri: Uri | undefined): Promise<details> {
    const hierarchy = this.getHierarchy(uri)
    let devclass: string = this.guessParentByType(hierarchy, PACKAGE)
    const objType = await this.guessOrSelectObjectType(hierarchy)
    // user didn't pick one...
    if (!objType) return
    const name = await this.askName(objType.typeId)
    if (!name) return
    const description = await this.askInput("description", false)
    if (!description) return
    const responsible = this.server.client.username.toUpperCase()
    const parentType = parentTypeId(objType.typeId)
    let parentName
    if (parentType !== PACKAGE) {
      parentName = this.guessParentByType(hierarchy, "FUGR/F")
      if (!parentName) [parentName, devclass] = await this.askParent(parentType)
      if (!parentName) return
    }

    if (!devclass) {
      const packageResult = await this.server.objectFinder.findObject(
        "Select package",
        PACKAGE
      )
      if (!packageResult) return
      devclass = packageResult.name
    }
    if (parentType === PACKAGE) parentName = devclass</details>
github marcellourbani / vscode_abap_remote_fs / client / src / adt / abap / AbapClass.ts View on Github external
public async getChildren(
    client: ADTClient
  ): Promise {
    if (this.isLeaf()) throw FileSystemError.FileNotADirectory(this.vsName)
    if (!this.structure) await this.loadMetadata(client)
    if (!this.structure) throw FileSystemError.FileNotFound(this.vsName)

    const ns: NodeStructureMapped = {
      categories: new Map(),
      objectTypes: new Map(),
      nodes: []
    }
    const main = this.selfLeafNode()
    main.OBJECT_URI = ADTClient.mainInclude(this.structure)
    const sources = ADTClient.classIncludes(this.structure)
    this.structure.includes.forEach(i =&gt; {
      const node = {
        EXPANDABLE: "",
        OBJECT_NAME: this.name + "." + i["class:includeType"],
        OBJECT_TYPE: i["adtcore:type"],
        OBJECT_URI: sources.get(i["class:includeType"] as classIncludes) || "",
        OBJECT_VIT_URI: "",
        TECH_NAME: i["class:includeType"] // bit of a hack, used to match include metadata
      }
      if (node.OBJECT_URI) {
        if (i["abapsource:sourceUri"] === "source/main") ns.nodes.unshift(node)
        else ns.nodes.push(node)
      }
    })

    const aggregated = aggregateNodes(ns, this.type)
github marcellourbani / vscode_abap_remote_fs / client / src / adt / AdtServer.ts View on Github external
public async saveFile(
    file: AbapNode,
    content: Uint8Array,
    uri: Uri
  ): Promise {
    if (file.isFolder) throw FileSystemError.FileIsADirectory()
    if (!isAbapNode(file))
      throw FileSystemError.NoPermissions("Can only save source code")

    const obj = file.abapObject
    if (!obj.structure) await file.stat(this.client)
    const lm = LockManager.get()

    // check file is locked. Waits if locking is in progress
    if (!(await lm.getFinalStatus(uri)))
      throw adtException(`Object not locked ${obj.type} ${obj.name}`)

    const transport = await this.selectTransportIfNeeded(
      obj,
      lm.getTransport(uri)
    )

    if (!transport.cancelled) {
      let lockId = lm.getLockId(uri)
      try {
        await this.runInSession(client =&gt;
          obj.setContents(client, content, lockId, transport.transport)
        )
      } catch (e) {
        if (isExpired(e) || e.type === LOCKEXPIRED) {
          if (await reconnectExpired(uri)) {
            lockId = lm.getLockId(uri)
github marcellourbani / vscode_abap_remote_fs / client / src / adt / AdtServer.ts View on Github external
public async relogin() {
    this.currentCancel.cancel()
    this.currentCancel = new CancellationTokenSource()
    this.currentCall = Promise.resolve()
    if (this.mainClient.stateful === session_types.stateful) {
      try {
        this.mainClient.stateful = session_types.stateless
        // juts in case I have pending locks...
        await this.mainClient.logout()
      } catch (error) {
        // ignore
      }
      await this.mainClient.login()
    }
  }
github marcellourbani / vscode_abap_remote_fs / client / src / adt / operations / AdtObjectActivator.ts View on Github external
public async activate(object: AbapObject, uri: Uri) {
    // TODO: handle multiple inactive components
    const inactive = object.getActivationSubject()
    let result
    let message
    try {
      result = await this.client.activate(inactive.name, inactive.path)
      if (result.inactive.length > 0) {
        const inactives = inactiveObjectsInResults(result)
        result = await this.client.activate(inactives)
      }
    } catch (e) {
      if (isAdtError(e) && e.type === "invalidMainProgram") {
        const provider = IncludeLensP.get()
        const mainProg = await provider.selectIncludeIfNeeded(uri)
        if (mainProg)
          result = await this.client.activate(
            inactive.name,
            inactive.path,
            mainProg
          )
      } else message = e.toString()
    }
    if (result && result.success) {
      await inactive.loadMetadata(this.client)