grouping data in rpgle

565 pts.
Tags:
#AS400 #RPGLE #as400
I have sample data in file as below - (Model/Library/Format is key field in PF)

Model     Library    Format  LastDate
--------     ----------   ---------   -----------
Model1	Lib1	       Fmt1    1-Oct 
Model2  Lib2    Fmt2  2-Oct
Model1	Lib1	       Fmt1    10-Sep
Model1	Lib2    Fmt2    5-Sep  
Below is the format I need the information- (#TimesPrinted should be sorted in descending order and the LastDate should hold the record with the last date)

#TimesPrinted   Model     Library    Format  LastDate
-------------------   --------      ---------    ---------   ------------
	 		Model1	Lib1	       Fmt1    1-Oct 
1           Model2  Lib2    Fmt2  2-Oct
1	    Model1  Lib2    Fmt2  5-Sep
Any inputs?

0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 7  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • TheRealRaven
    And what is the problem you ran into? Show us the code that demonstrates the problem. If we don't know what's going wrong, we can't guess how to fix it.
    36,095 pointsBadges:
    report
  • sri8707
    I am not sure what is the best way to write this logic. As i mentioned, my PF has model, library, format, date.

    I am looking for idea to perform group by clause in RPGLE so that my result will be something like -
    Number of records/model/library/format/first date
    565 pointsBadges:
    report
  • sri8707
    To add to this, I can create another PF (say PF2). When records are written into PF1, I can subsequently check PF2 and add records accordingly - something like below.

    Read model/library/format from PF1
    If record not in PF2, write to PF2 with count as 1.
    If record in PF2, update PF2 record with count as count + 1.

    But, is there a way to do this without introducing another file?
    565 pointsBadges:
    report
  • ToddN2000
    Easiest way is create a LF with the new key sequence. If you cannot create a new file (class assignment?) then I'd use embedded SQL and create your new view. Something like this perhaps..C/EXEC SQL                                                             
    C+    DECLARE FILE CURSOR FOR                                            
    C+       SELECT FLD1, FLD2, FLD3, FLD4    
    C+       FROM  FILE                                                      
    C+       ORDER BY FLD1, FLD2, FLD3, FLD4                                               
    C/END-EXEC                                                             
    C/EXEC SQL                                                             
    C+    OPEN FILE                                                           
    C/END-EXEC  
    134,855 pointsBadges:
    report
  • sri8707
    Hi Todd,

    Thanks for your reply. I do not prefer SQLRPGLE for performance reasons. I thought about LF, but the problem is with the COUNT field which is not part of PF. I have to count records dynamically as I keep reading from PF. 

    My aim is to basically display the reults on a screen. (as a subfile). I can implement this change using a new PF, but I am trying to find a way to avoid creating a new file for this


    565 pointsBadges:
    report
  • ToddN2000
    If you don't want to create a LF or use SQL, it will take some more work. Like you said the other option would be to change the key on the current PF.  If that is used elsewhere you may not have that option. Creating a second PF means maintaining two sets of data to keep things in sync. Not my choice, too much margin for error. Another way to go might be to use a table to hold the data, Do a lookup and see if you have a matching key then update the count and dates as needed.. Just a quick thought..

    134,855 pointsBadges:
    report
  • sri8707
    Thanks Todd. I am thinking about using an array data structure to hold the values, from which i can sort descending to display records on screen. If it doesnt work out, will go with SQL.
    565 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: