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

to read data from excel layout

Former Member
0 Likes
1,055

Hi friends..

is there any functional module to read the data from grid output which is excel layout ?

note..

i want to read data from excel ?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
995

See the following ex:

REPORT ZFI_EXCEL .

*Read the data from the locally held spreadsheet

*Once read using this FM, the data will be held like:-

*ROW |COL |VALUE

*---|-|---

*0001 |0001 |2

*0001 |0002 |00000000001

*0001 |0003 |1

*0001 |0004 |

*0001 |0005 |2

*0001 |00010|SHORT TEXT for a/c

*0001 |00011|LONG TEXT a/c 0000000001

*.

*.

*0002 |0001 |2

*0002 |0002 |00000000002

*0002 |0003 |1

*0002 |0004 |

*0002 |0005 |2

*0002 |00010|SHORT TEXT for a/c

*0001 |00011|LONG TEXT a/c 0000000002

*

*etc........

data: begin of excel_tab occurs 0.

include structure alsmex_tabline.

data: end of excel_tab .

data: begin of itab occurs 0,

bldat like bkpf-bldat,

blart like bkpf-blart,

bukrs like bkpf-bukrs,

budat like bkpf-budat,

waers like bkpf-waers,

bschl like bseg-bschl,

hkont like bseg-hkont,

sgtxt like bseg-sgtxt,

end of itab.

data: process_tab_struct_tmp like itab.

field-symbols: <fs1>.

selection-screen: begin of block blk.

parameters: fname type rlgrap-filename.

selection-screen: end of block blk.

at selection-screen on value-request for fname.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = 'ZFI_EXCEL'

DYNPRO_NUMBER = '1000'

FIELD_NAME = 'FNAME'

IMPORTING

FILE_NAME = FNAME.

START-OF-SELECTION.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = FNAME

i_begin_col = 1

i_begin_row = 1

i_end_col = 24

i_end_row = 60000

tables

intern = EXCEL_TAB

LOOP AT EXCEL_TAB.

assign component excel_tab-col of structure

process_tab_struct_tmp to <fs1>.

<fs1> = excel_tab-value.

at end of row.

move-corresponding: process_tab_struct_tmp to itab. “Move values to itab

append itab.

endat.

ENDLOOP.

LOOP AT ITAB.

WRITE:/2 ITAB-BLDAT,14(8) ITAB-BLART,20(10) ITAB-BUDAT.

ENDLOOP.

regards,

rewards point.

Hi friends..

is there any functional module to read the data from grid output which is excel layout ?

note..

i want to read data from excel ?

7 REPLIES 7
Read only

Former Member
0 Likes
995

use fm ALSM_EXCEL_TO_INTERNAL_TABLE.

regards

rewards point

Read only

Former Member
0 Likes
996

See the following ex:

REPORT ZFI_EXCEL .

*Read the data from the locally held spreadsheet

*Once read using this FM, the data will be held like:-

*ROW |COL |VALUE

*---|-|---

*0001 |0001 |2

*0001 |0002 |00000000001

*0001 |0003 |1

*0001 |0004 |

*0001 |0005 |2

*0001 |00010|SHORT TEXT for a/c

*0001 |00011|LONG TEXT a/c 0000000001

*.

*.

*0002 |0001 |2

*0002 |0002 |00000000002

*0002 |0003 |1

*0002 |0004 |

*0002 |0005 |2

*0002 |00010|SHORT TEXT for a/c

*0001 |00011|LONG TEXT a/c 0000000002

*

*etc........

data: begin of excel_tab occurs 0.

include structure alsmex_tabline.

data: end of excel_tab .

data: begin of itab occurs 0,

bldat like bkpf-bldat,

blart like bkpf-blart,

bukrs like bkpf-bukrs,

budat like bkpf-budat,

waers like bkpf-waers,

bschl like bseg-bschl,

hkont like bseg-hkont,

sgtxt like bseg-sgtxt,

end of itab.

data: process_tab_struct_tmp like itab.

field-symbols: <fs1>.

selection-screen: begin of block blk.

