CA Easytrieve for Windows batch/cmd sample

Document ID : KB000032869
Last Modified Date : 14/02/2018
Show Technical Document Details

Introduction:

 

This document describes how to compile and run a CA Easytrieve program via Windows cmd file in batch mode.

The ERRORLEVEL will be checked too - that means if for instance the compile fails, the procedure stops the batch process.

The compile output will be copied to a ...\LOG\ folder.

SYSPRINT will be copied to the ...\LOG\ folder too - but need CA Easytrieve build 13080 installed at least.

Also a Microsoft SORT step is included in this sample.

 

Note: This is just a sample - use at your own risk!

 

 

 

Instructions:

 

  1. Create some folders  


 

  1. Create test data

 

 


 

 

  1. Create a simple CA Easytrieve test program

 

 


...

 

 

  1. Create a cmd file - ezt_pgm1.cmd

 


 

Description

 

Here you can set the

-          program name

-          project path

-          file names used in the Easytrieve program and SORT below

-          also setting a SORT start value

 

à

 

REM ----------------------------------------------------------------------

REM setting user variables                                             >>>

REM ----------------------------------------------------------------------

 

SET eztpgm=CA_cmd_test_pgm1

SET ProjectPath=C:\Easytrieve\CA_cmd_test_project1

SET INFILE1=%ProjectPath%\DATA\test_data1.txt

SET SORTIN=%ProjectPath%\DATA\sortin.txt

SET SortStart=5

SET SORTOUT=%ProjectPath%\DATA\sortout_%SortStart%.txt

 

REM ----------------------------------------------------------------------

REM setting user variables                                             <<<

REM ----------------------------------------------------------------------

 

When you are compiling Easytrieve programs using the ezt line command as shown below, then you have to copy the options table to the working directory - inclusive ErrorLevel checking..

This is done in the next part - that way you are always using the current EZOPTBL from the Easytrieve bin folder.

à

 

REM ----------------------------------------------------------------------

REM COPY EZOPTBL to compile directory                                  >>>

REM ----------------------------------------------------------------------

 

SET EZTPATH="C:\Program Files (x86)\CA\Easytrieve\bin"

SET StepName="COPY EZOPTBL"

copy %EZTPATH%\EZOPTBL %ProjectPath%\EZT\

if ERRORLEVEL 1 GOTO ErrorLabel

echo COPY EZOPTBL done.

 

REM ----------------------------------------------------------------------

REM COPY EZOPTBL to compile directory                                  <<<

REM ----------------------------------------------------------------------

 

The next part is only required if you would like to add a date/time stamp to the compile listing output file name à

 

REM ----------------------------------------------------------------------

REM setting up date/time stamp                                         >>>

REM ----------------------------------------------------------------------

 

SET DT=%date%_%TIME%

SET DT=%DT:/=%

SET DT=%DT:-=%

SET DT=%DT::=%

SET DT=%DT:.=%

SET DT=%DT:,=.%

SET DT=%DT: =%

 

REM ----------------------------------------------------------------------

REM setting up date/time stamp                                         <<<

REM ----------------------------------------------------------------------

 

The compile command - inclusive ErrorLevel checking à

 

REM ----------------------------------------------------------------------

REM compile EZT #1 - copy BBBB and CCCC records from INFILE1 to SORTIN >>>

REM ----------------------------------------------------------------------

 

SET StepName="Easytrieve Compile"

ezt %ProjectPath%\EZT\%eztpgm%.ezt -P -L >> %ProjectPath%\LOG\%DT%_CMPLST.txt

if ERRORLEVEL 1 GOTO ErrorLabel

echo Easytrieve Compile done

echo see %ProjectPath%\LOG\%DT%_CMPLST.txt

 

 

REM ----------------------------------------------------------------------

REM compile EZT #1 - copy BBBB and CCCC records from INFILE1 to SORTIN <<<

REM ----------------------------------------------------------------------

 

 

Execute the Easytrieve PCO file - inclusive ErrorLevel checking and copying SYSPRINT to the ...\LOG\ folder and adding a date/time stamp à

 

REM ----------------------------------------------------------------------

REM execute EZT #1 - copy BBBB and CCCC records from INFILE1 to SORTIN <<<

REM ----------------------------------------------------------------------

 

SET StepName="Execute Easytrieve program"

ezterp %ProjectPath%\EZT\%eztpgm%.pco

if ERRORLEVEL 1 GOTO ErrorLabel

copy %ProjectPath%\EZT\SYSPRINT %ProjectPath%\LOG\%DT%_SYSPRINT.txt

del %ProjectPath%\EZT\SYSPRINT

echo Easytrieve program has ended successfully.

 

REM ----------------------------------------------------------------------

REM execute EZT #1 - copy BBBB and CCCC records from INFILE1 to SORTIN <<<

REM ----------------------------------------------------------------------

 

 

SORT the SORTIN file which has been created by the eztpgm above à

 

REM ----------------------------------------------------------------------

REM SORT - sort SORTIN to SORTOUT                                      >>>

REM ----------------------------------------------------------------------

 

SET StepName="SORT"

SORT %SORTIN% /O %SORTOUT% /+%SortStart%

if ERRORLEVEL 1 GOTO ErrorLabel

echo SORT program has ended successfully.

 

REM ----------------------------------------------------------------------

REM SORT - sort SORTIN to SORTOUT                                      <<<

REM ----------------------------------------------------------------------

 

PAUSE

EXIT 

 

If no error was encountered it stops here.

Of course you could add more Easytrieve and more SORT steps.

 

If an error was encountered, the following will be executed à

 

:ErrorLabel

powershell -Command Write-Host "************************ Error ************************" -foreground "Red"

 

echo in Step:    %StepName%

 

if %StepName% == "Easytrieve Compile" echo see: %ProjectPath%\LOG\%DT%_CMPLST.txt

 

if %StepName% == "Execute Easytrieve program" (

      echo see: %ProjectPath%\EZT\SYSPRINT

      copy %ProjectPath%\EZT\SYSPRINT %ProjectPath%\LOG\%DT%_SYSPRINT.txt

      del %ProjectPath%\EZT\SYSPRINT

)

 

echo stopping execution now.

 

powershell -Command Write-Host "************************ Error ************************" -foreground "Red

 

PAUSE

EXIT

 

 

  

  1. Run the CA_cmd_test_project1.cmd file

 

You should see the following if all worked fine à

 


 

Here are the folders after running the CA_cmd_test_project1.cmd file.

The EZT folder à

 

 


 

The LOG folder with the compile listing and SYSPRINT à

 

 


 

 

The DATA folder with SORTIN à

 


The DATA folder with SORTOUT à

 


 

All required files are attached to this email.

Please rename

CA_cmd_test_project1.txt

to

CA_cmd_test_project1.cmd

before using it. 

 

 

  1. If the compile fails

 


 


...

 

 

  1. If the excution fails

 


 

 


 

 

Additional Information:

 

All files you need for this test are attached here as "CA_test_project1.zip".

 

File Attachments:
TEC1860443.zip