NESTED VARIABLE SIZED ARRAY - Need help on this



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

NESTED VARIABLE SIZED ARRAY - Need help on this

Postby hariharan_bk » Thu Mar 30, 2017 11:36 pm

Hi All,

Need help in handling one nested OCCURS array (variable length).

The first array has an element, which holds the number of occurrence for the second array. But this is not getting accepted in COBOL. Please help on this.


01 COUNT-1 PIC 9(3).

01 TABLE-1.  
   05 PHONE-DATA-1 OCCURS 0 TO 25 TIMES            
                     DEPENDING ON COUNT-1.
      10 PHONE-SUB-DATA-S.                                  
         15 COUNT-2 PIC S9(9) COMP-5 SYNC.
         15 TABLE-2.            
              20 PHONE-DATA-2  OCCURS 0 TO 25 TIMES              
                  DEPENDING ON COUNT-2.                                                            
                        25 PHN-NUM  PIC X(10).
 


ERROR DESC:
IGYGR1263-S "OCCURS DEPENDING ON" OBJECT "COUNT-2" WAS DEFINED AS
            TABLE ELEMENT.  THE "DEPENDING ON" PHRASE WAS DISCARDED.  



I tried the following in the second array, even then it failed
20 PHONE-DATA-2  OCCURS 0 TO 25 TIMES              
                  DEPENDING ON COUNT-2(COUNT-1)
 


ERROR DESC:
IGYDS1089-S "(" WAS INVALID.  SCANNING WAS RESUMED AT THE NEXT AREA "A" ITEM,  
            LEVEL-NUMBER, OR THE START OF THE NEXT CLAUSE.                    
                                                                               
IGYGR1263-S "OCCURS DEPENDING ON" OBJECT "COUNT-2" WAS DEFINED AS
            TABLE ELEMENT.  THE "DEPENDING ON" PHRASE WAS DISCARDED.          
 
Many Thanks,
Harry
hariharan_bk
 
Posts: 73
Joined: Thu Mar 29, 2012 11:13 am
Has thanked: 5 times
Been thanked: 0 time

Re: NESTED VARIABLE SIZED ARRAY - Need help on this

Postby Robert Sample » Fri Mar 31, 2017 12:28 am

What you want to do is not allowed in COBOL -- period. From page 201 of the 6.1 Language Reference manual (with emphasis added by me):
OCCURS DEPENDING ON clause
The OCCURS DEPENDING ON clause specifies variable-length tables.
data-name-1
Identifies the object of the OCCURS DEPENDING ON clause; that is, the
data item whose current value represents the current number of occurrences of the
subject item. The contents of items whose occurrence numbers exceed the value of the object are undefined.
The object of the OCCURS DEPENDING ON clause (data-name-1) must describe an integer data item.
The object of the OCCURS DEPENDING ON clause must not occupy any storage position within the range of the table (that is, any storage position
from the first character position in the table through the last character
position in the table).
The object of the OCCURS DEPENDING ON clause cannot be variably
located; the object cannot follow an item that contains an OCCURS
DEPENDING ON clause
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: NESTED VARIABLE SIZED ARRAY - Need help on this

Postby BillyBoyo » Fri Mar 31, 2017 2:38 am

Perhaps you can describe what you are trying to represent. Why do you need OCCURS DEPENDING ON at all?

If you do nest OCCURS DEPENDING ON, I am prepared to bet it won't do what you imagine. Each entry in your subordinate OCCURS item will be the same length, although that length will change each time you change the ODO item.

Are you trying to do something with XML generation? Otherwise, I can't think of a need. And if you are after XML structures, do all the preparation in fixed-length tables, and only as the last think put the data into the nested ODO, with the length of the nested OCCURS known (same length for each item).
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: NESTED VARIABLE SIZED ARRAY - Need help on this

Postby hariharan_bk » Fri Mar 31, 2017 2:22 pm

