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

OO inserting into db tables

Former Member
0 Likes
1,074

Is there a certain syntax for inserting into db tables with OO? I have no errors when I MODIFY the table from within the same method, but when I use INSERT I get an error saying the field is not recognized.

Edited by: zmwhite on Nov 3, 2011 4:15 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
983

The code is as folows, the statment to MODIFY does not give me an error but the INSERT statement gives the message: zobserve is not a field group.

METHOD save_answers.

IF s1000_flg1 = 'UPDT'. "update existing record

MODIFY zobserve FROM wa_zobserve. *NO ERROR*

IF SY-SUBRC <>'0'.

message_id = 7.

lcl_message->get_message(

EXPORTING

text_id = message_id

text = ' ' ).

SET SCREEN 1000.

RETURN.

ELSE.

COMMIT WORK.

saved_flg = 'X'.

MESSAGE 'Record Updated' TYPE 'S'.

ENDIF.

ELSE. "add new record

INSERT WA_ZOBSERVE INTO ZOBSERVE. *ERROR: zobserve is not a field group*

IF SY-SUBRC <> '0'.

message_id = 8.

lcl_message->get_message(

EXPORTING

text_id = message_id

text = ' ' ).

SET SCREEN 1000.

ELSE.

COMMIT WORK.

saved_flg = 'X'.

MESSAGE 'Record Saved' TYPE 'S'.

ENDIF.

ENDIF.

Is there a certain syntax for inserting into db tables with OO? I have no errors when I MODIFY the table from within the same method, but when I use INSERT I get an error saying the field is not recognized.

Edited by: zmwhite on Nov 3, 2011 4:15 PM

6 REPLIES 6
Read only

Former Member
0 Likes
983

Code lines and exact error ?

Read only

Former Member
0 Likes
983

Post the dump

Read only

Clemenss
Active Contributor
0 Likes
983

Hi zim

thank you for not posting code but asking questions regarding code.

I don't know what you expect. But you will have taken into account that you always INSERT / MODIFY / UPDATE databse FROM work area or FROM TABLE itab.

Regards

Clemens

Read only

Former Member
0 Likes
984

The code is as folows, the statment to MODIFY does not give me an error but the INSERT statement gives the message: zobserve is not a field group.

METHOD save_answers.

IF s1000_flg1 = 'UPDT'. "update existing record

MODIFY zobserve FROM wa_zobserve. *NO ERROR*

IF SY-SUBRC <>'0'.

message_id = 7.

lcl_message->get_message(

EXPORTING

text_id = message_id

text = ' ' ).

SET SCREEN 1000.

RETURN.

ELSE.

COMMIT WORK.

saved_flg = 'X'.

MESSAGE 'Record Updated' TYPE 'S'.

ENDIF.

ELSE. "add new record

INSERT WA_ZOBSERVE INTO ZOBSERVE. *ERROR: zobserve is not a field group*

IF SY-SUBRC <> '0'.

message_id = 8.

lcl_message->get_message(

EXPORTING

text_id = message_id

text = ' ' ).

SET SCREEN 1000.

ELSE.

COMMIT WORK.

saved_flg = 'X'.

MESSAGE 'Record Saved' TYPE 'S'.

ENDIF.

ENDIF.

Read only

0 Likes
983

Hi,

Please go thru this link

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3a6d358411d1829f0000e829fbfe/content.htm

Write your statement like these (below)

To insert a single line into a database table, use the following:

INSERT INTO <target> VALUES <wa> .

INSERT <target> FROM <wa >

Multiple lines

INSERT <target> FROM TABLE <itab>

Hope I helped!

Thanks,

Reetesh

Read only

0 Likes
983

Thanks, I had actually copied that line from the model my boss gave me, and he wasn't using OO. It originally gave a message that in OO the syntax needed an INTO with the INSERT formatted that way, so I changed it and it never worked after that. I must have had something else wrong that I have fixed in the process. Not sure why, but it works now.