Topic
  • 22 replies
  • Latest Post - ‏2014-05-28T21:18:28Z by JerryG2
JerryG2
JerryG2
3 Posts

Pinned topic WITH Block for referencing Qualified Data Sructures

‏2014-02-01T09:17:08Z |

(Is this the place to offer a Request For Enhancement for RPG?)

I like the clarity provided by using Qualified Data Structures, but sometimes they can become cumbersome, particularly when you have multiple levels and possibly multiple occurrences of data items. 

How about a WITH control block, which would define a level of qualification to be applied to all the statements within the block?

For example, instead of:

IF    ddgTermsArray.ddgTermsRec(i).trTermYears < cPermanentTagYears;
  dsTermsArray.ValidTermEntry(j).teTermExpireDate
      =   ZeroDate
        + %YEARS(*YEAR)
        + %YEARS(ddgTermsArray.ddgTermsRec(i).trTermYears)
        - %YEARS(wAdjustment1);
  dsTermsArray.ValidTermEntry(j).teTermExpireDate
      = dsTermsArray.ValidTermEntry(j).teTermExpireDate
        + %MONTHS(ddgExpireMonth) - %MONTHS(1);
  dsTermsArray.ValidTermEntry(j).teTermExpireDate
      = dsTermsArray.ValidTermEntry(j).teTermExpireDate
        + %DAYS(ddgExpireDay) - %DAYS(1);
  dsTermsArray.ValidTermEntry(j).teTermDescr
      = gTermStandrdzd + ' (Expires '
      + %CHAR(dsTermsArray.ValidTermEntry(j).teTermExpireDate) + ')';
ELSE;
  dsTermsArray.ValidTermEntry(j).teTermExpireDate = cHighDate;
  dsTermsArray.ValidTermEntry(j).teTermDescr
      = gTermStandrdzd + ' (' + cPermanentTagExpLabel + ')';
ENDIF;

... we might see something like this:

WITH dsTermsArray.ValidTermEntry(j) DO;
  IF    ddgTermsArray.ddgTermsRec(i).trTermYears < cPermanentTagYears;                                    
    teTermExpireDate               
        =   ZeroDate
          + %YEARS(*YEAR)                                         
          + %YEARS(ddgTermsArray.ddgTermsRec(i).trTermYears)        
          - %YEARS(wAdjustment1);
    teTermExpireDate = teTermExpireDate + %MONTHS(ddgExpireMonth) - %MONTHS(1);                 
    teTermExpireDate = teTermExpireDate + %DAYS(ddgExpireDay) - %DAYS(1);                       
    teTermDescr      = gTermStandrdzd + ' (Expires ' + %CHAR(teTermExpireDate) + ')';
  ELSE;                                                             
    teTermExpireDate = cHighDate;
    teTermDescr      = gTermStandrdzd + ' (' + cPermanentTagExpLabel + ')'; 
  ENDIF;
ENDWITH;

... where all the items qualified by "dsTermsArray.ValidTermEntry(j)" are referenced with their lower-level names, saving us all the typing? The "WITH" would be a signal to the compiler to first look for data items within the named data structure.

Just an idea inspired by my old Pascal programming days. (Anyone remember THAT?)

 

