Sie sind auf Seite 1von 8

Attachments in Oracle Applications

Attachment in Oracle Application


What is attachment in oracle application?
The attachments feature in oracle application enables users to link unstructured data, such as images, word-processing
documents, spreadsheets, or text to their application data. For example, users can link images to items or video to operations as
operation instructions.
Where to find an attachment?
There is an attachment icon in the oracle application toolbar that indicates whether the Attachments feature is enabled in a form
block. When the button is dimmed, the Attachment feature is not available. When the Attachment feature is enabled in a form block,
the icon becomes a solid paper clip. The icon switches to a paper clip holding a paper when the Attachment feature is enabled in a
form lock and the current record has at least one attachment.
Attachment types:
An attached document can be:
1] Short Text
Text stored in the database containing less than 2000 characters.
2] Long Text
Text stored in the database containing 2000 characters or more.
3] Image
An image that Oracle Forms can display, including: bmp, cals, jfif, jpeg, gif, pcd, pcx, pict, ras, and tif.
4] OLE Object
An OLE Object that requires other OLE server applications to view, such as Microsoft Word or Microsoft Excel.
5] Web Page
A URL reference to a web page which you can view with your web browser.
Tables Involved:
For Importing Attachments in oracle application one has to populate following tables.
1. FND_DOCUMENTS
2. FND_ATTACHED_DOCUMENTS
3. FND_DOCUMENTS_TL
4. FND_DOCUMENT_DATATYPES.
5. FND_DOCUMENT_CATEGORIES
6. FND_DOCUMENTS_LONG_TEXT (Long text type attachment).
7. FND_DOCUMENTS_SHORT_TEXT (Short text type attachment).
8. FND_DOCUMENTS_LONG_RAW
9. FND_LOBS (File type attachments).
FND_DOCUMENTS:
FND_DOCUMENTS stores language-independent information about a document. For example, each row contains a document
identifier, a category identifier, the method of security used for the document (SECURITY_TYPE, where 1=Organization,2=Set of
Books, 3=Business unit,4=None), the period in which the document is active, and a flag to indicate whether or not the document
can be shared outside of the security type (PUBLISH_FLAG).

Other specifications in this table include: datatype (DATATYPE_ID, where 1=short text,2=long text, 3=image, 4=OLE object), image
type, and storage type (STORAGE_TYPE, where 1=stored in the database, 2=stored in the file system).
The document can be referenced by many application entities and changed only in the define document form (USAGE_TYPE=S); it
can be used as a fill-in-the-blanks document, where each time you use a template, you make a copy of it (USAGE_TYPE=T); or it
can be used only one time (USAGE_TYPE=O).Images and OLE Objects cannot be used as templates.
FND_ATTACHED_DOCUMENTS:
FND_ATTACHED_DOCUMENTS stores information relating a document to an application entity. For example, a record may link a
document to a sales order or an item. Each row contains foreign keys to FND_DOCUMENTS and FND_DOCUMENT_ENTITIES.
There is also a flag to indicate whether or not an attachment was created automatically.
FND_DOCUMENTS_TL:
FND_DOCUMENTS_TL stores translated information about the documents in FND_DOCUMENTS. Each row includes the
document identifier, the language the row is translated to, the description of the document, the file in which the image is stored, and
an identifier (MEDIA_ID) of the sub-table in which the document is saved (FND_DOCUMENTS_SHORT_TEXT,
FND_DOCUMENTS_LONG_TEXT, or FND_DOCUMENTS_LONG_RAW).
FND_DOCUMENT_DATATYPES:
FND_DOCUMENT_DATATYPES stores the document datatypes that are supported. Initial values are: short text, long text, image,
and OLE Object (DATATYPE_ID=1, 2, 3, or 4). Customers can add datatypes to handle documents stored outside of Oracle and
use non-native Forms applications to view/edit their documents. The table uses a duplicate record model for handling multi-lingual
needs. That is, for each category there will be one record with the same CATEGORY_ID and CATEGORY_NAME for each
language.
FND_DOCUMENT_CATEGORIES:
FND_DOCUMENT_CATEGORIES stores information about the categories in which documents are classified. For example,
documents may be considered Bill of Material Comments, WIP Job Comments, etc. Document categories are used to provide a
measure of security on documents. Each form that enables the attachment feature lists which categories of documents can be
viewed in the form. This table uses a duplicate record model for handling multi-lingual needs.
FND_DOCUMENTS_LONG_TEXT:
FND_DOCUMENTS_LONG_TEXT stores information about long text documents.
FND_DOCUMENTS_SHORT_TEXT:
FND_DOCUMENTS_SHORT_TEXT stores information about short text documents.
FND_DOCUMENTS_LONG_RAW:
FND_DOCUMENTS_LONG_RAW stores images and OLE Objects, such as Word Documents and Excel spreadsheets, in the
database.
FND_DOCUMENT_ENTITIES:
FND_DOCUMENT_ENTITIES lists each entity to which attachments can be linked. For example, attachments can be linked to
Items, Sales Orders, etc. Since the table uses a duplicate record model for handling multi-lingual needs, for each document entity
there will be one record with the same DOCUMENT_ENTITY_ID and DATA_OBJECT_CODE for each language.

