home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / database / 8810 < prev    next >
Encoding:
Text File  |  1993-01-05  |  5.3 KB  |  148 lines

  1. Newsgroups: comp.databases
  2. Path: sparky!uunet!almserv!mimas!g9utxu
  3. From: g9utxu@fnma.COM (Tanin Uthayanaka)
  4. Subject: Re: Pls help: algorithm wanted (xbase, pref foxpro)
  5. Message-ID: <1993Jan5.144438.15119@almserv.uucp>
  6. Sender: usenet@almserv.uucp
  7. Nntp-Posting-Host: mimas
  8. Reply-To: g9utxu@fnma.COM
  9. Organization: Fannie Mae
  10. References: <durai.107.726186277@ortta.umn.edu>
  11. Date: Tue, 5 Jan 1993 14:44:38 GMT
  12. Lines: 134
  13.  
  14. In article 726186277@ortta.umn.edu, durai@ortta.umn.edu (Durai Venkatasubramanian) writes:
  15. >In article <1993Jan4.201319.9088@almserv.uucp> g9utxu@fnma.COM (Tanin Uthayanaka) writes:
  16.  
  17. >I really appreciate the time and effort Tanin and Tom have taken to help me (
  18. >and others, probably) out.  I am yet to translate(!)  Tom's code to foxpro.
  19. >
  20. >Just to set the records straight, I would like to share the results of 
  21. >running Tanin's code.  No offence please.   I am not here to point out bugs 
  22. >or inefficient coding, but just to acknowledge the fact about how the code 
  23. >works.  
  24. >
  25. >Records in my rate.dbf
  26. >
  27. >Rate  Start_date   End_date   Status
  28. >01    07/01/91     06/30/93   Provisional
  29. >02    07/01/92     06/30/93   Final
  30. >03    07/01/93     12/31/93   Provisional
  31. >
  32. >
  33. >Test data 1:  dstart = 01/01/92, dend = 01/06/93
  34. >
  35. >Results:  01/01/92 - 12/31/93  Provisional
  36. >          01/01/94 - 01/06/93  Uncovered
  37. >
  38. >whereas, the results should have been
  39. >          01/01/92 - 06/30/92  Provisional
  40. >          07/01/92 - 01/06/93  Final
  41. >
  42.  
  43. I must have misunderstood your requirement because my assumption was that there 
  44. should not be an overlapping of periods in RATE.DBF. For example, record # 1 with 
  45. 07/01/91 - 06/30/93 dates should have been 07/01/91 - 06/30/92 otherwise there is 
  46. a conflict between 07/01/92 - 06/30/93 wether the status should be Provisional or 
  47. Final. If the the dates in record # 1 were changed to 07/01/91 - 06/30/92 then the 
  48. results would have been:
  49.  
  50. 01/01/92 - 06/30/92 Provisional
  51. 07/01/92 - 01/06/93 Final
  52.  
  53. I have tested the program already and I can guarantee that the program works. If 
  54. you want a copy of the .EXE file just e-mail me and I'll send it to you.
  55.  
  56.  
  57.  
  58. >Test data 2: dstart = 07/01/91, dend = 12/31/93
  59. >
  60. >Results: 07/01/91 - 06/03/93  Provisional
  61. >         07/01/92 - 06/30/93  Final
  62. >         07/01/93 - 12/31/93  Provisional
  63. >         01/01/94 - 12/31/93  Uncovered
  64. >
  65. >whereas, the last line should not have even appeared, forget the 
  66. >error (12/31/93).  I amended the code a little bit, and eliminated 
  67. >the last line.  
  68. >
  69. >The code works fine as long as the records in the database match the dstart 
  70. >and dend variables.  Most of the times, the contract periods either start 
  71. >before, or end after, the rate agreement dates.  These algorithms tend to 
  72. >ignore the fact.
  73. >
  74.  
  75. Congrads...you found the bug. For that you win $10,000,000. Just kidding.
  76. Since you found the bug I'll give you my final version which runs perfectly assuming 
  77. there is no overlap of dates.
  78.  
  79. CLEAR
  80. dStart:=dEnd:=CTOD("  /  /  ")
  81. @ 3,5 SAY "Starting Date: " GET dStart PICTURE "99/99/99"
  82. @ 4,5 SAY "  Ending Date: " GET dEnd PICTURE "99/99/99"
  83. READ
  84.  
  85. @ 10,10 SAY "Subcontract Period: "+DTOC(dStart)+" - "+DTOC(dEnd)
  86. @ 11,0  SAY ""
  87. USE RATE
  88. INDEX ON START_DATE TO START
  89. *** Soft seek in Clipper will search the next available record if there is no match
  90. SET SOFTSEEK ON
  91. SEEK dStart
  92. *** FOUND() statement can NOT be used because soft seek will always be .F. for FOUND()
  93. IF ! EOF()
  94.    *** When you are at the next available record, you MUST skip back to check if the 
  95.    *** ending date in the RATE.DBF and compare it with the user's beginning date
  96.    SKIP -1
  97.    IF RATE->END_DATE >= dStart
  98.       *** Since the ending date in RATE.DBF is greater then the contract status 
  99.       *** should be printed between the user's beginning and the RATE.DBF ending date
  100.       @ ROW()+1,15 SAY DTOC(dStart)+" - "+DTOC(RATE->END_DATE)
  101.       @ ROW(),  40 SAY RATE->STATUS
  102.    ENDIF
  103.    *** Now that you have checked if the above, you MUST return to the next available 
  104.    *** record
  105.    SKIP +1
  106.    *** You may now loop until the RATE.DBF starting date is greater than or equal to
  107.    *** the user's starting date and compare the ending dates
  108.    DO WHILE RATE->START_DATE >= dStart
  109.       IF RATE->END_DATE <= dEnd
  110.          @ ROW()+1,15 SAY DTOC(RATE->START_DATE)+" - "+DTOC(RATE->END_DATE)
  111.          @ ROW(),  40 SAY RATE->STATUS
  112.       ELSE
  113.          @ ROW()+1,15 SAY DTOC(RATE->END_DATE+1)+" - "+DTOC(dEnd)
  114.          @ ROW(),  40 SAY "Uncovered"
  115.          EXIT
  116.       ENDIF
  117.       SKIP +1
  118.       IF EOF()
  119.          *** Eventhough you are at EOF(), you must skip back and check that the
  120.          *** ending date is still within the range 
  121.          SKIP -1
  122.          IF dEnd # RATE->END_DATE   && Here was the bug
  123.             @ ROW()+1,15 SAY DTOC(RATE->END_DATE+1)+" - "+DTOC(dEnd)
  124.             @ ROW(),  40 SAY "Uncovered"
  125.          ENDIF
  126.          EXIT
  127.       ENDIF
  128.    ENDDO
  129. ELSE
  130.    *** Again, eventhough you are at EOF(), you must skip back and check that the
  131.    *** ending date is still within the range (i.e. RATE.DBF with one record)
  132.    SKIP -1
  133.    IF RATE->END_DATE >= dStart
  134.       @ ROW()+1,15 SAY DTOC(dStart)+" - "+DTOC(RATE->END_DATE)
  135.       @ ROW(),  40 SAY RATE->STATUS
  136.       @ ROW()+1,15 SAY DTOC(RATE->END_DATE+1)+" - "+DTOC(dEnd)
  137.       @ ROW(),  40 SAY "Uncovered"
  138.    ELSE
  139.       @ ROW()+1,15 SAY DTOC(dStart)+" - "+DTOC(dEnd)
  140.       @ ROW(),  40 SAY "Uncovered"
  141.    ENDIF
  142. ENDIF
  143. SET SOFTSEEK OFF
  144. SET INDEX TO
  145. USE
  146.  
  147.  
  148.