跳到主要內容

更新或建立 ITEM CATEGORY


 DECLARE
  
   CURSOR C3 IS
   SELECT TRIM(A ) item_number, TRIM(D) g01
     FROM TMP_CCC
    where TRIM(d) is not null;

    v_process_id                    number;
    v_inventory_item_id                number;
    v_item_insert                   number:=0 ;
    v_category_id                    number;
    v_po_category_set_id            number;
    v_om_category_set_id            number;
    v_item_count                     number:=0 ;
    v_count1                        number:=0 ;
    v_request_id                    number;
    v_organization_id                number;
    xx_ls_phase                     varchar2(240 );
    xx_ls_status                    varchar2(240 );
    xx_ls_dummy1                    varchar2(240 );
    xx_ls_dummy2                    varchar2(240 );
    xx_ls_dummy3                    varchar2(240 );
    xx_lb_return                    boolean;
    v_buyer_id                        number;
    v_planner_code                    number;
    v_template_id                     number;
    v_template_name                    varchar2(30 );
    x_item_id                          number;
    dummy                                number;
    x_category_id                    number;
    v_uom                                varchar2(10 );
    v_weight_uom                    varchar2(10 );
    x_errbuf                           VARCHAR2(200 );
  x_retcode                          VARCHAR2(200 );
  V_CATEGORY_SET_ID_O   number;
  V_CATEGORY_ID_O       number;
  V_CATEGORY_CONCAT_SEGS   VARCHAR2(163 );
  V_CATEGORY_SET_ID     number;
  v_exist               VARCHAR2(1 ):= 'N';
BEGIN

DBMS_APPLICATION_INFO.SET_CLIENT_INFO (84);    --Organization_ID
--DBMS_APPLICATION_INFO.SET_CLIENT_INFO(FND_PROFILE.VALUE('LANG'));

    select    Mtl_system_items_intf_sets_s.nextval
    into     v_process_id
    from     dual;

  v_exist := 'N';

    for r in c3 loop
        v_exist := 'Y';

            begin
                select a.CATEGORY_ID
                        ,b. category_set_id
                into    v_category_id
                        ,v_po_category_set_id
                from     mtl_categories_b_kfv a
                        ,MTL_CATEGORY_SETS_V b
                WHERE     a.structure_id = b .structure_id
                and          b.CATEGORY_SET_NAME = 'Group01'    --只更新指定的Category Name
                and          a.CONCATENATED_SEGMENTS = r .g01;
            exception
                when others then
                     v_category_id := '';
                     v_po_category_set_id := '';
            end;
           
            select inventory_item_id into  v_inventory_item_id from mtl_system_items_b where segment1=r.item_number
                and organization_id=84 ;

            if v_category_id is not null then
           BEGIN
              SELECT CATEGORY_SET_ID, CATEGORY_ID, CATEGORY_CONCAT_SEGS
                INTO V_CATEGORY_SET_ID_O, V_CATEGORY_ID_O, V_CATEGORY_CONCAT_SEGS
                FROM MTL_ITEM_CATEGORIES_V A,
                     MTL_SYSTEM_ITEMS_B B
               WHERE A.Organization_id = B .Organization_id
                 AND A.Organization_id = 84
                 AND A.INVENTORY_ITEM_ID = B .INVENTORY_ITEM_ID
                 AND A.STRUCTURE_ID = 50272
                 AND B.SEGMENT1 = trim(upper( r.item_number ));
           EXCEPTION
              WHEN OTHERS THEN
                   V_CATEGORY_SET_ID_O := '';
                   V_CATEGORY_ID_O := '';
                   V_CATEGORY_CONCAT_SEGS := '';
           END;
                    BEGIN
                      IF V_CATEGORY_CONCAT_SEGS IS NOT NULL AND V_CATEGORY_CONCAT_SEGS ! = r.FUHSING_STOCKER THEN
                           Insert into MTL_Item_Categories_Interface (
                                                            inventory_item_id,
                                                            Organization_id,
                                                            Transaction_type,
                                                            process_flag,
                                                            Item_number,
                                                            Set_process_id,
                                                            category_set_id,
                                                            category_id,
                                                            OLD_CATEGORY_ID)
                                                    Values(
                                                             v_inventory_item_id,
                                                            84,
                                                            'UPDATE',
                                                             1,
                                                            trim(upper(r. item_number)),
                                                            v_process_id,
                                                            V_CATEGORY_SET_ID_O,
                                                            v_category_id,  -- NEW_CATEGORY_ID
                                                            V_CATEGORY_ID_O -- OLD_CATEGORY_ID
                              );

                      END IF;

                      IF V_CATEGORY_CONCAT_SEGS IS NULL THEN
                         Insert into MTL_Item_Categories_Interface (
                                                               inventory_item_id,
                                                               Organization_id,
                                                               last_update_date,
                                                               last_updated_by,
                                                               creation_date,
                                                               ----------------------5
                                                               created_by,
                                                               last_update_login,
                                                               category_set_id,
                                                               category_id,
                                                               Transaction_type,
                                                               ----------------------10
                                                               process_flag,
                                                               Item_number,
                                                               Set_process_id
                                                       )Values(
                                                               v_inventory_item_id,
                                                               84,
                                                               sysdate,
                                                               fnd_profile.VALUE('USER_ID' ),--fnd.user,
                                                               sysdate,
                                                               ----------------------5
                                                               fnd_profile.VALUE('USER_ID' ),--fnd.user,
                                                               fnd_profile.VALUE('USER_ID' ),--fnd.user,
                                                               v_po_category_set_id,
                                                               v_category_id,
                                                               'CREATE',
                                                               ----------------------10
                                                               1,
                                                               trim(upper(r. item_number)),
                                                               v_process_id
                                                               );
            END IF;
                  END;
            end if;   

        commit;

    end loop;

