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 statement not working properly....

Former Member
0 Likes
2,081

Hi friends...

here is a problem....this is in an interface... i'll download the data from SAP to a flat file...

i have the code like this...it is not working properly..

data: begin of i_md occurs 0,

matnr like mara-matnr,

component like stpo-idnrk,

mguide like stpo-idnrk,

...................

end of i_md.

data: begin of i_md2 occurs 0,

idnrk like stpo-idnrk,

end of i_md2.

data: str1(2) type c value 'O',

str1(2) type c value 'OP',

str1(2) type c value 'M',

str1(2) type c value 'MP'.

.......................................

....................................

perform get_component.

................................

..............................

form get_component.

if not i_md[] is initial.

select d~idnrk into i_md2-idnrk

from stpo as d

inner join stko as c

on dstlnr = cstlnr

inner join mast as b

on cstlnr = bstlnr

inner join mara as a

on bmatnr = amatnr

for all entries IN i_md

where a~matnr = i_mdata-matnr

and ( a~matkl = 'OST' or

a~matkl = 'OSP' )

and ( a~mtart = 'FERT' or

a~mtart = 'HAWA' )

and c~stktx = 'UNRESTRICTED'.

endselect.

endif.

if ( i_md2-idnrk cs str1 ) or ( i_md2-idnrk cs str2 ).

write i_md2-idnrk to i_md-component

no-zero left-justified.

elseif ( i_md2-idnrk cs str3 ) or ( i_md2 cs str4 ).

write i_md2-idnrk to i_md-mguide

no-zero left-justified.

endif.

endform. "get_component

...................................

......................................

transfer i_md to file1.

........................

.....................

my question is: when i debug the program for the form <b>"get_component"</b>, i could able to see the material numbers, but there is nothing coming up for the fields :

i_md-component and i_md-mguide.

could you plz tell me wt is the problem.?

thanks,

11 REPLIES 11
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,144

That form really doesn't make any sense to me. You are doing a SELECT ENDSELECT and putting value into I_MD2-IDNRK.. But you are also using FOR ALL ENTRIES in I_MD. Do you want to get a single component, mulitple? what?

Regards,

Rich Heilman

Read only

0 Likes
1,144

rich,

i want to get multiple values .....the thing is i have to use the material number of the I_MD internal table only for retrieving the components.

plz let me know if anything's not clear...

thnx

Read only

0 Likes
1,144

Hi,

Try this.

select stpo~idnrk

into table i_md2

from stpo

inner join stko

on stpostlnr = stkostlnr

*inner join mast

*on stpostlnr = maststlnr

inner join mara

on stpoidnrk = maramatnr

for all entries IN i_md

where mara~matnr = i_md-matnr

and mara~matkl in ('OST', 'OSP')

and mara~mtart in ('FERT', 'HAWA')

and stko~stktx = 'UNRESTRICTED'.

Read only

0 Likes
1,144

Hi Sey,

The select atatement attached by me (earlier) is working fine for me. It is populating multiple entries in I_MD2 table.

Please make sure that the <u>materials</u> in internal table I_MD <u>contains BOM</u>. Means Entries in STKO and STPO.

select d~idnrk

into table i_md2

from stpo as d

inner join stko as c

on dstlnr = cstlnr

inner join mast as b

on cstlnr = bstlnr

inner join mara as a

on bmatnr = amatnr

for all entries IN i_md

where a~matnr = i_md-matnr

and ( a~matkl = 'OST' or

a~matkl = 'OSP' )

and ( a~mtart = 'FERT' or

a~mtart = 'HAWA' )

and c~stktx = 'UNRESTRICTED'.

Lanka

Read only

0 Likes
1,144

hi phani,

its still coming like that only...

is the select statement wrong?

Read only

0 Likes
1,144

Hi Sey,

The select atatement attached by me (earlier) is working fine for me. It is populating multiple entries in I_MD2 table.

Please make sure that the materials in internal table I_MD contains BOM. Means Entries in STKO and STPO.

select d~idnrk

into table i_md2

from stpo as d

inner join stko as c

on dstlnr = cstlnr

inner join mast as b

on cstlnr = bstlnr

inner join mara as a

on bmatnr = amatnr

for all entries IN i_md

where a~matnr = i_md-matnr

and ( a~matkl = 'OST' or

a~matkl = 'OSP' )

and ( a~mtart = 'FERT' or

a~mtart = 'HAWA' )

and c~stktx = 'UNRESTRICTED'.

Lanka

Read only

Former Member
0 Likes
1,144

Hi,

When you are using for all entries for table i_md

then your where condition should have that table field..

change as

<b>for all entries IN i_md

where a~matnr = i_md-matnr</b>

OR change your select as..

select stpo~idnrk

into i_md2-idnrk

from stpo

inner join stko

on stpostlnr = stkostlnr

inner join mast

on stkostlnr = maststlnr

inner join mara

on mastmatnr = maramatnr

for all entries IN i_md

where mara~matnr = i_md-matnr

and mara~matkl in ('OST', 'OSP')

and mara~mtart in ('FERT', 'HAWA')

and stko~stktx = 'UNRESTRICTED'.

endselect.

Message was edited by: Phani Kiran Nudurupati

Read only

0 Likes
1,144

Hi Phani..

thnx...

actually it is <b>"for all entries IN i_md

where a!matnr = i_md-matnr"</b>...

sorry i have written wrongly in the mail...

plz tell me...even if it is like that also..it is not coming....

thnx

Read only

0 Likes
1,144

Hi,

Change the select like below...

select stpo~idnrk

into i_md2-idnrk

from stpo

inner join stko

on stpostlnr = stkostlnr

inner join mast

on stpostlnr = maststlnr

inner join mara

on stpoidnrk = maramatnr

for all entries IN i_md

where mara~matnr = i_md-matnr

and mara~matkl in ('OST', 'OSP')

and mara~mtart in ('FERT', 'HAWA')

and stko~stktx = 'UNRESTRICTED'.

endselect.

Read only

0 Likes
1,144

Hi Sey,

As Rich mentioned What you need a single record or all records.

Try this :

select d~idnrk

into table i_md2

from stpo as d

inner join stko as c

on dstlnr = cstlnr

inner join mast as b

on cstlnr = bstlnr

inner join mara as a

on bmatnr = amatnr

for all entries IN i_md

where a~matnr = i_md-matnr

and ( a~matkl = 'OST' or

a~matkl = 'OSP' )

and ( a~mtart = 'FERT' or

a~mtart = 'HAWA' )

and c~stktx = 'UNRESTRICTED'.

The above code fill internal table i_md2.

Lanka

Read only

0 Likes
1,144

Hi,

still it is not showing up anything for those 2 fields...

plz tell me is ther anything other wrong?

Rich,

I have to get multiple values....

thnx