Skip to Content
0
Former Member
Mar 24, 2008 at 08:36 PM

Uploding the Records into ztable from excel sheet

21 Views

Hi Friends,

i wrote a program tp upload the records from excel sheet into ztable..

probelm is :

Record aleardy in ztbale :

vendor num Document land1 Name1

(key field) (key field) (key field)

100 abc us MMMM

Record Excel Sheet :

100 abc us SSSS

Note : vendor num Document land1 are KEY FEILDS IN ZTABLE.

we do not CHANGE the ztable RECORD..but Excel sheet

Records should be uplod into the Ztable...

pls tell me the LOGIC FRO MY BELOW CODE.

.code :

DATA: it_excel LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.

TYPES: BEGIN OF t_record,

field1 LIKE it_excel-value,

field2 LIKE it_excel-value,

field3 LIKE it_excel-value,

field4 LIKE it_excel-value,

field5 LIKE it_excel-value,

field6 LIKE it_excel-value,

field7 LIKE it_excel-value,

END OF t_record.

DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,

wa_record TYPE t_record.

DATA: gd_currentrow TYPE i.

DATA: it_datatab TYPE TABLE OF ZTEST WITH HEADER LINE.

************************************************************************

  • S E L E C T I O N - S C R E E N

************************************************************************

PARAMETERS: p_file TYPE rlgrap-filename.

************************************************************************

  • AT S E L E C T I O N - S C R E E N ON VALUE REQUEST

************************************************************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

field_name = 'P_FILE'

IMPORTING

file_name = p_file.

************************************************************************

  • START-OF-SELECTION

************************************************************************

START-OF-SELECTION.

PERFORM it_data.

&----


*& Form it_data

&----


FORM it_data.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_file

i_begin_col = '1'

i_begin_row = '1'

i_end_col = '256'

i_end_row = '65536'

TABLES

intern = it_excel

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

IF sy-subrc NE 0.

MESSAGE e010(zz) WITH text-001. "Problem uploading Excel Spreadsheet

ENDIF.

SORT it_excel BY row col.

READ TABLE it_excel INDEX 1.

*

*

gd_currentrow = it_excel-row.

LOOP AT it_excel.

IF it_excel-row NE gd_currentrow.

it_datatab-mandt = wa_record-field1.

it_datatab-LIFNR = wa_record-field2.

it_datatab-land1 = wa_record-field3.

it_datatab-blart = wa_record-field4.

it_datatab-name1 = wa_record-field5.

APPEND it_datatab.

CLEAR wa_record.

gd_currentrow = it_excel-row.

ENDIF.

CASE it_excel-col.

WHEN '0001'.

wa_record-field1 = it_excel-value.

WHEN '0002'.

wa_record-field2 = it_excel-value.

WHEN '0003'.

wa_record-field3 = it_excel-value.

WHEN '0004'.

wa_record-field4 = it_excel-value.

WHEN '0005'.

wa_record-field5 = it_excel-value.

ENDCASE.

ENDLOOP.

it_datatab-mandt = wa_record-field1.

it_datatab-LIFNR = wa_record-field2.

it_datatab-land1 = wa_record-field3.

it_datatab-blart = wa_record-field4.

it_datatab-name1 = wa_record-field5.

APPEND it_datatab.

CLEAR wa_record.

MODIFY ZTEST FROM TABLE it_datatab.

if sy-subrc = 0.

Write: 'Updation has been Completed Sucessfully'.

else.

write:/ 'Updation failed'.

endif.

Regrads,

Venu.