Page 1 of 1

How to get difference between two current timstamp in cobol

PostPosted: Sat Jun 09, 2018 4:25 am
by dkuma14
I tried to search any information regarding this before posting here but unfortunately could not found.

Can someone please help on how to calculate difference between two timestamp.

Actually my requiremt is that My job should extract only those records from database which got processed (will be using database current timestamp) after last run of this job (here for last run I will be passing previous job run date as input which is last job run current timestamp).

Re: How to get difference between two current timstamp in co

PostPosted: Sat Jun 09, 2018 4:56 pm
by NicC
This is not a COBOL problem but an SQL problem which is why you did not find any examples (possibly). Try googling "select records greater than timestamp"

Re: How to get difference between two current timstamp in co

PostPosted: Sat Jun 09, 2018 5:18 pm
by dkuma14
Thanks for your response but it is not a db2 database but IMS.And moreover in my approach I need to check difference between two timestamp. One for processed date of transaction (this will be already present in an input file which is actual unload of that database) and second time stamp is of last run of my same job which will execute Cobol and second timestamp will be also coming from my another input file. Hence to summarise when this job run Cobol should consider those records only for processing which have processed date in input 1 after last run time. Right now I am using date format YYYY-MM-DD for processed date and last run. Then using function Integer of date (processed date) - function integer of date(last run) > 0 Then do Cobol logic. It’s working fine technically but it does not complete requirement completely. Suppose my job ran on 8 June around 14 PM , next day when it will run it will process only those records which got processed on 9th June after 00.01 and records which got processed on 8th June after 14 PM will not be processed which is incorrect, those record should also get processed actually.Hence need of comparing two timestamp will help and function Integer of date does not work on timestamp.

Re: How to get difference between two current timstamp in co

PostPosted: Sat Jun 09, 2018 5:35 pm
by enrico-sorichetti
convert the timestamps to seconds/milliseconds/microseconds whatever the timestamp precision dictates
compute the difference
convert the difference to the wanted units representation ...
seconds, minutes, hours, days

after that is just a programming exercise, You will find gazillions of examples googling

Re: How to get difference between two current timstamp in co

PostPosted: Sat Jun 09, 2018 7:37 pm
by Robert Sample
I think terminology is tripping you up. "Timestamp" is a term that has a very specific meaning and I don't think that meaning applies to what you are wanting to do.
Right now I am using date format YYYY-MM-DD for processed date and last run.
Why not have the last run as YYYY-MM-DD HH:MM:SS instead of just YYYY-MM-DD? Then your logic becomes
IF INPUT-DATE > LAST-RUN-DATE
    PROCESS THE RECORD
ELSE
    IF INPUT-DATE = LAST-RUN-DATE
    AND INPUT-TIME > LAST-RUN-TIME
        PROCESS THE RECORD
    END-IF
END-IF
Or you could use the LE run-time functions (such as CEESECS) to convert your date/time sets to Lillian format and compare the Lillian formats.

Re: How to get difference between two current timstamp in co

PostPosted: Sat Jun 09, 2018 8:26 pm
by dkuma14
Thanks Robert for your suggestion. Yes I saw some manual regarding CEESECS , will try it on Monday bcz Right now I can’t access mainframe . Your first approach looks simple and will suffix my requirement, my bad II didn’t think in this way. First I will try this approach. This is below I will do to achieve it, please correct me If I am going wrong.

WS-Processed-DT= 2018-06-08
WS-processed-time= 14:30:12 I will populate these two from my input 1 which have processed timestamp

We-lastrun-dt = 2018-06-08
WA-lastrun-time= 13:30:12. I will populate these two from my input 2 having last run timestamp

IF
WS-processed-dt > ws-lastrun-dt
Process the record
ELSE
IF ws-processed-dt = ws-lastrun-dt
AND ws-processed-time > ws-lastrun-Time
Process the record
END-IF
END-IF


In above scenarios ELSE part will be executed.