home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a063 / 6.img / SAMPLE / APTSQL / DSCIN_1.FPL < prev    next >
Encoding:
Text File  |  1990-08-24  |  2.1 KB  |  88 lines

  1. create apt proc dscin_1() as
  2. begin
  3.     variable vstoreid char(5)    
  4.     variable descrip char(40)
  5.     variable vlowqty  int
  6.     variable status   int
  7.  
  8.     useform sdsc_3
  9.     channel  sqlrowch
  10.  
  11.     /*
  12.     ** Note: sqlrows must not use $channel, the default channel. 
  13.     */
  14.     define discquery sqlrow on sqlrowch
  15.     sqlbegin
  16.         select discounttype, stor_id, lowqty, highqty,
  17.             percent = discount
  18.         from discounts
  19.         where    stor_id = {sqlexpr(storeid)}
  20.             or {quantity} >= lowqty
  21.             or {quantity} <= highqty
  22.             or (stor_id = NULL and lowqty = NULL
  23.                 and highqty = NULL)
  24.     sqlend
  25.  
  26.     /*
  27.     ** Beginning of executable statements.
  28.     */
  29.  
  30.     /*  The second channel, needed for sqlrows, is not opened until it
  31.     **  is actually needed.  This cuts down on the application startup
  32.     **  time.  The channel is closed when the application shuts down,
  33.     **  since we don't want to keep opening and closing expensive channels.
  34.     */
  35.     if sqlrowch:open = FALSE
  36.     begin
  37.         connect sqlrowch
  38.         submit on sqlrowch
  39.         sqlbegin
  40.             use pubs
  41.         sqlend
  42.     end
  43.  
  44.     /*
  45.     **  Clear the discount group, then load it from the database.  Note
  46.     **  that the "description" field is composed from descriptive words
  47.     **  and data from the Server, rather than a straight transfer.
  48.     */
  49.     reset grpdiscount
  50.  
  51.     opensql discquery
  52.     foreach discquery
  53.     begin
  54.         /* The transfer transfers just the 'discount', a percentage. */
  55.         transfer discquery
  56.  
  57.         descrip = discquery(discounttype)  + "  "
  58.  
  59.         /* At this time, "sqlrow(col) is NULL" is not a legal statement.
  60.         ** So we transfer column data to APT-SQL variables vstoreid and
  61.         ** vlowqty, and then test for NULL.
  62.         */
  63.         vstoreid = discquery(stor_id)
  64.         if vstoreid is not NULL
  65.         begin
  66.             descrip = descrip + "Store Id:" + discquery(stor_id)
  67.         end
  68.  
  69.         vlowqty = discquery(lowqty)
  70.         if vlowqty is not NULL
  71.         begin
  72.             descrip = descrip + discquery(lowqty):text + " -> " +
  73.                 discquery(highqty):text
  74.         end
  75.  
  76.         grpdiscount[discquery:index].description = descrip
  77.     end
  78.     closesql discquery 
  79.  
  80.     adddisc = 0
  81.     save field adddisc
  82.     totpercent = 0
  83.  
  84.     call clcst_1(quantity, totpercent, price,  totalcost, status)
  85.  
  86.         return
  87.    end
  88.