Deepika,
I have solved my issue, cause when read the DATASET to <hex_container>, I used 'sy-subrc' to depend whether the DATASET be read or not, if the left content of the file less than 255 bytes, it will be readed, otherwise, it will be aborted.
So 1)I use FM 'WS_QUERY' to get the size of the file, the length will depend how many times should the program read the file content to <hex_container>;
2) cause the size of the content be read at the last is less equal than 255 bytes, but the size of <hex_content> is 255 bytes, so the left part of <hex_content> will be filled with '0' s;
3) the '0's should not append to the file, so when add the attachment, we should use the real size of the file as value of parameter I_attachment_size, it will truncate the '0's;
Thanks again for you reply,
JiaMing
FYI, below is my code:
DATA: file(100) TYPE c.
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
LOGICAL_FILENAME = 'TEST-3'
PARAMETER_1 = '.xml'
IMPORTING
FILE_NAME = file
EXCEPTIONS
FILE_NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
ENDIF.
DATA : wa_bin type SOLIX.
DATA: file_len type i.
DATA: tim type i.
CALL FUNCTION 'WS_QUERY'
EXPORTING
FILENAME = file
QUERY = 'FL'
IMPORTING
RETURN = file_len.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
* write:/ 'file cannot find'.
ENDIF.
tim = file_len DIV 255 .
FIELD-SYMBOLS: <hex_container> type x.
OPEN DATASET file FOR INPUT IN BINARY MODE.
** plus 1 to append all content into hex_content,
** but the length of the hex_content will longer
** than the real length of the file with '0's
DO tim + 1 times.
ASSIGN wa_bin TO <hex_container> CASTING.
READ DATASET file INTO <hex_container>.
append wa_bin to hex_content.
ENDDO.
CLOSE DATASET file.
data: file_len_ch like SOOD-OBJLEN.
* the real length of the file will be the parameter
* of I_ATTACHMENT_SIZE
file_len_ch = file_len.
document->add_attachment(
EXPORTING
i_attachment_type = ''
i_attachment_subject = 'test1.doc'
I_ATTACHMENT_SIZE = file_len_ch
i_att_content_hex = hex_content ).