10-07-2008 2:12 PM
Hi,
The requirement is to display the list of document data (material master->additional data->Document data) assigned for the material and an option to view the picuture of the document in a report.
How to make this report?Any idea.
Thanks,
Bala Raja
10-07-2008 5:35 PM
Hi,
I've done something similar via BSP, there are two main R/3 function modules that I wrote to achieve this.
The first is to get a list of the documents attached to a material, you could use this to feed your report.
function zzdms_get_material_docs.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(MATNR) TYPE MATNR
*" TABLES
*" FILES STRUCTURE BAPI_DOC_FILES2
*"----------------------------------------------------------------------
data: lt_drad type table of drad,
lt_files type table of bapi_doc_files2.
field-symbols: <drad> type drad.
refresh files.
* Find the documents linked to this material
select * into table lt_drad
from drad
where dokob = 'MARA'
and objky = matnr.
* and DOKAR = xxx <-- Could restrict to bespoke document type(s) here
* Find the file(s) associated with the documents
loop at lt_drad assigning <drad>.
clear lt_files.
call function 'BAPI_DOCUMENT_GETDETAIL2'
exporting
documenttype = <drad>-dokar
documentnumber = <drad>-doknr
documentpart = <drad>-doktl
documentversion = <drad>-dokvr
tables
documentfiles = lt_files.
* Pass the files we are interested in back out of this function.
* In this example we are only interested in files that have been checked into SAP.
delete lt_files where file_id is initial.
append lines of lt_files to files.
endloop.
endfunction.
The second is to read the document and get the image data in an xstring so that it can be displayed. Again you could use this and display the image in an HTML viewer within your R/3 report.
function zzdms_read_doc.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_FILE) TYPE BAPI_DOC_FILES2
*" EXPORTING
*" REFERENCE(E_DATA) TYPE XSTRING
*" REFERENCE(E_MIMETYPE) TYPE STRING
*"----------------------------------------------------------------------
data: lt_asc type table of sdokcntasc,
lt_bin type table of sdokcntbin,
lt_info type table of scms_acinf,
lv_len type i,
lv_string type string.
field-symbols: <asc> type sdokcntasc,
<info> type scms_acinf.
clear e_data.
* Read the document
call function 'SCMS_DOC_READ'
exporting
stor_cat = i_file-storagecategory
doc_id = i_file-file_id
tables
access_info = lt_info
content_bin = lt_bin
CONTENT_TXT = lt_asc
exceptions
others = 15.
read table lt_info assigning <info> index 1.
check ( <info> is assigned ).
* Convert the binary document data to an xstring
call function 'SCMS_BINARY_TO_XSTRING'
exporting
input_length = <info>-comp_size
importing
buffer = e_data
tables
binary_tab = lt_bin
exceptions
failed = 1
others = 2.
e_mimetype = <info>-mimetype.
endfunction.
Regards,
Darren
10-07-2008 5:35 PM
Hi,
I've done something similar via BSP, there are two main R/3 function modules that I wrote to achieve this.
The first is to get a list of the documents attached to a material, you could use this to feed your report.
function zzdms_get_material_docs.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(MATNR) TYPE MATNR
*" TABLES
*" FILES STRUCTURE BAPI_DOC_FILES2
*"----------------------------------------------------------------------
data: lt_drad type table of drad,
lt_files type table of bapi_doc_files2.
field-symbols: <drad> type drad.
refresh files.
* Find the documents linked to this material
select * into table lt_drad
from drad
where dokob = 'MARA'
and objky = matnr.
* and DOKAR = xxx <-- Could restrict to bespoke document type(s) here
* Find the file(s) associated with the documents
loop at lt_drad assigning <drad>.
clear lt_files.
call function 'BAPI_DOCUMENT_GETDETAIL2'
exporting
documenttype = <drad>-dokar
documentnumber = <drad>-doknr
documentpart = <drad>-doktl
documentversion = <drad>-dokvr
tables
documentfiles = lt_files.
* Pass the files we are interested in back out of this function.
* In this example we are only interested in files that have been checked into SAP.
delete lt_files where file_id is initial.
append lines of lt_files to files.
endloop.
endfunction.
The second is to read the document and get the image data in an xstring so that it can be displayed. Again you could use this and display the image in an HTML viewer within your R/3 report.
function zzdms_read_doc.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_FILE) TYPE BAPI_DOC_FILES2
*" EXPORTING
*" REFERENCE(E_DATA) TYPE XSTRING
*" REFERENCE(E_MIMETYPE) TYPE STRING
*"----------------------------------------------------------------------
data: lt_asc type table of sdokcntasc,
lt_bin type table of sdokcntbin,
lt_info type table of scms_acinf,
lv_len type i,
lv_string type string.
field-symbols: <asc> type sdokcntasc,
<info> type scms_acinf.
clear e_data.
* Read the document
call function 'SCMS_DOC_READ'
exporting
stor_cat = i_file-storagecategory
doc_id = i_file-file_id
tables
access_info = lt_info
content_bin = lt_bin
CONTENT_TXT = lt_asc
exceptions
others = 15.
read table lt_info assigning <info> index 1.
check ( <info> is assigned ).
* Convert the binary document data to an xstring
call function 'SCMS_BINARY_TO_XSTRING'
exporting
input_length = <info>-comp_size
importing
buffer = e_data
tables
binary_tab = lt_bin
exceptions
failed = 1
others = 2.
e_mimetype = <info>-mimetype.
endfunction.
Regards,
Darren
10-08-2008 6:19 AM
Hi Darren,
Thanks a lot for reply.
For most of the document number the value of FILE_ID is empty in the function module BAPI_DOCUMENT_GETDETAIL2.
Hence I could not proceed here after.
Please provide me the input condition to obtain this value.
Regards,
Bala Raja