ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Need some suggestions on how to code this routine.

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

  • Need some suggestions on how to code this routine.

    I have a transaction file like this.

    History Records.
    Account # Transaction date Amount
    1234 20080101 1.00
    1234 20080102 2.00
    1234 20080130 5.00
    Balance 8.00

    Transaction Records
    If I have transactions that come in like this
    Account # Transaction date Amount
    1234 20080120 (3.00)

    I need to code a routine that will look at the transaction date compare it to history. If the transaction date falls between the history transaction date then I need to recalcualate the balance.

    I can code this by doing a setll to the first record in the history file and then read the records until the account# changes and hold the beginning and ending date in a variable and then compare the transaction date with the range.

    I was wondering if there was a better way of coding this.

    Any suggestions.

    Thanks,

    DAC

  • #2
    Re: Need some suggestions on how to code this routine.

    Are you storing the "Balance 8.00" as a record in the Transaction history file?
    Your future President
    Bryce

    ---------------------------------------------
    http://www.bravobryce.com

    Comment


    • #3
      Re: Need some suggestions on how to code this routine.

      Nope. Just calculating the new balance based on the transaction date. I really need a routine that tells me if a date falls between two dates or after the latest date.

      DAC

      Comment


      • #4
        Re: Need some suggestions on how to code this routine.

        Hi dcutaia:

        Another approach is to create a summary work file of acct, from-date, to-date, balance from the history file. Then use the work file to drive the program.

        Just a thought

        GLS
        Last edited by GLS400; April 4, 2008, 07:29 AM.
        The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

        Comment


        • #5
          Re: Need some suggestions on how to code this routine.

          I was going to suggest doing something similar except not using a work file, just storing the from-date, to-date, and balance in a couple vars. Six of one, half dozen of the other...
          Your future President
          Bryce

          ---------------------------------------------
          http://www.bravobryce.com

          Comment


          • #6
            Re: Need some suggestions on how to code this routine.

            Does anyone have a routine to convert 20080101 to julian?

            DAC

            Comment


            • #7
              Re: Need some suggestions on how to code this routine.

              you mean the date you have to compare is in julian?
              Your future President
              Bryce

              ---------------------------------------------
              http://www.bravobryce.com

              Comment


              • #8
                Re: Need some suggestions on how to code this routine.

                No I need to convert 20080101 to julian so I can see if a date falls between a date range.

                Comment


                • #9
                  Re: Need some suggestions on how to code this routine.

                  Hi dcutaia:

                  No need to convert the date.

                  Code:
                  if mydate>= fromdt and mydate <=todate;
                      this is a keeper();
                  endif;
                  works with ccyymmdd as well as jul

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

                  Comment


                  • #10
                    Re: Need some suggestions on how to code this routine.

                    yeppers
                    Your future President
                    Bryce

                    ---------------------------------------------
                    http://www.bravobryce.com

                    Comment


                    • #11
                      Re: Need some suggestions on how to code this routine.

                      Lets say we create a Logical with the account number and transaction dates as key fields.

                      1.) Get the first record of the account using Chain or SETLL + READE combo using the account number alone.
                      2.) Store the transaction date in a variable
                      3.) Get the last record of the account using SETGT and READPE using the account number alone. (Am not sure if this is the exact way as its been a while since i used SETGT)
                      4.) Store the transaction date of the last record in another variable.
                      5.) Now use these 2 variables as limits and compare with the transaction date for your processing.

                      Comment


                      • #12
                        Re: Need some suggestions on how to code this routine.

                        How about something like this?

                        exec SQL Select min(trandate), max(trandate) into ldest, :newest from historyfile where account = :accountnum;

                        if newdate > oldest and newdate < newest;
                        do whatever ...
                        endif;

                        well ... you get the idea

                        Comment


                        • #13
                          Re: Need some suggestions on how to code this routine.

                          Well i guess it could be done like that as well

                          Comment

                          Working...
                          X