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

open file

madan_ullasa
Contributor
0 Likes
1,858

hi frnds,

im downloading some records into a text file. At the end of the abap process i want to open the text file automatically when i click on a push button.. is this possible??

points assured to all..

madan..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,794

Hi madan,

1. use like this.

(this will open the file in notepad, DIRECTLY)

2.

REPORT ABC.

CALL FUNCTION 'GUI_EXEC'

EXPORTING

command = 'NOTEPAD'

PARAMETER = 'D:\ABCD.TXT'

  • IMPORTING

  • RETURNCODE =

.

regards,

amit m.

17 REPLIES 17
Read only

hymavathi_oruganti
Active Contributor
0 Likes
1,794

yes,

u can write a logic at

AT USER-COMMAND.

CASE SY-UCOMM. or CASE SSCRFIELDS-UCOMM (If on selection screen)

WHEN ' '.

OPEN DATASET.(if in application server)

or else CALL FN 'WS_UPLOAD'.

Read only

0 Likes
1,794

aarrey i kno that buddy..

my requirement is like,

i have the file downloaded in the presentation server...

at the end of the abap process, i display a message like "Display Log file ?"..

if the user cliks 'yes', the the file which has been downloaded shud be opened in the note pad automatically... this means that the user will not go to the drive and open it himself...hope its clear to u..

madan....

Read only

0 Likes
1,794

Hi Madan,

It is very simple.

Pass your file name to the below method call.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE

EXPORTING

DOCUMENT = <file_name>

It is working fine for me.

Regards,

Abdul Hakim

Read only

0 Likes
1,794

Hi madan,

call this in the button click handle.

at user-command.

case sy-ucomm.
when 'DISP'.

          CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
            EXPORTING
              DOCUMENT               = 'C:test.txt'
               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.
           MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                      WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.

endcase.

Regards

vijay

Read only

0 Likes
1,794

HI, U CAN DO LIKE THIS.

CASE SY-UCOMM.

WHEN '......'.

CALL SCREEN 100.----


> DESIGN A MODAL DIALOG.

ENDCASE.

*******IN PAI OF SCREEN 100*********

CASE SY-UCOMM.

WHEN 'YES'.

CALL 'GUI_UPLOAD'.

ENDCASE

Read only

Former Member
0 Likes
1,795

Hi madan,

1. use like this.

(this will open the file in notepad, DIRECTLY)

2.

REPORT ABC.

CALL FUNCTION 'GUI_EXEC'

EXPORTING

command = 'NOTEPAD'

PARAMETER = 'D:\ABCD.TXT'

  • IMPORTING

  • RETURNCODE =

.

regards,

amit m.

Read only

0 Likes
1,794

hey amit,

im getting a msg that 'gui_exec' is obsolete.. dont use it.. any other func. module..

Read only

0 Likes
1,794

Hi,

Try this code.Push button is here in selection screen.

TYPE-POOLS: slis.

SELECTION-SCREEN BEGIN OF BLOCK b_2 WITH FRAME TITLE text-018.

SELECTION-SCREEN PUSHBUTTON /1(24) name USER-COMMAND flds.

SELECTION-SCREEN END OF BLOCK b_2.

AT SELECTION-SCREEN.

IF sy-ucomm = 'FLDS'.

CALL FUNCTION 'GUI_EXEC'

EXPORTING

command = 'NOTEPAD'

PARAMETER = 'D:\ABAP\Miscilaneous\ABAP to XML.Txt'.

ENDIF.

Read only

0 Likes
1,794

Hi again,

1. do not worry, still u can use it.

2. If we can find other FM / class,

we can also do that.

3. For the time being, u can use it , no problem.

regards,

amit m.

Read only

0 Likes
1,794

Hi Madan,

Use my method call which i have mentioned above..

Regards,

Abdul

Read only

0 Likes
1,794

Hi Madan,

Check FM GUI_RUN

Thanks

Lakshman

Read only

abdul_hakim
Active Contributor
0 Likes
1,794

Use FILE_OPEN function module..

Abdul Hakim

Read only

Former Member
0 Likes
1,794

hi madan,

do you want the contents to be dispalyed when a button is pressed..

regards

satesh

Read only

Former Member
0 Likes
1,794

hi,

you can do it with OLE,but in terms of excel..

need to place the below code in the button handling...

REPORT ztest_excel.
data: begin of itab occurs 0,
      vbeln like vbak-vbeln,
      posnr like vbap-posnr,
      end of itab.
