2017-07-07 34 views
0

如何從正在進行的db中獲取數值4gl,最初有一個來自用戶的輸入,用於根據記錄顯示的值來選擇記錄。我們嘗試,但我們無法獲取確切的價值。如何檢索正在進行的db數據4gl?

這是我們的計劃:

def var b as int. 
def var obj as int. 
/*set obj. 
prompt-for obj.*/ 
def var sum as int. 
def var a as int no-undo. 
def var i as int no-undo. 
for each po_mstr break by po_nbr. 
select count (*) from po_mstr. 
    assign 
     a = 1 
     b = 583 . 
    repeat: 
     if first-of (po_nbr) then 
      set obj. 
     prompt-for obj. 
     if (a le obj and obj lt b) then 
      disp po_nbr po_vend po_ship po_ord_date with 2 col. 
    end. 
end. 

我可以檢索單個數據只有我們給超過2值意味着它將顯示相同的第一個值。

+0

在ABL中使用SELECT是一個壞主意! – Austin

回答

0

我們來分析一下。你在使用很多命令而沒有真正意識到它們的用途。

FOR EACH打開一個塊並按照選定的排序順序(如果沒有被選擇,則它使用主索引)爲每個循環執行記錄讀取。

SELECT將執行數據庫操作,但不一定在執行,但它可能會。

REPEAT還會打開一個塊,其中您可能會或可能不會使用其他命令循環記錄。話雖如此,以下是我如何寫這個:

def var a as int no-undo. 
def var b as int. 
def var sum as int. 
/* 
def var obj as int. 
update obj. 
def var i as int no-undo. 
you're not using this */ 
select count (*) into sum from po_mstr. 
/* is this what you wanted? To have the count in sum? I don't see a reason, but suit yourself */ 
assign a = 1 b = 583 . /* or use UPDATE a b. if you would like to make that variable */ 
/* Since a and b are not changing, I moved it to outside the loop */ 
for each po_mstr where po_nbr >= a and po_nbr < b: 
    disp po_nbr po_vend po_ship po_ord_date with 2 col. 
end. 

我採取了一些自由。我刪除了obj,因爲據我所能評估,你試圖將po_nbr值複製到它,然後用它來查看它是否在你想看到的範圍內。因爲我相信po_nbr代表po數,這可能是獨一無二的,我也猜想每次迭代都會有不同的值。所以如果是第一次就不需要使用。它也消除了將其複製到變量的需要。只需將其與您想要查看的寶的範圍直接比較即可。最後,顯示應該沒問題。

我打算繼續並假設你的團隊還沒有接受過培訓。這將是非常重要的,因爲QAD(實際上任何ERP軟件)都會誇大實際上快速且寫得很差的代碼,即使無害,可能會影響性能和可用性,這可能會成爲整個操作的問題。堆棧溢出可能對準時性問題有所幫助,但如果您沒有準備好,遇到的問題可能無法在此處解決。

希望這會有所幫助。