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

Data Retrieval mismatch (MSKA)

jogeswararao_kavala
Active Contributor
0 Likes
2,607

Dear Experts,

Please see the code below.

(This is while debugging with single material code)

select matnr lgort charg sobkz kalab from mska into corresponding fields of table it_mska

for all entries in itab where  matnr = itab-matnr and lgort = 'XYZ1' and sobkz = 'E'.

This code gives me 6 rows, but when I query table MSKA (SE16) with same inputs, it gives me 23 lines.

This is happening with almost all material codes.

Then when I hardcode the matnr value in the code for testing, it returns all the 23 values.

select matnr lgort charg sobkz kalab from mska into corresponding fields of table it_mska

for all entries in itab1

where  matnr = '000019876123456789' and lgort = 'XYZ1' and sobkz = 'E'.


Why so?

Jogeswara Rao K

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,519

Add the max key fields of table mska to your select statement

like  VBELN , POSNR

Modify the code like this

select matnr lgort charg sobkz kalab vbeln posnr from mska into corresponding fields of table it_mska

for all entries in itab where  matnr = itab-matnr and lgort = 'XYZ1' and sobkz = 'E'.

(it_mska structure to be modified accordingly)

Regards

Rakhee Prabhu

Dear Experts,

Please see the code below.

(This is while debugging with single material code)

select matnr lgort charg sobkz kalab from mska into corresponding fields of table it_mska

for all entries in itab where  matnr = itab-matnr and lgort = 'XYZ1' and sobkz = 'E'.

This code gives me 6 rows, but when I query table MSKA (SE16) with same inputs, it gives me 23 lines.

This is happening with almost all material codes.

Then when I hardcode the matnr value in the code for testing, it returns all the 23 values.

select matnr lgort charg sobkz kalab from mska into corresponding fields of table it_mska

for all entries in itab1

where  matnr = '000019876123456789' and lgort = 'XYZ1' and sobkz = 'E'.


Why so?

Jogeswara Rao K

9 REPLIES 9
Read only

Former Member
0 Likes
2,520

Add the max key fields of table mska to your select statement

like  VBELN , POSNR

Modify the code like this

select matnr lgort charg sobkz kalab vbeln posnr from mska into corresponding fields of table it_mska

for all entries in itab where  matnr = itab-matnr and lgort = 'XYZ1' and sobkz = 'E'.

(it_mska structure to be modified accordingly)

Regards

Rakhee Prabhu

Read only

0 Likes
2,519

Thank you both Rakhee and Vijay,

I've just tested and found issue solved.

This is good learning for me.

Jogeswara Rao K

Read only

matt
Active Contributor
0 Likes
2,519

Here's some more tips

1. Rewrite as an INNER JOIN, instead of FAE, and see the benefits.

2. NEVER EVER use itab as the name of a internal table. Use meaningful variable names.

Read only

0 Likes
2,519

Thank you for tips

itab is used in the example. We use git_ prefixes.

Jogeswara Rao K

Read only

matt
Active Contributor
0 Likes
2,519

Only if it's global. And you do know that the fewer global variables the better?

Read only

0 Likes
2,519

OK, thanks again.

Read only

Former Member
0 Likes
2,519

hello,

When you use for all entries it always gives you unique records according to your selection.

In a select query you didn't get all primary key fields.

whereas when you goto to se16, system always considers all primary keys and returns 23 lines.

So use all primary fields in your select query

Regards,

Vj

Read only

Former Member
0 Likes
2,519

Dear  Jogeswara,

Please pass all key fields on your select queries

SELECT MATNR WERKS LGORT CHARG SOBKZ VBELN POSNR

             FROM MSKA INTO TABLE GT_MSKA

             XXXXXX.

Because,duplicates entries are deleting internally that's what you are not getting all the entries.

Thanks and Regards,

buz_sap

Read only

0 Likes
2,519

Thank you