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: 

updating a ztable from flat file

Former Member
0 Kudos

hi

can anyone tell me how to upload data into a ztable from a flat file with an example.

rg

sandeep

1 ACCEPTED SOLUTION

former_member184495
Active Contributor
0 Kudos

hi,

use BDC for uploading data from flat file to a table.

else

using function module 'GUI_UPLOAD', upload the flat file data to an internal table, and then using statement INSERT, insert it to the table, this would be helpful if data is very less and flat file structure is small.

cheers,

Aditya.

11 REPLIES 11

former_member184495
Active Contributor
0 Kudos

hi,

use BDC for uploading data from flat file to a table.

else

using function module 'GUI_UPLOAD', upload the flat file data to an internal table, and then using statement INSERT, insert it to the table, this would be helpful if data is very less and flat file structure is small.

cheers,

Aditya.

0 Kudos

hi

i have tried it using gui_upload. but when i checked the table entries in se11 it says no entries found; though the ztable is filled with the entries.i am giving u my code.plz help

points will be rewarded as soon as my problem is solved

rg

sandeep

REPORT ZVV_ZTABLE .

tables: zvvemployee1.

data: itab like standard table of zvvemployee1 with header line."occurs

  • empno like zvvemployee1-z_vvempno,

  • empname like zvvemployee1-z_vvempname,

  • empdept like zvvemployee1-z_vvempdept,

  • empsal like zvvemployee1-z_vvempsal,

  • end of itab.

*

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'c:\book1.txt'

FILETYPE = 'ASC'

  • HAS_FIELD_SEPARATOR = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = itab

  • 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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

ENDIF.

*insert lines of itab into table zvvemployee1 .

*loop at itab.

*write:/ itab-z_vvempno, itab-z_vvempname, itab-z_vvempdept,

  • itab-z_vvempsal.

*endloop.

*update zvvemployee1 from table itab.

loop at itab into zvvemployee1.

insert zvvemployee1.

endloop.

loop at zvvemployee1.

write:/ zvvemployee1-z_vvempno, zvvemployee1-z_vvempname,

zvvemployee1-z_vvempdept, zvvemployee1-z_vvempsal.

endloop.

*insert zvvemployee1 from table itab.

Message was edited by: sandeep akula

0 Kudos

Sandeep,

Set a breakpoint at the INSERT statement. What is the Sy-subrc value after this INSERT is executed ? Is it zero or something else?

Also - run t-code SE16, enter in the ZWEMP table name and press enter and then exexcute. Do you see your records ?

Former Member
0 Kudos

data: begin of file_rec,

vbeln like vbak-vbeln,

kunnr like vbak-kunnr,

netwr like vbak-netwr,

end of file_rec.

tables: z_orders.

data: filenm(20) value '/filesystem/file.txt'.

open dataset filenm for input in text mode.

if sy-subrc <> 0.

exit. " file not available for processing

endif.

do.

read dataset filenm into file_rec.

if sy-subrc <> 0.

exit. "end of file reached

endif.

move-corresponding file_rec to z_orders.

modify z_orders.

enddo.

close dataset filenm.

0 Kudos

Hi John,

Try this sample code..

The internal table will have the entire row of the file in each record. you split it based on the fields of your table and store it in another internal table. then insert that table to your z table.

REPORT CHAP2602.

  • Data declarations for later use

TABLES CUSTOMERS.

PARAMETERS FILENAME(128) DEFAULT '/usr/tmp/testfile.dat'

LOWER CASE.

DATA: MSG_TEXT(50),

ALL_CUSTOMER_NAMES LIKE CUSTOMERS-NAME OCCURS 100

WITH HEADER LINE.

  • Opening the File

OPEN DATASET FILENAME FOR INPUT IN TEXT MODE

MESSAGE MSG_TEXT.

IF SY-SUBRC NE 0.

WRITE: 'File cannot be opened. Reason:', MSG_TEXT.

EXIT.

ENDIF.

  • Reading Data

DO.

READ DATASET FILENAME INTO ALL_CUSTOMER_NAMES.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

APPEND ALL_CUSTOMER_NAMES.

ENDDO.

  • Closing the file

CLOSE DATASET FILENAME.

  • Display the result

LOOP AT ALL_CUSTOMER_NAMES.

WRITE / ALL_CUSTOMER_NAMES.

ENDLOOP.

Regards,

Prema

Former Member
0 Kudos

Hi,

I think you might know how to UPLOAD from flat file into internal table.

After UPLOADING and validations look at my example.....

data bplan_it like standard table of zfbillplanitm with header line.

loop at bplan_it.

update zfbillplanitm from bplan_it.

if sy-subrc eq 0.

commit work.

format color col_positive intensified off.

write:/ a, (04) bplan_it-bukrs,

a, (10) bplan_it-fplnr,

a, (07) bplan_it-fpltr centered,

a, (10) bplan_it-vbeln,

a, (40) text-h05, a.

else.

rollback work.

format color col_negative intensified off.

write:/ a, (04) bplan_it-bukrs,

a, (10) bplan_it-fplnr,

a, (07) bplan_it-fpltr centered,

a, (10) bplan_it-vbeln,

a, (40) text-h09, a.

endif.

clear bplan_it.

endloop.

Thanks.

If this helps you reward with points.

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Try this.

Here T_input is an internal table which is having similar structure as ztable.[But each field should be declared as character type even for other data types].

DATA: BEGIN OF T_INPUT OCCURS 0, " Flat file data

PERNR(9) TYPE C,

AMOUNT(15) TYPE C,"Even currency should be declared as character

W_TYPE(5) TYPE C,

END OF T_INPUT.

data G_FILE1 TYPE STRING.

parameters P_FILE LIKE RLGRAP-FILENAME.

G_FILE1 = P_FILE.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = G_FILE1

FILETYPE = C_ASC

HAS_FIELD_SEPARATOR = C_X

TABLES

DATA_TAB = T_INPUT

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 E000 WITH TEXT-014 G_FILE1.

Else.

insert ztable from table t_input.

endif.

Kindly reward points by clicking the star on the left of reply,if it helps.

Former Member
0 Kudos

Sandeep,

Have you completed your task with the items cited here?

If so, please reward points accordingly and close the thread.

If not, please provide more detail of needs.

Former Member
0 Kudos

Hi Sandeep,

Do you want to upload data into an internal table or datbase table?

Regards,

Neeraj Gupta

Former Member
0 Kudos

hi all

i got the ztable updated.

thanx

0 Kudos

sandeep ,

pls send the code to me

i want to upload the flat file to ztable can u suggest me