MainframeSupports
tip week 39/2012:
If you ever were in a situation where you wanted to retrieve a timestamp in DB2 format,
but you did not have access to DB2, then this tip can help you. The following assembler
program called TMSTMP may be called from COBOL or PL/I and return a timestamp in DB2 format.
The program is reentrant and can be used in CICS programs. It will also continue to work
after the seventh of september 2042 where the original time format called TOD wraps around:
* NAME : TMSTMP
* FUNCTION : THIS SUBROUTINE RETURNS A LOCAL TIMESTAMP IN DB2 FORMAT.
* CALL CBL : CALL TMSTMP USING TIMESTMP
* CALL PLI : CALL TMSTMP(TIMESTMP)
* REMARKS : PROGRAM IS FULLY REENTRANT.
* PARAMETERS: THE PARAMETERS PASSED TO THIS SUBROUTINE ARE DEFINED AS
* FOLLOWS:
* TIMESTMP DS CL32 THE STORAGE WHERE THE TIMESTAMP IS STORED
* IN THE FIRST 26 BYTES AND THE REMAINING
* 6 BYTES ARE USED AS WORK AREA.
*
* REG-15 WILL CONTAIN THE FOLLOWING RETURN CODE:
* 0: TIMESTAMP WAS SUCCESSFULLY RETRIEVED
* IN THE FOLLOWING COMMENTS TIMESTMP FORMAT=YYYY-MM-DD-TT.MI.SS.ABCDEF
TMSTMP CSECT MY NAME IS ...
TMSTMP AMODE ANY I CAN LIVE IN HEAVEN..
TMSTMP RMODE ANY ..OR THAT OTHER PLACE
BAKR R14,0 ESA STYLE SAVE
BASR R12,0 ADDRESS THIS CSECT
USING *,R12 AH .. ADDRESSABILITY
L R2,0(R1) R2->TIMESTMP
TIME DEC,(R2),ZONE=LT,LINKAGE=SYSTEM,MF=(E,(R2)), X
DATETYPE=YYYYMMDD
UNPK 13(13,R2),0(7,R2) D2C OF TIME-PORTION
L R3,8(R2) MOVE DATE-PORTION ...
ST R3,9(R2) ... ONE BYTE TO THE RIGHT
UNPK 0(9,R2),9(5,R2) D2C OF DATE-PORTION
LH R3,4(R2) R3=MM
LH R4,6(R2) R4=DD
MVI 4(R2),C'-' PUT DASH AFTER YYYY
STH R3,5(R2) PUT MM IN CORRECT POSITION
MVI 7(R2),C'-' PUT DASH AFTER MM
STH R4,8(R2) PUT DD IN CORRECT POSITION
MVI 10(R2),C'-' PUT DASH AFTER DD
MVC 11(2,R2),13(R2) MOVE TT TO CORRECT POSITION
MVI 13(R2),C'.' PUT DOT AFTER T
MVC 14(2,R2),15(R2) MOVE MI TO CORRECT POSITION
MVI 16(R2),C'.' PUT DOT AFTER MI
L R3,19(R2) R3=ABCD
LH R4,23(R2) R4=EF
MVI 19(R2),C'.' PUT DOT AFTER SS
ST R3,20(R2) MOVE ABCD TO CORRECT POSITION
STH R4,24(R2) MOVE EF TO CORRECT POSITION
SR R15,R15 RC=0
TMSTMPR EQU *
PR RETURN TO CALLER
LTORG
YREGS
END
I have tried to comment the program after by best abilities. The most important point is
that when you call the program from COBOL or PL/I you must call it using an area of 32 bytes.
In the first 26 bytes of this area the timestamp is returned. The remaining six bytes are
used by the TIME macro as a work area. I could have coded the program with a parameter of
only 26 bytes, but then the program had to allocate a work area for the TIME macro. It would
have complicated the program and made it a little slower.
If you prefer to call a timestamp program with a parameter of 26 bytes, then you can
create a program in COBOL or PL/I which accepts a 26 bytes parameter. In this program you
define a local variable of 32 bytes which you use to call TMSTMP. When the timestamp is
returned to your program you simply move the first 26 bytes from the local variable to the
26 bytes parameter of the program.
TMSTMP returns a timestamp using the local time (ZONE=LT on the TIME macro). If you want
to return the GMT time instead, you just replace ZONE=LT with ZONE=GMT.
Previous tip in english
Forrige danske tip
Tip list