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

Export itab data into container as excel format

former_member788515
Discoverer
0 Likes
766

Hi experts ,

I upload data from excel into itab,then i want to export itab data into dynpro container as excel formt.

3 REPLIES 3
Read only

Former Member
0 Likes
619

Hi,

Dynpro container?

Please elaborate your requirement.

Regards

Lekha

Read only

Former Member
0 Likes
619


CONSTANTS:
           c_basis         TYPE char5              VALUE 'Basis',
           c_cc_excel      TYPE char10             VALUE 'W_CC_EXCEL',
           c_excel         TYPE char5              VALUE 'Excel',
           c_excel_sh      TYPE char12             VALUE 'Excel.Sheet'.


DATA:
       w_container         TYPE REF TO cl_gui_custom_container,
       w_error             TYPE REF TO i_oi_error,
       w_retcode           TYPE soi_ret_string,
       w_control           TYPE REF TO i_oi_container_control,
       w_document          TYPE REF TO i_oi_document_proxy,
       w_handle            TYPE REF TO i_oi_spreadsheet.

*"Create the instance CONTROL

  CALL METHOD c_oi_container_control_creator=>get_container_control
    IMPORTING
      control = w_control
      error   = w_error.

*"Create a container

  CLEAR w_container.

  CREATE OBJECT w_container
    EXPORTING
      container_name = c_cc_excel.

*"Create the object that manages the link to the OLE interface

  IF w_control IS NOT INITIAL.

    MOVE c_x TO w_inplace.

    CALL METHOD w_control->init_control
      EXPORTING
        r3_application_name      = c_basis
        inplace_enabled          = w_inplace
        inplace_scroll_documents = c_x
        parent                   = w_container
        register_on_close_event  = c_x
        register_on_custom_event = c_x
        no_flush                 = c_x
      IMPORTING
        error                    = w_error.


    CALL METHOD w_control->get_document_proxy
      EXPORTING
        document_type  = c_excel_sh
      IMPORTING
        document_proxy = w_document
        error          = w_error.


    IF w_document IS NOT INITIAL.

      CALL METHOD w_document->create_document
        EXPORTING
          document_title = text-065
          open_inplace   = c_x.

      CALL METHOD w_document->has_spreadsheet_interface
        IMPORTING
          is_available = w_available
          error        = w_error
          retcode      = w_retcode.

      CALL METHOD w_document->get_spreadsheet_interface
        IMPORTING
          sheet_interface = w_handle.


*"Fill Data in Excel
        CALL METHOD w_handle->insert_full
          EXPORTING
           n_vrt_keys        = 2
           n_hrz_keys        = 1
           n_att_cols        = 8
            sema              = t_sema[]
            hkey              = t_hkey[]
            vkey              = t_vkey[]
            online_text       = t_online[]
            data              = t_out
          EXCEPTIONS
            dim_mismatch_data = 1
            dim_mismatch_sema = 2
            dim_mismatch_vkey = 3
            error_in_hkey     = 4
            error_in_sema     = 5
            inv_data_range    = 6
            error_in_vkey     = 7.

        ENDIF.
ENDIF.
Read only

Former Member
0 Likes
619

Check out the following sample code


TYPES: BEGIN OF y_print.
        INCLUDE STRUCTURE gxxlt_p.
TYPES: END   OF y_print.

TYPES: BEGIN OF  y_hkey.
        INCLUDE STRUCTURE gxxlt_h.
TYPES: END   OF y_hkey .

TYPES: BEGIN OF y_vkey.
        INCLUDE STRUCTURE gxxlt_v.
TYPES: END   OF y_vkey .

TYPES: BEGIN OF y_online.
        INCLUDE STRUCTURE gxxlt_o.
TYPES: END   OF y_online.

TYPES: BEGIN OF y_sema.
        INCLUDE STRUCTURE gxxlt_s.
TYPES: END   OF y_sema.

TYPES: BEGIN OF y_out,
        vbeln TYPE vbak-vbeln,
        vkorg TYPE vbak-vkorg,
        vtweg TYPE vbak-vtweg,
        spart TYPE vbak-spart,
       END   OF y_out.

DATA:e_hkey              TYPE y_hkey,
       e_vkey              TYPE y_vkey,
       e_online            TYPE y_online,
       e_sema              TYPE y_sema.

DATA:
* Internal table for holding the horizontal key.
       t_hkey        TYPE TABLE OF y_hkey,
* Internal table for holding the vertical key.
       t_vkey        TYPE TABLE OF y_vkey,
* Internal table for holding the online text....
       t_online      TYPE TABLE OF y_online,
* Internal table to hold SEMA data..............
       t_sema        TYPE TABLE OF y_sema,
       t_out         TYPE TABLE OF y_out.

