ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Question about Nested DS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question about Nested DS

    I'll try the possibility to use the Nested ds but they dont work like I wonder, here's an example:

    Code:
    **free                                                 
    Ctl-Opt                                                
      DftActGrp(*no) ActGrp('QILE')                        
      BndDir('QC2LE' )                                     
      Option(*NoUnRef :*SrcStmt :*NoDebugIo)               
      DatFmt(*iso) TimFmt(*iso)                            
      DecEdit('0.')                                        
      Debug                                                
      AlwNull(*UsrCtl);                                    
    
      //  Not Nested                                       
    Dcl-Ds NBA2 Qualified;                                                                           
      *n char(11)    inz('1LAKERS    ');                                                             
      *n Char(11)    inz('2BULLS     ');                                                             
      *n Char(11)    inz('3CAVALIERS ');                                                             
      *n Char(11)    inz('4WARRIOS   ');                                                             
      a LikeDs(A_Template) dim(4) Pos(1) ;                                                           
    End-Ds;                                                                                          
    
    Dcl-Ds a_template  Qualified;                                                                    
      Code         Char(1)  ;                                                                        
      Team         Char(10) ;                                                                        
    End-Ds ;                                                                             
    
      //  Nested DS                                        
    Dcl-Ds NBA Qualified;                                  
      *n char(11)    inz('1LAKERS    ');                   
      *n Char(11)    inz('2BULLS     ');                   
      *n Char(11)    inz('3CAVALIERS ');                   
      *n Char(11)    inz('4WARRIOS   ');                   
      Dcl-Ds Nested     dim(4) Pos(1);                     
        Code         Char(1)  ;                            
        Team         Char(10) ;                            
      End-Ds Nested;                                       
    End-Ds;                                                
    
    Dsply  ('Michael Jordan played into: ' + NBA2.A(%Lookup('2' :Nba2.A(*).Code)).Team);             
    Dsply  ('Michael Jordan played into: ' + NBA.Nested(%Lookup('2' :Nba.Nested(*).Code)).Team);     
    
    Return ;
    The first declaration (NBA2) works, while the second no, Because NBA.Nested for all element is '1LAKERS'.
    Why?
    Many thanks.

  • #2
    You're right - NBA does not work how I would expect.

    I ran it through debug - The data structure seems to be correctly qualified and fully functional in the RPG, but for NBA all 4 *N fields are initialised to 1LAKERS. If I use debug to amend NBA.nested(2).code to '2' then the %lookup ion the second DSPLY works.

    It looks like this may be a compile bug? The compiler is not correctly parsing NBAs nested and overlayed DS?

    Comment


    • #3
      Definition should be as follows

      Code:
      Dcl-DCL-Ds NBA Qualified;
         *n char(11) inz('1LAKERS ');
         *n Char(11) inz('2BULLS ');
         *n Char(11) inz('3CAVALIERS ');  
         *n Char(11) inz('4WARRIOS ');
         Nested dim(4) Pos(1);
           Code Char(1) Overlay(Nested);
           Team Char(10) Overlay(Nested: *Next);
      End-Ds;
      Birgitta
      Last edited by B.Hauser; December 14, 2017, 07:28 AM.

      Comment


      • #4
        HI Birgitta,
        thanks.
        It's not a Nested Ds but it works.

        Bye

        Comment


        • #5
          Originally posted by paolinosal View Post
          I'll try the possibility to use the Nested ds but they dont work like I wonder, here's an example:


          The first declaration (NBA2) works, while the second no, Because NBA.Nested for all element is '1LAKERS'.
          Why?
          Many thanks.
          Simply put, what you are attempting to define is not really nested data structure. That said - this appears to be a compiler error and when seen in debug all four elements do actually have the same value which is wrong.

          I removed the Inz values and manually assigned the data i.e.
          NBA.Nested(1) = '1LAKERS';

          NBA.Nested(2) = '2BULLS';

          NBA.Nested(3) = '3CAVALIERS';

          NBA.Nested(4) = '4WARRIORS';

          When done that way it works.

          Birgitta's answer is IMO the right way to do it because creating this as a nested structure is misleading at best. That said it should have worked.

          Comment


          • #6
            Please report this problem to IBM.

            Comment


            • #7
              Since the subfields of NBA are initialized in the order they are declared I would expect NBA to contain spaces due to the initialization of datastructure Nested.

              Comment

              Working...
              X