Queries:
1] To find all Long Text attachments:

SELECT

FROM

WHERE

FAD.SEQ_NUM "Seq Number",


FDAT.USER_NAME "Data Type",
FDCT.USER_NAME "Category User Name",
FAD.ATTACHED_DOCUMENT_ID "Attached Document Id",
FDET.USER_ENTITY_NAME "User Entity",
FD.DOCUMENT_ID "Document Id",
FAD.ENTITY_NAME "Entity Name",
FD.MEDIA_ID "Media Id",
FD.URL "Url",
FDT.TITLE "Title",
FDLT.LONG_TEXT "Attachment Text"
FND_DOCUMENT_DATATYPES FDAT,
FND_DOCUMENT_ENTITIES_TL FDET,
FND_DOCUMENTS_TL FDT,
FND_DOCUMENTS FD,
FND_DOCUMENT_CATEGORIES_TL FDCT,
FND_ATTACHED_DOCUMENTS
FAD,
FND_DOCUMENTS_LONG_TEXT FDLT
FD.DOCUMENT_ID
= FAD.DOCUMENT_ID
AND FDT.DOCUMENT_ID
= FD.DOCUMENT_ID
AND FDCT.CATEGORY_ID
= FD.CATEGORY_ID
AND FD.DATATYPE_ID
= FDAT.DATATYPE_ID
AND FAD.ENTITY_NAME
= FDET.DATA_OBJECT_CODE
AND FDLT.MEDIA_ID
= FD.MEDIA_ID
AND FDAT.NAME
= 'LONG_TEXT';

2] To find all Short Text attachments:

SELECT

FROM

WHERE

FAD.SEQ_NUM "Seq Number",


FDAT.USER_NAME "Data Type",
FDCT.USER_NAME "Category User Name",
FAD.ATTACHED_DOCUMENT_ID "Attached Document Id",
FDET.USER_ENTITY_NAME "User Entity",
FD.DOCUMENT_ID "Document Id",
FAD.ENTITY_NAME "Entity Name",
FD.MEDIA_ID "Media Id",
FD.URL "Url",
FDT.TITLE "Title",
FDST.SHORT_TEXT "Attachment Text"
FND_DOCUMENT_DATATYPES FDAT,
FND_DOCUMENT_ENTITIES_TL FDET,
FND_DOCUMENTS_TL FDT,
FND_DOCUMENTS FD,
FND_DOCUMENT_CATEGORIES_TL FDCT,
FND_ATTACHED_DOCUMENTS
FAD,
FND_DOCUMENTS_SHORT_TEXT FDST
FD.DOCUMENT_ID
= FAD.DOCUMENT_ID
AND FDT.DOCUMENT_ID
= FD.DOCUMENT_ID
AND FDCT.CATEGORY_ID
= FD.CATEGORY_ID
AND FD.DATATYPE_ID
= FDAT.DATATYPE_ID
AND FAD.ENTITY_NAME
= FDET.DATA_OBJECT_CODE
AND FDST.MEDIA_ID
= FD.MEDIA_ID
AND FDAT.NAME
= 'SHORT_TEXT';