select vbeln
       posnr
       from vbap
       up to 20 rows
       into table itab.

* EXCEL sheet using OLE automation.
INCLUDE OLE2INCL.
* handles for OLE objects
DATA: H_EXCEL TYPE OLE2_OBJECT,        " Excel object
      H_WORK  TYPE OLE2_OBJECT,
      H_SHEET TYPE OLE2_OBJECT,
      H_CELL  TYPE OLE2_OBJECT,
      V_COL   LIKE SY-TABIX.     " column number of the cell
DATA:
  V_STEP(30),
  V_FILE LIKE RLGRAP-FILENAME.


* tell user what is going on
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
     EXPORTING
*           PERCENTAGE = 0
           TEXT       = 'Creating Excel...'
       EXCEPTIONS
            OTHERS     = 1.
* start Excel
  V_STEP = 'Starting Excel'.
  CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
  PERFORM ERR_HDL.

  SET PROPERTY OF H_EXCEL  'Visible' = 1.

*  CALL METHOD OF H_EXCEL 'OPEN' EXPORTING  #1 = 'C:DMC_REC.XLS'.

*  PERFORM ERR_HDL.
* tell user what is going on
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
     EXPORTING
*           PERCENTAGE = 0
           TEXT       = 'Adding Data to Excel...'
       EXCEPTIONS
            OTHERS     = 1.
* Get the list of workbooks
  V_STEP = 'Preaparing Excel'.
  CALL METHOD OF H_EXCEL 'WORKBOOKS' = H_WORK.
  PERFORM ERR_HDL.

** Add new workbook (create a file)
  CALL METHOD OF H_WORK 'ADD'.
  PERFORM ERR_HDL.
* Get the created worksheet
  CALL METHOD OF H_EXCEL 'WORKSHEETS' = H_SHEET EXPORTING #1 = 1.
  PERFORM ERR_HDL.
* Activate (select) the first sheet
  CALL METHOD OF H_SHEET 'ACTIVATE'.
  PERFORM ERR_HDL.


* tell user what is going on
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
     EXPORTING
*           PERCENTAGE = 0
           TEXT       = 'Adding Data to Excel...'
       EXCEPTIONS
            OTHERS     = 1.
* output column headings to active Excel sheet
  V_STEP = 'Adding data to Excel'.
  LOOP AT ITAB.
    V_COL = SY-TABIX.
    PERFORM FILL_CELL USING 1 V_COL ITAB-vbeln.
    PERFORM FILL_CELL USING 2 V_COL ITAB-posnr.
  ENDLOOP.
  V_STEP = 'Releasing Excel'.
  FREE OBJECT H_EXCEL.
  PERFORM ERR_HDL.
  H_EXCEL-HANDLE = -1.

*&---------------------------------------------------------------------*
*&      Form  ERR_HDL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*----------------------------------------------------------------------*
FORM ERR_HDL.

  IF SY-SUBRC <> 0.
    WRITE: / 'Error in processing Excel File:', V_STEP.
    STOP.
  ENDIF.

ENDFORM.                    " ERR_HDL
*&---------------------------------------------------------------------*
*&      Form  FILL_CELL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_1      text
*      -->P_1      text
*      -->P_1      text
*----------------------------------------------------------------------*
FORM FILL_CELL USING  ROW COL VAL.
  CALL METHOD OF H_EXCEL 'Cells' = H_CELL
                 EXPORTING #1 = ROW #2 = COL.
  PERFORM ERR_HDL.
  SET PROPERTY OF H_CELL 'Value' = VAL .
  PERFORM ERR_HDL.
ENDFORM.                    " FILL_CELL

Regards

Vijay

Read only

Former Member
0 Likes
1,794

hi

TRY FM 'GUI_EXEC'.

I believe u will be able to open notepad and u can pass the file.

Read only

Former Member
0 Likes
1,794

Hi madan,

this works fine, did you check it...

at user-command.

case sy-ucomm.
when 'DISP'.

          CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
            EXPORTING
              DOCUMENT               = 'C:test.txt'
               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.
           MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                      WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.

endcase.

Read only

Former Member
0 Likes
1,794

Hi Madan,

After the user clicks yes on the pop-up

Call FM GUI_RUN

In the Command(exporting parameter) just give the path of the downloaded file.

Example :

CALL FUNCTION 'GUI_RUN'

EXPORTING

command = 'C:\empdtls.txt'

Regards,

Sriranjani