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: 

code for reading particular fields from the file placed in application

Former Member
0 Kudos
258

hi,

code for reading particular fields from the file placed in application server in to the internal table.

3 REPLIES 3

Former Member
0 Kudos
110

Hi,

Use the GUI_UPLOAD FM to upload the File into ur Internal Table.

DATA : FILE_TABLE TYPE FILE_TABLE OCCURS 0,

fwa TYPE FILE_TABLE,

FILENAME TYPE STRING,

RC TYPE I.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

EXPORTING

WINDOW_TITLE = 'Open File'

  • DEFAULT_EXTENSION =

  • DEFAULT_FILENAME =

  • FILE_FILTER =

  • INITIAL_DIRECTORY =

  • MULTISELECTION =

  • WITH_ENCODING =

CHANGING

FILE_TABLE = FILE_TABLE

RC = RC

  • USER_ACTION =

  • FILE_ENCODING =

EXCEPTIONS

FILE_OPEN_DIALOG_FAILED = 1

CNTL_ERROR = 2

ERROR_NO_GUI = 3

NOT_SUPPORTED_BY_GUI = 4

others = 5

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

READ TABLE FILE_TABLE INDEX 1 into fwa.

FILENAME = fwa-FILENAME.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = filename

FILETYPE = 'DAT'

  • IMPORTING

  • FILELENGTH =

TABLES

data_tab = itab

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 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.

Regards,

Balakumar.G

Reward Points if helpful.

Former Member
0 Kudos
110

HI,

Use this code

data : filename(250) type c value '/usr/sap/tmp/ASHOKTEST11.TXT'.
start-of-selection.
open dataset filename for input in text mode encoding default.
do.
if sy-subrc <> 0.
exit.
endif.
read dataset filename into itab.
append itab.
enddo.
loop at itab.
write: itab-lifnr.
endloop.

close dataset filename.

Regards,

S.Nehru.

Former Member
0 Kudos
110

Hi Bharath,

files in application server are called DATASETs.

for reading/writing data into a dataset we can use

OPEN DATASET file

FOR INPUT

IN BINARY MODE.

DO.

READ DATASET file

INTO <itab> with key itab-fieldname='fld val'

ENDDO.

CLOSE DATASET file.

reward if helpfull.

Regards

Lakshman