Updated on 2014-02-01T10:00:29Z at 2014-02-01T10:00:29Z by JerryG2
  • barbara_morris
    barbara_morris
    393 Posts

    Re: WITH Block for referencing Qualified Data Sructures

    ‏2014-02-03T16:54:13Z  

    Hi Jerry, this is a place to discuss suggested enhancements, but it isn't an official requirements site.

    Currently, the places you can submit requirements are:  

  • barbara_morris
    barbara_morris
    393 Posts

    Re: WITH Block for referencing Qualified Data Sructures

    ‏2014-02-03T17:07:27Z  

    Hi again Jerry,

    I do remember "with" from Pascal.

    I think it would be cool to allow multiple WITHs using "as", similar to SQL. Giving a name to the data-structure expression would also make it less ambiguous for both the programmer and the compiler.

    WITH dsTermsArray.ValidTermEntry(j) AS VTE
       : ddgTermsArray.ddgTermsRec(i) AS TR;
       IF    TR.trTermYears < cPermanentTagYears;
         VTE.teTermExpireDate
             =   ZeroDate
               + %YEARS(*YEAR)
               + %YEARS(TR.trTermYears)
               - %YEARS(wAdjustment1);
         VTE.teTermExpireDate
             = VTE.teTermExpireDate
               + %MONTHS(ddgExpireMonth) - %MONTHS(1);
         VTE.teTermExpireDate
             = VTE.teTermExpireDate
               + %DAYS(ddgExpireDay) - %DAYS(1);
         VTE.teTermDescr
             = gTermStandrdzd + ' (Expires '
             + %CHAR(VTE.teTermExpireDate) + ')';
       ELSE;
         VTE.teTermExpireDate = cHighDate;
         VTE.teTermDescr
             = gTermStandrdzd + ' (' + cPermanentTagExpLabel + ')';
       ENDIF;
    ENDWITH;
  • johnerps
    johnerps
    2 Posts

    Re: WITH Block for referencing Qualified Data Sructures

    ‏2014-02-07T15:30:13Z  

    Hi again Jerry,

    I do remember "with" from Pascal.

    I think it would be cool to allow multiple WITHs using "as", similar to SQL. Giving a name to the data-structure expression would also make it less ambiguous for both the programmer and the compiler.

    WITH dsTermsArray.ValidTermEntry(j) AS VTE
       : ddgTermsArray.ddgTermsRec(i) AS TR;
       IF    TR.trTermYears < cPermanentTagYears;
         VTE.teTermExpireDate
             =   ZeroDate
               + %YEARS(*YEAR)
               + %YEARS(TR.trTermYears)
               - %YEARS(wAdjustment1);
         VTE.teTermExpireDate
             = VTE.teTermExpireDate
               + %MONTHS(ddgExpireMonth) - %MONTHS(1);
         VTE.teTermExpireDate
             = VTE.teTermExpireDate
               + %DAYS(ddgExpireDay) - %DAYS(1);
         VTE.teTermDescr
             = gTermStandrdzd + ' (Expires '
             + %CHAR(VTE.teTermExpireDate) + ')';
       ELSE;
         VTE.teTermExpireDate = cHighDate;
         VTE.teTermDescr
             = gTermStandrdzd + ' (' + cPermanentTagExpLabel + ')';
       ENDIF;
    ENDWITH;

    YES!

    Like

  • AVROHOMN
    AVROHOMN
    16 Posts

    Re: WITH Block for referencing Qualified Data Sructures

    ‏2014-03-26T07:13:59Z  

    Programming Advice: avoid using one-letter variables.

     

    It is hard to find where the variable is used. Searching for the letter "I"  or "J" in the source will give so many results.

    Instead use "I1", "I2", etc.

    I wolud suggest to use not less than 3 letters: "I100", "J100".

  • tuohyp
    tuohyp
    4 Posts

    Re: WITH Block for referencing Qualified Data Sructures

    ‏2014-03-26T08:31:06Z  
    • AVROHOMN
    • ‏2014-03-26T07:13:59Z

    Programming Advice: avoid using one-letter variables.

     

    It is hard to find where the variable is used. Searching for the letter "I"  or "J" in the source will give so many results.

    Instead use "I1", "I2", etc.

    I wolud suggest to use not less than 3 letters: "I100", "J100".

    I'm sorry, but I don't think this advise applies to ILE RPG programs.

    If you are using subprocedures, you should be using locally defined variables. So, i and j should be defined in each subprocedure where they are used.

    The three letter+ naming convention made sense when all variables are global - effectively, you are making them "local" to where they are used by giving them a unique name. No longer required when using subprocedures.

  • AVROHOMN
    AVROHOMN
    16 Posts

    In ILE RPG there is room for variables names 14 character length

    ‏2014-03-26T09:20:33Z  
    • tuohyp
    • ‏2014-03-26T08:31:06Z

    I'm sorry, but I don't think this advise applies to ILE RPG programs.

    If you are using subprocedures, you should be using locally defined variables. So, i and j should be defined in each subprocedure where they are used.

    The three letter+ naming convention made sense when all variables are global - effectively, you are making them "local" to where they are used by giving them a unique name. No longer required when using subprocedures.

    In  ILE RPG there is room for variables names 14 character length.  You do not need to use it up, but there is no reason to squeze into a 1 letter variable.

    If the procedure is more than 20 lines, it becomes hard to search where the variable is used and assuring not to miss any instance of it.

    By the way, what is the exact name of our operating system? it used to be as400, the Iseries, it thing that now it is just one letter "I", typing it in google would give funny results.

    Maybe I am mistaking and the exact name is  IBM I:

    http://en.wikipedia.org/wiki/IBM_i

     

    Updated on 2014-03-26T09:38:27Z at 2014-03-26T09:38:27Z by AVROHOMN
  • Liam_H
    Liam_H
    14 Posts

    Re: In ILE RPG there is room for variables names 14 character length

    ‏2014-03-26T09:29:55Z  
    • AVROHOMN
    • ‏2014-03-26T09:20:33Z

    In  ILE RPG there is room for variables names 14 character length.  You do not need to use it up, but there is no reason to squeze into a 1 letter variable.

    If the procedure is more than 20 lines, it becomes hard to search where the variable is used and assuring not to miss any instance of it.

    By the way, what is the exact name of our operating system? it used to be as400, the Iseries, it thing that now it is just one letter "I", typing it in google would give funny results.

    Maybe I am mistaking and the exact name is  IBM I:

    http://en.wikipedia.org/wiki/IBM_i

     

    So true it needed saying thrice :)
     

  • Liam_H
    Liam_H
    14 Posts

    Re: In ILE RPG there is room for variables names 14 character length

    ‏2014-03-26T09:31:30Z  
    • AVROHOMN
    • ‏2014-03-26T09:20:33Z

    In  ILE RPG there is room for variables names 14 character length.  You do not need to use it up, but there is no reason to squeze into a 1 letter variable.

    If the procedure is more than 20 lines, it becomes hard to search where the variable is used and assuring not to miss any instance of it.

    By the way, what is the exact name of our operating system? it used to be as400, the Iseries, it thing that now it is just one letter "I", typing it in google would give funny results.

    Maybe I am mistaking and the exact name is  IBM I:

    http://en.wikipedia.org/wiki/IBM_i

     

    So true it need saying thrice :) 

  • AVROHOMN
    AVROHOMN
    16 Posts

    Re: In ILE RPG there is room for variables names 14 character length

    ‏2014-03-26T09:49:44Z  
    • Liam_H
    • ‏2014-03-26T09:31:30Z

    So true it need saying thrice :) 

    It was sent htrice by mistake. I deleted the extra ones.

  • JonParis
    JonParis
    117 Posts

    Re: In ILE RPG there is room for variables names 14 character length

    ‏2014-03-26T14:30:53Z  
    • Liam_H
    • ‏2014-03-26T09:29:55Z

    So true it needed saying thrice :)
     

    I have to disagree on two fronts. First I think a one character variable name is perfectly valid in the case of a loop control. 

    e.g. For i = 1 to limit;

    i is just an index and should not be used outside the loop so why make life complicated by adding a number.

    Second - I can search for i by itself just fine - I just include the space before and/or after in the search string. No problem. 

  • tuohyp
    tuohyp
    4 Posts

    Re: In ILE RPG there is room for variables names 14 character length

    ‏2014-03-26T14:31:26Z  
    • AVROHOMN
    • ‏2014-03-26T09:20:33Z

    In  ILE RPG there is room for variables names 14 character length.  You do not need to use it up, but there is no reason to squeze into a 1 letter variable.

    If the procedure is more than 20 lines, it becomes hard to search where the variable is used and assuring not to miss any instance of it.

    By the way, what is the exact name of our operating system? it used to be as400, the Iseries, it thing that now it is just one letter "I", typing it in google would give funny results.

    Maybe I am mistaking and the exact name is  IBM I:

    http://en.wikipedia.org/wiki/IBM_i

     

    In ILE RPG, variable names can be up to 4096 characters in length - and it is not a question of squeezing it into one character. 

    I think is is a convention in nearly every programming language (at least the ones I have used) that the variables i, j, k, x, y. z (and sometimes l, m and n) are universally used for loop counters and array indexes. 

    for i = 1 to numberOfRows; 

    as opposed to

    for i100 = 1 to numberOfRows; (RPG is the only place I have ever seen this and, as I said, only to localize the variable)

    In RSE, filter selected will show you all instances of where a variable is used. In 20 lines or 2000 lines.

    The name of the OS is just "i" although it is written as IBM i - and I think google might explode if you just googled "i" <g>. But I guess someone else bet them to iOS. The name of the platform is Power Systems. 

  • JonParis
    JonParis
    117 Posts

    Re: In ILE RPG there is room for variables names 14 character length

    ‏2014-03-26T14:39:00Z  
    • Liam_H
    • ‏2014-03-26T09:29:55Z

    So true it needed saying thrice :)
     

    I have to disagree on two fronts. First I think a one character variable name is perfectly valid in the case of a loop control. 

    e.g. For i = 1 to limit;

    i is just an index and should not be used outside the loop so why make life complicated by adding a number.

    Second - I can search for i by itself just fine - I just include the space before and/or after in the search string. No problem. 

  • JonParis
    JonParis
    117 Posts

    Re: WITH Block for referencing Qualified Data Sructures

    ‏2014-03-26T14:41:45Z  

    I agree with Paul and disagree with the OP on two fronts.

    First, as Paul said, a one character variable name is perfectly valid in the case of a loop control. It is a universal convention is all programming languages - there's nothing special in RPG that requires longer names.

    e.g. For i = 1 to limit;

    i is just an index and should not be used outside the loop so why make life complicated by adding a number.

    Second - I can search for i by itself just fine - I just include the space before and/or after in the search string. No problem. 

  • barbara_morris
    barbara_morris
    393 Posts

    Re: WITH Block for referencing Qualified Data Sructures

    ‏2014-03-26T15:50:20Z  

    If you use RDI, you can easily find all the places that any name is used in the outline view.

    I wouldn't use a name like i100 for a loop counter. It looks like the 100 is important for the loop. If I needed to use a longer name for some reason, I would use something like index or idx (although, hmm, idx could mean i60 if we interpret DX as a Roman numeral :-).

  • Liam_H
    Liam_H
    14 Posts

    Re: WITH Block for referencing Qualified Data Sructures

    ‏2014-03-26T16:34:28Z  
    • JonParis
    • ‏2014-03-26T14:41:45Z

    I agree with Paul and disagree with the OP on two fronts.

    First, as Paul said, a one character variable name is perfectly valid in the case of a loop control. It is a universal convention is all programming languages - there's nothing special in RPG that requires longer names.

    e.g. For i = 1 to limit;

    i is just an index and should not be used outside the loop so why make life complicated by adding a number.

    Second - I can search for i by itself just fine - I just include the space before and/or after in the search string. No problem. 


    First point, just because everyone does it doesn't mean it's right.:)

    Second point, you're assuming everyone before and after you codes the same way and that you/they don't typo:
    For i=1 to limit;
    Would cause you to miss a loop if searching for ' i '.
    Now you've just overlooked some business critical logic for the sake of a couple of letters.
    You get fired, you default on your mortgage, your wife leaves you, you hit the bottle.
    Where does it end?




     

  • JonParis
    JonParis
    117 Posts

    Re: WITH Block for referencing Qualified Data Sructures

    ‏2014-03-26T18:16:04Z  

    Well for one thing I would not allow i=1 in my shop - it would fail the coding standards.

    No - it doesn't mean it is right because everyone does it - but it is a common standard. As Paul noted - adding a number gives the implication that the number has significance - it doesn't. 

    Barbara - and someone else also noted that if you use a decent editor such as RDi then the Outline view gives you all easy access to all instances of the variable.

    Sorry - I'm not going to make the code less obvious just to enable searching in old editors such as SEU.

  • AVROHOMN
    AVROHOMN
    16 Posts

    Re: In ILE RPG there is room for variables names 14 character length

    ‏2014-03-27T06:03:00Z  
    • tuohyp
    • ‏2014-03-26T14:31:26Z

    In ILE RPG, variable names can be up to 4096 characters in length - and it is not a question of squeezing it into one character. 

    I think is is a convention in nearly every programming language (at least the ones I have used) that the variables i, j, k, x, y. z (and sometimes l, m and n) are universally used for loop counters and array indexes. 

    for i = 1 to numberOfRows; 

    as opposed to

    for i100 = 1 to numberOfRows; (RPG is the only place I have ever seen this and, as I said, only to localize the variable)

    In RSE, filter selected will show you all instances of where a variable is used. In 20 lines or 2000 lines.

    The name of the OS is just "i" although it is written as IBM i - and I think google might explode if you just googled "i" <g>. But I guess someone else bet them to iOS. The name of the platform is Power Systems. 

    "In RSE, filter selected will show you all instances of where a variable is used. In 20 lines or 2000 lines."

    In our shop we still use SEU.

    Updated on 2014-03-27T06:07:09Z at 2014-03-27T06:07:09Z by AVROHOMN
  • AVROHOMN
    AVROHOMN
    16 Posts

    Re: In ILE RPG there is room for variables names 14 character length

    ‏2014-03-27T06:05:16Z  
    • JonParis
    • ‏2014-03-26T14:39:00Z

    I have to disagree on two fronts. First I think a one character variable name is perfectly valid in the case of a loop control. 

    e.g. For i = 1 to limit;

    i is just an index and should not be used outside the loop so why make life complicated by adding a number.

    Second - I can search for i by itself just fine - I just include the space before and/or after in the search string. No problem. 

    "just include the space before and/or after in the search string"

    It will not help in this case:

     

    "ddgTermsArray.ddgTermsRec(i)"

     

  • barbara_morris
    barbara_morris
    393 Posts

    Re: In ILE RPG there is room for variables names 14 character length

    ‏2014-03-27T15:30:15Z  
    • AVROHOMN
    • ‏2014-03-27T06:03:00Z

    "In RSE, filter selected will show you all instances of where a variable is used. In 20 lines or 2000 lines."

    In our shop we still use SEU.

    You can use the Cross Reference section of the compiler listing to find where a variable is used.

  • AVROHOMN
    AVROHOMN
    16 Posts

    Re: In ILE RPG there is room for variables names 14 character length

    ‏2014-03-30T04:55:55Z  

    You can use the Cross Reference section of the compiler listing to find where a variable is used.

    1. Neeed to compile first. write downsthe the numbers from the spool listing, then going back and forth by line numbers. Extra steps. Also in the listing itself, how do You find variable "I"?

    2. In ILE Debuger listing, there is no way to find where a variable is used.

    I would rather keep it simple and add just one extra letter to the I: I1. As simple as that. it is less typing than going back and forth within the compile listing. 

    Updated on 2014-03-30T05:10:33Z at 2014-03-30T05:10:33Z by AVROHOMN
  • JonParis
    JonParis
    117 Posts

    Re: In ILE RPG there is room for variables names 14 character length

    ‏2014-03-30T11:47:53Z  
    • AVROHOMN
    • ‏2014-03-30T04:55:55Z

    1. Neeed to compile first. write downsthe the numbers from the spool listing, then going back and forth by line numbers. Extra steps. Also in the listing itself, how do You find variable "I"?

    2. In ILE Debuger listing, there is no way to find where a variable is used.

    I would rather keep it simple and add just one extra letter to the I: I1. As simple as that. it is less typing than going back and forth within the compile listing. 

    You really do work hard to avoid using a decent editor don't you <grin>

    Use RDi and no need for any of the silly games.

     

     

  • JerryG2
    JerryG2
    3 Posts

    Re: WITH Block for referencing Qualified Data Sructures

    ‏2014-05-28T21:05:27Z  

    Hi again Jerry,

    I do remember "with" from Pascal.

    I think it would be cool to allow multiple WITHs using "as", similar to SQL. Giving a name to the data-structure expression would also make it less ambiguous for both the programmer and the compiler.

    WITH dsTermsArray.ValidTermEntry(j) AS VTE
       : ddgTermsArray.ddgTermsRec(i) AS TR;
       IF    TR.trTermYears < cPermanentTagYears;
         VTE.teTermExpireDate
             =   ZeroDate
               + %YEARS(*YEAR)
               + %YEARS(TR.trTermYears)
               - %YEARS(wAdjustment1);
         VTE.teTermExpireDate
             = VTE.teTermExpireDate
               + %MONTHS(ddgExpireMonth) - %MONTHS(1);
         VTE.teTermExpireDate
             = VTE.teTermExpireDate
               + %DAYS(ddgExpireDay) - %DAYS(1);
         VTE.teTermDescr
             = gTermStandrdzd + ' (Expires '
             + %CHAR(VTE.teTermExpireDate) + ')';
       ELSE;
         VTE.teTermExpireDate = cHighDate;
         VTE.teTermDescr
             = gTermStandrdzd + ' (' + cPermanentTagExpLabel + ')';
       ENDIF;
    ENDWITH;

    Great suggestion, Barbara; really enhances readability. I accept it as a friendly amendment. ;-)

    Updated on 2014-05-28T21:26:18Z at 2014-05-28T21:26:18Z by JerryG2
  • JerryG2
    JerryG2
    3 Posts

    Re: In ILE RPG there is room for variables names 14 character length

    ‏2014-05-28T21:18:28Z  
    • AVROHOMN
    • ‏2014-03-26T09:20:33Z

    In  ILE RPG there is room for variables names 14 character length.  You do not need to use it up, but there is no reason to squeze into a 1 letter variable.

    If the procedure is more than 20 lines, it becomes hard to search where the variable is used and assuring not to miss any instance of it.

    By the way, what is the exact name of our operating system? it used to be as400, the Iseries, it thing that now it is just one letter "I", typing it in google would give funny results.

    Maybe I am mistaking and the exact name is  IBM I:

    http://en.wikipedia.org/wiki/IBM_i

     

    If/when you get to Rational Developer, use the Find dialog's "Whole word" option. It's a great help for finding "words" as short as one character, whether delimited by spaces, parentheses, or other special characters.

    And FWIW, as Jon mentioned, the "i" in the code snippet in my original post is indeed a loop control variable. And as Paul suggested, it's a custom, in my case -- and this will date me! -- a holdover from Fortran, where (IIRC) variables starting with I, J, K, L, M, and N are automatically defined as integer values.

    Updated on 2014-05-28T21:19:38Z at 2014-05-28T21:19:38Z by JerryG2