Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

UPLOADING FROM EXCEL TO Z TABLE

Hi ,

CAN YOU TAKE A LOOK AT THIS CODE AND LET ME WHATS WRONG IN IT AS ITS LEADING TO SHORT DUMP ERROR.

I need to update a ztable from an excel sheet.

Help me out

data : begin of t_upload1 occurs 0,

ZZPHYACT like zfix2-ZZPHYACT,

ZZLNAME like zfix2-ZZLNAME,

ZZFNAME like zfix2-ZZFNAME,

end of t_upload1.

  • selection-screen

selection-screen: begin of block blk with frame title text-001.

selection-screen : skip 1.

parameters : p_file like rlgrap-filename.

selection-screen : skip 1.

selection-screen : end of block blk.

at selection-screen on value-request for p_file.

    • F4 Value for File

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

  • PROGRAM_NAME = sy-repid

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

STATIC = 'X'

  • MASK = ' '

CHANGING

FILE_NAME = p_file

EXCEPTIONS

MASK_TOO_LONG = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

START-OF-SELECTION.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = p_file

I_BEGIN_COL = 1

I_BEGIN_ROW = 2

I_END_COL = 3

I_END_ROW = 12507

TABLES

INTERN = t_upload1

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

LOOP AT t_upload1.

WRITE: / t_upload1-ZZPHYACT, 20 t_upload1-ZZLNAME , 45 t_upload1-ZZFNAME.

HERE IAM JUST CHECKING I NEED TO UPDATE A ZTABLE

ENDLOOP.

Tags:
replied

Hi Suchitra,

I have modified your code . You just run this code . It will directly upload the data from the excel file into the internal table.

(Here I have created a custom table Zkunal1 . It comsists of 4 fields , MANDT, FNAME, LNAME & PLACE. In the test file, you can enter the data as

100 Ram Kumar Delhi

100 Shyam Kumar B'lore.)

(after running it you just have to use your database table thats it.)

&----


*& Report ZKUN_FILE14 *

*& *

&----


*& *

*& *

&----


REPORT ZKUN_FILE14 .

tables : zkunal1.

FIELD-SYMBOLS : <fs> .

DATA : fldname(50) TYPE c.

DATA itab TYPE TABLE OF alsmex_tabline WITH HEADER LINE.

data : begin of t_upload1 occurs 0.

include structure zkunal1.

data :end of t_upload1.

data : col type i.

DATA : cmp LIKE TABLE OF rstrucinfo WITH HEADER LINE.

data: progname like sy-repid,

dynnum like sy-dynnr.

  • selection-screen

selection-screen: begin of block blk with frame title text-001.

selection-screen : skip 1.

parameters : p_file like rlgrap-filename.

selection-screen : skip 1.

selection-screen : end of block blk.

at selection-screen on value-request for p_file.

    • F4 Value for File

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

  • PROGRAM_NAME = sy-repid

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

STATIC = 'X'

  • MASK = ' '

CHANGING

FILE_NAME = p_file

EXCEPTIONS

MASK_TOO_LONG = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

START-OF-SELECTION.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = p_file

I_BEGIN_COL = 1

I_BEGIN_ROW = 1

I_END_COL = 4

I_END_ROW = 5

TABLES

INTERN = itab

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

CALL FUNCTION 'GET_COMPONENT_LIST'

EXPORTING

program = SY-REPID

fieldname = 'ZKUNAL1'

tables

components = cmp

.

LOOP AT ITAB.

AT NEW row.

IF sy-tabix <> 1.

APPEND T_UPLOAD1.

ENDIF.

ENDAT.

col = itab-col.

READ TABLE cmp INDEX col.

CONCATENATE 'T_UPLOAD1-' cmp-compname INTO fldname.

ASSIGN (fldname) TO <fs>.

<fs> = ITAB-value.

ENDLOOP.

Append t_upload1.

LOOP AT t_upload1.

WRITE: / t_upload1-fname , 20 t_upload1-lname , 45 t_upload1-place.

*HERE IAM JUST CHECKING I NEED TO UPDATE A ZTABLE

ENDLOOP.

Regards,

Kunal.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question