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

Select quiry issue

Former Member
0 Likes
629

Hi All,

1. first select quirey

2. for second select quiry i am using for all ntries of first select quiry internal table data

3. now here in third select quiry in where condition i have to use first internal table data and second internal table data as well,

this third select quiry how to handle please suggest with code.

Ex:

SELECT ABKRS UABRJ UABRP FROM T569V INTO TABLE gt_t569v
                              FOR ALL ENTRIES IN gt_0001
                                WHERE ABKRS = gt_0001-abkrs.

          if gt_t569v is not initial.

            SELECT PERMO FROM T549A INTO TABLE GT_T549A
                                 FOR ALL ENTRIES IN gt_0001
                                WHERE ABKRS = GT_0001-ABKRS.

            IF NOT GT_T569v[] IS INITIAL.
              SELECT BEGDA FROM T549Q INTO TABLE gt_T549Q
                               FOR ALL ENTRIES IN GT_T569v
                                  WHERE PERMO = gt_T549A-PERMO AND
                                        PABRJ = gt_T569V-UABRJ AND
                                        PABRP = gt_T569V-UABRP.

the third select quiry is showing error, Please correct it.

Regards,

Reddy

Moderator message - Please use code tags around your code

Edited by: Rob Burbank on Jan 12, 2010 1:48 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
581

Please change the code as below.



if gt_0001[] is not initial.

SELECT ABKRS 
              VWSAZ               " Fetch all key fields while using for all entries to get all data
              UABRJ 
              UABRP FROM T569V INTO TABLE gt_t569v
                              FOR ALL ENTRIES IN gt_0001
                                WHERE ABKRS = gt_0001-abkrs.


 SELECT ABKRS              " Fetch all key fields while using for all entries to get all data
               PERMO 
               FROM T549A INTO TABLE GT_T549A
                                 FOR ALL ENTRIES IN gt_0001
                                WHERE ABKRS = GT_0001-ABKRS.
 

 LOOP AT GT_T569V INTO WA_T569V.
      READ TABLE GT_T549A INTO WA_T549A WITH KEY ABKRS = WA_T569V-ABKRS BINARY SEARCH.

            IF SY-SUBRC  = 0.

               WA_FINAL-PERMO = WA_T549A-PERMO.
               WA_FINAL-UABRJ = WA_T569V-UABRJ.
               WA_FINAL-UABRP = WA_T569V-UABRP.
              APPEND WA_FINAL TO IT_FINAL.
               CLEAR WA_FINAL.

ENDLOOP.

IF IT_FINAL[] IS NOT INITIAL.

SELECT PERMO 
             PABRJ
             PABRP
             BEGDA FROM T549Q INTO TABLE gt_T549Q
                               FOR ALL ENTRIES IN GT_T569v
                                  WHERE PERMO = IT_FINAL-PERMO AND
                                        PABRJ = IT_FINAL-UABRJ AND
                                        PABRP = IT_FINAL-UABRP.
       

Let me know if you need further info

Regards

Satish Boguda

3 REPLIES 3
Read only

Former Member
0 Likes
581

You cannot use FOR ALL ENTRIES with more than one table. You should be able to use a JOIN instead and get all your data with one SELECT, though.

Rob

Read only

Former Member
0 Likes
582

Please change the code as below.



if gt_0001[] is not initial.

SELECT ABKRS 
              VWSAZ               " Fetch all key fields while using for all entries to get all data
              UABRJ 
              UABRP FROM T569V INTO TABLE gt_t569v
                              FOR ALL ENTRIES IN gt_0001
                                WHERE ABKRS = gt_0001-abkrs.


 SELECT ABKRS              " Fetch all key fields while using for all entries to get all data
               PERMO 
               FROM T549A INTO TABLE GT_T549A
                                 FOR ALL ENTRIES IN gt_0001
                                WHERE ABKRS = GT_0001-ABKRS.
 

 LOOP AT GT_T569V INTO WA_T569V.
      READ TABLE GT_T549A INTO WA_T549A WITH KEY ABKRS = WA_T569V-ABKRS BINARY SEARCH.

            IF SY-SUBRC  = 0.

               WA_FINAL-PERMO = WA_T549A-PERMO.
               WA_FINAL-UABRJ = WA_T569V-UABRJ.
               WA_FINAL-UABRP = WA_T569V-UABRP.
              APPEND WA_FINAL TO IT_FINAL.
               CLEAR WA_FINAL.

ENDLOOP.

IF IT_FINAL[] IS NOT INITIAL.

SELECT PERMO 
             PABRJ
             PABRP
             BEGDA FROM T549Q INTO TABLE gt_T549Q
                               FOR ALL ENTRIES IN GT_T569v
                                  WHERE PERMO = IT_FINAL-PERMO AND
                                        PABRJ = IT_FINAL-UABRJ AND
                                        PABRP = IT_FINAL-UABRP.
       

Let me know if you need further info

Regards

Satish Boguda

Read only

Former Member
0 Likes
581

Hi Kumar,

You are checking the INITIAL condition for one internal table and using the command FOR ALL ENTRIES for a different internal table. It doesnu2019t make sense.

As suggested by ROB you can for a join between the tables and get the result in one go.

Else you may proceed like this:

1.Select data from your first table T0001 (I guess this is first table) into the internal table gt_0001.

2.Select required data from the table T569V into the internal table gt_569V for all entries in gt_0001.

3.Here looping and comparing the key fields in the 2 internal tables obtained above, prepare a third internal table, say gt_data.

4.Now select data from your third table T549Q for all entries in the internal table gt_data.

But this might be tedious process. Also you may like 2 choose a join between the first 2 table and then go for a u201Cfor all entriesu201D for the selection from 3rd table. Both the procedures have pros and cons. You will need to take a call depending how much data you have in the 3 tables.

Cheers,

Pritam