-1

a single customer could have multiple orders and corresponding cost. now the cost/price has to be added and according to the max price the customer's should be displayed. i have just written the skeleton of the prog , please help me.

  define temp-table ttorder
  field ocust-num like order.cust-num 
  field oorder-num   like order.order-num.
  define variable i as int.
  define variable a as int.

  define temp-table ttorderln
  field oprice like order-line.price.

  for each order where order-date > 01/08/93 /*by cust-num*/ . 

      create ttorder .
      assign
        ttorder.ocust-num   =cust-num
        ttorder.oorder-num = order-num.

    for each order-line where order-line.order-num = ttorder.oorder-num break by ocust-num.

    i = order-line.price.
     a = i + a. 
  /*   display cust-num order-num a. */
    if last-of (ttorder.ocust-num) then
        do:


        create ttorderln.
        ttorderln.oprice=a. 

        end. 

   display ttorderln.

    end.  


  end.
Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
sri
  • 11
  • 1
  • 7
  • This doesn't seem like a Progress or even a programming question, but rather an algorithm/logic question. I am not sure this is the right place for you to ask that. The cost/price has to be added, do you mean you should display the order totals? By order or just the max? – bupereira Dec 15 '16 at 14:40

1 Answers1

2

If you're looking for the top customers, you should use a temp table based on customers, not orders. Go through the orders and order lines, accumulating the amounts by customer.

define temp-table ttcust
  field cust-num like order.cust-num 
  field order-tot as decimal
  index idx1 cust-num
  index idx2 order-tot.

define variable i as integer.

  for each order where order-date > 01/08/93: 

      /* Find or create a customer temp record. */
      find first ttcust where ttcust.cust-num = order.cust-num no-error.
      if not available(ttcust) then
      do:
          create ttcust.
          ttcust.cust-num = order.cust-num.
      end.

      /* Add up the order lines. */
      for each order-line where order-line.order-num = order.order-num no-lock:
          ttcust.order-tot = ttcust.order-tot + order-line.extended-price.
      end.

  end.

  /* Display the top 10. */
  for each ttcust by order-tot descending:
    i = i + 1.

        message "Cust: " ttcust.cust-num skip
                "Total: " ttcust.order-tot view-as alert-box.

    if i >= 10 then leave.

  end.
Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
TheDrooper
  • 1,182
  • 1
  • 7
  • 14
  • Thanks for the edit, Tom. I see my original answer would have looped through all of the ttcust records even though only 10 were needed. – TheDrooper Dec 15 '16 at 22:14