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

Inserting data from internal table back to system

Former Member
0 Likes
720

This could be a relatively simple question/answer, but I've spent a rediculously long time trying to figure it out...

I have a program that is reading a tab delimited file into an internal table. I can see that the internal table is being populated correctly. How do I get the data from the internal table inserted into a database table?

The database table is YMMOM and has five fields: mandt (clnt 3), matnr (char 18), ylegacy (char 4), ycount (char 4), and zbismt (char 30). The internal table is set up as follows:

data: begin of in_tab occurs 0,
        matnr   like ymmom-matnr,
        ylegacy like ymmom-ylegacy,
        ycount  like ymmom-ycount,
        zbismt  like ymmom-zbismt,
      end of in_tab.

I've tried

MOVE-CORRESPONDING in_tab TO ymmom.

and I can see in the debugger that the structure is being populated, but when I go back and try to look at the contents of ymmom, the data hasn't been actually uploaded.

Thanks in advance for any help you can provide.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
688

Hi,

You have to user INSERT statement to insert records to the database table..

data: begin of in_tab occurs 0,

matnr like ymmom-matnr,

ylegacy like ymmom-ylegacy,

ycount like ymmom-ycount,

zbismt like ymmom-zbismt,

end of in_tab.

<b>MOVE-CORRESPONDING in_tab TO ymmom.

ymmom-mandt = sy-mandt.

  • Insert the records to the databse table.

INSERT ymmom.

IF SY-SUBRC = 0.

COMMIT WORK.

ENDIF.</b>

Thanks,

Naren

6 REPLIES 6
Read only

Former Member
0 Likes
689

Hi,

You have to user INSERT statement to insert records to the database table..

data: begin of in_tab occurs 0,

matnr like ymmom-matnr,

ylegacy like ymmom-ylegacy,

ycount like ymmom-ycount,

zbismt like ymmom-zbismt,

end of in_tab.

<b>MOVE-CORRESPONDING in_tab TO ymmom.

ymmom-mandt = sy-mandt.

  • Insert the records to the databse table.

INSERT ymmom.

IF SY-SUBRC = 0.

COMMIT WORK.

ENDIF.</b>

Thanks,

Naren

Read only

0 Likes
688

This did the trick, thanks! And especially for the quick response!

Read only

0 Likes
688

Hi,

Nice query.

Kishore.

Read only

Former Member
0 Likes
688

Hi

Perhpas you're transfering records with the same key or that records are in the table YMMOM or you didn't do the insert.

Your code seems to be ok, only the insert is missing:

MOVE-CORRESPONDING in_tab TO ymmom.

<b>INSERT YMMOM.</b>

Max

Read only

Former Member
0 Likes
688

Hi,

Use UPDATE statement to update Database table.

Regards,

Chandra

Read only

Former Member
0 Likes
688

Hi Bryan,

<b>One important point is ..................... </b> You can use either OPEN sql

commands or NATIVE sql commands. But, if you insert records into the table

through program either using OPEN sql commands or NATIVE sql commands,

be aware that you are inserting records WITHOUT any checks like Check table validation,Fixed values, and some others validations which are required for the field. Always, insert records into database through screen for consistency

of the data. In very extreme cases we insert records through program.

If you want to insert bulk amount of records.You can acheive this

using BDC technique<b>( WITH consistency )</b> that is either using CALL TRANSACTION method or SESSION method, instead of using either OPEN sql commands or NATIVE sql commands<b>(WITHOUT consistency)</b> in program.

If you have queries regarding this, you are welcome.

If you already know this ignore this.

Hope that, the above desc. is helpful for you.

Regards,

V.Raghavender.