问题描述
嗨,有人可以帮我做点什么吗。抱歉,我是新手。
我有一个文件“dntData”,一列有 9 个数字。 6是数据库表中的数字,3是组合数字。
我想要做的就是让程序读取输入,查找表中的数字并返回这些数字是否存在于表中。
出于某种原因,我的程序只返回它可以找到的数字,而不返回它不能找到的数字 - 这对我的目的没有用。我需要一个输出来告诉我“找不到号码”以及要查找的号码。
这是我写的代码:
def stream inputStream.
def stream outStream.
def var dntData as char extent 1 no-undo.
def var vl-CIN# as integer.
def var vl-error as char.
def var vl-match as char.
input stream inputStream from "/home/xxx/xxx/xxx/xxx/FirstInput.csv".
output stream outStream to "/home/xxx/xxx/xxx/xxx/FirstOutput.csv".
export stream outStream delimiter "'" "CustomerID" "Match" "Error".
Repeat:
assign
dntData = "".
import stream inputStream delimiter "'" dntData.
assign
vl-CIN# = integer(dntnData[1]).
find first members where cin# = vl-CIN#.
if not available(members) then
assign
vl-error = "Could Not Find".
if available(members) then
assign
vl-match = "Account Exists".
export stream outStream delimiter "'" vl-CIN# vl-match vl-error.
解决方法
当 FIND
找不到记录时,它会抛出错误,因此您需要将 NO-ERROR
添加到您的 find 语句中。
参见 ABLdojo 上的简单示例:
define temp-table tt
field id as int
.
create tt. tt.id = 1.
// create tt. tt.id = 2.
create tt. tt.id = 3.
def var cc as char extent 1.
def var id as int.
input from "input.csv".
repeat:
cc = ''.
import delimiter "'" cc.
id = integer( cc[1] ).
find first tt where tt.id = id no-error.
if not available tt then
message 'not found' id.
else
message 'found' tt.id.
end.
input close.
输入文件为:
1'one
2'two
3'three
几点说明:
- 如果您在 key 上查找记录,则应使用
find
而不是find first
- 如果您对记录的内容不感兴趣,而只是想知道它是否存在,请使用
can-find
函数(返回真/假,不需要no-error
)