12-09-2005 2:07 PM
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
12-09-2005 2: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
12-09-2005 2: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
12-09-2005 2:11 PM
12-09-2005 2:17 PM
12-09-2005 2: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
12-09-2005 2: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
12-09-2005 2: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?
12-09-2005 2: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.
12-09-2005 2:37 PM
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).
12-09-2005 2: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?
12-09-2005 2:44 PM
12-09-2005 2:52 PM
12-09-2005 2:58 PM
Hi!
Good idea. There is a xstring, which can hold up to 2GB - should be enough. It's recommended to use a binary type for reading binary files, so conversion should be explicit in the program.
Regards,
Christian