Yes. We are working with JSON data. The input we receive is JSON and we are working with CICS assistant to get it converted to COBOL COPYBOOK.
The conversion things are working. But it ended in nested arrays.
Many Thanks,
Harry
hariharan_bk
 
Posts: 73
Joined: Thu Mar 29, 2012 11:13 am
Has thanked: 5 times
Been thanked: 0 time

Re: NESTED VARIABLE SIZED ARRAY - Need help on this

Postby hariharan_bk » Fri Mar 31, 2017 2:26 pm

{
              "name": "m_field1",
              "complexType": {
                "sequence": {
                  "element": {
                    "name": "entry",
                    "minOccurs": "0",
                    "maxOccurs": "unbounded",
                    "complexType": {
                      "sequence": {
                        "element": [
                          {
                            "name": "key",
                            "minOccurs": "0",
                            "type": "string"
                          },
                          {
                            "name": "value",
                            "minOccurs": "0",
                            "type": "FieldTO"
                          }
                        ]
                      }
                    }
                  }
                }
              }
            },

{
        "name": "FieldTO",
        "sequence": {
          "element": [
            {
              "name": "Name",
              "type": "string",
              "minOccurs": "0"
            },
            {
              "name": "Value",
              "type": "anyType",
              "minOccurs": "0"
            },
            {
              "name": "messageList",
              "type": "tns:MsgTO",
              "nillable": "true",
              "minOccurs": "0",
              "maxOccurs": "unbounded"
            }
          ]
        }
      },
{
        "name": "MsgTO",
        "sequence": {
          "element": [
            {
              "name": "msg_num",
              "type": "integer"
            },
            {
              "name": "msg_dsc",
              "type": "string",
              "minOccurs": "0"
            }
          ]
        }
      },



Above is a small snippet of the schema. This is how our input data structure looks like.
Many Thanks,
Harry
hariharan_bk
 
Posts: 73
Joined: Thu Mar 29, 2012 11:13 am
Has thanked: 5 times
Been thanked: 0 time

Re: NESTED VARIABLE SIZED ARRAY - Need help on this

Postby Robert Sample » Fri Mar 31, 2017 5:44 pm

What does the schema you posted have to do with the original post?

Nested OCCURS DEPENDING ON variables are really difficult to work with. For example, in your original post for you to change the value of COUNT-1, you first have to move all occurrences of TABLE-2 to a work area, change the COUNT-1 variable, and then move the TABLE-2 data back -- and this is assuming you create an 01 level for COUNT-2 to get rid of the illegal structure you posted. I've used them a few times in my 40+ years of COBOL coding, and it is always difficult to get them to work correctly without overlaying data.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: NESTED VARIABLE SIZED ARRAY - Need help on this

Postby BillyBoyo » Sat Apr 01, 2017 9:47 pm

What you want to do is not going to work by using nested ODO tables, because those simply don't work (COBOL Standard) to how those JSON definitions can operate. You need a structure that has a different number of items in the subordinate ODO entries, and that is just not possible. Each subordinate entry will be the same length, at any given moment, and the length of each entry will change, all of them, each time you change the ODO item.

I'd suggest a "windowing" approach (nothing to do with Windows in Windows or any other OS, they stole our perfectly good word after already using it for many years).

By this I mean define the nested part of your structure, non-nested, and change the start of the structure so that it can point to a specific JSON-sub-structure. When yoouu've finished with that JSON-sub-structure, point the start of your structure to the start of the next JSON-sub-structure.

You used to be able to do this with REDEFINES directly, but since the 1986 Standard, IBM loosened the hold on their Language Extension which allowed use of a REDEFINES of an ODO. So...

You use a LINKAGE SECTION structure to do an "implicit REDEFINES", and change the address of the start of that structure to match the start of the data you want to map for processing.

If you are new to this, set up a very simple equivalent structure and write a program to understand that very simple structure. Once you understand the processing to represent that data, then you should be able to apply it yourself to the JSON.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post