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

A Select statement with Appending table statement in it.

Former Member
0 Likes
41,417

Hi,

How can I use a select statement with a <Appening table> statement in it.

SELECT DISTINCT <field Name>

FROM <DB table name>

APPENDING TABLE <itab>

WHERE <fieldname> EQ <Itab1-fieldname>

AND <fieldname> EQ <itab2-fieldname>.

Can I use the above select statement.If I'm using this...how this works?

Regards

Dharmaraju

1 ACCEPTED SOLUTION
Read only

Former Member
13,899

Hi

Check this

LOOP AT LTAB1.

READ TABLE ITAB2 with KEY field1 = 'UR Value' or LTAB1-F1.

SELECT DISTINCT <field Name>

FROM <DB table name>

APPENDING TABLE <itab>

WHERE <fieldname> EQ <Itab1-fieldname>

AND <fieldname> EQ <itab2-fieldname>.

ENDLOOP ,

Hope it helps else..let us know ur reqmt..

Praveen

5 REPLIES 5
Read only

Former Member
13,900

Hi

Check this

LOOP AT LTAB1.

READ TABLE ITAB2 with KEY field1 = 'UR Value' or LTAB1-F1.

SELECT DISTINCT <field Name>

FROM <DB table name>

APPENDING TABLE <itab>

WHERE <fieldname> EQ <Itab1-fieldname>

AND <fieldname> EQ <itab2-fieldname>.

ENDLOOP ,

Hope it helps else..let us know ur reqmt..

Praveen

Read only

gopi_narendra
Active Contributor
13,899

Appending table will append the records (to an existing internal table with records in it) that are fetched from that select statement.

For ex : see this below

    SELECT bukrs kunnr umskz zuonr gjahr belnr bldat
           xblnr shkzg dmbtr wrbtr sgtxt zfbdt
           FROM bsid
           INTO TABLE it_accnt
           FOR ALL ENTRIES IN it_tab1
           WHERE bukrs EQ 'JTC1'
             AND kunnr EQ it_tab1-kunnr
             AND umskz IN so_umskz
             AND zuonr EQ it_tab1-zuonr
             AND bldat LE p_date.

 " when executed the above statement it_accnt might contain 10 records

    SELECT bukrs kunnr umskz zuonr gjahr belnr bldat
           xblnr shkzg dmbtr wrbtr sgtxt zfbdt
           FROM bsad
           APPENDING TABLE it_accnt
           FOR ALL ENTRIES IN it_tab1
           WHERE bukrs EQ 'JTC1'
             AND kunnr EQ it_tab1-kunnr
             AND umskz IN so_umskz
             AND zuonr EQ it_tab1-zuonr
             AND bldat LE p_date
             AND augdt GE p_date.
 " and now when this statement executed retrieves 10 more records from the table BSAD, 
 " then totally it_accnt contains 20 records.

Hope this is clear.

Regards

Gopi

Read only

0 Likes
13,899

This message was moderated.

Read only

Former Member
0 Likes
13,899

Hi, Dharma Raju Kondeti.

I found this in the SAP online help, hope this can help you.

Specifying Internal Tables

When you read several lines of a database table, you can place them in an internal table. To do this, use the following in the INTO clause:

SELECT ... INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE <itab>

[PACKAGE SIZE <n>] ...

The same applies to the line type of <itab>, the way in which the data for a line of the database table are assigned to a table line, and the CORRESPONDING FIELDS addition as for flat work areas (see above).

The internal table is filled with all of the lines of the selection. When you use INTO, all existing lines in the table are deleted. When you use APPENDING; the new lines are added to the existing internal table <itab>. With APPENDING, the system adds the lines to the internal table appropriately for the table type. Fields in the internal table not affected by the selection are filled with initial values.

If you use the PACKAGE SIZE addition, the lines of the selection are not written into the internal table at once, but in packets. You can define packets of <n> lines that are written one after the other into the internal table. If you use INTO, each packet replaces the preceding one. If you use APPENDING, the packets are inserted one after the other. This is only possible in a loop that ends with ENDSELECT. Outside the SELECT loop, the contents of the internal table are undetermined. You must process the selected lines within the loop.

Regards,

feng.

Edited by: feng zhang on Feb 21, 2008 10:20 AM

Read only

Former Member
0 Likes
13,899

Dharma Raju,

When you are using below statement there should be Endselect.Reason is

Ex: Your program is running very slow because of huge data(say 100000) in Database table and going Dump because of select statement into itab.

To come out from this problem You have to use PACKAGE SIZE in select statement .

PACKAGE SIZE : means every time your taking 20000 records and appending the records to ITAB.

That time you have to use APPENDING TABLE .

So every select statement will run with in time and append the records to itab.