07-22-2008 2:58 PM
Well, I'm finally at a client site that has DMS running over an external content server. (Some of you may remember last year, when I was at a site using the old internal SOFFDB table - it turned out to be very tricky to put a URL on a picture so you could pop it in PM.)
Anyway, the requirement here is as follows.
Given a SalesOrder (and therefore the associated busienss object for the SO):
a) pick a particular document attached to the Business Object;
b) extract it from DMS
c) attach it to an email (in its native format, e.g. an "xls", or a "doc", etc.
Please advise at your earliest convenience.
07-22-2008 3:15 PM
Hi,
Good to see u back.
1. For getting the content server you can use
i_object-typeid = 'KNA1'. " Please change the object id
i_object-catid = 'BO'. " ?
i_object-instid = docno.
refresh : i_brel, i_link.
* Get Attachment List
append 'ATTA' to i_brel.
if not i_brel is initial.
select *
from srgbtbrel
appending corresponding fields of table i_link
for all entries in i_brel
where
instid_a eq i_object-instid and
typeid_a eq i_object-typeid and
catid_a eq i_object-catid and
reltype eq i_brel-reltype.
endif.
wa_filter-send_info = 'X'.
wa_filter-no_content = 'X'.
loop at i_link into ls_link.
clear : wa_doc_data.
wa_fol_cont-doc_id = ls_link-instid_b.
call function 'SO_DOCUMENT_READ_API1'
exporting
document_id = wa_fol_cont-doc_id
filter = wa_filter
importing
document_data = wa_doc_data
exceptions
document_id_not_exist = 1
operation_no_authorization = 2
others = 3.
then use fm to send mail out
call function 'SO_DOCUMENT_SEND_API1'
or use class if you want to single mail with all the attachments of that document.
please check this link
a®
07-22-2008 3:04 PM
There is some simialr requirement. But it will download the attachment.
Report zorders.
************************************************************************
* TABLES
************************************************************************
TABLES:
caufvd,
itcpo.
************************************************************************
* DATA - INTERNAL TABLES
************************************************************************
* Internal table to hold the key of the document
DATA:
BEGIN OF i_key OCCURS 0,
order LIKE srgbtbrel-instid_a, " Order/Notif.
key LIKE srgbtbrel-instid_b,
END OF i_key.
* Internal table to hold the file locations
DATA:
i_files TYPE so_url OCCURS 0 WITH HEADER LINE.
* Internal table to hold the document details
DATA:
i_sood LIKE STANDARD TABLE OF sood WITH HEADER LINE.
* structure to split the key
DATA:
BEGIN OF fs_key,
foltp LIKE sood4-foltp, " Folder type
folyr LIKE sood4-folyr, " Folder year
folno LIKE sood4-folno, " Folder Number
objtp LIKE sood-objtp, " Object type
objyr LIKE sood-objyr, " Object Year
objno LIKE sood-objno, " Object Number
END OF fs_key.
************************************************************************
* DATA - Variables
************************************************************************
DATA:
sw_document LIKE sood4,
sw_lines LIKE sy-tabix,
sw_operation TYPE string.
*&---------------------------------------------------------------------*
*& Form PRINT_ATTA
*&---------------------------------------------------------------------*
* No interface parameters required
*----------------------------------------------------------------------*
* This subroutine is triggered for printing attachments of work order
*----------------------------------------------------------------------*
FORM print_atta.
DATA:
exec TYPE REF TO cl_gui_frontend_services.
DATA:
w_dir TYPE string, " Directory
w_result TYPE abap_bool. " Result
CREATE OBJECT exec.
DATA:
sw_document1 TYPE string.
* Select key for attachments linked to work order
SELECT instid_a
instid_b
FROM srgbtbrel
INTO TABLE i_key
WHERE typeid_a EQ 'BUS2007'
AND instid_a EQ caufvd-aufnr.
* Select key for attachments linked to notifications
SELECT instid_a
instid_b
FROM srgbtbrel
APPENDING TABLE i_key
WHERE typeid_a EQ 'BUS2038'
AND instid_a EQ caufvd-qmnum.
DESCRIBE TABLE i_key LINES sw_lines.
IF sw_lines > 0.
IF itcpo-tdpreview EQ 'X'.
MOVE:
'OPEN' TO sw_operation.
ELSE.
MOVE:
'PRINT' TO sw_operation.
ENDIF.
* First check whether H: exist in the system directories. If H: exist
* Application is running in The Citrix. If H: Does not exist then
* Use the C:
MOVE: 'H:' TO w_dir.
CLEAR w_result.
CALL METHOD cl_gui_frontend_services=>directory_exist
EXPORTING
directory = w_dir
RECEIVING
result = w_result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF w_result IS INITIAL.
MOVE: 'C:' TO w_dir.
ENDIF. " IF sy-subrc NE 0.
LOOP AT i_key.
MOVE i_key-key TO fs_key.
SHIFT i_key-order LEFT DELETING LEADING '0'.
* Select attachments
SELECT *
FROM sood
INTO TABLE i_sood
WHERE objno EQ fs_key-objno
AND objtp EQ fs_key-objtp
AND objyr EQ fs_key-objyr.
IF sy-subrc EQ 0.
* loop at all the attachments
LOOP AT i_sood.
MOVE-CORRESPONDING i_sood TO sw_document.
MOVE-CORRESPONDING fs_key TO sw_document.
REFRESH i_files.
* Formulate the file name
* To include the Order/ Notification in the path
CONCATENATE w_dir '\WORKATTA' '_'
i_key-order '_'
sy-datum
sy-uzeit '.'
sw_document-file_ext
INTO i_files.
APPEND i_files.
* This function module creates a file in the PC
CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
EXPORTING
method = 'PUTCONTENTTOFILE'
office_user = sy-uname
TABLES
files = i_files
CHANGING
document = sw_document.
READ TABLE i_files INDEX 1.
MOVE:
i_files TO sw_document1.
* Printing the file created on the PC
CALL METHOD exec->execute
EXPORTING
document = sw_document1
operation = sw_operation.
ENDLOOP. " LOOP AT i_sood
ENDIF. " IF sy-subrc EQ 0
ENDLOOP. " LOOP AT i_key
ENDIF. " IF sy-subrc EQ 0
ENDFORM. "print_atta
07-22-2008 3:44 PM
Vijay -
Thank you, new friend.
Although aRs's solution is closer to what we presently need, there is very useful corollary material in your answer, and I will keep it handy.
Best regards
djh
07-22-2008 3:47 PM
Welcome , and you are also My new friend.
Best Regards
Vijay Babu Dudla
07-22-2008 3:15 PM
Hi,
Good to see u back.
1. For getting the content server you can use
i_object-typeid = 'KNA1'. " Please change the object id
i_object-catid = 'BO'. " ?
i_object-instid = docno.
refresh : i_brel, i_link.
* Get Attachment List
append 'ATTA' to i_brel.
if not i_brel is initial.
select *
from srgbtbrel
appending corresponding fields of table i_link
for all entries in i_brel
where
instid_a eq i_object-instid and
typeid_a eq i_object-typeid and
catid_a eq i_object-catid and
reltype eq i_brel-reltype.
endif.
wa_filter-send_info = 'X'.
wa_filter-no_content = 'X'.
loop at i_link into ls_link.
clear : wa_doc_data.
wa_fol_cont-doc_id = ls_link-instid_b.
call function 'SO_DOCUMENT_READ_API1'
exporting
document_id = wa_fol_cont-doc_id
filter = wa_filter
importing
document_data = wa_doc_data
exceptions
document_id_not_exist = 1
operation_no_authorization = 2
others = 3.
then use fm to send mail out
call function 'SO_DOCUMENT_SEND_API1'
or use class if you want to single mail with all the attachments of that document.
please check this link
a®
07-22-2008 3:43 PM
aRs -
Thank you, my old and dear friend.
Superb response as usual.
07-22-2008 10:26 PM
I have a method "GETDETAIL2" I can run from the DMS Business Object "DRAW" that returns the folowing info on attached files.
APPLICATION_ID FILE_ID
Can I then use this data to create the attachment to the email?
Instead of getting to the data via the Sales Order, can I get to it this way?
07-22-2008 3:20 PM
Hello,
I think you can get the list of attached documents by reading the table TOA01 using object VBAK. There you will find the Document ID. With the DocID you can use ARCHIVOBJECT_DISPLAY to retrieve the file.
Regards,
Juan
07-22-2008 3:45 PM
Hi Juan -
Judging from Vijay's and aRs' responses, I'm not sure what you're suggesting is the right way to go.
But I will investigate.
Thanks very much for taking the time to respond.
djh
07-22-2008 3:42 PM
07-22-2008 10:04 PM
I have a method "GETDETAIL2" I can run from the DMS Business Object "DRAW" that returns the folowing info on attached files.
APPLICATION_ID FILE_ID
Can I then use this data to create the attachment to the email?
Instead of getting to the data via the Sales Order, can I get to it this way?
07-23-2008 3:24 PM
a®s explained the way to get at the attachments to a Business Object using
the SRGTBREL table.
Are the entries in the SRGTBREL table somehow related to the APPLICATION ID
and FILE ID that are returned by the GETDETAIL2 method of the DMS Business Object
"DRAW"?
If so, how?
If not, what are APP ID and FILE ID for?
Thanks for considering this matter.
Ted Smith