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: 

FM needed

Former Member
0 Kudos
76

Hi,

I want to open txt file for that is there any FM.

I want to pass path name then file should open.

regards,

vijay

1 ACCEPTED SOLUTION

Former Member
0 Kudos
55

Check this sample code:


REPORT ZV_F4 .
PARAMETERS: P_FILE TYPE EPSDIRNAM.
CALL FUNCTION 'WS_EXECUTE'
  EXPORTING
    DOCUMENT                 = 'X'
*      CD                       = ' '
*      COMMANDLINE              = ' '
*      INFORM                   = ' '
     PROGRAM                  = P_FILE
*      STAT                     = ' '
*      WINID                    = ' '
*      OSMAC_SCRIPT             = ' '
*      OSMAC_CREATOR            = ' '
*      WIN16_EXT                = ' '
*      EXEC_RC                  = ' '
*    IMPORTING
*      RBUFF                    =
  EXCEPTIONS
    FRONTEND_ERROR           = 1
    NO_BATCH                 = 2
    PROG_NOT_FOUND           = 3
    ILLEGAL_OPTION           = 4
    GUI_REFUSE_EXECUTE       = 5
    OTHERS                   = 6.

IF SY-SUBRC <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

If useful reward.

Vasanth

4 REPLIES 4

Former Member
0 Kudos
56

Check this sample code:


REPORT ZV_F4 .
PARAMETERS: P_FILE TYPE EPSDIRNAM.
CALL FUNCTION 'WS_EXECUTE'
  EXPORTING
    DOCUMENT                 = 'X'
*      CD                       = ' '
*      COMMANDLINE              = ' '
*      INFORM                   = ' '
     PROGRAM                  = P_FILE
*      STAT                     = ' '
*      WINID                    = ' '
*      OSMAC_SCRIPT             = ' '
*      OSMAC_CREATOR            = ' '
*      WIN16_EXT                = ' '
*      EXEC_RC                  = ' '
*    IMPORTING
*      RBUFF                    =
  EXCEPTIONS
    FRONTEND_ERROR           = 1
    NO_BATCH                 = 2
    PROG_NOT_FOUND           = 3
    ILLEGAL_OPTION           = 4
    GUI_REFUSE_EXECUTE       = 5
    OTHERS                   = 6.

IF SY-SUBRC <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

If useful reward.

Vasanth

Former Member
0 Kudos
55

Hi,

1.Try this.(This will open the file in Notepad, DIRECTLY)

2.Sample Code

REPORT ABC.

....

....

CALL FUNCTION 'GUI_EXEC'

EXPORTING

command = 'NOTEPAD'

PARAMETER = 'D:\ABCD.TXT'

  • IMPORTING

  • RETURNCODE =

.

Regards,

Padmam.

Former Member
0 Kudos
55

Hi Vijay,

here is the Fm 'F4_FILENAME'. this the function module for finding the path of the file. to upload use GUI_UPLOAD.

reward point

regards

reena

Former Member
0 Kudos
55

hi

Opening a File for Read Access

To open a file for reading, use the FOR INPUT addition to the OPEN DATASET statement.

Syntax

OPEN DATASET <dsn> FOR INPUT.

The file must already exist, otherwise, the system sets SY-SUBRC to 8, and ignores the statement.

If the file exists and is already open (for read or write access, or for appending), the position is reset to the beginning of the file. However, it is good programming style to close files that are already open before you reopen them for a different operation (for further information about closing files, refer to Closing a File).

DATA FNAME(60) VALUE 'myfile'.

OPEN DATASET FNAME FOR INPUT.

IF SY-SUBRC = 0.

WRITE / 'File opened'.

.....

ELSE.

WRITE / 'File not found'.

ENDIF.

This example opens the file "myfile" for reading.

-


To open a file for writing, use the FOR OUTPUT addition to the OPEN DATASET statement.

Syntax

OPEN DATASET <dsn> FOR OUTPUT.

If the file does not already exist, it is created automatically. If it does already exist, but is closed, its contents are overwritten. If the file exists and is already open (for read or write access, or for appending), the position is reset to the beginning of the file. If the system can open the file <dsn> successfully, SY-SUBRC is set to 0. If not, it is set to 8.

DATA: MESS(60),

FNAME(10) VALUE '/tmp'.

OPEN DATASET FNAME FOR OUTPUT MESSAGE MESS.

IF SY-SUBRC <> 0.

WRITE: 'SY-SUBRC:', SY-SUBRC,

/ 'System Message:', MESS.

ENDIF.

If the R/3 System is ruining under UNIX, the output looks like this:

The system cannot open the file, since the name you specified is that of a directory.

-


To open a file so that you can append data to the end of it, use the FOR APPENDING addition in the OPEN DATASET statement:

Syntax

OPEN DATASET <dsn> FOR APPENDING.

This statement opens a file to which you can append data. If the file does not already exist, it is created automatically. If it does exist, but is closed, the system opens it, and sets the position to the end of the file. If the file exists and is already open (for read or write access, or for appending), the position is set to the end of the file. SY-SUBRC is always 0.

It is good programming style to close files that are already open before you reopen them for a different operation (for further information about closing files, refer to Closing a File).

DATA FNAME(60) VALUE 'myfile'.

DATA NUM TYPE I.

OPEN DATASET FNAME FOR OUTPUT.

DO 5 TIMES.

NUM = NUM + 1.

TRANSFER NUM TO FNAME.

ENDDO.

OPEN DATASET FNAME FOR INPUT.

OPEN DATASET FNAME FOR APPENDING.

NUM = 0.

DO 5 TIMES.

NUM = NUM + 10.

TRANSFER NUM TO FNAME.

ENDDO.

OPEN DATASET FNAME FOR INPUT.

DO.

READ DATASET FNAME INTO NUM.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

WRITE / NUM.

ENDDO.

The output appears as follows:

1

2

3

4

5

10

20

30

40

50

thanks

Ashu