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: 

INSERT PROBLEM IN SE11 table

Former Member
0 Kudos

Hello,

I have a (maybe simple) problem:

I defined a table in se11.

I want to write a abap report to write datasets into it.

Therefore I created a workare and a string to count to the next Primary key (Primary Key is PK).

Once I write the table to screen it will only get me the first dataset I wrote to table. I am a beginner and don't know what I forgot. Do I need to do something like a db-commit?

My Code is:

TABLES ZTDM_SAPOUTPUT.

* Zeichenkette für den PK deklarieren
DATA:
zsapoutputPK LIKE ZTDM_SAPOUTPUT-MATNR.

* Arbeitsbereich definieren
DATA:
wa_ZTDM_SAPOUTPUT LIKE ZTDM_SAPOUTPUT.

WRITE: 'Ausgabe der Tabelle vor dem INSERT:'.
SKIP.

SELECT * FROM ZTDM_SAPOUTPUT.
  Write: /  ZTDM_SAPOUTPUT-FNCODE,
            ZTDM_SAPOUTPUT-MATNR,
            ZTDM_SAPOUTPUT-MAKTX,
            ZTDM_SAPOUTPUT-ZEINR,
            ZTDM_SAPOUTPUT-MATKL.
ENDSELECT.
SKIP.

* neuen Datensatz in Workarea schreiben
zsapoutputPK = ZTDM_SAPOUTPUT-PK.
zsapoutputPK = zsapoutputPK + 1.

wa_ZTDM_SAPOUTPUT-PK = zsapoutputPK.
wa_ZTDM_SAPOUTPUT-FNCODE ='ABCD'.
wa_ZTDM_SAPOUTPUT-MATNR ='ABCD'.
wa_ZTDM_SAPOUTPUT-MAKTX ='ABCD'.
wa_ZTDM_SAPOUTPUT-ZEINR ='ABCD'.
wa_ZTDM_SAPOUTPUT-MATKL ='ABCD'.

*INSERT-STATEMENT
INSERT ZTDM_SAPOUTPUT FROM wa_ZTDM_SAPOUTPUT.

* neuen Datensatz in Workarea schreiben
zsapoutputPK = zsapoutputPK + 1.

wa_ZTDM_SAPOUTPUT-PK = zsapoutputPK.
wa_ZTDM_SAPOUTPUT-FNCODE ='DEFG'.
wa_ZTDM_SAPOUTPUT-MATNR ='DEFG'.
wa_ZTDM_SAPOUTPUT-MAKTX ='DEFG'.
wa_ZTDM_SAPOUTPUT-ZEINR ='DEFG'.
wa_ZTDM_SAPOUTPUT-MATKL ='DEFG'.

*INSERT-STATEMENT
INSERT ZTDM_SAPOUTPUT FROM wa_ZTDM_SAPOUTPUT.

* Ausgabe nach INSERT
WRITE: 'Ausgabe der Tabelle NACH dem INSERT:'.
SKIP.

SELECT * FROM ZTDM_SAPOUTPUT.
  Write: /  ZTDM_SAPOUTPUT-FNCODE,
            ZTDM_SAPOUTPUT-MATNR,
            ZTDM_SAPOUTPUT-MAKTX,
            ZTDM_SAPOUTPUT-ZEINR,
            ZTDM_SAPOUTPUT-MATKL.
ENDSELECT.

The code should write 2 datasets to the table and then give the complete table to screen. Can you tell me my mistake?

Edited by: Daniel Gerne on May 30, 2008 9:46 AM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

MATNR field is type Character, so the value of material wold be ALPHABATES or Numeric or Alpha numeric. If you add 1 to the material number (as MATNR is a Primary Key) and the value is alphabate then no change was made, so it is trying to insert with the same key. And the statement INSERT will fail.

Rgds,

Bujji

19 REPLIES 19

Sm1tje
Active Contributor
0 Kudos

try to add the commit work if insert was successfull.

Former Member
0 Kudos

no effect could there be a problem regarding my primary key?

Former Member
0 Kudos

once I try to output my PK it will give a empty space.

Is the problem that I chose the checkbox "Initial values" at se11?

Sm1tje
Active Contributor
0 Kudos

check table contents via SE11, are there any values in the table already?

In other words, since your are not checking the RETURN CODE sy-subrc after INSERT, is there an error when INSERTING???

Edited by: Micky Oestreich on May 30, 2008 10:02 AM

Former Member
0 Kudos

@ Micky I get a Output without a PK at the time before I do the Insert and give the table to screen.

Where can I see the datasets in se11?

Sm1tje
Active Contributor
0 Kudos

there is a button when displaying the data in SE11, right next to the button technical settings. Press that and next do F8.

Former Member
0 Kudos

Hi

U make sure to create the right new key, so u should extract data sorted by key field.

Anyway try to check the sy-subrc after inserting a new record.

Max

Former Member
0 Kudos

Hi,

MATNR field is type Character, so the value of material wold be ALPHABATES or Numeric or Alpha numeric. If you add 1 to the material number (as MATNR is a Primary Key) and the value is alphabate then no change was made, so it is trying to insert with the same key. And the statement INSERT will fail.

Rgds,

Bujji

0 Kudos

MATNR is not the PK.

PK is the field PK

0 Kudos

Hi,

What is the data type of field PK.

Rgds,

BUjji

0 Kudos

in this case don't think there will be a problem. You have defined the PK LIKE matnr. But you can add 1 to this character field and it would work.

0 Kudos

no I did not define the PK as matnr.

PK is defined as char4.

0 Kudos

your right, sorry for that.

After the insert statement, please check the return code, to see if an error occurs.

Have you already checked the contents of the table in SE11?

0 Kudos

I just changed the Pks to hardcoded: 'test1', 'test2'.

The funny thing is now there is a 2nd dataset in the table with pk 'test1'. But the same insert having 'test2' was not inserted.

About rc: 1=ok or 0=ok?

0 Kudos

sy-subrc = 0 is OK, rest is NOT OK.

0 Kudos

sy-subrc is 4.

0 Kudos

where can I find the explanation of the sy-subrc codes?

0 Kudos

I copied your report and it works just fine for me???

In your editor there is a button with letter I (info button). Click that and next write statement INSERT. you will get explanation about the return code.

You can also do F1 on statement.

0 Kudos

I got the problem:

I used more than 4 chars. I am so stupid. thank you for your support.