Attachment upload through API:


Attachments can also be uploaded through an oracle provided API called FND_ATTACHED_DOCUMENTS_PKG.

Where to the actual attachments/documents get stored for attachments?


Here are some queries to get back the Payables Invoice attachments of category "Invoice Internal" for
a given invoice. Attachments of type Web Page (URL or Filename)
select fad_f.seq_num
,

fdt_f.file_name media_data_text

from

fnd_attached_documents fad_f

fnd_documents fd_f

fnd_documents_tl fdt_f

fnd_document_categories_tl fdct_f

where

1 = 1

and

fad_f.document_id = fd_f.document_id

and

fad_f.document_id = fdt_f.document_id

and

fdct_f.category_id = fd_f.category_id

and

fdct_f.user_name = 'Invoice Internal'

and

fd_f.datatype_id = 5

and

fad_f.entity_name = 'AP_INVOICES'

and

fad_f.pk1_value = '63227';

Attachments of type "Long Text"


select fad_f.seq_num
,

fdlt_f.media_id

fdlt_f.long_text media_data_text

from

fnd_attached_documents fad_f

fnd_documents fd_f

fnd_documents_tl fdt_f

fnd_document_categories_tl fdct_f

fnd_documents_long_text fdlt_f

where

1 = 1

and

fad_f.document_id = fd_f.document_id

and

fad_f.document_id = fdt_f.document_id

and

fdct_f.category_id = fd_f.category_id

and

fdt_f.media_id = fdlt_f.media_id /* R11i */

-- and

media_id

fd_f.media_id = fdlt_f.media_id /* R12 */

and

fdct_f.user_name = 'Invoice Internal'

and

fad_f.entity_name = 'AP_INVOICES'

and

fad_f.pk1_value = '63227';

Attachments of type "Short Text"


select fad_f.seq_num
,

fdst_f.media_id

fdst_f.short_text media_data_text

media_id

from

fnd_attached_documents fad_f

fnd_documents fd_f

fnd_documents_tl fdt_f

fnd_document_categories_tl fdct_f

fnd_documents_short_text fdst_f

where

1 = 1

and

fad_f.document_id = fd_f.document_id

and

fad_f.document_id = fdt_f.document_id

and

fdct_f.category_id = fd_f.category_id

and

fdt_f.media_id = fdst_f.media_id /* R11i */

-- and

fd_f.media_id = fdst_f.media_id /* R12 */

and

fdct_f.user_name = 'Invoice Internal'

and

fad_f.entity_name = 'AP_INVOICES'

and

fad_f.pk1_value = '63227';

Attachments of type "File"


select fad_l.seq_num
,

fl_l.file_id

media_id

fl_l.file_data

media_data_blob

from

fnd_attached_documents fad_l

fnd_documents fd_l

fnd_documents_tl fdt_l

fnd_document_categories_tl fdct_l

fnd_lobs fl_l

where

1 = 1

and

fad_l.document_id = fd_l.document_id

and

fad_l.document_id = fdt_l.document_id

and

fdct_l.category_id = fd_l.category_id

and

fdt_l.media_id = fl_l.file_id /* Release 11i */

-- and fd_l.media_id = fl_l.file_id /* Release 12 */


and

fad_l.entity_name = 'AP_INVOICES'

and

fdct_l.user_name = 'Invoice Internal'

and

fad_l.pk1_value = '63227';

Update: Added extra line to file query for R12. Update: In case anyone needs to delete any
attachments here's an example (thanks to Mark L):
declare
l_entity_name varchar2(20):= 'PO_LINES';

-- This defines the PO_LINES entity

