cancel
Showing results for 
Search instead for 
Did you mean: 

Excel display on user command in a report

Former Member
0 Kudos

hi fiends.

following is my code for putting Internal table data to Excel file...it is doing well..

but now i want to display that excel file from same list by pressing Entr Key ...Plz Help..

tables : mseg.

Data : begin of itab occurs 0,

matnr like mseg-matnr,

menge like mseg-menge,

end of itab.

parameters : docno like mseg-mblnr.

set pf-status 'MENU'.

select * into corresponding fields of table itab from mseg

where mblnr = docno.

write : 'Material Quantity' , / .

loop at itab.

write : / itab-matnr, itab-menge .

endloop.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'D:\abc.xls'

FILETYPE = 'ASC'

WRITE_FIELD_SEPARATOR = 'X'

tables

data_tab = itab

.

Accepted Solutions (1)

Accepted Solutions (1)

former_member188685
Active Contributor
0 Kudos

Hi,

This is the code , Just check it.

and set the Pf-status menu, and set the FCODE for enter

REPORT  ZTEST_EXCEL                             .

TABLES : MSEG.
DATA : BEGIN OF ITAB OCCURS 0,
MATNR LIKE MSEG-MATNR,
MENGE LIKE MSEG-MENGE,
END OF ITAB.

PARAMETERS : DOCNO LIKE MSEG-MBLNR.
START-OF-SELECTION.
SET PF-STATUS 'MENU'. "now set the pf-status for ENTER (Green Tick as <b>ENTER</b> in the Function keys)

SELECT * INTO CORRESPONDING FIELDS OF TABLE ITAB FROM MSEG
WHERE MBLNR = DOCNO.

WRITE : 'Material Quantity' , / .
LOOP AT ITAB.
  WRITE : / ITAB-MATNR, ITAB-MENGE .
ENDLOOP.


CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    FILENAME              = 'D:abc.xls'
    FILETYPE              = 'ASC'
    WRITE_FIELD_SEPARATOR = 'X'
  TABLES
    DATA_TAB              = ITAB.


AT USER-COMMAND.
  CASE SY-UCOMM.
    WHEN 'ENTER'.

      CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
        EXPORTING
          DOCUMENT               = 'D:abc.xls'
          OPERATION              = 'OPEN'
        EXCEPTIONS
          CNTL_ERROR             = 1
          ERROR_NO_GUI           = 2
          BAD_PARAMETER          = 3
          FILE_NOT_FOUND         = 4
          PATH_NOT_FOUND         = 5
          FILE_EXTENSION_UNKNOWN = 6
          ERROR_EXECUTE_FAILED   = 7
          SYNCHRONOUS_FAILED     = 8
          NOT_SUPPORTED_BY_GUI   = 9
          OTHERS                 = 10.
      IF SY-SUBRC <> 0.

      ENDIF.


  ENDCASE.

Regards

vijay

Answers (4)

Answers (4)

Former Member
0 Kudos

thanks vijay sir..

what i was missing is AT User-Command Event..

job done thanks...

Former Member
0 Kudos

Hi,

try this

tables : mseg.

Data : begin of itab occurs 0,

matnr like mseg-matnr,

menge like mseg-menge,

end of itab.

parameters : docno like mseg-mblnr.

set pf-status 'MENU'.

at selection-screen.

select * into corresponding fields of table itab from mseg

where mblnr = docno.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'D:\assign\abc.xls'

FILETYPE = 'ASC'

WRITE_FIELD_SEPARATOR = 'X'

tables

data_tab = itab

.

CALL METHOD cl_gui_frontend_services=>execute

EXPORTING

document = 'd:\assign\abc.xls'

OPERATION = 'OPEN'

EXCEPTIONS

cntl_error = 1

error_no_gui = 2

bad_parameter = 3

file_not_found = 4

path_not_found = 5

file_extension_unknown = 6

error_execute_failed = 7

synchronous_failed = 8

not_supported_by_gui = 9

OTHERS = 10 .

IF sy-subrc <> 0.

endif.

start-of-selection.

write : 'Material Quantity' , / .

loop at itab.

write : / itab-matnr, itab-menge .

regards

austin

Message was edited by: Joseph Austin Prabhu Paulthas

Former Member
0 Kudos

HI madan,

1. i have made an independent form

to open any specified xls file

(using ole technology)

2. just copy paste in new program

REPORT abc.

*----


Important

TYPE-POOLS ole2.

DATA workbook TYPE ole2_object.

DATA excel TYPE ole2_object.

DATA aw TYPE ole2_object. "-- active workbook

*----


PERFORM startexcel USING 'd:\abc.xls'.

*----


  • INDEPENDENT FORM

*----


FORM startexcel USING filename.

CREATE OBJECT excel 'Excel.Application' .

SET PROPERTY OF excel 'Visible' = 1.

CALL METHOD OF excel 'Workbooks' = workbook.

CALL METHOD OF workbook 'Open'

EXPORTING

#1 = filename.

CALL METHOD OF excel 'ActiveWorkbook' = aw.

ENDFORM. "startexcel

regards,

amit m.

former_member188685
Active Contributor
0 Kudos

hi,

WHEN YOU PRESS enter , handle the sy-ucomm,

case sy-ucomm.

when 'ENTER'.

      CALL METHOD cl_gui_frontend_services=>execute
        EXPORTING
          document               = 'C:Test.xls'
          OPERATION              = 'OPEN'
        EXCEPTIONS
          cntl_error             = 1
          error_no_gui           = 2
          bad_parameter          = 3
          file_not_found         = 4
          path_not_found         = 5
          file_extension_unknown = 6
          error_execute_failed   = 7
          synchronous_failed     = 8
          not_supported_by_gui   = 9
          OTHERS                 = 10
              .
      IF sy-subrc <> 0.

      endif.

endcase.

or else you can try with GUI_EXEC FM

Regards

vijay