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

strange behaviour in SELECT Query

Former Member
0 Likes
957

Hi!,

I don't understand a behaviour of an SELECT QUERY.

I have an internal table:

DATA:
   BEGIN OF pt_s032 OCCURS 0,
     werks LIKE s032-werks,
     matnr LIKE s032-matnr,
     mbwbest LIKE s032-mbwbest,
     wbwbest LIKE s032-wbwbest,
   END OF pt_s032.

I have an internal table of materials (this table only contains one material):

DATA:
   BEGIN OF pt_matnr OCCURS 0,
     matnr LIKE s032-matnr,
   END OF pt_matnr.

and I have a range of plants (this contains a little bit more than 100 rows):

DATA:
   BEGIN OF r_werks OCCURS 0,
     sign,
     option(2),
     low LIKE s032-werks,
     high LIKE s032-werks,
     END OF r_werks.

When I perform the following SELECT query I got 18 rows:

SELECT werks matnr mbwbest wbwbest
       FROM s032
       INTO CORRESPONDING FIELDS OF TABLE pt_s032
         FOR ALL ENTRIES IN pt_matnr
         WHERE ssour EQ c_ssour
     AND vrsio EQ c_vrsio
         AND werks IN r_werks
         AND matnr EQ pt_matnr-matnr.

BUT if I also add the field LGORT in my query, I got 19 rows:

SELECT werks LGORT matnr mbwbest wbwbest
       FROM s032
       INTO CORRESPONDING FIELDS OF TABLE pt_s032
         FOR ALL ENTRIES IN pt_matnr
         WHERE ssour EQ c_ssour
     AND vrsio EQ c_vrsio
         AND werks IN r_werks
         AND matnr EQ pt_matnr-matnr.


I would appreciate someone could explain this behaviour.

Thanks in advance.


1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
906

Hi Jose,

Using 'For all entries' deletes duplicates from the result set. When you introduce LGORT the werks matnr mbwbest wbwbest was not duplicate anymore.

Regards,

Shravan

Hello..

Follow the steps:

1.The for all entries always should be preceeded with the not initial condition.

2.Add the Lgort in the structure.

3.When using the move corresponding(which is least recomeneded),we need to take of the similar structure,or else there wud be wrong mapping.

Please check in the above way let me know.

regards,

Varun

6 REPLIES 6
Read only

varun_vadnala3
Active Participant
0 Likes
906

Hello..

Follow the steps:

1.The for all entries always should be preceeded with the not initial condition.

2.Add the Lgort in the structure.

3.When using the move corresponding(which is least recomeneded),we need to take of the similar structure,or else there wud be wrong mapping.

Please check in the above way let me know.

regards,

Varun

Read only

0 Likes
906

At first I didn't have the lgort field in my internat table, and I didn't have it in my query. But later I added the lgort field in both places, what I don't understand is why this field makes the query bring a different number of entries.

Read only

0 Likes
906

I think you're right, if I change my query and avoid the FOR ALL ENTRIES statement using a specific MATNR I got all the 19 entries.

SELECT werks matnr mbwbest wbwbest

      FROM s032

      INTO CORRESPONDING FIELDS OF TABLE pt_s032

            WHERE ssour EQ c_ssour

        AND vrsio EQ c_vrsio

        AND werks IN r_werks

        AND matnr EQ 'VN-058665-0051'.

Read only

0 Likes
906

Jose,

'For all Enteries In' will result in distict dataset so if 2 records in result table are same than result table

will have only 1 records,( result will be same as using distinct )

Raj Patel

Read only

Former Member
0 Likes
907

Hi Jose,

Using 'For all entries' deletes duplicates from the result set. When you introduce LGORT the werks matnr mbwbest wbwbest was not duplicate anymore.

Regards,

Shravan

Read only

0 Likes
906

Thank you Shravan