l_pk1_value varchar2 (20) := '200487';

-- PO_LINE_ID items are attached to

l_delete_document_flag varchar2 (1) := 'Y';

-- Delete the document

begin
--fnd_global.apps_initialize(0,20420,1); -- SYSADMIN System Administrator
fnd_attached_documents2_pkg.delete_attachments
( X_entity_name

=> l_entity_name

, X_pk1_value

=> l_pk1_value

, X_delete_document_flag

=> l_delete_document_flag

);
end;
/
commit;

/**
* Script Description :- Single Insert Script to Attachments *
* Author :- Venu Sreeramoju *
* Date :- 22 October 2011 *
* *
* *
* Pre-Requirements *
* *
* 1.Create a Custom Directory and Grant Permissions *
* 2.Place the Files in this Directory as Below *
* *
* CREATE OR REPLACE DIRECTORY Apps AS '/usr/tmp/venu'; *
* GRANT READ ON DIRECTORY Apps TO PUBLIC; *
* *
**/
DECLARE
l_rowid
ROWID;
l_attached_document_id NUMBER;
l_document_id
NUMBER;
l_media_id
NUMBER;
l_file_id
NUMBER;
l_category_id
NUMBER := 1;

Misc l_pk1_value fnd_attached_documents.pk1_value%TYPE :=


'204';
l_description
fnd_documents_tl.description%TYPE := 'Testing Attachment
File';
l_filename
fnd_documents_tl.file_name%TYPE := 'Testing pdf.pdf';
l_seq_num
NUMBER := 26;
l_blob
BLOB;
l_bfile
BFILE;
l_byte
NUMBER;
x_return_status
VARCHAR2(2000);
x_msg_count
NUMBER(10);
x_msg_data
VARCHAR2(1000);
blob_length
NUMBER;
x_blob
BLOB;
--1008030 Venu Sreeramoju
BEGIN
fnd_global.apps_initialize(1008030, 50583, 401);
SELECT FND_DOCUMENTS_S.nextval INTO l_document_id FROM dual;
SELECT FND_ATTACHED_DOCUMENTS_S.nextval
INTO l_attached_document_id
FROM dual;
SELECT
INTO
FROM
WHERE
AND

nvl(MAX(seq_num), 0) + 10
l_seq_num
fnd_attached_documents
pk1_value = l_pk1_value
entity_name = 'MTL_SYSTEM_ITEMS';

SELECT fnd_lobs_s.NEXTVAL INTO l_media_id FROM DUAL;