parameters: fname type rlgrap-filename.

selection-screen: end of block blk.

at selection-screen on value-request for fname.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = 'ZFI_EXCEL'

DYNPRO_NUMBER = '1000'

FIELD_NAME = 'FNAME'

IMPORTING

FILE_NAME = FNAME.

START-OF-SELECTION.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = FNAME

i_begin_col = 1

i_begin_row = 1

i_end_col = 24

i_end_row = 60000

tables

intern = EXCEL_TAB

LOOP AT EXCEL_TAB.

assign component excel_tab-col of structure

process_tab_struct_tmp to <fs1>.

<fs1> = excel_tab-value.

at end of row.

move-corresponding: process_tab_struct_tmp to itab. “Move values to itab

append itab.

endat.

ENDLOOP.

LOOP AT ITAB.

WRITE:/2 ITAB-BLDAT,14(8) ITAB-BLART,20(10) ITAB-BUDAT.

ENDLOOP.

regards,

rewards point.

Read only

0 Likes
995

hi abay..

thanks 4 ur effort on my queries..

my problem is

at runtime i change the layout from abap grid to excel layout.

in excel layout i edit data for some calculation.

now i want to move the edited data in excel to internal table. for that i want to save the data from excel to internal table at run time..

for that what to do ? can you please

Read only

0 Likes
995

hi abay..

thanks 4 ur effort on my queries..

my problem is

at runtime i change the layout from abap grid to excel layout.

in excel layout i edit data for some calculation.

now i want to move the edited data in excel to internal table. for that i want to save the data from excel to internal table at run time..

for that what to do ? can you please

Read only

Former Member
0 Likes
995

U can also this one:-

Use the FM ALSM_EXCEL_TO_INTERNAL_TABLE this will read your exel file and convert it into an internal table , you then need to map this to your internal tablw which you will use to modify the database table.

regards,

rewards point.

Read only

Former Member
0 Likes
995

Hi

if you want to upload the data from EXCEL sheet to internal table then use this function module

ALSM_EXCEL_TO_INTERNAL_TABLE

reward if usefull

Read only

Former Member
0 Likes
995

here check this program i am spliting the record depend upon ',' and dont use ws_upload etc fm's are obsolete....

data: begin of itab_string occurs 0,

record type char255,

end of itab_string.

data: L_FILETABLE TYPE FILETABLE,

L_FILETAB_H TYPE FILETABLE WITH HEADER LINE.

data: p_file1 type string.

  • selection screen .

PARAMETERS: P_FILE TYPE LOCALFILE.

initialization.

at selection-screen on value-request for P_FILE.

  • IF THE USER SELECT EXTENTION BUTTON IT WILL OPEN THE LOCAL DIRECTORY FOR SELECTING THE FILE LOCATION.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

  • EXPORTING

  • WINDOW_TITLE =

  • DEFAULT_EXTENSION = 'CSV'

  • DEFAULT_FILENAME = 'C:\Documents and Settings\196093\Desktop\STATUS.csv'

  • FILE_FILTER =

  • INITIAL_DIRECTORY = 'C:\Documents and Settings\196093\Desktop\'

  • MULTISELECTION =

  • WITH_ENCODING =

CHANGING

FILE_TABLE = L_FILETABLE

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.

ELSE.

LOOP AT l_filetable INTO L_FILETAB_H.

P_FILE = L_FILETAB_H-FILENAME.

move p_file to p_file1.

EXIT.

ENDLOOP.

ENDIF.

  • passing the selected file name to gui_upload for loading the data

  • into internal table

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = p_file1

  • FILETYPE = 'ASC'

  • HAS_FIELD_SEPARATOR = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = itab_string

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF SY-SUBRC <> 0.

MESSAGE I000(Z00) WITH 'PLEASE PROVIDE CORRECT FILE NAME'.

ENDIF.

loop at itab_string.

  • now split the statuses

split itab_string at ',' into itab_status-aufnr itab_status-asttx itab_status-asttx1.

  • and move one internal table

append itab_status.

clear itab_status.

endloop.

Reward if it is helpful,

kiran.M