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: 

MS_EXCEL_OLE_STANDARD_DAT field names

Former Member
0 Kudos

Hi all,

I'm confused about the fieldnames parameter of the above mentioned function call. I want to create a tabel of field names to pass in. Say...MATERIAL...PLANT...TEXT. i figured I could just do the following:

TYPES: BEGIN OF t_fieldNames,

fieldName TYPE C,

END OF t_fieldNames.

DATA: it_fieldNames TYPE STANDARD TABLE OF t_fieldNames INITIAL SIZE 0.

DATA: wa_fieldNames TYPE t_fieldNames.

wa_fieldNames-fieldName = 'Plant'.

APPEND wa_fieldNames TO it_fieldNames.

wa_fieldNames-fieldName = 'Material'.

APPEND wa_fieldNames TO it_fieldNames.

...and pass it_fieldNames in. But, I get the following error on execution:

The current statement is defined for character-type data objects only.

Following is the call:

CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'

EXPORTING

FILE_NAME = 'c:\TEMP\NO_EST_REPORT'

TABLES

DATA_TAB = gt_mkal_y

FIELDNAMES = it_fieldNames

EXCEPTIONS

FILE_NOT_EXIST = 1

FILENAME_EXPECTED = 2

COMMUNICATION_ERROR = 3

OLE_OBJECT_METHOD_ERROR = 4

OLE_OBJECT_PROPERTY_ERROR = 5

INVALID_PIVOT_FIELDS = 6

DOWNLOAD_PROBLEM = 7

OTHERS = 8.

any ideas?

regards,

Mat

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I'm not seeing the same error, but I'm sure that the definition of your field table is not helping.

Make it like 20 in length.

types: begin of t_fieldnames,
        fieldname<b>(20)</b> type c,
       end of t_fieldnames.

Regards,

Rich Heilman

5 REPLIES 5

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I'm not seeing the same error, but I'm sure that the definition of your field table is not helping.

Make it like 20 in length.

types: begin of t_fieldnames,
        fieldname<b>(20)</b> type c,
       end of t_fieldnames.

Regards,

Rich Heilman

Former Member
0 Kudos

Mathew,

What if you comment out the fieldnames... does it still error out?

If so, what is in interncal table "gt_mkal_y"? Are there any HEX or other "odd" data types in there?

0 Kudos

I can comment out the field names and the file is created.

laxmanakumar_appana
Active Contributor
0 Kudos

Hi,

check this working code :

TABLES: USR03,DD02L.
 
DATA: ZX030L LIKE X030L.
 
DATA BEGIN OF ZDFIES OCCURS 0.
     INCLUDE STRUCTURE DFIES.
DATA END OF ZDFIES.
 
DATA: BEGIN OF FLDITAB OCCURS 0,
      FLDNAME(11) TYPE C,
      END OF FLDITAB.
 
DATA ITABUSR03 LIKE USR03 OCCURS 0 WITH HEADER LINE.
 
DATA TNAME LIKE DD02L-TABNAME.
 
SELECT * FROM USR03 INTO TABLE ITABUSR03.
 
TNAME = 'USR03'.
 
PERFORM GETFIELEDS.
PERFORM SHOW123.
********************************************
FORM GETFIELEDS.
     CALL FUNCTION 'GET_FIELDTAB'
      EXPORTING
          LANGU              = SY-LANGU
          ONLY               = SPACE
          TABNAME            = TNAME
          WITHTEXT           = 'X'
      IMPORTING
          HEADER             = ZX030L
      TABLES
          FIELDTAB           = ZDFIES
      EXCEPTIONS
          INTERNAL_ERROR      = 01
          NO_TEXTS_FOUND      = 02
          TABLE_HAS_NO_FIELDS = 03
          TABLE_NOT_ACTIV     = 04.
 
     CASE SY-SUBRC.
        WHEN 0.
          LOOP AT ZDFIES.
               FLDITAB-FLDNAME = ZDFIES-FIELDNAME.
               APPEND FLDITAB.
          ENDLOOP.
        WHEN OTHERS.
             MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              with  SY-SUBRC.
      ENDCASE.
 
ENDFORM.
***********************************
FORM SHOW123.
 
CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
     EXPORTING
          FILE_NAME                 = 'C:USR03.XLS'
          DATA_SHEET_NAME           = 'USER LIST'
    TABLES
         DATA_TAB                  =  ITABUSR03
         FIELDNAMES                =  FLDITAB
 
    EXCEPTIONS
         FILE_NOT_EXIST            = 1
         FILENAME_EXPECTED         = 2
         COMMUNICATION_ERROR       = 3
         OLE_OBJECT_METHOD_ERROR   = 4
         OLE_OBJECT_PROPERTY_ERROR = 5
         INVALID_FILENAME          = 6
         INVALID_PIVOT_FIELDS      = 7
         DOWNLOAD_PROBLEM          = 8
         OTHERS                    = 9.
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
 
 
ENDFORM.

Regards

Appana

Former Member
0 Kudos

If you want to download into an excel sheet you can also use the function module XXL_FULL_API.

<b>Sample code:</b>

