PL/I

PL/I

PL/I

 View Only
  • 1.  EPLI, named constants & "like"

    Posted Thu May 28, 2015 08:33 AM

    Hi community,

    I'm trying to get rid of all those "magic numbers" in our code and therefor create name constants wherever i can. 

    To make the named constants unique i put e.g. the db2-table-name into the constants name.

    Sometimes magic numbers are used in several tables and i thought about the following (just a cut-to-minimal sample):

    dcl 1 tablex_sex,
            2 male char(1) value('m'),
            2 female char(1) value('f'),
            2 undefined char(1) value('x');
    dcl  tabley_sex like tablex_sex;
    if x = tabley_sex.male then ... << compiler error "IBM1766I-Value for tabley_sex.male must be evaluated before its first use"

    I think i understand that there are reasons for named constants and "like" not working well together, but i see no real "showstopper".

    Is there a way to make this or at least something similar work?

    br johann

    [edit 2015.06.09] fixed typo in "dcl tabley_sex ..."

    woecki


  • 2.  Re: EPLI, named constants & "like"

    Posted Thu June 04, 2015 11:17 PM

    DECLARE 1 tabley_sex like tablex_sex;

     

    may well be better, as in your example, every level would be "2" and so there's no corresponding structure.

    Robin400


  • 3.  Re: EPLI, named constants & "like"

    Posted Tue June 09, 2015 05:01 AM

    Hi Robin,

    Thanks for pointing out the typo! Fixed it.

    But the question remains (even if might be a stupid one).
    What i wanted to achieve is that tablex_sex and table_y sex are both bundles of constants with equal values but different names. From a memory-consumption - point-of-view this would be some waste. But readability and maintainability would improve.

    br Johann

     

    woecki


  • 4.  Re: EPLI, named constants & "like"

    Posted Tue June 09, 2015 11:05 PM

    A name with the VALUE attribute is merely an alias.

    By itself, it takes up no memory at run time.

     

    You use the name in some other (computational) statement,

    and the constant is inserted there.  That's where some run-time

    is used.

    Robin400


  • 5.  Re: EPLI, named constants & "like"

    Posted Wed June 10, 2015 07:44 AM

    Hi Robin,

    I was pretty sure that i saw the named constant in the memory map when i played around with my sample code, but i'm unable to reproduce and your explanation makes perfect sense.

    Thanks for pointing out!

    I still cannot achieve what i want :-( but got a better understanding how named constant work :-).

    br johann

     

    woecki