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: 

Upload all data into custom table

Former Member
0 Kudos

Hi,

Please see my code below, I am trying to upload data into custom table

Note : My custom table has 5 fields and MANDT is only primary Key

I learned if there is no primary key other than MANDT you always will have one entry in table. Correct me if i am wrong.

Keeping all in mind is there a way (using below code and MANDT is only field as primary key) I can upload all the data into table including duplicates?

DATA : IT_RECORD_IN TYPE TABLE OF zPHY_INV_HIS.

DATA : FILENAME TYPE STRING.

SELECTION-SCREEN BEGIN OF BLOCK BLKONE WITH FRAME TITLE TEXT-A01.

PARAMETERS: PATHNAME(80) DEFAULT 'C:\abc.CSV' OBLIGATORY.

SELECTION-SCREEN END OF BLOCK BLKONE.

FILENAME = PATHNAME.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = filename

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = IT_RECORD_IN

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.

ELSE.

  • MODIFY zPHY_INV_HIS FROM TABLE IT_RECORD_IN.

  • UPDATE zPHY_INV_HIS FROM TABLE IT_RECORD_IN.

  • INSERT zPHY_INV_HIS FROM TABLE IT_RECORD_IN.

INSERT zPHY_INV_HIS FROM TABLE IT_RECORD_IN ACCEPTING DUPLICATE KEYS.

ENDIF.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Shiva,

thanks for the reply, the only reason I have created this table without primary key is, there is going to be lot of dulplicate records. So keeping that in mind if i create table with Primary key I can't create duplicate records in table.

Correct me if i am wrong or please tell me if there is another way to where I create one primary key in table and also able to populate duplicate records in table.

Thanks

SB

6 REPLIES 6

Former Member
0 Kudos

Hi

If there is no primary key except MANDT, then system will hold the last record.

Even if you try to create a TMG, that is also will not be possible.

So you need to have at least a single primary key in table.

[Interesting answers for your query|;

Shiva

Former Member
0 Kudos

Hi Shiva,

thanks for the reply, the only reason I have created this table without primary key is, there is going to be lot of dulplicate records. So keeping that in mind if i create table with Primary key I can't create duplicate records in table.

Correct me if i am wrong or please tell me if there is another way to where I create one primary key in table and also able to populate duplicate records in table.

Thanks

SB

0 Kudos

Hi

There will be a different value in any of the field, so try make as many fields as primary keys. No other options as per my understanding.

Shiva

0 Kudos

Hi Sarath,

You can achieve your requirement thru this way:

add one more field which will be the primary key. So what is this field? this is a field which is a counting number. So the modified structure of your table would look like this

MANDT

PID (primary ID)

FIELD1

FIELD2

FIELD3

FIELD4

FIELD5

As I said, your PID field will be a continuos counting number, like 1, 2 , 3 etc.... In this manner, you will differentiate between records even they are duplicates (but not their primary key).

Hope it helps. Cheers

Former Member
0 Kudos

Hi,

MANDT is always added as one of the fields to make the table client specific and it has to be a primary key.

As rest of your fields are non-primary key fields, your table will have duplicate records for all the fields. You shall not get any error even if you enter duplicate entries.

As a general practice, it is always good to have at least one primary key on a a table apart from MANDT. This ensures faster data access and provides uniqueness for each record.

Also, if your table does not have at least one primary key apart from MANDT, you shall not be able to maintain the table via SM30 even if you create a Table Maintanence.

Regards,

Danish.

0 Kudos

This message was moderated.