ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

DS array and %elem() & %xfoot()

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

  • DS array and %elem() & %xfoot()

    hi all
    Code:
    D Mdata           ds                  DIM(12) Qualified      
    d QtySold                        5  0                        
    d Revenue                        4  0                        
    d                                                            
    d Year            Ds                  DIM(20) Qualified      
    d Month                               likeDs(Mdata) Dim(14)  
    ..
    ..
    for X = 1 to 12 by 1;               
    totQty += year(1).Month(X).QtySold ;
    totRve += year(1).Month(X).Revenue ;
    endfor;

    01) are there any function to remove this for loop?
    (to get month wise total Ex: year(2).allMonths.qtySold )


    02) asume data filled upto year(1).Month(4)
    & Year(2).Month(8) if so how to get that last element no (%elem - this is for forloop, )


    03) can i get year wise total of qtysold without writing loop?
    Example : allYears.allMonths.qtySold


    thanks
    regards
    dhanuxp
    Last edited by dhanuxp; August 4, 2008, 10:13 PM.

  • #2
    Re: DS array and %elem() & %xfoot()

    Hi dhanuxp:

    I think this is what you are looking for:

    Code:
    D*Mdata           ds                  DIM(12) Qualified               
    d*QtySold                        5  0                                 
    d*Revenue                        4  0                                 
    d                                                                     
    d Year            Ds                  DIM(20) Qualified               
    d Month                          9    Dim(14)                         
    d QtySold                        5  0 overlay(month) inz(1)           
    d Revenue                        4  0 overlay(month:*next) inz(2)     
    d totqty          s              8s 0                                 
    d totrev          s              8s 0                                 
    d x               s              2s 0                                 
     /free                                                                
          for x = 1 to 20;                                                
           totqty += %xfoot(year(x).qtysold);                             
           totrev += %xfoot(year(x).revenue);                             
          endfor;                                                         
          dsply totqty '';                        
          dsply totrev '';                        
          *inlr = *on;                            
     /end-free
    Totqty = 280
    Totrev = 560

    Best of Luck
    GLS
    The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

    Comment


    • #3
      Re: DS array and %elem() & %xfoot()

      thanks GLS,
      yes your example DS is another way of mine but its also shows
      Code:
      Array has too many omitted indexes; specification is ignored.
      so cant be achevied

      thanks
      dhanuxp

      Comment


      • #4
        Re: DS array and %elem() & %xfoot()

        Good coding practice:

        Before you start the for loop, init the total values !

        Code:
         /free 
        
              totqty = *zero;  
              totrev = *zero;                                                       
              
              for x = 1 to 20;

        Comment


        • #5
          Re: DS array and %elem() & %xfoot()

          and @GLS400
          as your example :
          how to get ( all_YEAR.all_AUGUST.qtysold ); ????
          thats y i declare above structure??

          pls
          thanks
          dhanuxp

          Comment


          • #6
            Re: DS array and %elem() & %xfoot()

            Hi dhanuxp:

            I'm not sure I understand the full issue.

            The example I posted will calc all qty/rev for 20 years/14(?) months

            For august only over 20 years
            Code:
                  for x = 1 to 20;                                                
                   totqty += (year(x).qtysold(8));                             
                   totrev += (year(x).revenue(8));                             
                  endfor;
            For 1 year's (year 08) total / 14 months:
            Code:
                 x=08;
                   totqty = %xfoot(year(x).qtysold);                             
                   totrev = %xfoot(year(x).revenue);
            for jan thru mar year 08
            Code:
                  x = 08;
                   totqty = %xfoot(%subarr(year(08).qtysold:1:3));
            Hope that helps
            GLS
            The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

            Comment


            • #7
              Re: DS array and %elem() & %xfoot()

              yep! grate help GLS, thanks

              Comment

              Working...
              X