Skip to main content

Run TSO commands via IKJEFT1B

Project description

batchtsocmd

Run TSO and Db2 commands via IKJEFT1B with automatic encoding conversion.

Description

batchtsocmd is a Python utility for z/OS that executes TSO commands through IKJEFT1B with automatic ASCII/EBCDIC encoding conversion. It handles SYSIN and SYSTSIN inputs from files, automatically converting them to EBCDIC as needed.

The package includes two main commands:

  • batchtsocmd - General TSO command execution
  • db2 - Simplified Db2 command execution via DSNTEP2

Features

  • Execute TSO commands via IKJEFT1B
  • Execute Db2 SQL commands via DSNTEP2
  • Automatic ASCII to EBCDIC conversion for input files
  • Optional STEPLIB support
  • Optional DBRMLIB support
  • Configurable output destinations (SYSTSPRT, SYSPRINT)
  • Environment variable support for Db2 parameters
  • Stdin piping support for SQL commands
  • Verbose mode for debugging

Requirements

  • Python 3.8 or higher
  • z/OS operating system
  • IBM Z Open Automation Utilities (ZOAU)
  • zoautil-py package
  • zos-ccsid-converter package

Installation

Note: This package can only be installed and run on z/OS systems.

pip install batchtsocmd

Usage

batchtsocmd - General TSO Command Execution

Basic Usage

batchtsocmd --systsin systsin.txt --sysin input.txt

With Output Files

batchtsocmd --systsin systsin.txt --sysin input.txt \
            --systsprt output.txt --sysprint print.txt

With STEPLIB and Verbose Output

batchtsocmd --systsin systsin.txt --sysin input.txt \
            --steplib DB2V13.SDSNLOAD --verbose

With STEPLIB and DBRMLIB

batchtsocmd --systsin systsin.txt --sysin input.txt \
            --steplib DB2V13.SDSNLOAD --dbrmlib DB2V13.DBRMLIB

With Concatenated STEPLIB Datasets

batchtsocmd --systsin systsin.txt --sysin input.txt \
            --steplib DB2V13.SDSNLOAD:DB2V13.SDSNLOD2:DB2V13.SDSNLOD3

With Concatenated STEPLIB and DBRMLIB Datasets

batchtsocmd --systsin systsin.txt --sysin input.txt \
            --steplib DB2V13.SDSNLOAD:DB2V13.SDSNLOD2 \
            --dbrmlib DB2V13.DBRMLIB:DB2V13.DBRMLI2

Command Line Options

  • --systsin PATH - Path to SYSTSIN input file (required)
  • --sysin PATH - Path to SYSIN input file (required)
  • --systsprt PATH - Path to SYSTSPRT output file or 'stdout' (optional, defaults to stdout)
  • --sysprint PATH - Path to SYSPRINT output file or 'stdout' (optional, defaults to stdout)
  • --steplib DATASET - Optional STEPLIB dataset name(s). Use colon (:) to concatenate multiple datasets (e.g., DB2V13.SDSNLOAD or DB2V13.SDSNLOAD:DB2V13.SDSNLOD2)
  • --dbrmlib DATASET - Optional DBRMLIB dataset name(s). Use colon (:) to concatenate multiple datasets (e.g., DB2V13.DBRMLIB or DB2V13.DBRMLIB:DB2V13.DBRMLI2)
  • -v, --verbose - Enable verbose output

Notes

  • Input files can be ASCII (ISO8859-1) or EBCDIC (IBM-1047)
  • Encoding is auto-detected via file tags; untagged files are assumed to be EBCDIC
  • Output files will be tagged as IBM-1047
  • Both --systsprt and --sysprint default to 'stdout'
  • When stdout is used, SYSTSPRT output is written first, then SYSPRINT output

db2 - Db2 Command Execution

The db2 command provides a simplified interface for executing Db2 SQL commands via DSNTEP2.

Basic Usage

# Using command line options
db2 --system DB2P --plan DSNTEP12 --toollib DSNC10.DBCG.RUNLIB.LOAD \
    --sysin query.sql

# Using environment variables
export DB2_SYSTEM=DB2P
export DB2_PLAN=DSNTEP12
export DB2_TOOLLIB=DSNC10.DBCG.RUNLIB.LOAD
db2 --sysin query.sql

# Using stdin pipe
echo "SELECT * FROM SYSIBM.SYSTABLES;" | db2 --system DB2P \
    --plan DSNTEP12 --toollib DSNC10.DBCG.RUNLIB.LOAD

# With STEPLIB
db2 --system DB2P --plan DSNTEP12 --toollib DSNC10.DBCG.RUNLIB.LOAD \
    --sysin query.sql --steplib DB2V13.SDSNLOAD

# With DBRMLIB directory
db2 --system DB2P --plan DSNTEP12 --toollib DSNC10.DBCG.RUNLIB.LOAD \
    --sysin query.sql --dbrmlib /u/myuser/dbrmlib

# With concatenated STEPLIB datasets
db2 --system DB2P --plan DSNTEP12 --toollib DSNC10.DBCG.RUNLIB.LOAD \
    --sysin query.sql --steplib DB2V13.SDSNLOAD:DB2V13.SDSNLOD2

