Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

To display the list of document data(material master) and view the picture

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

Tags:
Former Member
Former Member replied

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

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question