CONSTANTS:c_str           TYPE char3              VALUE 'STR',
          c_dft           TYPE char3              VALUE 'DFT',
           c_x             TYPE char1              VALUE 'X'    ,
           c_basis         TYPE char5              VALUE 'Basis',
           c_cc_excel      TYPE char10             VALUE 'W_CC_EXCEL',
           c_excel         TYPE char5              VALUE 'Excel',
           c_excel_sh      TYPE char12             VALUE 'Excel.Sheet'.


DATA:  w_inplace(1)        TYPE c,
       w_available         TYPE i,
       w_container         TYPE REF TO cl_gui_custom_container,
       w_error             TYPE REF TO i_oi_error,
       w_retcode           TYPE soi_ret_string,
       w_control           TYPE REF TO i_oi_container_control,
       w_document          TYPE REF TO i_oi_document_proxy,
       w_handle            TYPE REF TO i_oi_spreadsheet.

** Fill SEMA
FREE t_sema.
CLEAR e_sema.
MOVE: 1     TO e_sema-col_no,
      c_str TO e_sema-col_typ,
      c_dft TO e_sema-col_ops.
APPEND e_sema TO t_sema.
MOVE 2 TO e_sema-col_no.
APPEND e_sema TO t_sema.
MOVE 3 TO e_sema-col_no.
APPEND e_sema TO t_sema.
MOVE 4 TO e_sema-col_no.
APPEND e_sema TO t_sema.

** Fill VKey

FREE t_vkey.
CLEAR e_vkey.
MOVE: 1             TO e_vkey-col_no,
      'Sales Order'    TO e_vkey-col_name.
APPEND e_vkey TO t_vkey.

** Fill HKEY
FREE t_hkey.
CLEAR e_hkey.
MOVE: 1            TO e_hkey-row_no,
      1            TO e_hkey-col_no,
      'Sale Org'     TO e_hkey-col_name.
APPEND e_hkey TO t_hkey.
CLEAR e_hkey.
MOVE: 1                       TO e_hkey-row_no,
      2                       TO e_hkey-col_no,
      'Distribution Channel'  TO e_hkey-col_name.
APPEND e_hkey TO t_hkey.
CLEAR e_hkey.
MOVE: 1                       TO e_hkey-row_no,
      3                       TO e_hkey-col_no,
      'Division'  TO e_hkey-col_name.
APPEND e_hkey TO t_hkey.



SELECT vbeln
       vkorg
       vtweg
       spart
  FROM vbak
  INTO TABLE t_out
  UP TO 20 ROWS.

CALL SCREEN 9001.

*&---------------------------------------------------------------------*
*&      Module  M_DISPLAY_EXCEL  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE m_display_excel OUTPUT.

*"Create the instance CONTROL

  CALL METHOD c_oi_container_control_creator=>get_container_control
    IMPORTING
      control = w_control
      error   = w_error.

*"Create a container

  CLEAR w_container.

  CREATE OBJECT w_container
    EXPORTING
      container_name = c_cc_excel.

*"Create the object that manages the link to the OLE interface

  IF w_control IS NOT INITIAL.

    MOVE c_x TO w_inplace.

    CALL METHOD w_control->init_control
      EXPORTING
        r3_application_name      = c_basis
        inplace_enabled          = w_inplace
        inplace_scroll_documents = c_x
        parent                   = w_container
        register_on_close_event  = c_x
        register_on_custom_event = c_x
        no_flush                 = c_x
      IMPORTING
        error                    = w_error.


    CALL METHOD w_control->get_document_proxy
      EXPORTING
        document_type  = c_excel_sh
      IMPORTING
        document_proxy = w_document
        error          = w_error.


    IF w_document IS NOT INITIAL.

      CALL METHOD w_document->create_document
        EXPORTING
          document_title = text-065
          open_inplace   = c_x.

      CALL METHOD w_document->has_spreadsheet_interface
        IMPORTING
          is_available = w_available
          error        = w_error
          retcode      = w_retcode.

      CALL METHOD w_document->get_spreadsheet_interface
        IMPORTING
          sheet_interface = w_handle.


*"Fill Data in Excel
      CALL METHOD w_handle->insert_full
        EXPORTING
          n_vrt_keys        = 1
          n_hrz_keys        = 1
          n_att_cols        = 3
          sema              = t_sema[]
          hkey              = t_hkey[]
          vkey              = t_vkey[]
          online_text       = t_online[]
          data              = t_out
        EXCEPTIONS
          dim_mismatch_data = 1
          dim_mismatch_sema = 2
          dim_mismatch_vkey = 3
          error_in_hkey     = 4
          error_in_sema     = 5
          inv_data_range    = 6
          error_in_vkey     = 7.

    ENDIF.

  ENDIF.

ENDMODULE.                 " M_DISPLAY_EXCEL  OUTPUT