技术问询:如何将设备主数据表EQUI关联至文档信息表DRAW?
Great question! In SAP environments, connecting the equipment master table (EQUI) with the document info record table (DRAW) relies on standard SAP data models and tools. Here are the two most common, reliable methods:
1. Database Level: Use the DRAD Intermediate Table
SAP uses the Document Assignment Table (DRAD) as the official bridge between documents and business objects (like equipment, materials, etc.). This table stores the direct link between an equipment and its associated documents.
Key Fields for the Join:
EQUI-EQUNR: Unique equipment number (matchesDRAD-OBJKEY)DRAD-OBJECT: Must be set to'EQUI'to filter specifically for equipment-document linksDRAD-DOKNR,DRAD-DOKAR,DRAD-DOKVR,DRAD-DOKTL: These fields match the primary key ofDRAWto pull full document details
Example SQL Query:
SELECT e.EQUNR AS Equipment_Number, e.EQKTX AS Equipment_Description, d.DOKNR AS Document_Number, d.DOKAR AS Document_Type, d.DOKVR AS Document_Version, d.DOKTL AS Document_Part, d.DKTXT AS Document_Description FROM EQUI e INNER JOIN DRAD da ON e.EQUNR = da.OBJKEY AND da.OBJECT = 'EQUI' INNER JOIN DRAW d ON da.DOKNR = d.DOKNR AND da.DOKAR = d.DOKAR AND da.DOKVR = d.DOKVR AND da.DOKTL = d.DOKTL;
2. ABAP Development: Use Standard Function Modules
If you're building custom ABAP code, SAP provides pre-built function modules to handle document-object links cleanly, without writing raw SQL.
Example: Retrieve Documents Linked to an Equipment
DATA: lt_document_links TYPE TABLE OF doc_link, ls_link TYPE doc_link, ls_draw TYPE draw. " Define the equipment you want to query ls_link-object_type = 'EQUI'. ls_link-object_key = '000000123456'. " Replace with your actual equipment number " Fetch all documents linked to this equipment CALL FUNCTION 'CVAPI_DOC_GET_OBJECT_LINKS' EXPORTING object_type = ls_link-object_type object_key = ls_link-object_key TABLES links = lt_document_links. " Loop through the links to retrieve full DRAW records LOOP AT lt_document_links INTO ls_link. SELECT SINGLE * FROM draw INTO ls_draw WHERE doknr = ls_link-doknr AND dokar = ls_link-dokar AND dokvr = ls_link-dokvr AND doktl = ls_link-doktl. " Process the document data here (e.g., display, log, or integrate into your logic) ENDLOOP.
Bonus: Create a New Equipment-Document Link
To programmatically associate a document with an equipment, use CVAPI_DOC_LINK_TO_OBJECT:
CALL FUNCTION 'CVAPI_DOC_LINK_TO_OBJECT' EXPORTING doknr = 'DOC12345' dokar = 'DRW' dokvr = '01' doktl = '000' object_type = 'EQUI' object_key = '000000123456' EXCEPTIONS document_not_found = 1 object_not_found = 2 link_already_exists = 3 no_authority = 4 OTHERS = 5. IF sy-subrc <> 0. " Handle exceptions here (e.g., log an error message) ENDIF.
Important Notes
- Ensure the equipment-document link exists in the system first: You can create this manually via the equipment master data screen (transaction
IE02) under the Documents tab, or via document maintenance transactions (CV01N/CV02N). - Always use standard SAP objects (tables/function modules) instead of custom workarounds—this guarantees compatibility with future SAP updates and follows best practices.
内容的提问来源于stack exchange,提问作者Matthijs Mennens

