2016-12-15 1 views
-1

1人の顧客が複数の注文と対応するコストを持つことができます。 コスト/価格を追加する必要があり、最大価格に応じて顧客を表示する必要があります。 私はprogのスケルトンを書きました。私を助けてください。進捗状況を使用して、より高いコスト/注文価格で、上位10名の顧客を特定の開始日にリストする方法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

編集のおかげで、Tom。私は私の元の答えがすべてのttcustレコードをループしていたにもかかわらず、10個しか必要ではないことがわかりました。 – TheDrooper

関連する問題