[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference clt::cobol

Title:VAX/DEC COBOL
Notice:Kit,doc,performance talk info-->DIR/KEY=KIT or DOC or PERF_TALK
Moderator:PACKED::BRAFFITT
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3250
Total number of notes:13077

3249.0. "Group Initialization problem" by CSC32::J_HEISLER () Thu Jun 05 1997 16:15

Hi,

I could use some help.  I have a customer who provided me with the following 
example.  If I uncomment out the initialize statement the output (out1) is
printing out portions of the 2nd records ($0.00).  With the initialize state
of the group element commented out the correct (out2) record is printed out.
I know that initializing a group will only initialize with alphanumeric and he 
is using numeric and character data in the records but I can't explain why 
writting out record 1 appears to be also writting out a portion of record 2.

Thanks for the help,
Jim Heisler
LST Support Team

--

IDENTIFICATION DIVISION.
PROGRAM-ID. DEC_TEST.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT ODEC-FILE ASSIGN TO "DEC-TEST.RPT".
DATA DIVISION.
FILE SECTION.
FD  ODEC-FILE.
01  LP-FILE-1.
    02  ODEC-1A                   PIC 9(4).
    02  ODEC-2A                   PIC X.
    02  ODEC-3A                   PIC 9(3).
01  LP-FILE-2.
    02  ODEC-1B                   PIC X(24).
    02  ODEC-2B                   PIC $$$9.999.
WORKING-STORAGE SECTION.
01  COUNTER                   PIC 99.
PROCEDURE DIVISION.
START-OF-PROGRAM.
    OPEN OUTPUT ODEC-FILE.
    PERFORM WRITE-FILE THRU WRITE-FILE-EXIT VARYING COUNTER FROM 1 BY 1
            UNTIL COUNTER = 4.
WRITE-FILE.
                            Press RETURN to continue
*    INITIALIZE LP-FILE-1.
*    INITIALIZE LP-FILE-2.
    MOVE 9999 TO ODEC-1A.
    MOVE "-" TO ODEC-2A.
    MOVE 999 TO ODEC-3A.
    WRITE LP-FILE-1 BEFORE ADVANCING 2 LINES.
    INITIALIZE LP-FILE-1.
    MOVE "XXXXXXXXXXXXXXXXXXXXXXXX" TO ODEC-1B.
    MOVE 9999999 TO ODEC-2B.
    WRITE LP-FILE-2 BEFORE ADVANCING 4 LINES.
WRITE-FILE-EXIT.
    EXIT.
FINISH-PROGRAM.
    CLOSE ODEC-FILE.
    STOP RUN.
------

(out1) * bad output here when group is initialized:

9999-999                  $0.000

XXXXXXXXXXXXXXXXXXXXXXXX$999.000



9999-999                  $0.000

XXXXXXXXXXXXXXXXXXXXXXXX$999.000



9999-999                  $0.000

XXXXXXXXXXXXXXXXXXXXXXXX$999.000



9999-999                  $0.000

XXXXXXXXXXXXXXXXXXXXXXXX$999.000

---

(out2) correct output here when group is not initialized:

9999-999

XXXXXXXXXXXXXXXXXXXXXXXX$999.000



9999-999XXXXXXXXXXXXXXXX$999.000

XXXXXXXXXXXXXXXXXXXXXXXX$999.000



9999-999XXXXXXXXXXXXXXXX$999.000

XXXXXXXXXXXXXXXXXXXXXXXX$999.000



9999-999XXXXXXXXXXXXXXXX$999.000

XXXXXXXXXXXXXXXXXXXXXXXX$999.000
T.RTitleUserPersonal
Name
DateLines
3249.1Get fixed-length by defaultWIBBIN::NOYCEPulling weeds, pickin' stonesThu Jun 05 1997 16:4421
>out2) correct output here when group is not initialized:
>
>9999-999
>
>XXXXXXXXXXXXXXXXXXXXXXXX$999.000
>
>
>
>9999-999XXXXXXXXXXXXXXXX$999.000
>
>XXXXXXXXXXXXXXXXXXXXXXXX$999.000
>

Well, the first like "looks nicer", but the third line seems to show
that the problem isn't really solved.  I suspect the first line only
looks nice because the PIC $$$9.999 item wasn't properly initialized.

I think that your FD needs to say "RECORD CONTAINS 8 to 32 CHARACTERS"
or "RECORD IS VARYING IN SIZE" or something -- otherwise COBOL defaults
to using fixed-length records, whose length is as long as the longest
record given.  The various record formats all overlay each other...
3249.2RECORD IS VARYING gives consistent resultsPACKED::BRAFFITTThu Jun 05 1997 16:5646
>or "RECORD IS VARYING IN SIZE" or something -- otherwise COBOL defaults
    
    I verified Bill's suggestion with both VAX COBOL and DEC COBOL with and
    without INITIALIZE.  All 4 cases give identical results if you include
    
    	RECORD IS VARYING.
    
IDENTIFICATION DIVISION.
PROGRAM-ID. DEC_TEST.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT ODEC-FILE ASSIGN TO "DEC-TEST.RPT".
DATA DIVISION.
FILE SECTION.
FD  ODEC-FILE RECORD IS VARYING.
01  LP-FILE-1.
    02  ODEC-1A                   PIC 9(4).
    02  ODEC-2A                   PIC X.
    02  ODEC-3A                   PIC 9(3).
01  LP-FILE-2.
    02  ODEC-1B                   PIC X(24).
    02  ODEC-2B                   PIC $$$9.999.
WORKING-STORAGE SECTION.
01  COUNTER                   PIC 99.
PROCEDURE DIVISION.
START-OF-PROGRAM.
    OPEN OUTPUT ODEC-FILE.
    PERFORM WRITE-FILE THRU WRITE-FILE-EXIT VARYING COUNTER FROM 1 BY 1
            UNTIL COUNTER = 4.
WRITE-FILE.
\I	INITIALIZE LP-FILE-1.
\I	INITIALIZE LP-FILE-2.
    MOVE 9999 TO ODEC-1A.
    MOVE "-" TO ODEC-2A.
    MOVE 999 TO ODEC-3A.
    WRITE LP-FILE-1 BEFORE ADVANCING 2 LINES.
    INITIALIZE LP-FILE-1.
    MOVE "XXXXXXXXXXXXXXXXXXXXXXXX" TO ODEC-1B.
    MOVE 9999999 TO ODEC-2B.
    WRITE LP-FILE-2 BEFORE ADVANCING 4 LINES.
WRITE-FILE-EXIT.
    EXIT.
FINISH-PROGRAM.
    CLOSE ODEC-FILE.
    STOP RUN.
3249.3ADVANCING could be the culpritPACKED::BLATTThu Jun 05 1997 21:5716
Another thing I noticed is that when the program says ADVANCING
on the WRITE statement, that is a request for a VFC file.
Normally, two record description entries of different sizes
mean a variable-length record, but ADVANCING takes priority
and produces a VFC file, which means the entire buffer is
used for each WRITE statement.    It sounds like they are
expecting variable-length behavior.

If it is declared as RECORD IS VARYING (or remove the ADVANCING
clauses), then you will generate a true variable length record.
WRITEing the short record will only produce those characters
in the short-buffer.  WRITEing the long record will produce all 
the characters in the buffer.  When the delta of the short and the long
have spaces, it "looks nice" as .1 said, but that is still
data being written out.