Passing default value to variable



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

Passing default value to variable

Postby arya_starc » Thu Mar 12, 2020 6:25 pm

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.
arya_starc
 
Posts: 136
Joined: Mon Sep 21, 2015 1:39 pm
Has thanked: 5 times
Been thanked: 0 time

Re: Passing default value to variable

Postby Robert Sample » Thu Mar 12, 2020 6:55 pm

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.
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: Passing default value to variable

Postby Terry Heinze » Thu Mar 12, 2020 7:34 pm

Is there a reason for not using COBOL's INITIALIZE statement?
.... Terry
Terry Heinze
 
Posts: 239
Joined: Wed Dec 04, 2013 11:08 pm
Location: Richfield, MN, USA
Has thanked: 12 times
Been thanked: 11 times

Re: Passing default value to variable

Postby arya_starc » Thu Mar 12, 2020 7:50 pm

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.
arya_starc
 
Posts: 136
Joined: Mon Sep 21, 2015 1:39 pm
Has thanked: 5 times
Been thanked: 0 time

Re: Passing default value to variable

Postby arya_starc » Thu Mar 12, 2020 7:54 pm

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").
arya_starc
 
Posts: 136
Joined: Mon Sep 21, 2015 1:39 pm
Has thanked: 5 times
Been thanked: 0 time

Re: Passing default value to variable

Postby Robert Sample » Thu Mar 12, 2020 8:25 pm

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).
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: Passing default value to variable

Postby arya_starc » Fri Mar 13, 2020 12:09 am

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.
arya_starc
 
Posts: 136
Joined: Mon Sep 21, 2015 1:39 pm
Has thanked: 5 times
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post