Skip to Content
0
Former Member
Sep 20, 2006 at 01:34 PM

Ex cel to Internal Table

41 Views

hello friends i have written this piece of code, it dose not have any error but when ececuted it gives a dump.

tables : zash.

DATA : BEGIN OF it_table OCCURS 0,

vbeln LIKE zash-vbeln,

posnr LIKE zash-posnr,

uepos LIKE zash-uepos,

netwr LIKE zash-netwr,

matnr LIKE zash-matnr,

END OF it_table.

TYPE-POOLS: slis.

FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,

<dyn_wa>,

<dyn_field>.

DATA: it_fldcat TYPE lvc_t_fcat,

wa_it_fldcat TYPE lvc_s_fcat.

TYPE-POOLS : abap.

DATA: new_table TYPE REF TO data,

new_line TYPE REF TO data.

DATA: xcel TYPE TABLE OF alsmex_tabline WITH HEADER LINE.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text .

PARAMETERS: p_file TYPE rlgrap-filename DEFAULT

'C:\Test.csv'.

PARAMETERS: p_flds TYPE i.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

  • Add X number of fields to the dynamic itab cataelog

DO p_flds TIMES.

CLEAR wa_it_fldcat.

wa_it_fldcat-fieldname = sy-index.

wa_it_fldcat-datatype = 'C'.

wa_it_fldcat-inttype = 'C'.

wa_it_fldcat-intlen = 10.

APPEND wa_it_fldcat TO it_fldcat .

ENDDO.

.

  • Create dynamic internal table and assign to FS

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fldcat

IMPORTING

ep_table = new_table.

ASSIGN new_table->* TO <dyn_table>.

  • Create dynamic work area and assign to FS

CREATE DATA new_line LIKE LINE OF <dyn_table>.

ASSIGN new_line->* TO <dyn_wa>.

  • Upload the excel

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_file

i_begin_col = '1'

i_begin_row = '1'

i_end_col = '200'

i_end_row = '5000'

TABLES

intern = xcel

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

  • Reformt to dynamic internal table

LOOP AT xcel.

ASSIGN COMPONENT xcel-col OF STRUCTURE <dyn_wa> TO <dyn_field>.

IF sy-subrc = 0.

<dyn_field> = xcel-value.

ENDIF.

AT END OF row.

APPEND <dyn_wa> TO it_table.

CLEAR <dyn_wa>.

ENDAT.

ENDLOOP.

the dump occurs at the append statement into the internal atble it_table.

any advice,

Shejal Shetty.