HP3000-L Archives

May 2008, Week 4

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Walter J. Murray" <[log in to unmask]>
Reply To:
Walter J. Murray
Date:
Wed, 21 May 2008 22:42:09 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (114 lines)
Michael,

The compiler probably gave you a warning 55, "LEFT TRUNCATION MAY
OCCUR", on that MOVE statement, didn't it?  That may be exactly what
happened.

Here's a sample program that demonstrates the problem you probably
encountered, along with a technique I've recently used to expose such a
problem.  The size error phrase in my COMPUTE statement will cause the
entire receiving field to be filled with asterisks if it can't hold the
sending field.

-----cut here-----
IDENTIFICATION DIVISION.
 PROGRAM-ID. OVERFLOW-TEST.
 DATA DIVISION.
 WORKING-STORAGE SECTION.
 01  MYTEST        PIC S9(14)V9(4) COMP-3 VALUE 0.
 01  DISP-TOTAL    PIC ---------9.9999.
 PROCEDURE DIVISION.
 BEGIN.
     MOVE 12340000000000.0000 TO MYTEST
*
*    Following will experience left truncation
*    and display an incorrect answer.
*
     MOVE MYTEST TO DISP-TOTAL
     DISPLAY "DISP-TOTAL = " DISP-TOTAL
*
*    Following will flag the problem.
*
     COMPUTE DISP-TOTAL = MYTEST
         SIZE ERROR
             MOVE ALL "*" TO DISP-TOTAL (1:)
     END-COMPUTE
     DISPLAY "DISP-TOTAL = " DISP-TOTAL
*
     STOP RUN.
 END PROGRAM OVERFLOW-TEST.
-----cut here-----

Walter  

Walter J. Murray

-----Original Message-----
From: HP-3000 Systems Discussion [mailto:[log in to unmask]] On
Behalf Of Michael Anderson
Sent: Friday, May 16, 2008 10:25 AM
To: [log in to unmask]
Subject: [HP3000-L] Cobol Question

I consider myself an experienced Cobol Programmer,
but I seem to be missing something here.

Here's the question: In the following example an IF statement

"IF MYTEST <> 0" (IT IS TRUE),
then when MYTEST is moved to Disp-Total it displays 0.0000
What am I missing here?

 01 MYTEST PIC S9(14)V9(4) COMP-3 VALUE 0.
 01 CREDIT PIC S9(14)V9(4) COMP-3 VALUE 0.
 01 DEBIT  PIC S9(14)V9(4) COMP-3 VALUE 0.
 01 Disp-Total         Pic ---------9.9999.
 01 TRANST-AMOUNT PIC S9(9)V99.

Then the following is done while reading G/L transactions.
     INITIALIZE MYTEST CREDIT DEBIT.
 FTN2020.
D    DISPLAY "FTN2020".
     PERFORM GET-TRANST-CHAINED.
     IF END-OF-CHAIN GO TO FTN2040.
     IF TRANST-AMOUNT > 0 ADD TRANST-AMOUNT TO DEBIT.
     IF TRANST-AMOUNT < 0 ADD TRANST-AMOUNT TO CREDIT.
     GO TO FTN2020.

 FTN2040.
D    DISPLAY "FTN2040".
     COMPUTE MYTEST = DEBIT + CREDIT.
     IF MYTEST <> 0 GO TO FTN2090.
     MOVE "XX" TO BATCHX-CLEANBATCH.
     PERFORM LOCK-BATCHX.
     PERFORM UPDATE-BATCHX.
     PERFORM UNLOCK-BATCHX.
     GO TO FTN2000.
 FTN2090.
D    DISPLAY "FTN2090".
     MOVE "X" TO MYSWITCH.
     MOVE MYTEST TO Disp-Total.
     MOVE BATCHX-BATCH TO Disp-BATCH.
     Initialize BMT-STR.
     String "BATCH " Disp-BATCH
             " is out-of-balance by " Disp-Total
      DELIMITED BY SIZE INTO BMT-STR.
     PERFORM SHOW-BMT.
     GO TO FTN2000.

What the user sees is

BATCH     1 is out-of-balance by   0.0000

If any Cobol experts on the list can make sense of this, I would
appreciate the enlightenment ;-)

Thanks,
Mike.

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2