Skip to Content

Uploading PDF-file from unix to SAP internal table

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on May 13, 2005 at 10:29 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 13, 2005 at 10:24 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.