Domanda

Ciao a tutti. Sto avendo un po 'di problemi in un progetto di codifica che sto cercando di affrontare nell'ambiente zOS usando COBOL. Ho bisogno di leggere un file in e metterli in una tabella indicizzata (So che ci saranno meno di 90 record).

La cosa che mi sta gettando è che siamo legati dai parametri del progetto di utilizzare una variabile chiamata "Table-Size" (set a zero in dichiarazione).

Dato tutto questo, ho bisogno di fare qualcosa di simile "si verifica 1 a 90 volte a seconda del Tabella-Size", ma non capisco come ciò funzionerà se la tabella di dimensioni deve (per quanto posso dire) perché la tabella di formato viene incrementato oltre ad ogni voce che viene aggiunto alla tabella. Qualcuno può azzerare questo per me?

Grazie!

È stato utile?

Soluzione

It sounds like your primary concern is: how does the compiler know how much to allocate in the array if the size changes at run-time?

The answer is that it allocates the maximum amount of space (enough for 90 entries). Note that this is for space in working storage. When the record is written to a file, only the relevant portion is written.

An example:

01  TABLE-SIZE  PIC 9
01  TABLE OCCURS 1 TO 9 TIMES DEPENDING ON TABLE-SIZE
    03 FLD1  PIC X(4)

This will allocate 36 characters (9 multiplied by 4) for TABLE in working storage. If TABLE-SIZE is set to 2 when the record is written to a file, only 8 characters of TABLE will be written (over and above the characters written for TABLE-SIZE, of course).

So, for example, if the memory occupied by TABLE was AaaaBbbbCcccDdddEeeeFfffGgggHhhhIiii, the date written to the file may be the shortened (including size): 2AaaaBbbb.

Similarly, when the record is read back in, both TABLE-SIZE and the relevant bits of TABLE will be populated from the file (setting only the size and first two elements).

I don't believe that the unused TABLE entries are initialised to anything when that occurs. It's best to assume not anyway, and populate them explicitly if you need to add another item to the table.

For efficiency, you may want to consider setting the TABLE-SIZE to USAGE IS COMP.

Altri suggerimenti

We don't have quite enough information here, but the basic thing is that the variable named in the DEPENDING ON clause has to have a count of the variable number of groups. So you need something like

01   TABLE-SIZE     PIC 99
01   TABLE OCCURS 1 TO 90 TIMES
       DEPENDING ON TABLE-SIZE
    03 FIELD-1
    03 FIELD-2

and so on.

See this article or this article at Publib.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top