Application Development and Automation 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: 
Read only

how to process the binary content in internal table?

former_member213450
Participant
0 Likes
5,144

I've used the FM SO_ATTACHMENT_READ_API1 to retrieve a EXCEL data attachment.It returns the binary format. I want to process that data in internal table. I am able to download that binary data to Excel file using "cl_gui_frontend_services=>gui_download".I don't know how to process. Please help me.

12 REPLIES 12
Read only

Former Member
0 Likes
3,609

what should your processing do?

Read only

0 Likes
3,609


my internal table look like this....

types: begin of ty_output,
        matnr                  type marc-matnr,
        werks                 type marc-werks,
        QZGTP               type marc-QZGTP,
       description(10)     type c,
       end of ty_output.

data: it_output type standard table of ty_output.

my Excel attachment look like this..

-------------------------------------------------------------
MATNR | plant | Certificate | Description |
--------------------------------------------------------------
12345 | 1000  | ABC         | testing 1   |
-------------------------------------------------------------
67890|  1000  | CDE         | testing 2   |
----------------------------------------------------------  

I am using this FM  to read the attachment. and i am getting the data into "it_contents" in binary format.


call function 'SO_ATTACHMENT_READ_API1'
        exporting
          attachment_id              = it_attachment-attach_id
        tables
          contents_hex               = it_contents
        exceptions
          attachment_not_exist       = 1
          operation_no_authorization = 2
          parameter_error            = 3
          x_error                    = 4
          enqueue_error              = 5
          others                     = 6.


now i want to store the data to the internal table "it_output".

i am able to download the data to local excel file using following FM.
but unable to store  the data into  internal table it_output.


   input_length = it_attachment-att_size.

call method cl_gui_frontend_services=>gui_download
    exporting
      bin_filesize            = input_length
      filename                = 'D:\TMP\TEST.XLSX'
      filetype                = 'BIN'
    changing
      data_tab                = it_contents
    exceptions
      file_write_error        = 1
      no_batch                = 2.

any quick response appreciated.

Read only

0 Likes
3,609

Hi

Can you check the contents in the tables parameters of FM 'SO_ATTACHMENT_READ_API1'

ATTACHMENT_HEADER
ATTACHMENT_CONTENT <<< ofthis one
CONTENTS_HEX

Regards

Sree

Read only

0 Likes
3,609

Well what you want to achieve is importing an excel file from the attachments, parsing it and working with it in your code. That is really not something that can be done easily. You want to convert your binary data to a abap-like interpretation.

Have a look at the abap2xls project and search more for the words "read excel in abap".

Read only

0 Likes
3,609

hi Sreevisakh,

I have checked these Table parameters, but i couldn't get any thing.

the table ATTACHMENT_HEADER contains only below information.

&SO_FORMAT=BIN

&SO_FILENAME=material_details.xlsx

and

ATTACHMENT_CONTENT  contains something unreadable format.

CONTENTS_HEX contains binary format.

Read only

0 Likes
3,609

yeah exactly Jozef, but I don't know about  abap2xls project because i am new to ABAP.please provide me some information on this so that I  can get the solution..

Read only

0 Likes
3,609

please, search SCN, you will find many examples how to import excel to abap. Once you need it to operate only in foreground, you can use OLE interface. Only if background is needed, abap2xls could be useful.

Read only

0 Likes
3,609

Have you checked the sy-subrc value?

if sy-subrc is initial then.

     

       ATTACHEMENT_HEADER should have header

       ATTACHMENT_CONTENT should have content
endif.

Read only

0 Likes
3,609


hii,

      ATTACHEMENT_HEADER and   ATTACHMENT_CONTENT has the content. the problem here is   that content in ATTACHMENT_CONTENT and CONTENTS_HEX tables are in binary format. and i want to read that content in CONTENTS_HEX table to my internal table IT_OUTPUT.

Read only

0 Likes
3,609

Hi ram,

check below code
DATA : l_file TYPE string,
         it_raw TYPE truxs_t_text_data.
  l_file = pfname.
--


  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_field_seperator    = 'X'
      i_line_header        = 'X'
      i_tab_raw_data       = it_raw
      i_filename           = pfname
    TABLES
      i_tab_converted_data = it_upload[]
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.
  IF sy-subrc NE 0.
    MESSAGE 'Error in uploading file' TYPE 'E'.
Read only

0 Likes
3,609

hi Manoj,

Thank you for quick response,but here my requirement is to read the table "it_contents" and store the data into internal table "it_output" without downloading to local file.

Read only

0 Likes
3,609

Hi Ram Ramesh,

Have you achieved your requirement ?