Skip to Content
author's profile photo Former Member
Former Member

open dataset ... for input in binary mode

Okay, ten points for the first person who can tell me how to fix this.

I've got a binary file of size 281065 bytes which I want to attach to an e-mail I'm sending from an ABAP programme. Unfortunately, when I do this...

open dataset zfile for input in binary mode.
  do.
    read dataset zfile into ls_xcontent_hex-line.
    if sy-subrc eq 0.
      append ls_xcontent_hex to xcontent_hex.
    else.
      if zcounter eq 1.
        exit.
      else.
        add 1 to zcounter.
      endif.
    endif.
  enddo.
close dataset zfile.

...it manages to ignore the last 55 bytes of the attachment. Now, this being a .pdf file, this is obviously a problem, as it's missing the footer information (which is pretty important for a .pdf). (Aside from this it's all fine though.)

How can I get those last 55 bytes to read? The amount it's reading - 281,010 bytes - is an exact multiple of 255, which is also the line size of the field into which each bit is being read. I just need those last 55 bytes, and it's annoying me 😔

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Best Answer
    Posted on Dec 09, 2005 at 02:23 PM

    Hi Robert!

    What is the special reason for your zcounter? You ignore one sy-subrc ne 0, but you don't make an append (in else. add 1...)

    Nevertheless, normally line (or file length) is known, that's much easier (as Rich already said, field is big enough for whole line / file).

    If this is not possible with big dynamical PDF-files, go for single byte read, step by step. Then you can get every byte, put this internally together and nothing will be lost.

    DATA: hex_byte(1) TYPE x, 
                len TYPE i value 1. 
    
    OPEN DATASET zfile FOR INPUT IN BINARY MODE. 
    
    
    DO. 
      READ DATASET zfile INTO hex_byte MAXIMUM LENGTH 1. 
      IF sy-subrc = 0. 
    * append hex_byte to your xcontent_hex
      ELSE. 
        EXIT. 
      ENDIF. 
    ENDDO. 
    
    CLOSE DATASET file. 
    

    Regards,

    Christian

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 09, 2005 at 02:08 PM

    What is the definition of ls_xcontent_hex-line? May be you should use a string type for this field and try.

    Srinivas

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 09, 2005 at 02:11 PM

    how you defined <b>line</b> in this ls_xcontent_hex-line.

    vijay

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2005 at 02:23 PM

    Hi,

    Maybe you should add the keywords <b>MAXIMUM LENGTH</b> and <b>LENGTH</b> as in:

      DO.
        READ DATASET i_srv_file
                INTO e_data
                MAXIMUM LENGTH 1024
                LENGTH l_len.
    
        IF l_len GT 1024.
    *     Line length & exceeds 1024.
          MESSAGE e000 WITH l_len
                  RAISING file_read_error.
        ENDIF.
    
        IF NOT sy-subrc IS INITIAL.
          EXIT.
        ENDIF.
    
        APPEND e_data.
      ENDDO.
    

    Then you would get feedback if there's a line that's too long.

    Regards, Joerg

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2005 at 02:26 PM

    Apologies for that. ls_xcontent_hex-line is a char255. It isn't possible to do line(281065) type c, as the function module I'm using takes a table of type solix.

    Any ideas?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2005 at 02:29 PM

    People reply so fast on here!!!

    The zcounter was an attempt to demonstrate that even forcing it to read an extra line doesn't help.

    I like the byte-at-a-time idea - I'll try it. The longest line, by the way, far exceeds 255, it's roughly 15,000 bytes long.

    Add a comment
    10|10000 characters needed characters exceeded

    • Yes, I already had doubts about the use of an additional append.

      One other option would be: determine total file length in advance, read data in chunks of let's say 100 bytes until you need to read the rest (modulo 100). Just in case byte-by-byte is to slow (and no better solution is proposed).

  • author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2005 at 02:40 PM

    How about I declare a local field:

    data zfield(281065) type x.

    Then read it into there, and do it all internally using offsets and lengths?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2005 at 02:52 PM

    Hi,

    Try using the type "LCHR".

    Regards,

    Suman

    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.