ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

2 D Array from a DB file, best way to do it

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

  • 2 D Array from a DB file, best way to do it

    Hi All


    This is my 1st post so be gentle, I have a databse file which Ive built which is basically a excel spreadsheet which holds Weight & Miles with corresponding cost value for our transport

    Miles
    tonnes 10 15 20 25 30 .....
    .5 17.5 18.25 19.00 22.00 25.00 <---Cost value
    1 17.50 18.25 19.00 22.00 25.00
    1.5 17.06 17.79 18.53 21.45 24.38
    2 16.63 17.34 18.05 20.90 23.75
    ....
    Down to 25 tonnes & across to 450 miles

    Anyone know whats the best way to code this in RPG, I tried to do a setgt & readp but get odd results, Im sure im missing something obvious but am stuck.

    As far as i can see its a 2d array but not sure how best to access, I want to go to the nearest higher value, ie if 1.8 tonnes & 24 miles it should find 23.75 as a cost.

    Any help would be greatly appreciated.

    Tony
    ...

  • #2
    Re: 2 D Array from a DB file, best way to do it

    I would do it with a simple SQL statement.
    PHP Code:
    SELECT cost FROM PRICES
    WHERE miles
    <= ? AND weight <= ? 
    The native I/O solution is obviously dependant on the key to your file and whether it's ascending or descending.
    Ben

    Comment


    • #3
      Re: 2 D Array from a DB file, best way to do it

      1/ Shouldn't the nearest cost value for 1.8 tonnes & 24 miles be 20.90 instead ?

      2/ Can you pls paste the file layout used in the RPG program ?
      Philippe

      Comment


      • #4
        Re: 2 D Array from a DB file, best way to do it

        Code:
        Miles   10     15    20    25    30   Cost
        tonnes 00.50 17.50 18.25 19.00 22.00 25.00
               01.00 17.50 18.25 19.00 22.00 25.00
               01.50 17.06 17.79 18.53 21.45 24.38
               02.00 16.63 17.34 18.05 20.90 23.75
        I think it's supposed to be laid out like this. So you round up 24 to 25 and then scroll to the bottom of that column. 18.05 is well over 1.8 but there isn't a lower value. Then scroll to the end of that row and you get 23.75.
        Ben

        Comment

        Working...
        X