2016 Apr 22 9:20 AM
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?
2016 Apr 22 9:54 AM
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.
2016 Apr 22 9:32 AM
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
2016 Apr 22 9:33 AM
Hello
Obviously, there is an issue on performance for this query.
Try to split the select into smaller one.
Sab
2016 Apr 22 9:47 AM
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.
2016 Apr 22 9:54 AM
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.
2016 Apr 22 2:24 PM
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.
2016 Apr 22 9:59 AM
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