Skip to content

Submitting JCL to a Server

You can use the SubmitJCL method (function) from your program or script to submit JCL to a z/OS server. A situation where you might use SubmitJCL is when a program or script, that runs from Windows Task Scheduler, needs to submit a nightly batch job to a z/OS server.

The following scripts illustrate how to submit JCL to a z/OS server.

...

C# Example

...

/**********************************************************************
* C# Example
*
* File Name: SubmitJcl.cs
*
* Description: Submit job to server.
*
* Usage: SubmitJcl <server> <file.name>
*
* Copyright ©2007, Serena Software. Licensed material. All rights reserved.
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using ZosApi;

namespace SubmitJcl
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //////////////////////////////
                // Get command line arguments
                //////////////////////////////

                if (args.Length < 2)
                {
                    Console.WriteLine("Usage: SubmitJcl <server> <file.name>");
                    Environment.Exit(1);
                }
                String serverName = args[0];
                String fileName = args[1];

                //////////////
                // Submit JCL
                //////////////

                ZosNetwork network = new ZosNetwork();
                ZosServer server = network.Servers[serverName];

                ZosJesJob[] jobs = server.SubmitJcl(fileName);

                foreach (ZosJesJob job in jobs)
                {
                    Console.WriteLine("Job submitted: JobName={0} JobID={1}",
                        job.JobName,
                        job.JobID);
                 }
            }

            catch (Exception e)
            {
            Console.WriteLine(e.Message);
            Console.WriteLine(e.TargetSite);
            }
        }
    }
}

...

Visual Basic Example

...

' Visual Basic Example
'
' File Name: SubmitJcl.vb
'
' Description: Submit job to server.
'
' Usage: SubmitJcl <server> <file.name>
'
' Copyright ©2007, Serena Software. Licensed material. All rights reserved.
'**********************************************************************
Imports System
Imports ZosApi

Module SubmitJcl

    Sub Main()

        Try

            '----------------------------
            ' Get command line arguments
            '----------------------------

            Dim args As String() = Environment.GetCommandLineArgs()

            If args.Length < 3

            Console.WriteLine("Usage: SubmitJcl <server> <file.name>")
            Environment.Exit(1)

            End If

            Dim serverName As String = args(1)
            Dim fileName As String = args(2)

            '------------
            ' Submit JCL
            '------------

            Dim network As ZosNetwork = new ZosNetwork()
            Dim server As ZosServer = network.Servers(serverName)

            Dim suppressMessage As Boolean = false

            Dim jobs() as ZosJesJob = server.SubmitJcl(fileName)

            Dim job As ZosJesJob

            For Each job In jobs

                Console.WriteLine("Job submitted: JobName={0} JobID={1}", _
                    job.JobName, _
                    job.JobID)
            Next

        Catch e As Exception

            Console.WriteLine(e.Message)
            Console.WriteLine(e.TargetSite)

        End Try

    End Sub

End Module

...

JScript Example

...

/**********************************************************************
* JScript Example
*
* File Name: SubmitJcl.js
*
* Description: Submit job to server.
*
* Usage: SubmitJcl <server> <file.name>
*
* Copyright ©2007, Serena Software. Licensed material. All rights reserved.
**********************************************************************/
import System;
import ZosApi;

try
{
    //////////////////////////////
    // Get command line arguments
    /////////////////////////////
    /

    var args : String[] = Environment.GetCommandLineArgs();

    if (args.Length < 3)
    {
        Console.WriteLine("Usage: SubmitJcl <server> <file.name>");
        Environment.Exit(1);
    }
    var serverName : String = args[1];
    var fileName : String = args[2];

    //////////////
    // Submit JCL
    //////////////

    var network : ZosNetwork = new ZosNetwork();
    var server : ZosServer = network.Servers[serverName];

    var jobs: ZosJesJob[] = server.SubmitJcl(fileName);

    for (var job in jobs)
    {
    Console.WriteLine("Job submitted: JobName={0} JobID={1}",
        job.JobName,
        job.JobID);
    }
}
catch (e : Exception)
{
    Console.WriteLine(e.Message);
    Console.WriteLine(e.TargetSite);
}
Back to top