05-30-2008 8:43 AM
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
05-30-2008 9:00 AM
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
05-30-2008 8:47 AM
05-30-2008 8:52 AM
05-30-2008 8:55 AM
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?
05-30-2008 8:58 AM
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
05-30-2008 9:05 AM
@ 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?
05-30-2008 9:08 AM
there is a button when displaying the data in SE11, right next to the button technical settings. Press that and next do F8.
05-30-2008 9:14 AM
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
05-30-2008 9:00 AM
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
05-30-2008 9:02 AM
05-30-2008 9:04 AM
05-30-2008 9:07 AM
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.
05-30-2008 9:08 AM
05-30-2008 9:11 AM
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?
05-30-2008 9:15 AM
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?
05-30-2008 9:16 AM
05-30-2008 9:19 AM
05-30-2008 9:25 AM
05-30-2008 9:35 AM
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.
05-30-2008 9:36 AM
I got the problem:
I used more than 4 chars. I am so stupid. thank you for your support.