以下程式碼範例是用來在SO (訂單)裡加入附件迴紋針說明的用法,分享給各位讀者.該範例是例用SHORTTEXT來紀錄訂單的正面麥頭及側面麥頭
CREATE PROCEDURE SO_SHORTTEXT(I_ORG_ID IN NUMBER,
I_HEADER_ID IN NUMBER,
I_TITLE IN VARCHAR2, --PGM_NAME
I_DESCRIPTION IN VARCHAR2, --TITLE DESCRIPTION
I_TEXT IN VARCHAR2,
O_DOCUMENT_ID OUT NUMBER,
O_ATTACHED_DOC_ID OUT NUMBER,
O_MEDIA_ID OUT NUMBER)
IS
T_ROWID ROWID;
T_SEQ_NUM NUMBER;
T_FND_USER_ID NUMBER := 0; --DEFAULT SYSADMIN
T_SHORT_DATATYPE_ID NUMBER := 1; --SHORT_TEXT
T_CATEGORY_ID NUMBER := 326; --Documents
T_EXISTS VARCHAR2(10);
BEGIN
FND_PROFILE.GET('USER_ID',T_FND_USER_ID);
--
IF T_FND_USER_ID IS NULL THEN
T_FND_USER_ID := 0;
END IF;
--
SELECT DECODE(COUNT(*),
0,'N',
'Y')
INTO T_EXISTS
FROM HPX_OE_ORDER_MARK_V HOOM
WHERE HOOM.HEADER_ID = I_HEADER_ID
AND HOOM.ORG_ID = I_ORG_ID
AND HOOM.DOCUMENT_DESCRIPTION = I_TITLE;
--
IF I_TITLE = '訂單正麥' THEN
T_SEQ_NUM := 10;
ELSIF I_TITLE = '訂單側麥' THEN
T_SEQ_NUM := 20;
ELSE
SELECT NVL(MAX(FAD.SEQ_NUM),0)+1
INTO T_SEQ_NUM
FROM FND_ATTACHED_DOCUMENTS FAD
WHERE 1=1
AND FAD.PK1_VALUE = TO_CHAR(I_HEADER_ID);
END IF;
--
IF T_EXISTS = 'N' THEN
FND_DOCUMENTS_PKG.INSERT_ROW(
X_Rowid => T_ROWID,
X_document_id => O_DOCUMENT_ID,
X_creation_date => SYSDATE,
X_created_by => T_FND_USER_ID,
X_last_update_date => SYSDATE,
X_last_updated_by => T_FND_USER_ID,
X_datatype_id => T_SHORT_DATATYPE_ID,
X_create_doc => 'Y',
X_category_id => T_CATEGORY_ID,
X_security_type => 4,
X_security_id => NULL,
X_description => I_DESCRIPTION,
X_media_id => O_MEDIA_ID,
X_title => I_TITLE,
X_language => 'US',
X_publish_flag => 'N', --This flag allow the file to share across multiple organization
X_usage_type => 'O'); --O:可被修改 / S:不能修改
ELSE
SELECT MAX(HOOM.media_id)
INTO O_MEDIA_ID
FROM HPX_OE_ORDER_MARK_V HOOM
WHERE HOOM.HEADER_ID = I_HEADER_ID
AND HOOM.ORG_ID = I_ORG_ID
AND HOOM.DOCUMENT_DESCRIPTION = I_TITLE;
END IF;
--
IF O_MEDIA_ID IS NOT NULL AND T_EXISTS = 'N' THEN
INSERT INTO FND_DOCUMENTS_SHORT_TEXT(MEDIA_ID,SHORT_TEXT)
VALUES(O_MEDIA_ID,I_TEXT);
--
SELECT FND_ATTACHED_DOCUMENTS_S.NEXTVAL
INTO O_ATTACHED_DOC_ID
FROM DUAL;
--
INSERT INTO FND_ATTACHED_DOCUMENTS(
ATTACHED_DOCUMENT_ID,
DOCUMENT_ID,
CREATION_DATE,
CREATED_BY,
LAST_UPDATE_DATE,
LAST_UPDATED_BY,
SEQ_NUM,
ENTITY_NAME,
PK1_VALUE,
AUTOMATICALLY_ADDED_FLAG,
CATEGORY_ID)
VALUES(
O_ATTACHED_DOC_ID,
O_DOCUMENT_ID,
SYSDATE,
T_FND_USER_ID,
SYSDATE,
T_FND_USER_ID,
T_SEQ_NUM,
'OE_ORDER_HEADERS',
TO_CHAR(I_HEADER_ID),
'N',
T_CATEGORY_ID);
ELSIF T_EXISTS = 'Y' THEN
UPDATE FND_DOCUMENTS_SHORT_TEXT FST
SET FST.SHORT_TEXT = I_TEXT
WHERE FST.MEDIA_ID = O_MEDIA_ID;
--
UPDATE FND_DOCUMENTS FD
SET FD.USAGE_TYPE = 'O' --O:可被修改 / S:不能修改
WHERE FD.MEDIA_ID = O_MEDIA_ID;
END IF;
END;
沒有留言:
張貼留言