Sample Code :
PROCEDURE SEND_WF_NOTIFICATION(I_TO IN VARCHAR2,
I_SUBJECT IN VARCHAR2,
I_TEXT IN VARCHAR2)
IS
/*
I_TO : Oracle EBS帳號
I_SUBJECT : 要顯示在Worklist的主旨
I_TEXT : 內容
*/
V_NOTIFICATION_ID NUMBER;
--
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
V_NOTIFICATION_ID := WF_NOTIFICATION.SEND(ROLE => I_TO,
MSG_TYPE => 'CS_MSGS',
MSG_NAME => 'FYI_MESSAGE',
PRIORITY => 1);
WF_NOTIFICATION.SETATTRTEXT(NID => V_NOTIFICATION_ID,
ANAME => 'OBJECT_TYPE',
AVALUE => I_SUBJECT);
WF_NOTIFICATION.SETATTRTEXT(NID => V_NOTIFICATION_ID,
ANAME => 'MESSAGE_TEXT',
AVALUE => I_TEXT); --MESSAGE BODY
COMMIT;
END;
1. 這是個初學農友的農友日誌~ 2. Oracle ERP 分享 3. Oracle DBA 心得 4. Android 開發心得 5. MoJo寵物手作粉絲成員 6. 程式客製及外包專案接案
2013年10月6日 星期日
2013年9月24日 星期二
Oracle ERP R12. create locator using API (INV_LOC_WMS_PUB.CREATE_LOCATOR) - 建立Locator的API
若有需要大量新增Locator 則其有二種方式 :
1. Data Load
2. 呼叫 INV_LOC_WMS_PUB.CREATE_LOCATOR 該API
用法 :
FND_GLOBAL.APPS_INITIALIZE(1114,
51007,
401);
FND_MSG_PUB.Initialize;
INV_LOC_WMS_PUB.CREATE_LOCATOR(X_RETURN_STATUS => :X_RETURN_STATUS,
X_MSG_COUNT => :X_MSG_COUNT,
X_MSG_DATA => :X_MSG_DATA,
X_INVENTORY_LOCATION_ID => :X_INVENTORY_LOCATION_ID,
X_LOCATOR_EXISTS => :X_LOCATOR_EXISTS,
P_ORGANIZATION_ID => :P_ORGANIZATION_ID,
P_ORGANIZATION_CODE => :P_ORGANIZATION_CODE,
P_CONCATENATED_SEGMENTS => 儲位,
P_DESCRIPTION => 儲位描述,
P_INVENTORY_LOCATION_TYPE => 3,
P_PICKING_ORDER => :P_PICKING_ORDER,
P_LOCATION_MAXIMUM_UNITS => :P_LOCATION_MAXIMUM_UNITS,
P_SUBINVENTORY_CODE => 倉別,
P_LOCATION_WEIGHT_UOM_CODE => :P_LOCATION_WEIGHT_UOM_CODE,
P_MAX_WEIGHT => :P_MAX_WEIGHT,
P_VOLUME_UOM_CODE => :P_VOLUME_UOM_CODE,
P_MAX_CUBIC_AREA => :P_MAX_CUBIC_AREA,
P_X_COORDINATE => :P_X_COORDINATE,
P_Y_COORDINATE => :P_Y_COORDINATE,
P_Z_COORDINATE => :P_Z_COORDINATE,
P_PHYSICAL_LOCATION_ID => :P_PHYSICAL_LOCATION_ID,
P_PICK_UOM_CODE => :P_PICK_UOM_CODE,
P_DIMENSION_UOM_CODE => :P_DIMENSION_UOM_CODE,
P_LENGTH => :P_LENGTH,
P_WIDTH => :P_WIDTH,
P_HEIGHT => :P_HEIGHT,
P_STATUS_ID =>1,
P_DROPPING_ORDER => :P_DROPPING_ORDER,
P_ATTRIBUTE_CATEGORY => :P_ATTRIBUTE_CATEGORY,
P_ATTRIBUTE1 => :P_ATTRIBUTE1,
P_ATTRIBUTE2 => :P_ATTRIBUTE2,
P_ATTRIBUTE3 => :P_ATTRIBUTE3,
P_ATTRIBUTE4 => :P_ATTRIBUTE4,
P_ATTRIBUTE5 => :P_ATTRIBUTE5,
P_ATTRIBUTE6 => :P_ATTRIBUTE6,
P_ATTRIBUTE7 => :P_ATTRIBUTE7,
P_ATTRIBUTE8 => :P_ATTRIBUTE8,
P_ATTRIBUTE9 => :P_ATTRIBUTE9,
P_ATTRIBUTE10 => :P_ATTRIBUTE10,
P_ATTRIBUTE11 => :P_ATTRIBUTE11,
P_ATTRIBUTE12 => :P_ATTRIBUTE12,
P_ATTRIBUTE13 => :P_ATTRIBUTE13,
P_ATTRIBUTE14 => :P_ATTRIBUTE14,
P_ATTRIBUTE15 => :P_ATTRIBUTE15,
P_ALIAS => :P_ALIAS);
1. Data Load
2. 呼叫 INV_LOC_WMS_PUB.CREATE_LOCATOR 該API
用法 :
FND_GLOBAL.APPS_INITIALIZE(1114,
51007,
401);
FND_MSG_PUB.Initialize;
INV_LOC_WMS_PUB.CREATE_LOCATOR(X_RETURN_STATUS => :X_RETURN_STATUS,
X_MSG_COUNT => :X_MSG_COUNT,
X_MSG_DATA => :X_MSG_DATA,
X_INVENTORY_LOCATION_ID => :X_INVENTORY_LOCATION_ID,
X_LOCATOR_EXISTS => :X_LOCATOR_EXISTS,
P_ORGANIZATION_ID => :P_ORGANIZATION_ID,
P_ORGANIZATION_CODE => :P_ORGANIZATION_CODE,
P_CONCATENATED_SEGMENTS => 儲位,
P_DESCRIPTION => 儲位描述,
P_INVENTORY_LOCATION_TYPE => 3,
P_PICKING_ORDER => :P_PICKING_ORDER,
P_LOCATION_MAXIMUM_UNITS => :P_LOCATION_MAXIMUM_UNITS,
P_SUBINVENTORY_CODE => 倉別,
P_LOCATION_WEIGHT_UOM_CODE => :P_LOCATION_WEIGHT_UOM_CODE,
P_MAX_WEIGHT => :P_MAX_WEIGHT,
P_VOLUME_UOM_CODE => :P_VOLUME_UOM_CODE,
P_MAX_CUBIC_AREA => :P_MAX_CUBIC_AREA,
P_X_COORDINATE => :P_X_COORDINATE,
P_Y_COORDINATE => :P_Y_COORDINATE,
P_Z_COORDINATE => :P_Z_COORDINATE,
P_PHYSICAL_LOCATION_ID => :P_PHYSICAL_LOCATION_ID,
P_PICK_UOM_CODE => :P_PICK_UOM_CODE,
P_DIMENSION_UOM_CODE => :P_DIMENSION_UOM_CODE,
P_LENGTH => :P_LENGTH,
P_WIDTH => :P_WIDTH,
P_HEIGHT => :P_HEIGHT,
P_STATUS_ID =>1,
P_DROPPING_ORDER => :P_DROPPING_ORDER,
P_ATTRIBUTE_CATEGORY => :P_ATTRIBUTE_CATEGORY,
P_ATTRIBUTE1 => :P_ATTRIBUTE1,
P_ATTRIBUTE2 => :P_ATTRIBUTE2,
P_ATTRIBUTE3 => :P_ATTRIBUTE3,
P_ATTRIBUTE4 => :P_ATTRIBUTE4,
P_ATTRIBUTE5 => :P_ATTRIBUTE5,
P_ATTRIBUTE6 => :P_ATTRIBUTE6,
P_ATTRIBUTE7 => :P_ATTRIBUTE7,
P_ATTRIBUTE8 => :P_ATTRIBUTE8,
P_ATTRIBUTE9 => :P_ATTRIBUTE9,
P_ATTRIBUTE10 => :P_ATTRIBUTE10,
P_ATTRIBUTE11 => :P_ATTRIBUTE11,
P_ATTRIBUTE12 => :P_ATTRIBUTE12,
P_ATTRIBUTE13 => :P_ATTRIBUTE13,
P_ATTRIBUTE14 => :P_ATTRIBUTE14,
P_ATTRIBUTE15 => :P_ATTRIBUTE15,
P_ALIAS => :P_ALIAS);
2013年9月11日 星期三
Oracle ERP R12. How to select oe_transaction_type_syn ?
Before execute SQL :
declare
begin
MO_GLOBAL.SET_POLICY_CONTEXT('S',81); --Set Org_ID
end;
Then
select * from oe_transaction_types_syn;
declare
begin
MO_GLOBAL.SET_POLICY_CONTEXT('S',81); --Set Org_ID
end;
Then
select * from oe_transaction_types_syn;
2013年7月31日 星期三
Oracle ERP R12. Profile - OE: AutoPrice (自動更新Unit Selling Price時機設定)
經同仁反應,訂單的單價常會不明原因自動被更改掉,而user都不知道.
經查發現原因如下:
因為訂單會指定price list ,故只要訂單項次有調整任何一欄位(unit selling price欄除外),則系統會再自動從price list中取回目前最新的設定.
而該行為的主要原因是控制在一Profile => OE: AutoPrice , 該Profile的值預設為空值所導致的關係.
以下是該Profile設定的說明 : (本人測試得來的結果)
空值 => 不論是Entered 或是 Booked狀態皆會自動取回最新的price list值
Entry => 只有在訂單狀態為Entered 時才會自動取回最新的price list值
Booking => 不論狀態如何皆不會自動取回最新的price list值.
Ps :
以上純為本人測試之結果,若讀者測試後有任何心得請不吝指教,以該本人更新正確之資訊~
<<2013/08/04 不具名的網友 補充以下說明>>
通常業務流程而言, 應該定義為N (calculate_price_flag) , 避免訂單預定後仍可能因為手動或API變更而改變售價
*reference Doc ID 134326.1
· If it’s set to ‘Y’, both pricing and freight charge calculations are done.
· If it’s set to ‘P’, only the freight charge calculation is done.
'P' also indicates that modifiers assigned to a pricing phase
where freeze override is enabled could also be applied.
· If it’s set to ‘N’, neither pricing nor freight charge is calculated.
經查發現原因如下:
因為訂單會指定price list ,故只要訂單項次有調整任何一欄位(unit selling price欄除外),則系統會再自動從price list中取回目前最新的設定.
而該行為的主要原因是控制在一Profile => OE: AutoPrice , 該Profile的值預設為空值所導致的關係.
以下是該Profile設定的說明 : (本人測試得來的結果)
空值 => 不論是Entered 或是 Booked狀態皆會自動取回最新的price list值
Entry => 只有在訂單狀態為Entered 時才會自動取回最新的price list值
Booking => 不論狀態如何皆不會自動取回最新的price list值.
Ps :
以上純為本人測試之結果,若讀者測試後有任何心得請不吝指教,以該本人更新正確之資訊~
<<2013/08/04 不具名的網友 補充以下說明>>
通常業務流程而言, 應該定義為N (calculate_price_flag) , 避免訂單預定後仍可能因為手動或API變更而改變售價
*reference Doc ID 134326.1
· If it’s set to ‘Y’, both pricing and freight charge calculations are done.
· If it’s set to ‘P’, only the freight charge calculation is done.
'P' also indicates that modifiers assigned to a pricing phase
where freeze override is enabled could also be applied.
· If it’s set to ‘N’, neither pricing nor freight charge is calculated.
2013年7月30日 星期二
Oracle ERP R12. 如何透過Personalize功能呼叫另一form來回傳值. Get another form's result value (user personalize) .
狀況假設 :
A-Form(Rcv_transaction) 要呼叫另一客制form (B-Form),由B-Form運算後產生一結果回轉A-Form
Step 1. 建立一function用來取回B-Form的result
例 :
create or replace function
HPX_WEN_TEST_F(I_KEY VARCHAR2) return varchar2 is
T_Result VARCHAR2(100);
T_EXIT VARCHAR2(1) := 'N';
T_EXIT_TIME DATE := SYSDATE+5/(24*60);
begin
WHILE T_EXIT = 'N' LOOP
SELECT DECODE(COUNT(*),
0,'N',
'Y'),
MAX(HC.VALUE_2)
INTO T_EXIT,
T_RESULT
FROM HPX_CONFIG_T HC –假設該table為result
WHERE HC.KEY_ID = 'TEST'
AND
HC.VALUE_1 = I_KEY; --Key值,用來確認所抓取的資料無誤
--
IF T_EXIT_TIME <= SYSDATE THEN
T_EXIT := 'Y'; --逾時離開以避免無窮迴圈
END IF;
END LOOP;
return(T_Result);
end HPX_WEN_TEST_F;
Step 2. 在A-Form的WHEN-NEW-FORM-INSTANCE 加入一LOCAL
VARIABLE KEY的宣告,
及MENU BUTTON的宣告.
例 :
將游標固定至等定ITEM
呼叫B-Form
Step 4. 設定A-Form重新取得控制權後的行為動作.並由判斷KEY是否有值來確認是否要進入該程序
注意 : 由B-Form返回A-Form時只會觸發 WHEN-NEW-ITEM-INSTANCE , 故上步驟會先GO_ITEM.
2013年6月19日 星期三
Oracle ERP R12. Unassign or delete large number of items .
There is an option on the Tools menu of the Delete Item form that opens the Item Search screen.
There you can search on a number of criteria, including status, and the search results are populated in your Delete Group.
You can review the list, and delete unwanted entries (or add new ones, if necessary).
Then run the Delete process.
Reference from Metalink : ID 1347893.1
There you can search on a number of criteria, including status, and the search results are populated in your Delete Group.
You can review the list, and delete unwanted entries (or add new ones, if necessary).
Then run the Delete process.
Reference from Metalink : ID 1347893.1
2013年3月25日 星期一
Oracle ERP R12. 使用者忘記密碼 如何自行變更密碼
分享同事提供的自行變更密碼做法:
1. 在登入畫面下方,點選”Login
Assistance”
2. 輸入帳號,點選"Forgot Password" , 系統就會發送密碼重設的mail至該帳號上所定義的mail
3. 待收到mail後,點選mail內"Reset your password"的超連結,即可進入密碼重設的畫面.
2013年3月13日 星期三
狗爸的世界: Oracle ERP R12. 使用interface批量變更品號的operation code ....
狗爸的世界: Oracle ERP R12. 使用interface批量變更品號的operation code ....: Sample code : DECLARE -- T_OLD_OP VARCHAR2(10) := '2T02'; --**** old operation code T_NEW_OP VARCHAR2(10) := '2S02...
狗爸的世界: Oracle ERP R12. - 如何快速複製使用者權限 , How to grant privi...
狗爸的世界: Oracle ERP R12. - 如何快速複製使用者權限 , How to grant privi...: 以下Sample是當有新人時,可以快速複制user a 的權限至user b的作法 ~ My Sample code : (Package) /*PACKAGE HEADER*/ CREATE OR REPLACE PACKAGE XX_FND_USER_RESP_P...
狗爸的世界: Oracle ERP R12. 如何使用API (FND_USER_PKG)建立帳號. How to...
狗爸的世界: Oracle ERP R12. 如何使用API (FND_USER_PKG)建立帳號. How to...: 以下是使用FND_USER_PKG.CREATEUSER 建立使用者的範例程式碼 Sample code : FND_USER_PKG.CREATEUSER(X_USER_NAME => :USER_NAME , --USER ACCOUNT ...
2013年3月12日 星期二
Oracle ERP R12. 如何使用API (FND_USER_PKG)建立帳號. How to use FND_USER_PKG.CREATEUSER ?
以下是使用FND_USER_PKG.CREATEUSER 建立使用者的範例程式碼
Sample code :
FND_USER_PKG.CREATEUSER(X_USER_NAME => :USER_NAME , --USER ACCOUNT
X_OWNER => 'SEED',
X_UNENCRYPTED_PASSWORD => 'ABC234', --Default password
X_EMPLOYEE_ID => :EMPLOYEE_ID, --Mapping to employee id
X_EMAIL_ADDRESS => :EMAIL_ADDRESS); --user email
PS :
X_UNENCRYPTED_PASSWORD 需注意是否有啟用密碼的複雜度檢查,若有則必需符合其複雜度檢查規定
Oracle ERP R12. - 如何快速複製使用者權限 , How to grant privileges from one user to another user ?
以下Sample是當有新人時,可以快速複制user a 的權限至user b的作法 ~
My Sample code : (Package)
/*PACKAGE HEADER*/
CREATE OR REPLACE PACKAGE XX_FND_USER_RESP_PKG
IS
PROCEDURE XX_FND_COPY_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER,
I_MODE IN NUMBER DEFAULT 0);
--
PROCEDURE COPY_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER);
--
PROCEDURE DISABLE_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER);
--
PROCEDURE ENABLE_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER);
--
PROCEDURE DISABLE_USER_ALL_RESP(I_USER_ID IN NUMBER);
END XX_FND_USER_RESP_PKG;
/*PACKAGE BODY*/
CREATE OR REPLACE PACKAGE BODY XX_FND_USER_RESP_PKG
IS
PROCEDURE XX_FND_COPY_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER,
I_MODE IN NUMBER DEFAULT 0)
IS
/*
When Who What
===============================
20130313 WenShen Created for 複製某人權限至另一人
說明 :
1. I_MODE : 權限複製規則
0 : 只新增短少的權限,但不將即有卻失效的權限予以復權
1 : 新增短少的權限,且將即有卻失效的權限予以復權(且不影其它即有的權限)
2 : 完整複製,將原有權限全數失效後再執行I_MODE 2
*/
BEGIN
--
IF I_MODE = 0 THEN --只新增短少的權限,但不將即有卻失效的權限予以復權
--新增短少的權限
COPY_USER_RESP(I_FROM_USER_ID,
I_TO_USER_ID);
ELSIF I_MODE = 1 THEN --新增短少的權限,且將即有卻失效的權限予以復權
--Step 1. 新增短少的權限
COPY_USER_RESP(I_FROM_USER_ID,
I_TO_USER_ID);
--Step 2. 依來源USER權限設定將目標USER的權限的予以復權
ENABLE_USER_RESP(I_FROM_USER_ID,
I_TO_USER_ID);
ELSIF I_MODE = 2 THEN --完整複製,將原有權限全數失效後再執行I_MODE 2
--Step 1. 將所有權限予以停權
DISABLE_USER_ALL_RESP(I_TO_USER_ID);
--Step 2. 新增短少的權限
COPY_USER_RESP(I_FROM_USER_ID,
I_TO_USER_ID);
--Step 3. 依來源USER權限設定將目標USER的權限的予以復權
ENABLE_USER_RESP(I_FROM_USER_ID,
I_TO_USER_ID);
ELSE
NULL;
END IF;
END;
--
PROCEDURE COPY_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER)
IS
T_AP_ID NUMBER;
T_RESP_ID NUMBER;
--來源者權限表
CURSOR C_F_RESP
IS
SELECT FR.RESPONSIBILITY_KEY
FROM FND_USER_RESP_GROUPS_DIRECT FUR
JOIN FND_RESPONSIBILITY FR
ON FR.RESPONSIBILITY_ID = FUR.RESPONSIBILITY_ID
AND (FR.END_DATE IS NULL OR FR.END_DATE >= SYSDATE)
WHERE (FUR.END_DATE IS NULL OR FUR.END_DATE >= SYSDATE)
AND NOT EXISTS (SELECT 'X'
FROM FND_USER_RESP_GROUPS_DIRECT FUR2
WHERE FUR2.USER_ID = I_TO_USER_ID
AND FUR2.RESPONSIBILITY_ID = FUR.RESPONSIBILITY_ID) --已存在不重覆轉
AND FUR.USER_ID = I_FROM_USER_ID; --來源對象
BEGIN
FOR C1 IN C_F_RESP LOOP
--取得RESP資訊
SELECT FR.RESPONSIBILITY_ID,
FR.APPLICATION_ID
INTO T_RESP_ID,
T_AP_ID
FROM FND_RESPONSIBILITY FR
WHERE FR.RESPONSIBILITY_KEY = C1.RESPONSIBILITY_KEY;
--CALL API
BEGIN
FND_USER_RESP_GROUPS_API.INSERT_ASSIGNMENT(USER_ID => I_TO_USER_ID,
RESPONSIBILITY_ID => T_RESP_ID,
RESPONSIBILITY_APPLICATION_ID => T_AP_ID,
SECURITY_GROUP_ID => 0,
START_DATE => TRUNC(SYSDATE),
END_DATE => NULL,
DESCRIPTION => NULL);
COMMIT;
EXCEPTION WHEN OTHERS THEN
NULL;
END;
END LOOP;
END;
--
PROCEDURE DISABLE_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER)
IS
T_AP_ID NUMBER;
T_RESP_ID NUMBER;
T_END_DATE DATE;
--來源者權限表
CURSOR C_F_RESP
IS
SELECT FR.RESPONSIBILITY_KEY,FUR2.START_DATE
FROM FND_USER_RESP_GROUPS_DIRECT FUR
JOIN FND_RESPONSIBILITY FR
ON FR.RESPONSIBILITY_ID = FUR.RESPONSIBILITY_ID
JOIN FND_USER_RESP_GROUPS_DIRECT FUR2
ON FUR2.RESPONSIBILITY_ID = FUR.RESPONSIBILITY_ID
AND FUR2.USER_ID = I_TO_USER_ID
WHERE FUR.END_DATE < SYSDATE --已失效的部分
AND FUR.USER_ID = I_FROM_USER_ID; --來源對象
BEGIN
FOR C1 IN C_F_RESP LOOP
--取得RESP資訊
SELECT FR.RESPONSIBILITY_ID,
FR.APPLICATION_ID
INTO T_RESP_ID,
T_AP_ID
FROM FND_RESPONSIBILITY FR
WHERE FR.RESPONSIBILITY_KEY = C1.RESPONSIBILITY_KEY;
--
IF C1.START_DATE IS NOT NULL THEN
IF C1.START_DATE > SYSDATE THEN
T_END_DATE := C1.START_DATE;
ELSE
T_END_DATE := SYSDATE;
END IF;
END IF;
--
BEGIN
FND_USER_RESP_GROUPS_API.UPDATE_ASSIGNMENT(USER_ID => I_TO_USER_ID,
RESPONSIBILITY_ID => T_RESP_ID,
RESPONSIBILITY_APPLICATION_ID => T_AP_ID,
SECURITY_GROUP_ID => 0,
START_DATE => C1.START_DATE,
END_DATE => T_END_DATE,
DESCRIPTION => NULL);
EXCEPTION WHEN OTHERS THEN
NULL;
END;
END LOOP;
END;
--
PROCEDURE ENABLE_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER)
IS
T_AP_ID NUMBER;
T_RESP_ID NUMBER;
--來源者權限表
CURSOR C_F_RESP
IS
SELECT FR.RESPONSIBILITY_KEY,FUR2.START_DATE
FROM FND_USER_RESP_GROUPS_DIRECT FUR
JOIN FND_RESPONSIBILITY FR
ON FR.RESPONSIBILITY_ID = FUR.RESPONSIBILITY_ID
JOIN FND_USER_RESP_GROUPS_DIRECT FUR2
ON FUR2.RESPONSIBILITY_ID = FUR.RESPONSIBILITY_ID
AND FUR2.USER_ID = I_TO_USER_ID
WHERE (FUR.END_DATE IS NULL OR FUR.END_DATE >= SYSDATE)
AND FUR.USER_ID = I_FROM_USER_ID; --來源對象
BEGIN
FOR C1 IN C_F_RESP LOOP
--取得RESP資訊
SELECT FR.RESPONSIBILITY_ID,
FR.APPLICATION_ID
INTO T_RESP_ID,
T_AP_ID
FROM FND_RESPONSIBILITY FR
WHERE FR.RESPONSIBILITY_KEY = C1.RESPONSIBILITY_KEY;
--
BEGIN
FND_USER_RESP_GROUPS_API.UPDATE_ASSIGNMENT(USER_ID => I_TO_USER_ID,
RESPONSIBILITY_ID => T_RESP_ID,
RESPONSIBILITY_APPLICATION_ID => T_AP_ID,
SECURITY_GROUP_ID => 0,
START_DATE => C1.START_DATE,
END_DATE => NULL,
DESCRIPTION => NULL);
EXCEPTION WHEN OTHERS THEN
NULL;
END;
END LOOP;
END;
--
PROCEDURE DISABLE_USER_ALL_RESP(I_USER_ID IN NUMBER)
IS
T_AP_ID NUMBER;
T_RESP_ID NUMBER;
T_END_DATE DATE;
--來源者權限表
CURSOR C_F_RESP
IS
SELECT FR.RESPONSIBILITY_KEY,FUR.START_DATE
FROM FND_USER_RESP_GROUPS_DIRECT FUR
JOIN FND_RESPONSIBILITY FR
ON FR.RESPONSIBILITY_ID = FUR.RESPONSIBILITY_ID
WHERE (FUR.END_DATE IS NULL OR FUR.END_DATE >= SYSDATE)
AND FUR.USER_ID = I_USER_ID; --來源對象
BEGIN
FOR C1 IN C_F_RESP LOOP
--取得RESP資訊
SELECT FR.RESPONSIBILITY_ID,
FR.APPLICATION_ID
INTO T_RESP_ID,
T_AP_ID
FROM FND_RESPONSIBILITY FR
WHERE FR.RESPONSIBILITY_KEY = C1.RESPONSIBILITY_KEY;
--
IF C1.START_DATE IS NOT NULL THEN
IF C1.START_DATE > SYSDATE THEN
T_END_DATE := C1.START_DATE;
ELSE
T_END_DATE := SYSDATE;
END IF;
END IF;
--
BEGIN
FND_USER_RESP_GROUPS_API.UPDATE_ASSIGNMENT(USER_ID => I_USER_ID,
RESPONSIBILITY_ID => T_RESP_ID,
RESPONSIBILITY_APPLICATION_ID => T_AP_ID,
SECURITY_GROUP_ID => 0,
START_DATE => C1.START_DATE,
END_DATE => T_END_DATE,
DESCRIPTION => NULL);
EXCEPTION WHEN OTHERS THEN
NULL;
END;
END LOOP;
END;
END XX_FND_USER_RESP_PKG;
My Sample code : (Package)
/*PACKAGE HEADER*/
CREATE OR REPLACE PACKAGE XX_FND_USER_RESP_PKG
IS
PROCEDURE XX_FND_COPY_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER,
I_MODE IN NUMBER DEFAULT 0);
--
PROCEDURE COPY_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER);
--
PROCEDURE DISABLE_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER);
--
PROCEDURE ENABLE_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER);
--
PROCEDURE DISABLE_USER_ALL_RESP(I_USER_ID IN NUMBER);
END XX_FND_USER_RESP_PKG;
/*PACKAGE BODY*/
CREATE OR REPLACE PACKAGE BODY XX_FND_USER_RESP_PKG
IS
PROCEDURE XX_FND_COPY_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER,
I_MODE IN NUMBER DEFAULT 0)
IS
/*
When Who What
===============================
20130313 WenShen Created for 複製某人權限至另一人
說明 :
1. I_MODE : 權限複製規則
0 : 只新增短少的權限,但不將即有卻失效的權限予以復權
1 : 新增短少的權限,且將即有卻失效的權限予以復權(且不影其它即有的權限)
2 : 完整複製,將原有權限全數失效後再執行I_MODE 2
*/
BEGIN
--
IF I_MODE = 0 THEN --只新增短少的權限,但不將即有卻失效的權限予以復權
--新增短少的權限
COPY_USER_RESP(I_FROM_USER_ID,
I_TO_USER_ID);
ELSIF I_MODE = 1 THEN --新增短少的權限,且將即有卻失效的權限予以復權
--Step 1. 新增短少的權限
COPY_USER_RESP(I_FROM_USER_ID,
I_TO_USER_ID);
--Step 2. 依來源USER權限設定將目標USER的權限的予以復權
ENABLE_USER_RESP(I_FROM_USER_ID,
I_TO_USER_ID);
ELSIF I_MODE = 2 THEN --完整複製,將原有權限全數失效後再執行I_MODE 2
--Step 1. 將所有權限予以停權
DISABLE_USER_ALL_RESP(I_TO_USER_ID);
--Step 2. 新增短少的權限
COPY_USER_RESP(I_FROM_USER_ID,
I_TO_USER_ID);
--Step 3. 依來源USER權限設定將目標USER的權限的予以復權
ENABLE_USER_RESP(I_FROM_USER_ID,
I_TO_USER_ID);
ELSE
NULL;
END IF;
END;
--
PROCEDURE COPY_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER)
IS
T_AP_ID NUMBER;
T_RESP_ID NUMBER;
--來源者權限表
CURSOR C_F_RESP
IS
SELECT FR.RESPONSIBILITY_KEY
FROM FND_USER_RESP_GROUPS_DIRECT FUR
JOIN FND_RESPONSIBILITY FR
ON FR.RESPONSIBILITY_ID = FUR.RESPONSIBILITY_ID
AND (FR.END_DATE IS NULL OR FR.END_DATE >= SYSDATE)
WHERE (FUR.END_DATE IS NULL OR FUR.END_DATE >= SYSDATE)
AND NOT EXISTS (SELECT 'X'
FROM FND_USER_RESP_GROUPS_DIRECT FUR2
WHERE FUR2.USER_ID = I_TO_USER_ID
AND FUR2.RESPONSIBILITY_ID = FUR.RESPONSIBILITY_ID) --已存在不重覆轉
AND FUR.USER_ID = I_FROM_USER_ID; --來源對象
BEGIN
FOR C1 IN C_F_RESP LOOP
--取得RESP資訊
SELECT FR.RESPONSIBILITY_ID,
FR.APPLICATION_ID
INTO T_RESP_ID,
T_AP_ID
FROM FND_RESPONSIBILITY FR
WHERE FR.RESPONSIBILITY_KEY = C1.RESPONSIBILITY_KEY;
--CALL API
BEGIN
FND_USER_RESP_GROUPS_API.INSERT_ASSIGNMENT(USER_ID => I_TO_USER_ID,
RESPONSIBILITY_ID => T_RESP_ID,
RESPONSIBILITY_APPLICATION_ID => T_AP_ID,
SECURITY_GROUP_ID => 0,
START_DATE => TRUNC(SYSDATE),
END_DATE => NULL,
DESCRIPTION => NULL);
COMMIT;
EXCEPTION WHEN OTHERS THEN
NULL;
END;
END LOOP;
END;
--
PROCEDURE DISABLE_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER)
IS
T_AP_ID NUMBER;
T_RESP_ID NUMBER;
T_END_DATE DATE;
--來源者權限表
CURSOR C_F_RESP
IS
SELECT FR.RESPONSIBILITY_KEY,FUR2.START_DATE
FROM FND_USER_RESP_GROUPS_DIRECT FUR
JOIN FND_RESPONSIBILITY FR
ON FR.RESPONSIBILITY_ID = FUR.RESPONSIBILITY_ID
JOIN FND_USER_RESP_GROUPS_DIRECT FUR2
ON FUR2.RESPONSIBILITY_ID = FUR.RESPONSIBILITY_ID
AND FUR2.USER_ID = I_TO_USER_ID
WHERE FUR.END_DATE < SYSDATE --已失效的部分
AND FUR.USER_ID = I_FROM_USER_ID; --來源對象
BEGIN
FOR C1 IN C_F_RESP LOOP
--取得RESP資訊
SELECT FR.RESPONSIBILITY_ID,
FR.APPLICATION_ID
INTO T_RESP_ID,
T_AP_ID
FROM FND_RESPONSIBILITY FR
WHERE FR.RESPONSIBILITY_KEY = C1.RESPONSIBILITY_KEY;
--
IF C1.START_DATE IS NOT NULL THEN
IF C1.START_DATE > SYSDATE THEN
T_END_DATE := C1.START_DATE;
ELSE
T_END_DATE := SYSDATE;
END IF;
END IF;
--
BEGIN
FND_USER_RESP_GROUPS_API.UPDATE_ASSIGNMENT(USER_ID => I_TO_USER_ID,
RESPONSIBILITY_ID => T_RESP_ID,
RESPONSIBILITY_APPLICATION_ID => T_AP_ID,
SECURITY_GROUP_ID => 0,
START_DATE => C1.START_DATE,
END_DATE => T_END_DATE,
DESCRIPTION => NULL);
EXCEPTION WHEN OTHERS THEN
NULL;
END;
END LOOP;
END;
--
PROCEDURE ENABLE_USER_RESP(I_FROM_USER_ID IN NUMBER,
I_TO_USER_ID IN NUMBER)
IS
T_AP_ID NUMBER;
T_RESP_ID NUMBER;
--來源者權限表
CURSOR C_F_RESP
IS
SELECT FR.RESPONSIBILITY_KEY,FUR2.START_DATE
FROM FND_USER_RESP_GROUPS_DIRECT FUR
JOIN FND_RESPONSIBILITY FR
ON FR.RESPONSIBILITY_ID = FUR.RESPONSIBILITY_ID
JOIN FND_USER_RESP_GROUPS_DIRECT FUR2
ON FUR2.RESPONSIBILITY_ID = FUR.RESPONSIBILITY_ID
AND FUR2.USER_ID = I_TO_USER_ID
WHERE (FUR.END_DATE IS NULL OR FUR.END_DATE >= SYSDATE)
AND FUR.USER_ID = I_FROM_USER_ID; --來源對象
BEGIN
FOR C1 IN C_F_RESP LOOP
--取得RESP資訊
SELECT FR.RESPONSIBILITY_ID,
FR.APPLICATION_ID
INTO T_RESP_ID,
T_AP_ID
FROM FND_RESPONSIBILITY FR
WHERE FR.RESPONSIBILITY_KEY = C1.RESPONSIBILITY_KEY;
--
BEGIN
FND_USER_RESP_GROUPS_API.UPDATE_ASSIGNMENT(USER_ID => I_TO_USER_ID,
RESPONSIBILITY_ID => T_RESP_ID,
RESPONSIBILITY_APPLICATION_ID => T_AP_ID,
SECURITY_GROUP_ID => 0,
START_DATE => C1.START_DATE,
END_DATE => NULL,
DESCRIPTION => NULL);
EXCEPTION WHEN OTHERS THEN
NULL;
END;
END LOOP;
END;
--
PROCEDURE DISABLE_USER_ALL_RESP(I_USER_ID IN NUMBER)
IS
T_AP_ID NUMBER;
T_RESP_ID NUMBER;
T_END_DATE DATE;
--來源者權限表
CURSOR C_F_RESP
IS
SELECT FR.RESPONSIBILITY_KEY,FUR.START_DATE
FROM FND_USER_RESP_GROUPS_DIRECT FUR
JOIN FND_RESPONSIBILITY FR
ON FR.RESPONSIBILITY_ID = FUR.RESPONSIBILITY_ID
WHERE (FUR.END_DATE IS NULL OR FUR.END_DATE >= SYSDATE)
AND FUR.USER_ID = I_USER_ID; --來源對象
BEGIN
FOR C1 IN C_F_RESP LOOP
--取得RESP資訊
SELECT FR.RESPONSIBILITY_ID,
FR.APPLICATION_ID
INTO T_RESP_ID,
T_AP_ID
FROM FND_RESPONSIBILITY FR
WHERE FR.RESPONSIBILITY_KEY = C1.RESPONSIBILITY_KEY;
--
IF C1.START_DATE IS NOT NULL THEN
IF C1.START_DATE > SYSDATE THEN
T_END_DATE := C1.START_DATE;
ELSE
T_END_DATE := SYSDATE;
END IF;
END IF;
--
BEGIN
FND_USER_RESP_GROUPS_API.UPDATE_ASSIGNMENT(USER_ID => I_USER_ID,
RESPONSIBILITY_ID => T_RESP_ID,
RESPONSIBILITY_APPLICATION_ID => T_AP_ID,
SECURITY_GROUP_ID => 0,
START_DATE => C1.START_DATE,
END_DATE => T_END_DATE,
DESCRIPTION => NULL);
EXCEPTION WHEN OTHERS THEN
NULL;
END;
END LOOP;
END;
END XX_FND_USER_RESP_PKG;
/*使用說明 :*/
begin
XX_fnd_user_resp_pkg.hpx_fnd_copy_user_resp(i_from_user_id
=> :i_from_user_id, ç A使用者USER ID
i_to_user_id
=> :i_to_user_id, ç B使用者USER ID
i_mode
=> :i_mode); ç 複製規則,如下說明
end;
I_MODE
: 權限複製規則
0 : 只新增使用者B短少的權限,但不將即有卻失效的權限予以復權
1 : 新增使用者B短少的權限,且將即有但失效的權限予以復權(且不影使用者B較使用者A多的權限)
2 : 完整複製,將使用者B原有權限全數失效後再執行I_MODE 2
訂閱:
文章 (Atom)