Inside Cobol #48 (Readers tips)
Shawn Gordon
The Kompany

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 email, 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 CIS 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.

So we have one reader tip, one COBOL enhancement suggestion from me, and a COBOL debugging tip. Reader Victor Lu of See’s Candies sent me the following;

Hi Shawn:

Finally got to read this issue of 3000 NewsWire and 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 of changing OS clock for daylight savings without changing the hardware clock to mess things up too.

Just a suggestion. Thanks.
Victor Lu / See’s Candies

Victor brings up a very good point that I had forgotten about ever 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, second it’s returning 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, then 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 use 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 is right.

This next bit is a letter that I wrote in the middle of last year to be submitted to the COBOL ANSI comittee 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 on. 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 around the year 2000.

Actually COBOL needs to borrow a few commands from VB. We need a way to TRIM leading spaces, trailing spaces, 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, so something like;


to trim trailing spaces and append two strings together.

Now for some 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 your not expecting, or exactly how you get some where. 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 figure 1 for a code 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.

There is actually one other debugging use you can use in this scenario, but I am limited on space. I’ll give you a hint, it has to do with putting a D in column 7. I’ll try to cover that next month, stay tuned.

Figure 1



  MYPROG-SECT01            SECTION 1.
     DISPLAY "MYPROG (C) 1998 S.M.Gordon & Associates".
     PERFORM H1000-HELP    THRU H1000-EXIT.

do all your code here.....

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