2016-12-15 3 views
-1

у одного клиента может быть несколько заказов и соответствующая стоимость. теперь стоимость/цена должна быть добавлена ​​и в соответствии с максимальной ценой необходимо отобразить клиента. Я только что написал скелет прог, пожалуйста, помогите мне.Как выбрать первую десятку клиентов с указанной начальной датой с большей стоимостью/ценой заказов с использованием прогресса 4gl

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. 
+0

Это не похоже на прогресс или даже вопрос программирования, а скорее вопрос алгоритма/логики. Я не уверен, что это подходящее место для вас, чтобы спросить об этом. Стоимость/цена должна быть добавлена, вы имеете в виду, что вы должны отображать итоговые суммы заказа? По заказу или просто макс? – bupereira

ответ

2

Если вы ищете лучших клиентов, вы должны использовать временную таблицу на основе клиентов, а не заказов. Пройдите через строки заказов и заказов, аккумулируя суммы по клиенту.

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. 
+0

Спасибо за редактирование, Том. Я вижу, что мой первоначальный ответ зациклился бы на всех записях ttcust, хотя было необходимо только 10. – TheDrooper