返回列表 回复 发帖

關于form間的條件查詢問題

我剛剛學,碰到這個form間傳值的問題了,以下是我的問題:
從查詢form中選擇查詢條件后,按FIND按鈕,SHOW出查詢結果,查出來的內容是通過查詢條件篩選過的,如何寫代碼?謝謝賜教!
附件: 您所在的用户组无法下载或查看附件
假設我們現在要查 員工編號在 1000~2000 之間,且姓王的員工

<查詢畫面>
Block Name : B_QUERY_FIND
Item Name : emp_name "員工姓名" , emp_no_beg "員工編號起" , emp_no_end "員工編號迄"

<主畫面>
Block Name : B_MAIN
Item Name : emp_name "員工姓名" , emp_no "員工編號"

因為兩個 Block 的員工姓名資料是可以 maping 的,
在 B_MAIN 的 block level trigger : PRE-QUERY 中加上
copy( :B_QUERY_FIND.EMP_NAME , 'B_MAIN.EMP_NAME' );

如此不管在 :B_QUERY_FIND.EMP_NAME 打完整名稱,或以 % 來查詢都可以

因為員工編號的查詢條件是以區間來查詢,所以在  FIND Button 中處理
declare
   ls_where         varchar2(1000);
   ls_this_where    varchar2(1000);
