Skip to Content
avatar image
Former Member

Error while exporting data from ABAP to Excel

Hello All,

iam trying to download data from ABAP scrn to Excel using I_OI_SPREADSHEET METHODS. I get an error in method 'SET_RANGES_DATA' - 'Memory protection fault occurred in document interface'.

I have pasted my code below. Kindly help me to solve this issue.

    • Create container ??

    CALL METHOD c_oi_container_control_creator=>get_container_control

    IMPORTING

    control = g_control

    error = g_error.

      • Initialize

      CALL METHOD g_control->init_control

      EXPORTING

      r3_application_name = 'Basis'

      parent = g_container

      • register_on_close_event = c_reg_on_close_event

      • register_on_custom_event = c_reg_on_custom_event

      • no_flush = c_no_flush

      IMPORTING

      error = g_error.

        • Set Doc type

        g_document_type = 'Excel.Sheet'.

          • Create Proxy

          CALL METHOD g_control->get_document_proxy

          EXPORTING

          document_type = g_document_type

          IMPORTING

          document_proxy = g_document

          error = g_error.

          CALL METHOD g_document->create_document

          EXPORTING

          document_title = 'Excel'. "#EC NOTEXT

          CALL METHOD g_document->get_spreadsheet_interface

          IMPORTING

          sheet_interface = g_handle.

          CHECK g_document IS NOT INITIAL.

            • read selected line data from gtab

            READ TABLE g_tab_data INDEX 1 INTO l_wa_pos_trans.

            • Get Field Descriptions

            CALL FUNCTION 'DDIF_FIELDINFO_GET'

            EXPORTING

            tabname = 'TRIGS_EXPORT_EXCEL'

            langu = sy-langu

            TABLES

            dfies_tab = lt_dfies

            EXCEPTIONS

            not_found = 1

            internal_error = 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.

              • Header for User Data

              l_h_cnt = 1.

              LOOP AT lt_dfies INTO lwa_dfies.

              IF lwa_dfies-fieldname EQ 'USER_ID' OR

              lwa_dfies-fieldname EQ 'EXCEL_DATE' OR

              lwa_dfies-fieldname EQ 'EXCEL_TIME' OR

              lwa_dfies-fieldname EQ 'SECURITY_ACCOUNT' OR

              lwa_dfies-fieldname EQ 'SECURITY_ID' OR

              lwa_dfies-fieldname EQ 'COMPANY_CODE'.

              PERFORM fill_cell USING l_h_cnt 1 1 lwa_dfies-scrtext_m.

              l_h_cnt = l_h_cnt + 1.

              ENDIF.

              ENDLOOP.

              • Fill Header Values

              PERFORM fill_cell USING 1 2 1 sy-uname.

              PERFORM fill_cell USING 2 2 1 sy-datum.

              PERFORM fill_cell USING 3 2 1 sy-uzeit.

              PERFORM fill_cell USING 4 2 1 l_wa_pos_trans-company_code .

              PERFORM fill_cell USING 5 2 1 l_wa_pos_trans-security_account.

              PERFORM fill_cell USING 6 2 1 l_wa_pos_trans-security_id.

                • Texts

              • l_h_cnt = l_h_cnt + 1.

              • PERFORM fill_cell USING l_h_cnt 1 1 text-011.

                PERFORM fill_cell USING l_h_cnt 3 1 text-012.

                  • Range for header

                  range_item-name = 'RANGE1'.

                  range_item-rows = '7'.

                  range_item-columns = '3'.

                  range_item-code = g_handle->spreadsheet_insertall.

                  APPEND range_item TO range_list.

                  CALL METHOD g_handle->set_selection

                  EXPORTING

                  left = 1

                  top = 1

                  rows = 7

                  columns = 3

                  IMPORTING

                  retcode = retcode.

                  CALL METHOD g_handle->insert_range

                  EXPORTING

                  columns = 3

                  rows = 7

                  name = 'RANGE1'

                  IMPORTING

                  retcode = retcode.

                  CALL METHOD g_handle->set_ranges_data

                  EXPORTING

                  ranges = range_list

                  contents = gt_cell_data

                  IMPORTING

                  retcode = retcode.

                    • Columns for PC

                    CLEAR: gt_cell_data[].

                    l_pc_cnt = l_h_cnt + 1.

                    LOOP AT lt_dfies INTO lwa_dfies.

                    IF lwa_dfies-fieldname EQ 'SBWHR' OR

                    lwa_dfies-fieldname CP '_PC'.

                    PERFORM fill_cell USING l_pc_cnt 1 0 lwa_dfies-scrtext_m.

                    l_pc_cnt = l_pc_cnt + 1.

                    ENDIF.

                    ENDLOOP.

                      • Pos Curr - Values

                      PERFORM fill_cell USING 9 2 0 trls_position_value-sbwhr.

                      PERFORM fill_cell USING 10 2 0 trls_position_value-purch_pc.

                      PERFORM fill_cell USING 11 2 0 trls_position_value-charge_pc.

                      PERFORM fill_cell USING 12 2 0 trls_position_value-impmnt_pc.

                      PERFORM fill_cell USING 13 2 0 trls_position_value-amort_pc.

                      PERFORM fill_cell USING 14 2 0 trls_position_value-val_ti_pc.

                      PERFORM fill_cell USING 15 2 0 trls_position_value-val_idx_pc.

                      PERFORM fill_cell USING 16 2 0 trls_position_value-val_ch_ti_pc.

                      PERFORM fill_cell USING 17 2 0 trls_position_value-val_ti_npl_pc.

                      PERFORM fill_cell USING 18 2 0 trls_position_value-val_idx_npl_pc.

                      PERFORM fill_cell USING 19 2 0 trls_position_value-val_ch_ti_npl_pc.

                      PERFORM fill_cell USING 20 2 0 trls_position_value-book_val_pc.

                          • Columns for VC

                          l_vc_cnt = l_h_cnt + 1.

                          LOOP AT lt_dfies INTO lwa_dfies.

                          IF lwa_dfies-fieldname EQ 'SBWHR' OR

                          lwa_dfies-fieldname CP '_VC'.

                          PERFORM fill_cell USING l_vc_cnt 3 0 lwa_dfies-scrtext_m.

                          l_vc_cnt = l_vc_cnt + 1.

                          ENDIF.

                          ENDLOOP.

                            • Val Curr

                            PERFORM fill_cell USING 9 4 0 trls_position_value-svwhr.

                            PERFORM fill_cell USING 10 4 0 trls_position_value-purch_vc.

                            PERFORM fill_cell USING 11 4 0 trls_position_value-charge_vc.

                            PERFORM fill_cell USING 12 4 0 trls_position_value-impmnt_vc.

                            PERFORM fill_cell USING 13 4 0 trls_position_value-amort_vc.

                            PERFORM fill_cell USING 14 4 0 trls_position_value-val_ti_vc.

                            PERFORM fill_cell USING 15 4 0 trls_position_value-val_fx_vc.

                            PERFORM fill_cell USING 16 4 0 trls_position_value-val_idx_vc.

                            PERFORM fill_cell USING 17 4 0 trls_position_value-val_ch_ti_vc.

                            PERFORM fill_cell USING 18 4 0 trls_position_value-val_ch_fx_vc.

                            PERFORM fill_cell USING 19 4 0 trls_position_value-val_fx_npl_vc.

                            PERFORM fill_cell USING 20 4 0 trls_position_value-val_ti_npl_vc.

                            PERFORM fill_cell USING 21 4 0 trls_position_value-val_idx_npl_vc.

                            PERFORM fill_cell USING 22 4 0 trls_position_value-val_ch_ti_npl_vc.

                            PERFORM fill_cell USING 23 4 0 trls_position_value-val_ch_fx_npl_vc.

                            PERFORM fill_cell USING 24 4 0 trls_position_value-book_val_vc.

                                  • Range for PC and VC

                                  CLEAR: range_list[].

                                  range_item-name = 'RANGE2'.

                                  range_item-rows = '17'.

                                  range_item-columns = '4'.

                                  range_item-code = g_handle->spreadsheet_insertall.

                                  APPEND range_item TO range_list.

                                  CALL METHOD g_handle->set_selection

                                  EXPORTING

                                  left = 1

                                  top = 9

                                  rows = 17

                                  columns = 4

                                  IMPORTING

                                  retcode = retcode.

                                  CALL METHOD g_handle->insert_range

                                  EXPORTING

                                  columns = 4

                                  rows = 17

                                  name = 'RANGE2'

                                  IMPORTING

                                  retcode = retcode.

                                  CALL METHOD g_handle->set_ranges_data

                                  EXPORTING

                                  ranges = range_list

                                  contents = gt_cell_data

                                  IMPORTING

                                  retcode = retcode.

                                  ***********************************Form routine****************

                                  FORM fill_cell USING i j bold val.

                                  DATA:

                                  wa_cell_data TYPE soi_generic_item.

                                  wa_cell_data-row = i.

                                  wa_cell_data-column = j.

                                  wa_cell_data-value = val.

                                  APPEND wa_cell_data TO gt_cell_data.

                                  ENDFORM. "FILL_CELL

                                  Add comment
                                  10|10000 characters needed characters exceeded

                                  • Get RSS Feed

                                  1 Answer

                                  • avatar image
                                    Former Member
                                    Oct 01, 2007 at 07:44 AM

                                    Solved

                                    Add comment
                                    10|10000 characters needed characters exceeded