Command Line Options

  • --system ID - Db2 subsystem ID (or set DB2_SYSTEM env var) (required)
  • --plan NAME - Db2 plan name (or set DB2_PLAN env var) (required)
  • --toollib LIB - Db2 tool library (or set DB2_TOOLLIB env var) (required)
  • --sysin PATH - Path to SYSIN input file (optional, reads from stdin if not specified)
  • --systsprt PATH - Path to SYSTSPRT output file or 'stdout' (optional, defaults to stdout)
  • --sysprint PATH - Path to SYSPRINT output file or 'stdout' (optional, defaults to stdout)
  • --steplib DATASET - Optional STEPLIB dataset name(s). Use colon (:) to concatenate multiple datasets
  • --dbrmlib DATASET - Optional DBRMLIB dataset name(s) or directory (or set DB2_DBRMLIB env var). Use colon (:) to concatenate multiple datasets
  • -v, --verbose - Enable verbose output

Environment Variables

  • DB2_SYSTEM - Default Db2 subsystem ID
  • DB2_PLAN - Default Db2 plan name
  • DB2_TOOLLIB - Default Db2 tool library
  • DB2_DBRMLIB - Default DBRMLIB dataset or directory

Note: Command line options override environment variables.

DBRMLIB Handling

The --dbrmlib option (or DB2_DBRMLIB environment variable) can specify:

  • A dataset name (no slash): DB2V13.DBRMLIB
  • Multiple datasets (colon-separated): DB2V13.DBRMLIB:DB2V13.DBRMLI2
  • A directory path (contains slash): /u/myuser/dbrmlib
    • When a directory is specified, the command scans for .dbm files and uses them as datasets

Notes

  • Input can be from a file (--sysin) or stdin (pipe)
  • SQL commands are automatically padded to 80 bytes per line
  • Output files will be tagged as IBM-1047
  • Both --systsprt and --sysprint default to 'stdout'
  • When stdout is used, SYSTSPRT output is written first, then SYSPRINT output

Python API

You can also use the db2cmd function directly in Python:

from batchtsocmd.main import db2cmd

# Using content string
rc = db2cmd(
    sysin_content="SELECT * FROM SYSIBM.SYSTABLES;",
    system="DB2P",
    plan="DSNTEP12",
    toollib="DSNC10.DBCG.RUNLIB.LOAD",
    steplib="DB2V13.SDSNLOAD",
    verbose=True
)

# Using file
rc = db2cmd(
    sysin_file="query.sql",
    system="DB2P",
    plan="DSNTEP12",
    toollib="DSNC10.DBCG.RUNLIB.LOAD"
)

db2cmd Parameters

  • sysin_content - SQL commands as a string (mutually exclusive with sysin_file)
  • sysin_file - Path to file containing SQL commands (mutually exclusive with sysin_content)
  • system - Db2 subsystem ID (required)
  • plan - Db2 plan name (required)
  • toollib - Db2 tool library (required)
  • dbrmlib - Optional DBRMLIB dataset(s) - single string or list for concatenation
  • steplib - Optional STEPLIB dataset(s) - single string or list for concatenation
  • systsprt_file - Output destination for SYSTSPRT (default: 'stdout')
  • sysprint_file - Output destination for SYSPRINT (default: 'stdout')
  • verbose - Enable verbose output

License

Apache License 2.0

Author

Mike Fulton

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

batchtsocmd-0.1.10.tar.gz (30.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

batchtsocmd-0.1.10-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file batchtsocmd-0.1.10.tar.gz.

File metadata

  • Download URL: batchtsocmd-0.1.10.tar.gz
  • Upload date:
  • Size: 30.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/34.0 requests/2.32.5 requests-toolbelt/1.0.0 urllib3/2.6.0 tqdm/4.67.1 importlib-metadata/8.7.0 keyring/25.7.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.13.1

File hashes

Hashes for batchtsocmd-0.1.10.tar.gz
Algorithm Hash digest
SHA256 2a19bffb2469ecd3eda9c0f1df6e5fadc35a8cf88a0e10df2619a29e0a7514c2
MD5 cdd7b8e042167afdf6b68030b65ff526
BLAKE2b-256 1196b7df5fd45ee866f4a789a84e529ffe488c3ac74692f7f01bfa67ba5d55b7

See more details on using hashes here.

File details

Details for the file batchtsocmd-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: batchtsocmd-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/34.0 requests/2.32.5 requests-toolbelt/1.0.0 urllib3/2.6.0 tqdm/4.67.1 importlib-metadata/8.7.0 keyring/25.7.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.13.1

File hashes

Hashes for batchtsocmd-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 663a5034203b7288115de81cdf000ee7bdbaac74f4a0bef6c4e0d8ec360173e0
MD5 5578a039f356229ab737d74e9b2ff99d
BLAKE2b-256 054684b4c6a3fbedd6ec48c4cc8c7fac26163eb4b8f96302b64cd50ef778ab79

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page