begin
   if     :b_query_find.emp_no_beg is null
      and :b_query_find.emp_no_end is null
   then
      :parameter.g_query_find := 'FALSE';
      Fnd_Message.Set_Name('FND','You Must Enter Employee Number !!');
      Fnd_Message.Error;
   else
      ls_where := GET_BLOCK_PROPERTY('B_MAIN',DEFAULT_WHERE);
      if  ls_where is null
      then
         ls_this_where := '1=1 ';
      else
         ls_this_where := ls_where;
      end if;
      if    :b_query_find.emp_no_beg is not null
      then
         ls_this_where := ls_this_where||' and emp_no >= :b_query_find.emp_no_beg';
      end if;
      if    :b_query_find.emp_no_end is not null
      then
         ls_this_where := ls_this_where||' and emp_no <= :b_query_find.emp_no_end';
      end if;
      SET_BLOCK_PROPERTY(''B_MAIN',DEFAULT_WHERE,LS_THIS_WHERE);
      app_find.find('B_MAIN');
      SET_BLOCK_PROPERTY('B_MAIN',DEFAULT_WHERE,LS_WHERE);
   end if;
end;
:parameter.g_query_find := 'FALSE';

以此例而言 :
:B_QUERY_FIND.EMP_NAME := '王%'
:B_QUERY_FIND.EMP_NO_BEG := '1000'
:B_QUERY_FIND.EMP_NO_END := '2000'

就可以查詢出所要的資料
謝謝您,我先試試看,有結果告訴您!

我按FIND查詢后導向的是主從塊

小明,您好!

我按你寫的代碼去做了一下,沒有任何資料被查出來,
我的需求是按FIND導向一個主從塊,條件通過主塊level:pre-query的語句:
copy(:ns_model_distribution.distribution_number,':control.distribution_number');

看起來條件沒有被傳過來,或者傳過來了,沒有被FIND中的代碼檢測到,因為沒有查出任何東西。

特給您回復,還請幫忙看一下,我的檔案傳上來

其他大俠們也幫我看看吧!這個問題困擾我很久了。
附件: 您所在的用户组无法下载或查看附件
我的需求是按FIND導向一個主從塊,條件通過主塊level:pre-query的語句:
copy(:ns_model_distribution.distribution_number,':control.distribution_number');
=>依據你的檔案,並沒有看到這個 PRE-QUERY,而且我認為你 copy 過去的欄位值就是字串 ':control.distribution_number'

另外我查看你在  FIND 的 trigger : WHEN-BUTTON-PRESSED  中
set_block_property('ns_model_distributions',default_where,'distribution_number=:control.distribution_num');
我建議在此 block name 最好是大寫,因為在此是一個字串 (這點不確定啦^^)
set_block_property('NS_MODEL_DISTRIBUTIONS',default_where,'distribution_number=:control.distribution_num');

[ 本帖最后由 blueworm 于 2007-12-31 11:48 编辑 ]
我在你提供的檔案做了一些修改,你參考看看

1. 在查詢畫面增加兩個欄位 : START_DATE 及 END_DATE ,用來與 main block 的 START_DATE_ACTIVE 做區間比較(見 pic1)

2. 在 find 的 trigger : when-button-pressed 改寫如下 :
-- 2007/12/31 add by blueworm
declare
   ls_where         varchar2(1000);
   ls_this_where    varchar2(1000);
begin
   if     :control.distribution_num is null
             and :control.distribution_type is null
             and :control.target_name is null
             and :control.inventory_item_num is null
             and :control.item_num is null
             and :control.start_date_active is null
             and :control.start_date is null
             and :control.end_date is null
   then
        :parameter.g_query_find := 'FALSE';
        Fnd_Message.Set_Name('FND','請務必輸入一樣查詢資料!');
        Fnd_Message.Error;
   else
      :parameter.g_query_find := 'TRUE';
      ls_where := GET_BLOCK_PROPERTY('NS_MODEL_DISTRIBUTIONS',DEFAULT_WHERE);
      if  ls_where is null
      then
         ls_this_where := '1=1 ';
      else
         ls_this_where := ls_where;
      end if;
      -- 我另外增加兩個欄位 start_date / end_date 與 起始日期(start_date_active) 做區間比較
      if  :control.start_date is not null
      then
         ls_this_where :=  ls_this_where||' and start_date_active >= :control.start_date';
      end if;
      if  :control.end_date is not null
      then
         ls_this_where :=  ls_this_where||' and start_date_active <= :control.end_date';
      end if;
      SET_BLOCK_PROPERTY('NS_MODEL_DISTRIBUTIONS',DEFAULT_WHERE,LS_THIS_WHERE);
      app_find.find('NS_MODEL_DISTRIBUTIONS');
      -- 因為 default_where 已被變更,所以在查詢後要還原
      SET_BLOCK_PROPERTY('NS_MODEL_DISTRIBUTIONS',DEFAULT_WHERE,LS_WHERE);
   end if;
   :parameter.g_query_find := 'FALSE';
end;

3. 在 main block : NS_MODEL_DISTRIBUTIONS 增加兩個 trigger : PRE-QUERY / QUERY-FIND
<  PRE-QUERY  >
-- 2007/12/31 add by blueworm
IF :parameter.G_query_find = 'TRUE'
THEN
   copy( :CONTROL.DISTRIBUTION_NUM       , 'NS_MODEL_DISTRIBUTIONS.DISTRIBUTION_NUM'     );  -- 攤提案號
   copy( :CONTROL.DISTRIBUTION_TYPE      , 'NS_MODEL_DISTRIBUTIONS.DISTRIBUTION_TYPE'    );  -- 交易類型
   copy( :CONTROL.TARGET_NAME            , 'NS_MODEL_DISTRIBUTIONS.TARGET_NAME'          );  -- 往來對象
   copy( :CONTROL.INVENTORY_ITEM_NUM     , 'NS_MODEL_DISTRIBUTIONS.INVENTORY_ITEM_NUM'   );  -- 攤提料號
   copy( :CONTROL.ITEM_NUM               , 'NS_MODEL_DISTRIBUTIONS.ITEM_NUM'             );  -- 模具料號
   copy( :CONTROL.START_DATE_ACTIVE      , 'NS_MODEL_DISTRIBUTIONS.START_DATE_ACTIVE'    );  -- 起始日期
   :parameter.G_query_find := 'FALSE';
END IF;

<  QUERY-FIND  >
-- 2007/12/31 add by blueworm
-- app_find.query_find('<Result Block Window Name>',
--                     '<Find Window Name>',
--                     '<Find Window Block Name>');
app_find.clear;
APP_FIND.QUERY_FIND('NS_MODEL_DISTRIBUTIONS',
                    'CONTROL',
                    'CONTROL');
附件: 您所在的用户组无法下载或查看附件
謝謝!我受益非湥催^您的修正,已經明白原因了,非常感謝!
日后有問題希望能再得到您的幫助!

Denise Tian
very good
thank you
你们写的代码我怎么看不懂呢
非常好的办法,多谢多谢俄
返回列表