l_bfile := bfilename('SCMR', 'Testing pdf.pdf');
Bfile Checks THE File existance at directory
-DBMS_LOB.fileopen(l_bfile, DBMS_LOB.file_readonly);
blob_length := DBMS_LOB.getlength(l_bfile);
DBMS_LOB.fileclose(l_bfile);
INSERT INTO fnd_lobs
(file_id,
file_name,
file_content_type,
upload_date,
expiration_date,

program_name,
program_tag,
file_data,
LANGUAGE,
oracle_charset,
file_format)
VALUES
(l_media_id,
l_filename,
'application/pdf',
SYSDATE,
NULL,
'FNDATTCH',
NULL,
empty_blob(),
'US',
'UTF8',
'BINARY')
RETURNING file_data INTO x_blob;
DBMS_LOB.OPEN(l_bfile, DBMS_LOB.lob_readonly);
DBMS_LOB.OPEN(x_blob, DBMS_LOB.lob_readwrite);
DBMS_LOB.loadfromfile(x_blob, l_bfile, blob_length);
DBMS_LOB.CLOSE(x_blob);
DBMS_LOB.CLOSE(l_bfile);
COMMIT;
DBMS_OUTPUT.put_line('File Successfully Inserted into Table as BLOB');
DBMS_LOB.CREATETEMPORARY(x_blob, TRUE);
COMMIT;
IF DBMS_LOB.FILEEXISTS(l_bfile) = 1
THEN
dbms_output.put_line(' File Exists!');
ELSE
dbms_output.put_line('Not Exists!');
END IF;
fnd_documents_pkg.insert_row(X_ROWID
=> l_rowid,
X_DOCUMENT_ID
=> l_document_id,
X_CREATION_DATE
=> SYSDATE,
X_CREATED_BY
=> 1008030,
X_LAST_UPDATE_DATE => SYSDATE,
X_LAST_UPDATED_BY
=> 1008030,
X_LAST_UPDATE_LOGIN => 1008030,
X_DATATYPE_ID
=> 6 FILE,
X_CATEGORY_ID
=> l_category_id,
X_SECURITY_TYPE
=> 2,
X_PUBLISH_FLAG
=> 'Y',
X_USAGE_TYPE
=> 'O',
X_LANGUAGE
=> 'US',
X_DESCRIPTION
=> l_description,
X_FILE_NAME
=> l_filename,
X_MEDIA_ID
=> l_media_id);
COMMIT;
--dbms_output.put_line ('document id is l_document_id '||l_document_id);
fnd_documents_pkg.insert_tl_row(X_DOCUMENT_ID
=> l_document_id,
X_CREATION_DATE
=> SYSDATE,
X_CREATED_BY
=> 1008030,
X_LAST_UPDATE_DATE => SYSDATE,
X_LAST_UPDATED_BY
=> 1008030,
X_LAST_UPDATE_LOGIN => 1008030,
X_LANGUAGE
=> 'US',
X_DESCRIPTION
=> l_description,
X_FILE_NAME
=> l_filename,
X_MEDIA_ID
=> l_media_id);

COMMIT;
--dbms_output.put_line ('attachment_document id is l_attached_document_id '||
l_attached_document_id);
--l_document_id :=l_document_id-1;
fnd_attached_documents_pkg.insert_row(X_ROWID
=> l_rowid,
X_ATTACHED_DOCUMENT_ID
=>
l_attached_document_id,
X_DOCUMENT_ID
=> l_document_id,
X_CREATION_DATE
=> SYSDATE,
X_CREATED_BY
=> 1008030,
X_LAST_UPDATE_DATE
=> SYSDATE,
X_LAST_UPDATED_BY
=> 1008030,
X_LAST_UPDATE_LOGIN
=> 1008030,
X_SEQ_NUM
=> l_seq_num,
X_ENTITY_NAME
=>
'MTL_SYSTEM_ITEMS',
X_COLUMN1
=> NULL,
X_PK1_VALUE
=> l_pk1_value,
X_PK2_VALUE
=> 1225112164
carbody_d11991
car_433,
X_PK3_VALUE
=> NULL,
X_PK4_VALUE
=> NULL,
X_PK5_VALUE
=> NULL,
X_AUTOMATICALLY_ADDED_FLAG => 'N',
X_DATATYPE_ID
=> 6,
X_CATEGORY_ID
=> l_category_id,
X_SECURITY_TYPE
=> 2,
X_PUBLISH_FLAG
=> 'Y',
X_LANGUAGE
=> 'US',
X_DESCRIPTION
=> l_description,
X_FILE_NAME
=> l_filename,
X_MEDIA_ID
=> l_media_id);
COMMIT;
dbms_output.put_line('attachment_document id is l_attached_document_id ' ||
l_attached_document_id);
dbms_output.put_line('document id is l_document_id ' || l_document_id);
dbms_output.put_line(' l_media_id ' || l_media_id);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Failed ' || SQLERRM);
COMMIT;
END;
--------------------------select * from all_directories;
http://oracleappsengineering.blogspot.ca/2010/04/attachments-api-fnddocumentspkg.html
http://oraclemaniac.com/2012/01/07/attach-concurrent-program-output-to-the-apps-transaction/
http://garethroberts.blogspot.ca/2007/08/document-attachments-private-stuff.html
http://imdjkoch.wordpress.com/2010/09/02/attachment-in-oracle-application/

Das könnte Ihnen auch gefallen