Quantcast
Channel: SCN: Message List - ABAP Development
Viewing all articles
Browse latest Browse all 10425

XLSX and XLS not opening after attaching to order

$
0
0

Hi SAP Experts ,

 

I am trying to attach the Excel file to SAP work order and its getting attached. But not opening properly.

 

I am able to attach PDF  and open it fine  with no issues . Where am i going wrong ? What should i check for the XLS file and XLSX file to open properly.

 

Please suggest.

 

 

Here is the  test code snippet .

 

REPORT z_xls_attach.

PARAMETERS: p_key TYPE swo_typeid OBLIGATORY default '000060129553',

p_type TYPE swo_objtyp OBLIGATORY default 'BUS2088',

p_file TYPE string OBLIGATORY default '\\192.168.1.137\AMR\Inbound\VS_test.xlsx' lower case,

p_desc TYPE so_obj_des OBLIGATORY default 'VS_xlsx'.

 

 

DATA: ls_fol_id TYPE soodk,

ls_obj_id TYPE soodk,

ls_obj_data TYPE sood1,

ls_folmem_k TYPE sofmk,

ls_note TYPE borident,

ls_object TYPE borident,

lv_ep_note TYPE borident-objkey,

* lv_offset TYPE i,

lv_lines TYPE i,

lv_filename TYPE c LENGTH 100, " file name and ext

lv_extension TYPE c LENGTH 12."4. " extension only

 

 

DATA: it_objhead TYPE STANDARD TABLE OF soli,

it_content LIKE STANDARD TABLE OF soli,

wa_content LIKE soli.

data:it_contentx LIKE STANDARD TABLE OF solix,

wa_contentx LIKE solix,

wa_SOLI TYPE SOLI.

 

 

ls_object-objkey = p_key.

ls_object-objtype = p_type.

 

 

TRY.

    OPEN DATASET p_file FOR INPUT IN BINARY MODE.

    IF SY-SUBRC NE 0.

      MESSAGE 'No file available' TYPE 'I'.

      LEAVE  LIST-PROCESSING.

    ENDIF.

    WHILE sy-subrc = 0.

      READ DATASET p_file INTO wa_content.

      APPEND wa_content TO it_content.

    ENDWHILE.

    CLOSE DATASET p_file.

  CATCH cx_sy_file_access_error.

    MESSAGE 'Error reading file' TYPE 'E'.

ENDTRY.

 

 

CALL FUNCTION 'SO_CONVERT_CONTENTS_BIN'

  EXPORTING

    it_contents_bin = it_content[]

  IMPORTING

    et_contents_bin = it_content[].

 

 

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'

  EXPORTING

    region    = 'B'

  IMPORTING

    folder_id = ls_fol_id

  EXCEPTIONS

    OTHERS    = 1.

 

 

* Get file name and extension

CALL FUNCTION 'CH_SPLIT_FILENAME'

  EXPORTING

    complete_filename = p_file

  IMPORTING

    extension         = lv_extension

    name_with_ext     = lv_filename

  EXCEPTIONS

    invalid_drive     = 1

    invalid_path      = 2

    OTHERS            = 3.

IF sy-subrc <> 0.

  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

 

 

 

 

ls_obj_data-objsns = 'O'.

ls_obj_data-objla = sy-langu.

ls_obj_data-objdes = p_desc.

*lv_offset = STRLEN( p_file ) - 3.

*ls_obj_data-file_ext = p_file+lv_offset(3).

ls_obj_data-file_ext = lv_extension.

*ls_obj_data-objlen = LINES( it_content ) * 255.

CLEAR wa_content.

DESCRIBE TABLE it_content LINES lv_lines.

READ TABLE it_content INTO wa_content INDEX lv_lines.

ls_obj_data-objlen = ( lv_lines - 1 ) * 255 + strlen( wa_SOLI ).

 

 

* Object header

CLEAR wa_content.

wa_content = '&SO_FORMAT=BIN'.

APPEND wa_content TO it_objhead.

CLEAR wa_content.

CONCATENATE '&SO_FILENAME=' lv_filename INTO wa_content.

APPEND wa_content TO it_objhead.

 

 

CALL FUNCTION 'SO_OBJECT_INSERT'

  EXPORTING

    folder_id             = ls_fol_id

    object_type           = 'EXT'

    object_hd_change      = ls_obj_data

  IMPORTING

    object_id             = ls_obj_id

  TABLES

    objhead               = it_objhead

    objcont               = it_content

  EXCEPTIONS

    active_user_not_exist = 35

    folder_not_exist      = 6

    object_type_not_exist = 17

    owner_not_exist       = 22

    parameter_error       = 23

    OTHERS                = 1000.

 

 

IF sy-subrc = 0 AND ls_object-objkey IS NOT INITIAL.

  ls_folmem_k-foltp = ls_fol_id-objtp.

  ls_folmem_k-folyr = ls_fol_id-objyr.

  ls_folmem_k-folno = ls_fol_id-objno.

  ls_folmem_k-doctp = ls_obj_id-objtp.

  ls_folmem_k-docyr = ls_obj_id-objyr.

  ls_folmem_k-docno = ls_obj_id-objno.

  lv_ep_note = ls_folmem_k.

  ls_note-objtype = 'MESSAGE'.

  ls_note-objkey = lv_ep_note.

  CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'

    EXPORTING

      obj_rolea    = ls_object

      obj_roleb    = ls_note

      relationtype = 'ATTA'

    EXCEPTIONS

      OTHERS       = 1.

ELSE.

  MESSAGE 'Not OK' TYPE 'I'.

  RETURN.

ENDIF.

 

 

IF sy-subrc = 0.

  MESSAGE 'OK' TYPE 'I'.

ELSE.

  MESSAGE 'Not OK' TYPE 'I'.

ENDIF.


Viewing all articles
Browse latest Browse all 10425

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>