Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Totaling Records 1

Status
Not open for further replies.

rstitzel

MIS
Apr 24, 2002
286
US
I have two files. One is a full detailed file named OOVSH containing Route, Day Number, Product Number and Quantity Ordered. The keys are Route, Day and Prod Number.

The other is an output totals file named WSX that will contain the summary records.

I want to read through the input detail file totaling the QUANTITY for EACH PRODUCT by ROUTE.

I'm sorta new to RPG IV and so far haven't had to combine records into a total. I know how it's done in RPG II as I have that code but I'm rewriting the program in IV and need some help.

If someone could post some "rough code" outlining how this is done in RPG IV it would very much appreciated.

Thank you.
 
rstitzel,

How does DAY come into play? You said you need total QUANTITY for each PRODUCT by ROUTE. I suspect you may need a logical file by ROUTE and PRODUCT to do what you want.

HTH,
MdnghtPgmr

PS. Did you want the code in free or regular?
 
Let's exclude the day field for now.

I JUST created a logical file that is keyed by the route and product number. Sorted Ascending by route, prod.

Now what? :)

You can put the code in free format. I'm TRYING to use "free" as much as possible.

THANK YOU VERY MUCH!
 
rstitzel,

Here is some code. Untested and uncompiled. Hopefully it will at least point you in the right direction.

Code:
FOOVSH     IF   E           K DISK    PREFIX( Oo )                                       
                                                                                         
FWSX       O    E             DISK    PREFIX( Ws )                                       
                                                                                         
D OldProduct      S                   LIKE( PRODUCT )                                    
D OldRoute        S                   LIKE( ROUTE )                                      
                                                                                         
D TotProduct      S              9  2                                                    
D TotRoute        S              9  2                                                    
                                                                                         
 /FREE                                                                                   
                                                                                         
                                                                                         
  SetLL *START OOVSH;                                                                    
  DoU %EOF( OOVSH );                                                                     
      Read( OOVSH );                                                                     
      If NOT( %EOF( WWVSH ) );                                                           
         If OldProduct <> OoPRODUCT;                                                     
            ExSr ProdBreak;                                                 
         EndIf;                                                                          
         If OldRoute <> OoROUTE;                                                         
            ExSr RoutBreak;
                           
            
         EndIf;                                                      

     EndIf;                                                                                   
      TotProduct += OoQuantity;                                                                
      TotRoute   += OoQuantity;                                                                
  EndDo;                                                                                       
                                                                                               
  *INLR = *ON;                                                                                 
                                                                                               
                                                                                               
                                                                                               
  //*******************************************************************************************
  //* Subroutine - ProdBreak - A break in product number                                       
  //*******************************************************************************************
                                                                                               
  BegSr ProdBreak;                                                                             
                                                                                               
     Clear WSX;  // this needs to be changed to WSX's format name                              
     WsRoute = OldRoute;                                                                       
     WsProd = OldProduct;                                                                      
     WsQTY   = TotProduct;                                                                     
     Write WSX;  // this needs to be change to WSX's format name                               
     TotProduct = *ZEROS;                                                                      
     OldProduct = OoROUTE;                                                     EndSr;                                                                                     
                                                                                            
                                                                                            
                                                                                            
 //*****************************************************************************************
 //* Subroutine - RoutBreak - A break in the route number                                   
 //*****************************************************************************************
                                                                                            
 BegSr RoutBreak;                                                                           
                                                                                            
    Clear WSX;  // this needs to be changed to WSX's format name                            
    WsRoute = OldRoute;                                                                     
    WsProd = OldProduct;                                                                    
    WsQTY   = TotRoute;                                                                     
    Write WSX;  // this needs to be change to WSX's format name                             
    TotRoute = *ZEROS;                                                                      
    OldRoute = OoROUTE;                                                                     
                                                                                            
 EndSr;

The formatting of the code got a little funny but I got tired of trying to fix it. Hope you can read it anyway. Let me know if you have more questions.

HTH,
MdnghtPgmr
 
Thank you!! Yes it does get me going in the right direction. I've never used or seen the PREFIX keyword so this is great. Learning several new "things".

Have a Star!
 
rstitzel,

Thanks for the star. Keep in mind, there must be a million ways to do what you want. I just wanted to give you enough to have something to build on. Some folks would say that you could use the cycle and level breaks. I do not like cycle code and prefer the more modern methods. It's a style thing I guess. Anyway, never stop learning!

My two cents,
MdnghtPgmr
 
Yes in my RPGII code that's how it's done...through level controls. Makes sense to use modern methods.

I do understand like many things there is more than one way to do it...but it does give me something to build from.

For Sure...NEVER STOP LEARNING!

Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top