REPORT Excel.
TABLES: sflight.
*	header data................................
DATA :
header1 LIKE gxxlt_p-text VALUE 'Raj',
header2 LIKE gxxlt_p-text VALUE 'Excel sheet'.

*	Internal table for holding the SFLIGHT data DATA BEGIN OF t_sflight OCCURS 0.
INCLUDE STRUCTURE sflight.
DATA END   OF t_sflight.
*	Internal table for holding the horizontal key.
DATA BEGIN OF  t_hkey OCCURS 0.
INCLUDE STRUCTURE gxxlt_h.
DATA END   OF t_hkey .
*	Internal table for holding the vertical key.
DATA BEGIN OF t_vkey OCCURS 0.
INCLUDE STRUCTURE gxxlt_v.
DATA END   OF t_vkey .
*	Internal table for holding the online text....
DATA BEGIN OF t_online OCCURS 0.
INCLUDE STRUCTURE gxxlt_o.
DATA END   OF t_online.
*	Internal table to hold print text.............
DATA BEGIN OF t_print OCCURS 0.
INCLUDE STRUCTURE gxxlt_p.
DATA END   OF t_print.
*	Internal table to hold SEMA data..............
DATA BEGIN OF t_sema OCCURS 0.
INCLUDE STRUCTURE gxxlt_s.
DATA END   OF t_sema.
*	Retreiving data from sflight.
SELECT * FROM sflight
INTO TABLE t_sflight.
*	Text which will be displayed online is declared here....
t_online-line_no    = '1'.
t_online-info_name  = 'Created by'.
t_online-info_value = 'Sid'.
APPEND t_online.

*	Text which will be printed out..........................
t_print-hf     = 'H'.
t_print-lcr    = 'L'.
t_print-line_no = '1'.
t_print-text   = 'This is the header'.
APPEND t_print.

t_print-hf     = 'F'.
t_print-lcr    = 'C'.
t_print-line_no = '1'.
t_print-text   = 'This is the footer'.
APPEND t_print.

*	Defining the vertical key columns.......
t_vkey-col_no   = '1'.
t_vkey-col_name = 'MANDT'.
APPEND t_vkey.

t_vkey-col_no   = '2'.
t_vkey-col_name = 'CARRID'.
APPEND t_vkey.

t_vkey-col_no   = '3'.
t_vkey-col_name = 'CONNID'.
APPEND t_vkey.

t_vkey-col_no   = '4'.
t_vkey-col_name = 'FLDATE'.
APPEND t_vkey.

*	Header text for the data columns................

t_hkey-row_no = '1'.
t_hkey-col_no = 1.
t_hkey-col_name = 'PRICE'.
APPEND t_hkey.

t_hkey-col_no = 2.
t_hkey-col_name = 'CURRENCY'.
APPEND t_hkey.

t_hkey-col_no = 3.
t_hkey-col_name = 'PLANETYPE'.
APPEND t_hkey.

t_hkey-col_no = 4.
t_hkey-col_name = 'SEATSMAX'.
APPEND t_hkey.

t_hkey-col_no = 5.
t_hkey-col_name = 'SEATSOCC'.
APPEND t_hkey.

t_hkey-col_no = 6.
t_hkey-col_name = 'PAYMENTSUM'.
APPEND t_hkey.

*	populating the SEMA data.......................... 
t_sema-col_no  = 1.
t_sema-col_typ = 'STR'. 
t_sema-col_ops = 'DFT'. 
APPEND t_sema.
t_sema-col_no = 2.
APPEND t_sema.

t_sema-col_no = 3.
APPEND t_sema.

t_sema-col_no = 4.
APPEND t_sema.

t_sema-col_no = 5.
APPEND t_sema.

t_sema-col_no = 6.
APPEND t_sema.

t_sema-col_no = 7.
APPEND t_sema.

t_sema-col_no = 8.
APPEND t_sema.

t_sema-col_no = 9.
APPEND t_sema.

t_sema-col_no = 10.
t_sema-col_typ = 'NUM'.
t_sema-col_ops = 'ADD'.
APPEND t_sema.

CALL FUNCTION 'XXL_FULL_API'
EXPORTING
*	DATA_ENDING_AT          = 54
*	DATA_STARTING_AT        = 5
   filename                = 'TESTFILE'
   header_1                = header1
   header_2                = header2
   no_dialog               = 'X'
   no_start                = ' '
    n_att_cols              = 6
    n_hrz_keys              = 1
    n_vrt_keys              = 4
   sema_type               = 'X'
*	SO_TITLE                = ' '
TABLES
    data                    = t_sflight
    hkey                    = t_hkey
    online_text             = t_online
    print_text              = t_print
    sema                    = t_sema
    vkey                    = t_vkey
EXCEPTIONS
   cancelled_by_user       = 1
   data_too_big            = 2
   dim_mismatch_data       = 3
   dim_mismatch_sema       = 4
   dim_mismatch_vkey       = 5
   error_in_hkey           = 6
   error_in_sema           = 7
   file_open_error         = 8
   file_write_error        = 9
   inv_data_range          = 10
   inv_winsys              = 11
   inv_xxl                 = 12
   OTHERS                  = 13
          .
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.