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-Options not working properly

Former Member
0 Likes
2,881

Hello Everyone

I have a select-options field called p_vkunr which is 'Ship-to-field'.

I'm using the following code to get the values related to this field:

IF p_vkunr IS INITIAL.

     SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_output

           FROM vbak AS a INNER JOIN vbap AS b ON

                a~vbeln = b~vbeln

           WHERE a~vbeln IN p_vbeln

            AND  a~vkorg = p_vkorg

            AND  a~vtweg = p_vtweg

            AND  a~spart = p_spart

            AND  a~auart IN p_auart

            AND  b~pstyv IN p_pstyv

            AND  a~erdat IN p_erdat

            AND  a~zzcallindt IN p_cindt

            AND  b~lprio IN p_lprio

            AND  b~zzrefcont_pwcs IN p_refco

            AND  b~zztail IN p_tail

            AND  b~zzesn IN p_esn

            AND  b~matnr IN ( SELECT matnr FROM mara WHERE matkl IN

                            p_matkl AND matnr IN p_matnr ).

   ELSE.

     SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_output

       FROM vbak AS a INNER JOIN vbap AS b ON

            a~vbeln = b~vbeln

       WHERE a~vbeln IN p_vbeln

        AND  a~vkorg = p_vkorg

        AND  a~vtweg = p_vtweg

        AND  a~spart = p_spart

        AND  a~auart IN p_auart

        AND  b~pstyv IN p_pstyv

        AND  a~erdat IN p_erdat

        AND  a~zzcallindt IN p_cindt

        AND  b~lprio IN p_lprio

        AND  b~zzrefcont_pwcs IN p_refco

        AND  b~zztail IN p_tail

        AND  b~zzesn IN p_esn

        AND  b~matnr IN ( SELECT matnr FROM mara WHERE matkl IN

                        p_matkl AND matnr IN p_matnr )

        AND  b~vbeln IN ( SELECT c~vbeln FROM vbak AS c INNER JOIN knvp AS d

                          ON c~kunnr = d~kunnr WHERE d~parvw = 'WE' AND c~kunnr IN p_vkunr ).

   ENDIF.


But the problem is when I give a range of values in p_vkunr on the screen like 10410 to 10726, while displaying the fields, it displays all the fields which are not there in the range provided by me.


What to do?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,816

I guess the JOIN on VBAK and KNVP returns no result. So the IN-operator is ignored by the main SELECT and you have no limitation on VBELN.

So, check first if the sub-select should return some values for your searched range.

The route cause of your problem could be also the domain definition, if it uses ALPHA conversion for example. Maybe your SELOPT says: get range from 10410 to 10726, but it should say e.g.: 00010410 to 00010726.

6 REPLIES 6
Read only

SimoneMilesi
Active Contributor
0 Likes
1,816

Select-option is fine, it's your code to be wrong: put a break point here


IF p_vkunr IS INITIAL.

and check the content of p_vkunr as well the one of p_vkunr[] in debug and you'll guess the error (and the solution).

This should be the first thing you have to do when you face problem in your code.

Another thing: pay attention about words.

The select returns different records not fields

Read only

sab125
Participant
0 Likes
1,816

Hello

Obviously, there is an issue on performance for this query.

Try to split the select into smaller one.

Sab

Read only

Former Member
0 Likes
1,816

That I would not say in general. If your database has a good optimizer, is well defined and you have created indexes wisely, the database will win the race.

Read only

Former Member
0 Likes
1,817

I guess the JOIN on VBAK and KNVP returns no result. So the IN-operator is ignored by the main SELECT and you have no limitation on VBELN.

So, check first if the sub-select should return some values for your searched range.

The route cause of your problem could be also the domain definition, if it uses ALPHA conversion for example. Maybe your SELOPT says: get range from 10410 to 10726, but it should say e.g.: 00010410 to 00010726.

Read only

0 Likes
1,816

Yes. There was a problem with the join. I corrected it.

And in the end for extra precaution before it displayed the list, I used DELETE FROM it_table WHERE kunnr = p_vkunr. It worked.

Read only

ThomasZloch
Active Contributor
0 Likes
1,816

Only commenting on the P_VKUNR part, you should include table VAKPA in the join to find sales orders for partner numbers, then you could remove the awkward subquery and the IF/ELSE construct. Maybe it solves the reported issue as well.

See note 185530 for SD performance tips.

Thomas