You can define named constants by declaring a variable with the VALUE attribute. If you use static variables with the INITIAL attribute and you do not alter the variable, you should declare the variable a named constant using the VALUE attribute. The compiler does not treat NONASSIGNABLE scalar STATIC variables as true named constants.
The compiler generates better code whenever expressions are evaluated during compilation, so you can use named constants to produce efficient code with no loss in readability. For example, identical object code is produced for the two usages of the VERIFY built-in function in the following example:
dcl numeric char value('0123456789');
jx = verify( string, numeric );
jx = verify( string, '0123456789' );
The following examples illustrate how you can use the VALUE attribute to get optimal code without sacrificing readability.
dcl x bit(8) aligned; select( x ); when( '01'b4 ) . . . when( '02'b4 ) . . . when( '03'b4 ) . . . end;
dcl ( a1 init( '01'b4)
,a2 init( '02'b4)
,a3 init( '03'b4)
,a4 init( '04'b4)
,a5 init( '05'b4)
) bit(8) aligned static nonassignable;
dcl x bit(8) aligned;
select( x );
when( a1 )
.
.
.
when( a2 )
.
.
.
when( a3 )
.
.
.
end;
dcl ( a1 value( '01'b4)
,a2 value( '02'b4)
,a3 value( '03'b4)
,a4 value( '04'b4)
,a5 value( '05'b4)
) bit(8);
dcl x bit(8) aligned;
select( x );
when( a1 )
.
.
.
when( a2 )
.
.
.
when( a3 )
.
.
.
end;