Skip to content
This repository was archived by the owner on Aug 27, 2019. It is now read-only.

Run ABL code example

zerovian edited this page Jun 28, 2019 · 10 revisions

Following is an example of how to use the Run ABL Code task

    import io.gitlab.grabl.*
    apply plugin: 'io.gitlab.grabl.grabl'
    apply plugin: 'base'


    task createDB(type: CreateDatabase) {
        dbName = "sports2020"
        destDir = "${buildDir}/db"
        sourceDb = "$System.env.DLC/sports2020"
        largeFiles = true
    }

    task connectDB(type: DBConnection) {
        dependsOn createDB
        dbName = 'sports2020'
        dbDir = "${buildDir}/db/"
        id = 'sports2020'
        singleUser = true
    }

    task runABL(type : RunAbl) {
        dependsOn connectDB

        procedure = file("src/abl/ablrun.p").path
        dbConnections << 'sports2020'
    }

    build {
        dependsOn runABL
    }

    clean {
        delete "${buildDir}"
    }

    defaultTasks 'clean', 'build'

There are a lot of properties available. See the documentation for PCT Run for the full set.

Troubleshooting PCTRun

If your procedure successfully runs, but you still get a PCTRun returned 1 error, then pay attention to the documentation for PCTRun. It expects that your procedure returns a string indicating the return code.

The following is an example of ABL code that can be run that prints the customer names to a file. notice the last line of the file returns a 0. Without this, the build would fail with an error.

output to "build\output.txt".

for each customer no-lock:
    message customer.name.
end.

output close.

return "0"

Enabling the profiler

By default the profiler is not enabled when ABL code is executed. You can enable it using the following example. The profiler will generate it's output to the specified output. Other options such as listings, enabled, description, coverage, and statistics options are supported.

    task runABL(type : RunAbl) {

        procedure = file("src/abl/ablrun.p").path

        profiler {
            outputDir = file("${buildDir}/test/profiler")
        }
    }

Working with environment variables

It is possible to set environment variables individually or as a map. The environment variables will be passed to the AVM when it is launched. The ABL run task starts with the set of environment variables set as defaults assigned through the abl defaults task. Any environment variables assigned at the task replace or add to the default list.

When assigning the environment property, all previous values are removed, and the contents of the environment map are copied internally.

Environment variable map example

    task runABL(type : RunAbl) {

        procedure = file("src/abl/ablrun.p").path

        environment = ["bob" : "marley", "jim" : "morris"]
    }

Using environment variables.

You can set individual environment variables by calling the 'env' function on the RunAbl task. This accepts two strings, one for the key, and one for the value of the parameter.

When the "env" function is invoked. An environment variable is added to the existing set of environment variables

    task runABL(type : RunAbl) {

        procedure = file("src/abl/ablrun.p").path

        env ("bob", "marley")
        env ("jim", "morris")
    }

Clone this wiki locally