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

how to extract data from text file to database table

Former Member
0 Likes
1,112

Hi ,

I am trying to upload data in text file to database table using GUI_UPLOAD function .what would be the program for that.

thanks in advance.

Hi ,

I am trying to upload data in text file to database table using GUI_UPLOAD function .what would be the program for that.

thanks in advance.

3 REPLIES 3
Read only

Former Member
0 Likes
635

Hi,

I don't think you have a standard sap program to upload data from file to database table...

Instead you can create a custom program like this..

DATA: T_FILEDATA(1000) OCCURS 0 WITH HEADER LINE.

DATA: T_ZTABLE LIKE ZTABLE OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'C:\TEST.TXT'

tables

data_tab = T_FILEDATA

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.

LOOP AT T_FILEDATA.

T_ZTABLE = T_FILEDATA.

APPEND T_ZTABLE.

ENDLOOP.

MODIFY ZTABLE FROM TABLE T_ZTABLE.

COMMIT WORK..

Thanks,

Naren

Read only

Former Member
0 Likes
635

You can use fm CREATE_TEXT:


  CALL FUNCTION 'CREATE_TEXT'
       EXPORTING
            FID         = HEADER-TDID
            FLANGUAGE   = HEADER-TDSPRAS
            FNAME       = HEADER-TDNAME
            FOBJECT     = HEADER-TDOBJECT
            SAVE_DIRECT = 'X'
            FFORMAT     = '*'
            MODE_INSERT = ' '
       TABLES
            FLINES      = TEXT_LINES
       EXCEPTIONS
            NO_INIT     = 01
            NO_SAVE     = 02.

Rob

Read only

Former Member
0 Likes
635

Hi,

there are different ways to upload data to a database table.

1. Read the contents of the file.

2. If your table is a SAP Standard table, then there would be certain BAPIs or probably transactions to load the records. Check for the BAPIs or Transactions.

For example, if your database table if MARA (material master) you can use BAPI which can upload records in MARA. One can directly upload records into table DB table using ABAP Commnands. But this may sometimes effect the table. The data should be validated before uploading into the tables. Thus you should make sure to validate the records if you are not using either BAPI or BDC.

3. If the table table has a forien key relations and if the data uploaded is not properly validated, then there can be a lot of discrepencies in the table, which ultimately effect the performance of your database.

4. After the data is validated, do not forget to lock the table which is to be updated. This is to avoid any Lock errors.

5. Upload the records, either by using BAPI, BDC. If you are using a BAPI, then do not forget to Commit the BAPI. Unless you commit the BAPI, data will not be uploaded into DB Table.

6. Capture the error records and create a BDC session for those records. This allows the user to rectify the errors online.

8. Unlock the table.

9. The Most Important is error log, maintain the error log for the incorrect entries.

I hope your question is answered.

Regards,

Vara