Click here for Watson System Resources sponsor message

Clocks, TRIM and debugging

By Shawn M. Gordon

This month I was going to share some readers’ tips with you – and I have one, but I am very embarrassed to say that I lost the other. I told you about a reader who sent me a tip on doing mapped file access in COBOL. I saved his e-mail, and was sitting down to write this month’s issue, and I could not find it anywhere. I am going to blame the new version of Compuserve software that I installed, because I’m sure it couldn’t have been my fault. But if the gentleman is reading this column, please send your tip to me again so I can share it with everyone (and you can get your HP 3000 Always Online cap!).

I do have one reader tip, one COBOL enhancement suggestion and a COBOL debugging tip. Reader Victor Lu of See’s Candies sent me the following:

I finally got to read the issue of the 3000 NewsWire with your “Readying COBOL for Year 2000.” I think you need to warn readers about the danger of calling function CURRENT DATE, since it reads the hardware clock instead of the OS clock, and the possibility to mess things up by changing the OS clock for daylight savings without changing the hardware clock.

Victor Lu
See’s Candies


Victor brings up a very good point that I forgot about since I got my system clock correct. The CURRENT-DATE function does a couple of things: first, it checks the TimeZone variable TZ, to find out what your offset is from GMT; and second it returns the value that you see from SHOWCLOCK instead of SHOWTIME. So if TZ is not set correctly, or if you don’t have daylight savings set up correctly, then you will return the wrong time.

Now this isn’t that big a deal if you are just worried about getting the date, but it is if you are working around midnight – the date returned could be wrong. In some cases the clock is so far off that you could be months off using the CURRENT-DATE function. There is no perfect solution here, but one thing that I have started doing is using the FUNCTION CURRENT-DATE to get the full date and time. Then I use the COBOL ACCEPT FROM DATE and ACCEPT FROM TIME to overwrite everything but the century that was returned by CURRENT-DATE. It’s probably a good idea to check your system to make sure that the date and time are right.

How about a TRIM?

This next bit is a letter that I wrote in the middle of last year to be submitted to the COBOL ANSI committee for consideration in the next version of COBOL. I don’t want to get into a wish list situation, but I wouldn’t mind hearing other people’s suggestions, and I can forward the information. It may not be too late to get some of this stuff put in. I’m not sure of the current status on the new COBOL release, but it’s still supposed to be out around the year 2000.

COBOL needs to borrow a few commands from Visual Basic. We need a way to TRIM leading spaces, trailing spaces, or remove all spaces. These all could be supported by enhancing the INSPECT command so you could modify a string with separate lengths, i.e., converting " " to "", but it’s important that it doesn’t take ““ to be NULL. I have suffered with this for a long time.

This could even be a new FUNCTION, something like:

STRING FUNCTION(RTRIM(VAR1)) DELIMITED BY SIZE
VAR2 DELIMITED BY SPACES INTO VAR3

to trim trailing spaces and append two strings together.

Debugging tips

There is a neat little bit of code that you can add to your program so that if you run it with a PARM=1 you can see the flow through your paragraphs. This can help you to see if you are falling through in areas you’re not expecting, or exactly how to get somewhere. There are two pieces of code that you need to add to have this work for you. The first is the WITH DEBUGGING MODE on the SOURCE-COMPUTER line. The second is the DECLARATIVES and the inclusion of a DEBUG SECTION.

Take a look at the code below for a sample and a run sample of the program. I would actually be very interested in any tips that show other ways to use the DECLARATIVES section, so if you know anything, send it in and get a free hat and the admiration of thousands.

SOURCE-COMPUTER. HP-3000 WITH DEBUGGING MODE.
OBJECT-COMPUTER. HP-3000.

PROCEDURE DIVISION.
DECLARATIVES.
DEBUG SECTION.
USE FOR DEBUGGING ON ALL PROCEDURES.
000-DEBUG-TRACE.
DISPLAY DEBUG-NAME DEBUG-CONTENTS “ LINE = “ DEBUG-LINE.
END DECLARATIVES.
MYPROG-SECT01 SECTION 1.
A0000-MACROS.
A1000-OPEN.
DISPLAY “MYPROG (C) 1998 S.M.Gordon & Associates”.
PERFORM H1000-HELP THRU H1000-EXIT.
A1000-PROMPT.

do all your code here.....

RUN MYPROG;PARM=1
MYPROG-SECT01 START PROGRAM LINE = 014600
A0000-MACROS FALL THROUGH LINE =013000
A1000-OPEN FALL THROUGH LINE =013000
MYPROG (C) 1998 S.M.Gordon & Associates
H1000-HELP PERFORM LOOP LINE =014700
H1000-EXIT FALL THROUGH LINE =042900
A1000-PROMPT FALL THROUGH LINE = 014700

There is actually one other debugging tip you can use in this scenario. I’ll give you a hint, it has to do with putting a D in column 7. I’ll cover it next month, so stay tuned.

Don’t forget, if your tips make it into The Wire, you get a free 3000 Always Online hat. Send them to me at smga@compuserve.com, or fax them to the NewsWire at 512.331.3807.

Shawn M. Gordon, whose S.M. Gordon & Associates firm supplies HP 3000 utilities, has worked with 3000s since 1983.


Copyright 1998, The 3000 NewsWire. All rights reserved.