Tuesday, August 4, 2015

Can we delay the execution of a mainframe job?OPSWAIT is an option

Have you ever tried to keep a job or certain steps in a job to wait for sometime and then execute without using any scheduler ?

When would it be useful to ask mainframes to sleep like this?

Few days back ,came across a specific scenario when it was needed to put a job step on hold for sometime and then execute it.

Say for unit testing you want to execute two jobs in certain instance to check dataset conflict or table conflict.
Suppose we have a job with 3  steps. We want to execute step1 an then wait for sometime, say 1 minute, and then execute the remaining 2 steps. How do we do it ?

OPSWAIT is the option which can help us in this scenario.  (We need CA tool to be installed in our environment).
The OPSWAIT function suspends processing of the program or rule for a specified period in an OPS/REXX program or REQ rule.This  function can be used in OPS/REXX, AOF rules, TSO/E REXX, or CLIST.

//Jobcard..
//PSTEP01 EXEC PGM=TSTPGM
...
//PSTEP02  EXEC PGM=OPSWAIT,PARM='FOR(01:00)'
//PSTEP03  EXEC PGM=TSTPGM2
....
Once you submit this JCL, it till execute the step PSTEP01,then it will cause the mainframe to sleep for 1 min and then execute step 2.
We can try this command going into TSO command (option 6) and typing OPSWAIT 01:00.(01=mins,00=seconds)

We can also use this JCL to put the program on hold.
//SLEEP EXEC PGM=IKJEFT01 
//SYSPRINT DD SYSOUT=* 
//SYSTSPRT DD SYSOUT=* 
//SYSTSIN DD * 
OPSWAIT FOR(01:10) 
//* 

Saturday, August 1, 2015

Date functions in cobol. Why and when do we use IGZEDT4 ,CEELOCT , CURRENT-DATE ?

We come across certain instance when we need to get the time/date in certain formats in cobol.
We all know that we can get the dates in cobol using ACCEPT verb in the following way.
                        ACCEPT WS-DATE FROM DATE
But we would not get it in the format we prefer to use ,say in the format YYYYMMDD.
DATE has the picture clause of PIC 9(6). So when we use the above cobol statement, we would get the date in the format like below when read  sequentially from left to right:
First 2 digits for the year of the century, next 2 for the month and next 2 digits with the date.
Example: This if the current date is 25-JUL-1994, we would get  as 940725.

VS cobol II does not support the date format giving results in YYYY format. However the results can be interpolated in many ways to get our desired result.Some of the utilities are described below.

For NON LE Cobol Environment 
1.IBM has offered a non-LE callable interface known as  IGZEDT4 which can be used to achieve our
desired function.  When we call it , it will give the desired result in the YYYYMMDD format.

01  WS-YYYYMMDD                         PIC  9(08).
01  WS-DATE-IGZEDT4                     PIC  X(08) VALUE 'IGZEDT4'.
*
CALL WS-IGZEDT4      USING WS-YYYYMMDD

2.  Another way to do this is to use the LE callable function CEELOCT. We need to check with the mainframe infrastructure team to know if LE is optionally installed in our LPAR. If yes, then we can call this function which returns the result in the format of YYYYMMDD.  CEELOCT returns the result in 3 formats.
 a: Lilian  Date
 b.Lilian Seconds
 c. Gregorian  character strings.
It also returns the feedback code(CEE000 if call is successful)  which decides whether the function executed successfully or not.

WORKING-STORAGE SECTION.
01 WS-LILIAN PIC S9(9) COMP.
01 WS-XSECONDS PIC S9(18) COMP.
01 WS-GREGORN PIC X(17).
01 WS-FC.
    03 CEEIGZCT-RC PIC X.
        88 CEE000 VALUE LOW-VALUE.
PROCEDURE DIVISION.
       MAIN-SECTION.
           CALL 'CEELOCT' USING WS-LILIAN
                                WS-XSECONDS
                                WS-GREGORN
                                WS-FC
           IF CEE000 OF WS-FC
             DISPLAY 'Time: '    WS-GREGORN
           ELSE
             DISPLAY 'CEELOCT error' UPON CONSOLE
           END-IF

For LE enabled environment

3.  CURRENT-DATE  FUNCTION has been introduced after cobol II, which makes life much simpler. It is a 21 byte alphanumeric value which contains the below fields when read from left to right .

01  WS-CURRENT-DATE-FIELDS.
             05  WS-CURRENT-DATE.
                 10  WS-CURRENT-YEAR    PIC  9(4).
                 10  WS-CURRENT-MONTH   PIC  9(2).
                 10  WS-CURRENT-DAY     PIC  9(2).
             05  WS-CURRENT-TIME.
                 10  WS-CURRENT-HOUR    PIC  9(2).
                 10  WS-CURRENT-MINUTE  PIC  9(2).
                 10  WS-CURRENT-SECOND  PIC  9(2).
                 10  WS-CURRENT-MS      PIC  9(2).
             05  WS-DIFF-FROM-GMT       PIC S9(4).
 We need to use the cobol code like below and use the appropriate values as per our requirement.
 MOVE FUNCTION CURRENT-DATE TO WS-CURRENT-DATE-FIELDS