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: 

how to fetch data from single database table using 2 internal tables.

Former Member
0 Kudos

Hi friends,

i am a new user of ABAP and also SDN.

i need a help.

i want to fetch data from one database table based on primary keys of 2 internal tables. how to put in where clause.

Thanks in advance.

7 REPLIES 7

Former Member
0 Kudos

hii

refer to following code ..i hope it will help you

SELECT matnr                         " Material Number
    FROM mara
    INTO TABLE i_mara
   WHERE matnr IN s_matnr.


  IF i_mara[] IS NOT INITIAL.
    SELECT matnr                       " Material Number
           werks                       " Plants
           prctr                       " Profit Center
      FROM marc
      INTO TABLE i_marc
       FOR ALL ENTRIES IN i_mara
     WHERE matnr = i_mara-matnr
       AND werks IN s_werks.

  ENDIF.                               " IF i_mara[] IS NOT INITIAL

  i_output = i_marc.

  IF i_marc[] IS NOT INITIAL.

    SELECT matnr                       " Material Number
           werks                       " Plants
           lgort                       " Storage Location
      FROM mard
      INTO TABLE i_mard
       FOR ALL ENTRIES IN i_marc
     WHERE matnr EQ i_marc-matnr
       AND werks EQ i_marc-werks
       AND lgort IN s_lgort.

  ENDIF.                               " IF i_mara[] IS NOT INITIAL

regards

twinkal

naveen_inuganti2
Active Contributor
0 Kudos

Hi...

> primary keys of 2 internal tables

Correst your post, because internal table fields never contains primary key and Non-primary key catogories!

Thanks,

Naveen.I

Former Member
0 Kudos

refer

[http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3a1f358411d1829f0000e829fbfe/content.htm]

Former Member
0 Kudos

HI,

Thanks for your message. As per your coding, it is fetching from 2 different tables, but my requirement is to fetch from one table based on 1 field from one internal table and 1 field from another internal table. Please help.

Former Member
0 Kudos

select * from <table name> where <field name1> = <itab1-field> and <field name2> = <itab2-field>.

Former Member
0 Kudos

Hi,

Use FOR ALL ENTRIES keyword

Examples

select * into table it_result from mara

for all entries in <itab>

where matnr eq <itab>-fieldname.

select * into table it_result1 from mara

for all entries in <itab2>

where matnr eq <itab2>-fieldname.

Former Member
0 Kudos

Thank you so much. I could able to fetch.