Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How can show binary attachment from SAP GUI.

Former Member
0 Kudos

<H5>Does have anybody idea,

to show some file stored in memory on local machine ?</H5>

For example binary stream of file is stored in local value typed xstring, binary table or raw data in database table.

<H6>Sample scenario:

1) store file to database table

2) show stored file, without copy to local machine.</H6>

One way is copy file to local machine using CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD,

than call

CALL FUNCTION 'WS_EXECUTE'

EXPORTING

COMMANDLINE = '/C start filename'

PROGRAM = 'cmd'

<H6>but it's not optimal way</H6>

1 ACCEPTED SOLUTION

former_member194669
Active Contributor
0 Kudos

Have you check this method of WD

Here the following code will be export the Internal Table to pdf


 LOOP AT lt_mara INTO wa_mara.
    CONCATENATE mara_string
                wa_mara-matnr
                wa_mara-ersda
                wa_mara-ernam
                wa_mara-matkl
                wa_mara-meins
                cl_abap_char_utilities=>cr_lf INTO mara_string
                                        SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
  ENDLOOP.
 
  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      text   = mara_string
    IMPORTING
      buffer = mara_xstring.

cl_wd_runtime_services=>attach_file_to_response( 
   i_filename = 'report.pdf'
   i_content = mara_xstring          " Pass XSTRING here
   i_mime_type = 'application/pdf' 
   i_in_new_window = 'X' 
   i_inplace = 'X' ). 

5 REPLIES 5

former_member194669
Active Contributor
0 Kudos

Have you check this method of WD

Here the following code will be export the Internal Table to pdf


 LOOP AT lt_mara INTO wa_mara.
    CONCATENATE mara_string
                wa_mara-matnr
                wa_mara-ersda
                wa_mara-ernam
                wa_mara-matkl
                wa_mara-meins
                cl_abap_char_utilities=>cr_lf INTO mara_string
                                        SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
  ENDLOOP.
 
  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      text   = mara_string
    IMPORTING
      buffer = mara_xstring.

cl_wd_runtime_services=>attach_file_to_response( 
   i_filename = 'report.pdf'
   i_content = mara_xstring          " Pass XSTRING here
   i_mime_type = 'application/pdf' 
   i_in_new_window = 'X' 
   i_inplace = 'X' ). 

Former Member
0 Kudos

Thank you, but I need way withou using WebDynpro ?

0 Kudos

Peter,

For this you don't need WD. You are using only a general class of WD.

Former Member
0 Kudos

Hi,

primary I need this for SAP 4.7 where aren 't webdynpro classes.

But I have tested your sollution on ECC 6.0 and get sytem sytem dump on method attach_file_to_response


method attach_file_to_response.

  wdr_task=>client_window->client->attach_file_to_response(
    i_filename      = i_filename
    i_content       = i_content
    i_mime_type     = i_mime_type
    i_in_new_window = i_in_new_window
    i_inplace       = i_inplace ).

endmethod.

You attempted to use a 'NULL' object reference (points to 'nothing')

access a component (variable: " ").

An object reference must point to an object (an instance of a class)

before it can be used to access components.

Either the reference was never set or it was set to 'NULL' using the

CLEAR statement.

<h4>

Sample code

</h4>


types: begin of ZEFX_BINARY_LINE,
          data(256) type x,
       end of ZEFX_BINARY_LINE,

"      riadok suboru
       ZEFX_BINARY_TABLE type table of ZEFX_BINARY_LINE.

data: xtable type ZEFX_BINARY_TABLE,
      size type I,
      xstr type xstring.




  data: _fullPath type string.
  concatenate 'C:\' 'dohoda_BPS.pdf' into _fullPath.

  data: _filename type string,
        xml_table_size type i,
        xbuffer type xstring,
        oRef type ref to CX_ROOT,
        strErr type string.


  CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
    EXPORTING
      FILENAME                = _fullPath
      FILETYPE                = 'BIN'
*      HAS_FIELD_SEPARATOR     = SPACE
*      HEADER_LENGTH           = 0
*      DAT_MODE                = SPACE
*      CODEPAGE                = SPACE
*      IGNORE_CERR             = ABAP_TRUE
*      REPLACEMENT             = '#'
*      VIRUS_SCAN_PROFILE      =
*      READ_BY_LINE            = 'X'
    IMPORTING
      FILELENGTH              = size
*      HEADER                  =
    CHANGING
      DATA_TAB                = xtable
    EXCEPTIONS
      FILE_OPEN_ERROR         = 1
      FILE_READ_ERROR         = 2
      NO_BATCH                = 3
      GUI_REFUSE_FILETRANSFER = 4
      INVALID_TYPE            = 5
      NO_AUTHORITY            = 6
      UNKNOWN_ERROR           = 7
      BAD_DATA_FORMAT         = 8
      HEADER_NOT_ALLOWED      = 9
      SEPARATOR_NOT_ALLOWED   = 10
      HEADER_TOO_LONG         = 11
      UNKNOWN_DP_ERROR        = 12
      ACCESS_DENIED           = 13
      DP_OUT_OF_MEMORY        = 14
      DISK_FULL               = 15
      DP_TIMEOUT              = 16
      NOT_SUPPORTED_BY_GUI    = 17
      ERROR_NO_GUI            = 18
      others                  = 19
          .
  IF SY-SUBRC <> 0.
   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 raising FILE_OPEN_ERROR.
  ENDIF.




CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
  EXPORTING
    INPUT_LENGTH       = size
*   FIRST_LINE         = 0
*   LAST_LINE          = 0
 IMPORTING
   BUFFER             = xstr
  TABLES
    BINARY_TAB         = xtable
 EXCEPTIONS
   FAILED             = 1
   OTHERS             = 2
          .
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


  cl_wd_runtime_services=>attach_file_to_response(
   i_filename = 'report.pdf'
   i_content = xstr
   i_mime_type = 'application/pdf'
   i_in_new_window = 'X'
   i_inplace = 'X' ).