任何建議從進展4GL大師來看看4GL代碼波紋管塊,看看它是否過度完成?可以這樣做,以便更容易跟蹤/更具可讀性?Openedge進度4GL表加入
我TBLA
Report
6998077
6998078
6998097
7062816
而且TBLB
+-----------+------------+-----------+
| ID | Source| Report |
+-----------+------------+-----------+
| 4976117 | 6998077 | 6998077 |
| 4976118 | 6998078 | 6998078 |
| 4976137 | 6998097 | 6998097 |
| 5107798 | 7062816 | 6998078 |
| 5107799 | 7062816 | 6998097 |
+-----------+------------+-----------+
,我有,在我看來,一個複雜的進展4GL循環:
def temp-table TblTemp no-undo
field cTypeOfRec as char
field Report as int
field Source as int
field ID as int
index key is unique primary Report Source ID.
procedure SOOptimize:
output stream dOut1 to value("/OutPut.txt").
export stream dOut1 delimiter "|"
"Report"
"Source"
"ID".
for each TblA no-lock
on error undo, return error on stop undo, return error:
for each TblB no-lock where
TblB.Source = TblA.Report
on error undo, return error on stop undo, return error:
find TblTemp exclusive-lock where
TblTemp.SrcPltSeq = TblA.Report and
TblTemp.RptPltSeq = TblB.Report and
TblTemp.ID = TblB.ID
no-error.
if NOT available TblTemp
then do:
create TblTemp.
assign
TblTemp.cTypeOfRec = "From LoopA"
TblTemp.SrcPltSeq = TblA.Report
TblTemp.RptPltSeq = TblB.Report
TblTemp.ID = TblB.ID.
end.
end.
for each TblB no-lock where
TblB.Report = TblA.Report
on error undo, return error on stop undo, return error:
find TblTemp exclusive-lock where
TblTemp.SrcPltSeq = TblB.Source and
TblTemp.RptPltSeq = TblA.Report and
TblTemp.ID = TblB.ID
no-error.
if NOT available TblTemp
then do:
create TblTemp.
assign
TblTemp.cTypeOfRec = "From LoopB"
TblTemp.SrcPltSeq = TblB.Source
TblTemp.RptPltSeq = TblA.Report
TblTemp.ID = TblB.PltSrcSeq.
end.
end.
end.
for each TblTemp no-lock
on error undo, return error on stop undo, return error:
export stream dOut1 delimiter "|"
TblTemp.
end.
end procedure.
然後我進步的輸出代碼是:
+------------+---------+---------+---------+
| cTypeOfRec | Source | Report | ID |
+------------+---------+---------+---------+
| From LoopA | 6998077 | 6998077 | 4976117 |
| From LoopA | 6998078 | 6998078 | 4976118 |
| From LoopB | 7062816 | 6998078 | 5107798 |
| From LoopA | 6998097 | 6998097 | 4976137 |
| From LoopB | 7062816 | 6998097 | 5107799 |
+------------+---------+---------+---------+
我對Progress 4GL的知識非常有限。這段代碼似乎過於完成了嗎?它可以更簡單嗎?
我來自SQL背景。所以在SQL中,我可以快速輕鬆地解決這個問題。我的意思是,所有這塊進展代碼基本上只是說,如果從LoopA中,如果在LoopB中爲NULL,否則說「從LoopB」
下面是我提出的SQL等價物:
Select
case when B.ID is null then 'From LoopA'
else B.cTypeOfRec
End "cTypeOfRec"
, A.*
from #TblTemp A
left join (
select A.*, 'From LoopB' "cTypeOfRec" from (select * from #TblTemp)A
left join (
select B.Source, A.Report, B.ID from #TblA A
Inner join #TblB B
on B.Report=A.Report)B
on A.Source = B.Report
where B.Source is null) B
on A.Report=B.Report
and a.ID = b.ID
and a.Source= b.Source
order by A.Report
, case when B.ID is null then 'From LoopA'
else B.cTypeOfRec
End
從進度4GL大師任何意見採取的上述4GL代碼塊上偷看,看看它是否過於做了什麼?可以這樣做,以便更容易遵循/可讀?
但我對任何回答都很開放,如果這是在4GL中編寫代碼以實現最終結果的正確方法,那麼我就可以。
謝謝謝謝