END;
/

執行完上述的PL/SQL之後,可以到ERP來執行。

1、找出set_process_id

select set_process_id from   mtl_item_categories_interface ;


2、執行ERP,填入Set_Process_id





留言

這個網誌中的熱門文章

Line如何換行

在電腦版的Line輸入文字時,遇到需要換行的情形時,我都是用記事本先寫好再複製上去,這樣就可以有換行的效果,可是這樣的做法好像失去Line的便利性。 於是查了一下,原來有一個設定可以指定Enter換行,而不是發訊息出去。 完成設定之後,要發送訊息就改用Alt+Enter,而Enter就可以換行了。

在Windows下,利用tasklist與taskkill來刪除Process

Windows7 / Windows8 kill process Linux下要刪除某個程序通常會使用 ps 配合 kill 來刪除程序。 例如:ps -ef |grep [PROCESS NAME]       kill -9 [PID] 在Windows下,通常是開啟工作管理員來強制結束應用程式,但是如果要寫成Script,就必須改為命令式。 TASKLIST [/S system [/U username [/P [password]]]]          [/M [module] | /SVC | /V] [/FI filter] [/FO format] [/NH]           TASKKILL [/S system [/U username [/P [password]]]]          { [/FI filter] [/PID processid | /IM imagename] } [/T] [/F]           (Tasklist:查詢Process ; Taskkill:刪除Process)           例如要刪除已開啟的記事本(notepad): 1、查詢記事本的Process訊息     C:\> tasklist |find /i "notepad.exe"     notepad.exe      6092 Console     1     5,832 K 2、由上得知記事本的PID為6092     C:\> taskkill /f /PID 6092     成功:處理程序 PID 6092 已經終止了。     taskkill使用的參數     /f:指定此參數可強制終止處理程序     /PID:指定要終止之處理程序的 PID      3、也可以直接以程式名稱刪除     C:\ taskkill /f /im notepad.exe     成功:處理程序 "notepad.exe" <PID 6092> 已經終止了      下面是我自己測試的Script,可以刪除多個相同的程式,例如同時開啟了三個記事本: @echo off for /f &quo

Shell Script簡易教學

一、概論 在許多的情況之下,我們都需要固定一組可以重覆或判斷資訊的指令, 而把這些指令存被在文字檔中,再交由Shell執行,就是Script。 一般會將Shell Script的副檔名命名為.sh,雖然副檔名在Linux中並非必要, 但是有副檔名可以讓我們更容易管理這些檔案。 假設有一個名為test.sh 的 Shell Script,首先用文字編輯器來撰寫內容如下: #!/bin/bash echo Hello World 第一行是必需的,它是用來定義你要使用的 shell。Linux中有許多的Shell可以使用, 如:ksh、bash,但是彼此之間語法有所差異,所以我們首先需要定義使用哪一個Shell。 而第二行的 echo 代表列出一個字串,預設會把後面的字串「Hello World」顯示在螢幕上。 將test.sh存檔後,可以用下列其中一種方式執行它: 1、直接輸入 sh test.sh 2、改變test.sh的權限,加上可以執行的權限,    chmod a+x test.sh    接著直接執行它:    ./test.sh 在Shell Script中,「#」表示註解,在#後面將視為註解並且被程式忽略。 例如: #pwd ls -l Shell只會執行ls -l,而不會執行ls -l 而「;」 則代表指令的分隔,例如: pwd;ls -l 和 pwd ls -l 都是一樣執行pwd及ls -l。 二、變數的使用 在Shell Script中,所有的變數都視為字串,因此不需要在定義變數類型。 在Shell中定義和使用變數時並不一樣。 例如,定義一個變數id並且設定值為2013001,接著還要將印出變數的值: id=2013001 -> 定義變數時前面不加「$」符號 echo $id   -> 使用變數時前面要加「$」符號 注意,在等號的二邊不可以有空白,否則將出現錯誤。 再介紹一個範例: dir=/home/oracle ls $dir 這裡我們定義了變數dir的值為/home/oracle,接著用ls指令來印出變數dir, 此時指令會變為ls /home/oracle,所以就把目錄中所有檔案都列出來。 我們再來看一個例子,說明如何使用變數來定義