HOME  NEWS  FORUM  DOWNLOAD  LINK
OpenCOBOL - an open-source COBOL compiler
Main Menu
Download
Documentation
Development
Who's Online
21 user(s) are online (9 user(s) are browsing Forum)

Members: 1
Guests: 20

human, more...
Powered by
SourceForge

Xoops

Creative Commons

OpenCOBOL Forum Index
   OpenCOBOL
     No Bug with OCCURS DEPENDING ON with INITIALIZE
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
human
Posted on: 2009/10/27 14:27
Home away from home
Joined: 2007/5/15
From:
Posts: 967
Online
No Bug with OCCURS DEPENDING ON with INITIALIZE
If you MOVE something to a table that length was defined via DEPENDING ON, all seems fine (only the defined length is used). But if you do an INITIALIZE the whole table is used.

The code
      *-----------------------------------------------------------------
       IDENTIFICATION DIVISION.
       PROGRAM-ID.    INITTST.
       DATA DIVISION.
      *
       WORKING-STORAGE SECTION.
       77  TAB-AKT     pic 9(01) value 0.
       01  TAB-test.
           05 filler occurs 0 to 5 depending on TAB-AKT.
              10 ta    pic x value 'A'.
              10 t9    pic 9 value 9.
       77  omitted-var pic x.
      *-----------------------------------------------------------------
       PROCEDURE DIVISION.
      *-----------------------------------------------------------------
       main section.
       00.
           display ' '
           end-display
           display 'Tab with Length 0:'
           end-display
           move all 'B' to TAB-test
           display 'Here comes Tab-Test "' tab-test '"'
           end-display

           initialize TAB-test
           display 'Here comes Tab-Test "' tab-test '"'
           end-display

           initialize TAB-test all to value
           display 'Here comes Tab-Test "' tab-test '"'
           end-display
           
           
           move 2 to TAB-AKT
           
           display ' '
           end-display
           display 'Tab with Length 2:'
           end-display
           move all 'B' to TAB-test
           display 'Here comes Tab-Test "' tab-test '"'
           end-display

           initialize TAB-test
           display 'Here comes Tab-Test "' tab-test '"'
           end-display

           initialize TAB-test all to value
           display 'Here comes Tab-Test "' tab-test '"'
           end-display
           
           
           display ' '
           end-display
           display 'Tab with different Length, displayed 4:'
           end-display
           
           
           move 3 to TAB-AKT
           move all 'B' to TAB-test
           move 4 to TAB-AKT
           display 'Here comes Tab-Test "' tab-test '"'
           end-display

           move 2 to TAB-AKT
           initialize TAB-test
           move 4 to TAB-AKT
           display 'Here comes Tab-Test "' tab-test '"'
           end-display

           move 1 to TAB-AKT
           initialize TAB-test all to value
           move 4 to TAB-AKT
           display 'Here comes Tab-Test "' tab-test '"'
           end-display

           accept omitted-var
           end-accept
      *
           continue.
       ex. stop run.
      *-----------------------------------------------------------------
      *--- End of program INITTST --------------------------------------


Leads to Quote:
$>cobc -Debug -x -W INITTST.COB
$>INITTST.exe

Tab with Length 0:
Here comes Tab-Test ""
Here comes Tab-Test ""
Here comes Tab-Test ""

Tab with Length 2:
Here comes Tab-Test "BBBB"
Here comes Tab-Test " 0 0"
Here comes Tab-Test "A9A9"

Tab with different Length, displayed 4:
Here comes Tab-Test "BBBBBBA9"
Here comes Tab-Test " 0 0 0 0"
Here comes Tab-Test "A9A9A9A9"


I thought the last ones should be Quote:
Here comes Tab-Test "BBBBBBA9"
Here comes Tab-Test " 0 0BBA9"
Here comes Tab-Test "A9 0BBA9"

I was wrong, the current pre-release is fine, as Roger clarified in the next post.

human
simrw
Posted on: 2009/10/29 12:45
Webmaster
Joined: 2005/5/31
From: Bad Soden, Germany
Posts: 776
Re: Bug with OCCURS DEPENDING ON with INITIALIZE
You are (I think) :-)

Bill will correct me if I am wrong; however,
Micro Focus produces the same result.

It took a bit of digging in the proposed
COBOL standard (the one dated 2009-08-23)
to find the relevant rule.
It's actually under the discussion of the
VALUE clause at General Rules 13.18.62.3
paragraph 6.

Snip

6) If a VALUE clause is specified in a data description that also contains an OCCURS clause with the DEPENDING
phrase, the initialization of the associated data item behaves as if the value of the data item referenced by the
DEPENDING phrase in the OCCURS clause specified for the variable-occurrence data item is set to the
maximum number of occurrences as specified by that OCCURS clause. A data item is associated with an
occurs-depending table when a data item is one of the following:
a) a group data item that contains an occurs-depending table.
b) an occurs-depending table.
c) a data item that is subordinate to an occurs-depending table.


Roger
human
Posted on: 2009/10/29 13:21
Home away from home
Joined: 2007/5/15
From:
Posts: 967
Online
Re: NO Bug with OCCURS DEPENDING ON with INITIALIZE
I see, thank you for your answer! I'll changed the thread title to "No Bug".

human
Threaded | Newest First Previous Topic | Next Topic | Top

Register To Post
 
Copyright (C) 2005 The OpenCOBOL Project. All rights reserved.
Powered by Xoops2 | PHP | MySQL | Apache
ocean-net