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: 

File Corrupted Downloading SRM attachments - Converting RAW to XSTRING

prabhu_s2
Active Contributor
0 Kudos


Hi!

I'm reading the SRM attachments via the function module BBP_PD_CTR_GETDETAIL where the attachments like PDF, DOCS etc (if any attached in the SRM documents) are provided in RAW format (data type SDOK_SDATX). To download the files I provide the pop-up option via the class method   cl_wd_runtime_services=>attach_file_to_response

When i'm able to convert the RAW to XSTRING using the below code and download PDF files successfully I couldn't download DOCX file types. Not sure if the conversion of RAW to XSTRING is incorrect. Anyone had experienced this earlier? Please can u help?

    

Code to convert RAW to STRING:

LOOP AT attachment-phio_content INTO ls_attachmt.

   
MOVE ls_attachmt-line TO l_xstring.

   
CONCATENATE lv_content l_xstring

          
INTO lv_content IN BYTE MODE.

   
CLEAR l_xstring.

 
ENDLOOP.

2 REPLIES 2

Former Member
0 Kudos

Length of the file needs to be considered. For example I have 1055 byte file stored in table of line length 1022.. Table will have 2 records of length 1022, but only 33 byte of second line needs to be considered. In your case, resulting xstring will have 1022*2 length, not 1055.

alisonv
Explorer
0 Kudos
DATA: lt_access_info       TYPE TABLE OF sdokfilaci,
lt_ascii_content TYPE TABLE OF sdokcntasc,
lt_binary_content TYPE TABLE OF sdokcntbin.
DATA: lv_doc_lenght TYPE i,
lv_qty_lines TYPE i,
lv_xstring TYPE xstring.
CALL FUNCTION 'SDOK_PHIO_LOAD_CONTENT'
EXPORTING
object_id = w_object_id
raw_mode = 'X'
TABLES
file_access_info = lt_access_info
file_content_ascii = lt_ascii_content
file_content_binary = lt_binary_content
EXCEPTIONS
not_existing = 1
not_authorized = 2
no_content = 3
bad_storage_type = 4
OTHERS = 5.
IF sy-subrc <> 0.
RETURN.
ENDIF.
FIELD-SYMBOLS: <lt_access_info> LIKE LINE OF lt_access_info.
READ TABLE lt_access_info ASSIGNING <lt_access_info> INDEX 1.
IF sy-subrc IS INITIAL AND <lt_access_info>-file_size IS NOT INITIAL.
lv_doc_lenght = <lt_access_info>-file_size.
ELSE.
lv_qty_lines = lines( lt_binary_content ).
lv_doc_lenght = lv_qty_lines * 1022.
ENDIF.