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: 

Uploading PDF-file from unix to SAP internal table

h_senden2
Active Contributor
0 Kudos
317

Hi,

i have to write an abap that sends a pdf-file from a unix (SAP server) by mail to some people.

The mailing part is done, but for creating the attachment. I'm reading the pdf-file into an internal table (in a binary way). Then i'm using this int.table to send the mail.

The email is sent with an attachment, but i cannot open the pdf-file because of an error ( file damaged ). So before sending it by mail, i'm downloading the pdf file to my pc by using WS_DOWNLOAD with the same internal table. The download file gives the same error.

If i look at the size :

- originally pdf file 71743 bytes

- resulting pdf file 71665 bytes (281 lines x 255)

The creation of the internal table is as follows :

 open dataset g_file for input in binary mode. 
  check sy-subrc eq 0. 
  do. 
*    read dataset g_file MAXIMUM LENGTH 255 into wa_pdf. 
    read dataset g_file into wa_pdf. 
    if sy-subrc ne 0. exit. endif. 
    append wa_pdf_hex to i_pdf. 
  enddo. 
  close dataset g_file.

where:

types:  tt_pdf  type table of soli,   "raw 255 long 
data: i_pdf type tt_pdf, 
         wa_pdf like line of i_pdf

Is there a better way to read in the pdf-file ? Any suggestions ?

regards,

Hans

hans.senden@philips.com

1 ACCEPTED SOLUTION

FredericGirod
Active Contributor
0 Kudos
124

Hello Hans,

this is a little example from a program to send mail with picture. The problem is the same

form p_create_mail tables itab_html.


  data : object_hd_change like sood1 occurs 0 with header line,
         objpara          like selc  occurs 0 with header line,
         receivers        like soos1 occurs 0 with header line,
         packing_list     like soxpl occurs 0 with header line,
         fic_attach       like soli  occurs 0 with header line,

         struct_user_adress like usaddress ,
         v_file(80) type c ,
         v_buff(255) type c ,
         v_num(9) type n,
         v_length type i ,
         v_total_length type i,
         v_len(9) type n.




  move : 'HTM'  to object_hd_change-file_ext ,
         'PIOU' to object_hd_change-objdes.
  append object_hd_change.


* Find email addr for the username.
  loop at s_bname.

    call function 'SUSR_USER_READ'
      exporting
        user_name                  = s_bname-low
      importing
        user_address               = struct_user_adress
      exceptions
        user_name_not_exists       = 1
        internal_error             = 2
        others                     = 3.
    select single smtp_addr
           into receivers-recextnam
           from adr6
           where addrnumber eq struct_user_adress-addrnumber
           and   persnumber eq struct_user_adress-persnumber.
    if sy-subrc eq space.
      move 'U' to receivers-recesc.
      append receivers.
    endif.

  endloop.

* Get the picture.
  move '/sap_interfaces/D27/pzr_00/data/test/logopharma.gif'
       to v_file.
  open dataset v_file for input in binary mode.
  do.
    read dataset v_file into v_buff length v_length.
    v_total_length = v_length + v_total_length.
    move v_buff+0(v_length) to fic_attach-line+0(v_length).
    append fic_attach.
    if sy-subrc ne space.
      exit.
    endif.
  enddo.
  describe table fic_attach lines v_num.
  describe field fic_attach-line length v_len.
  move : 'Logo' to packing_list-objdes ,
         'Logo' to packing_list-objnam ,
         '1'    to packing_list-body_start ,
         'raw'  to packing_list-objtp ,
         'GIF'  to packing_list-file_ext .
  packing_list-body_num = v_num.
  packing_list-objlen   =  v_num * v_len.
  append packing_list.


* Send mail.
  call function 'SO_OBJECT_SEND'
       exporting
           object_hd_change           = object_hd_change
           object_type                = 'RAW'
           owner                      = sy-uname
       tables
           objcont                    = itab_html
           objpara                    = objpara
           receivers                  = receivers
           packing_list               = packing_list
           att_cont                   = fic_attach
       exceptions
           others                     = 01.




endform.                     " P_CREATE_MAIL.

Regards

Frédéric

3 REPLIES 3

Former Member
0 Kudos
124

You can use for example command 'mailx' on unix where you indicate the path file of pdf directly on server unix.

In abap program, you can try to open the file using open dataset; transfer the data into internal table defined as structure 'tline'; call standard fm "QCE1_CONVERT" to convert the format table. In this mode I'm able to read a document using acrobat reader without problem.

Gianluca

FredericGirod
Active Contributor
0 Kudos
125

Hello Hans,

this is a little example from a program to send mail with picture. The problem is the same

form p_create_mail tables itab_html.


  data : object_hd_change like sood1 occurs 0 with header line,
         objpara          like selc  occurs 0 with header line,
         receivers        like soos1 occurs 0 with header line,
         packing_list     like soxpl occurs 0 with header line,
         fic_attach       like soli  occurs 0 with header line,

         struct_user_adress like usaddress ,
         v_file(80) type c ,
         v_buff(255) type c ,
         v_num(9) type n,
         v_length type i ,
         v_total_length type i,
         v_len(9) type n.




  move : 'HTM'  to object_hd_change-file_ext ,
         'PIOU' to object_hd_change-objdes.
  append object_hd_change.


* Find email addr for the username.
  loop at s_bname.

    call function 'SUSR_USER_READ'
      exporting
        user_name                  = s_bname-low
      importing
        user_address               = struct_user_adress
      exceptions
        user_name_not_exists       = 1
        internal_error             = 2
        others                     = 3.
    select single smtp_addr
           into receivers-recextnam
           from adr6
           where addrnumber eq struct_user_adress-addrnumber
           and   persnumber eq struct_user_adress-persnumber.
    if sy-subrc eq space.
      move 'U' to receivers-recesc.
      append receivers.
    endif.

  endloop.

* Get the picture.
  move '/sap_interfaces/D27/pzr_00/data/test/logopharma.gif'
       to v_file.
  open dataset v_file for input in binary mode.
  do.
    read dataset v_file into v_buff length v_length.
    v_total_length = v_length + v_total_length.
    move v_buff+0(v_length) to fic_attach-line+0(v_length).
    append fic_attach.
    if sy-subrc ne space.
      exit.
    endif.
  enddo.
  describe table fic_attach lines v_num.
  describe field fic_attach-line length v_len.
  move : 'Logo' to packing_list-objdes ,
         'Logo' to packing_list-objnam ,
         '1'    to packing_list-body_start ,
         'raw'  to packing_list-objtp ,
         'GIF'  to packing_list-file_ext .
  packing_list-body_num = v_num.
  packing_list-objlen   =  v_num * v_len.
  append packing_list.


* Send mail.
  call function 'SO_OBJECT_SEND'
       exporting
           object_hd_change           = object_hd_change
           object_type                = 'RAW'
           owner                      = sy-uname
       tables
           objcont                    = itab_html
           objpara                    = objpara
           receivers                  = receivers
           packing_list               = packing_list
           att_cont                   = fic_attach
       exceptions
           others                     = 01.




endform.                     " P_CREATE_MAIL.

Regards

Frédéric

0 Kudos
124

Thanx Frederic,

your code has helped me with the solution of the problem.

regards,

Hans