一、数据窗口的设置
有时候,我们需要一些符合某些情况下的数据,它的结果有可能是集合。比如查找入库时间为今天的货品id。如果按照Java的思想,直接将查询结果放到集合里面返回,再对该集合进行其他操作。首先pb的特点就是随时随地都可以直接写sql查数据进行数据库操作,pb的操作也大致是这样,可以将我们的数据窗口理解为实体类entity,datasource就是mybatis里的sql,设置好数据窗口的参数和返回值(返回列),对数据窗口实例化,然后对该对象进行传参和retrieve,最后对该数据窗口对象进行其他操作。
新建数据窗口 d_selectgoods,然后点击菜单栏data source
点击菜单栏 Design》》retrieval Arguments 进行参数的设置(注意类型和名字)
然后编写sql,注意参数的格式:as_barcode
还有:as_pid
,选择的列就是我们要的返回值
select
max(b.goodsname) as goodsname,
max(decode(nvl(d.xinghao,' '),' ',b.goodstype,d.xinghao)) as goodstype,
max(b.prodarea) as prodarea ,
max(d.lotname) as lotname,
max(d.expirydate) as expirydate,
a.upgoodsid as upgoodsid ,
a.uplotid as uplotid
from w_bpack_mst a ,gen_goods_upper b, gen_lot_upper d
where a.upgoodsid = b.upgoodsid
and a.uplotid = d.uplotid and
(a.barcode =:as_barcode or upper(a.factorycode) = :as_barcode) and a.useflag = 0 and (a.pid = :as_pid or a.pid is null)
group by a.uplotid ,a.upgoodsid
窗口
此时我们可以自己传参测试一下。
菜单栏 Rows》》Retrieve
注意
如果retrieve是灰色的,那就View>>preview一下
二、代码中实例化
ids_goods = create fc_ds
ids_goods.dataobject = 'd_selectgoods'
ids_goods.settransobject(sqlca)
//传参,上一层传进来的参数
ids_goods.retrieve(as_barcode,as_pid)
//查找该数据窗口里的符合条件的列,查找是否存在某些数据
//首先拼接一个字符串
ls_find = "barcode='"+ls_temp_barcode+"'" + " and upgoodsid="+string(ll_upgoodsid) + " and uplotid ="+string(ll_uplotid)
//然后调用窗口方法 find(expression,start,end)
ids_goods.find(ls_find,1,999999) //从第1行开始,到999999结束
//返回指定范围内满足查找条件的第一个数据行的行号;未找到则返回0;出错返回-1;如果任何参数的值为null,则返回值也为null
//例:如果数据窗口集合里无这条数据,则***
if ids_goods.find(ls_find,1,999999) <= 0 then
***
***
end if