Page 1 of 1

Passing default value to variable

PostPosted: Thu Mar 12, 2020 6:25 pm
by arya_starc
Hi All,

I have defined one below variable in my program in working section. I need to initialize or pass the default values to the variable before using it without using INITIALIZE syntax of cobol.


011900 01  ORG-COUNTS.                                            
012000     03  CARD-TYPE           OCCURS 8 TIMES                
012200                             INDEXED BY CARD-TYPE-IDX.      
012300         05  ACT-CNT             OCCURS 90 TIMES            
012400                                 INDEXED BY ACT-CNT-IDX    
012500                                 PIC S9(12) COMP-3.        
012600*                                                          
 

Simply move statement like below is not working as expected.


 001112 106412    MOVE ZEROES TO ORG-COUNTS.  
 


Kindly suggest.

Thanks in advance.

Re: Passing default value to variable

PostPosted: Thu Mar 12, 2020 6:55 pm
by Robert Sample
You need to review the internal structure of variables in COBOL. Your MOVE ZEROES TO ORG-COUNTS statement is moving to a group and hence zoned decimal zeroes will be moved. Since your elementary variables are packed decimal (COMP-3) and not zoned decimal, none of your elementary variables will be valid.

Re: Passing default value to variable

PostPosted: Thu Mar 12, 2020 7:34 pm
by Terry Heinze
Is there a reason for not using COBOL's INITIALIZE statement?

Re: Passing default value to variable

PostPosted: Thu Mar 12, 2020 7:50 pm
by arya_starc
Hi Terry,

The reason for not using INITIALIZE that I am measuring optimization by not considering INITIALIZE verb.
In my lots of application program the same way is used for passing default value.
I just want to check by not using INITIALIZE and measure the performance.

Re: Passing default value to variable

PostPosted: Thu Mar 12, 2020 7:54 pm
by arya_starc
Robert Sample wrote:You need to review the internal structure of variables in COBOL. Your MOVE ZEROES TO ORG-COUNTS statement is moving to a group and hence zoned decimal zeroes will be moved. Since your elementary variables are packed decimal (COMP-3) and not zoned decimal, none of your elementary variables will be valid.



Thanks for Suggestion Mr. Sample.

But out of curiosity, Is there any way I can pass default value to elementary variables which are packed decimal(COMP-3)("considering by not changing the internal structures of variables").

Re: Passing default value to variable

PostPosted: Thu Mar 12, 2020 8:25 pm
by Robert Sample
You are wasting time doing things that have already been done. A 2010 Share Anaheim paper on COBOL performance (Google cobol initialize vs move and look for the COBOL Performance Tuning Paper) has this:
Performance considerations for INITIALIZE on a program
that has 5 OCCURS clauses in the group:
• When each OCCURS clause in the group contained 100
elements, a MOVE to the group was 8% faster than an
INITIALIZE of the group.
• When each OCCURS clause in the group contained 1000
elements, a MOVE to the group was 23% faster than an
INITIALIZE of the group.


Is there any way I can pass default value to elementary variables which are packed decimal(COMP-3)("considering by not changing the internal structures of variables").
Yes -- first, note that PIC S9(12) COMP-3 is not recommended since packed decimal variables should ALWAYS have an odd number of digits in their PICTURE. PIC S9(12) COMP-3 with a value of zero has internal representation of X'0000000000000C' so if you code
MOVE ALL X'0000000000000C' TO ORG-COUNTS
all of the table elements will be initialized to zeroes. Note that this only works as long as all the table entries have the same PICTURE; otherwise, you have to code up a hexadecimal string that has all the variables for a single occurrence of the table and MOVE ALL on that string (it could be a variable, which might make it easier).

Re: Passing default value to variable

PostPosted: Fri Mar 13, 2020 12:09 am
by arya_starc
Hi Mr Sample,

Thanks for sharing Anaheim paper quote.
It will be good to implement if it had been already proven that Move statement is more faster than INITIALIZE.
This will help in improve the overall cpu performance.