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

Logic required for select query

Former Member
0 Likes
890

i have a internal table with 4 columns. 3 columns having varrious material numbers. i want to check every material with mara table. its available or not?

I need to write a single select queary? how to do this?

My internal table looks like

matnr idnrk s_idnrk normt

test10 10UPC3050 F14839030 test.

i wrotes like below

select matnr from mara into table

i_mara2 for all entries in

i_sub_file

where matnr = i_sub_file-matnr and

matnr = i_sub_file-idnrk and

matnr = i_sub_file-s_idnrk.

Its not working, How to manage this? Anyone help this.

Mohaha

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
857

Hi Mohaha.

TRY:

select matnr from mara into table

i_mara2 for all entries in i_sub_file

where matnr = i_sub_file-matnr.

I think this works

Gr. Frank.

8 REPLIES 8
Read only

Former Member
0 Likes
857

Create 1 ranges TYPE of Matnr.

Append all your 3 fields material into the ranges.

Then just use IN in the select statements

like e.g

select matnr from mara

into table i_mara2

where matnr IN rg_matnr.

Read only

former_member222860
Active Contributor
0 Likes
857

What's the error your getting?

May be there's no data for the given where condition.

pl.check your master table: MARA

Read only

Former Member
0 Likes
857

hi,

loop at internal table.

insert the values of three columns of material nos into one internal table with field matnr.

select from matnr where mara in internal table.

now u can check with the first internal table value.

process ...

endloop.

Read only

Former Member
0 Likes
857

Hi

Write three select singles in loop.

For each material one select single.

or

First take all this material into one internal table and fetch the

all meterial data from MARA.

then in loop use read statement on internal table three times.

Read only

Former Member
0 Likes
858

Hi Mohaha.

TRY:

select matnr from mara into table

i_mara2 for all entries in i_sub_file

where matnr = i_sub_file-matnr.

I think this works

Gr. Frank.

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
857

Hi,

Use something like:-


tables : mara.
ranges : r_matnr for mara-matnr.

loop at itab.
  r_matnr-sign = 'I'.
  r_matnr-option = 'EQ'.
  r_matnr-low = itab-matnr.
  append r_matnr.

  r_matnr-sign = 'I'.
  r_matnr-option = 'EQ'.
  r_matnr-low = itab-idnrk.
  append r_matnr.

  r_matnr-sign = 'I'.
  r_matnr-option = 'EQ'.
  r_matnr-low = itab-s_idnrk.
  append r_matnr.
endloop.

select matnr from mara into it_matnr where matnr in r_matnr.
"you will get all matnr for all matnr in itab.

loop at itab.
  if not itab-matnr in r_matnr.
    "code
  elseif not itab-idnrk in r_matnr.
    "code
  elseif not itab-s_idnrk in r_matnr.
    "code
  endif.
endloop.

Hope this helps you.

Regards,

Tarun

Read only

Former Member
0 Likes
857

make one more internaltable say itab1.

select matnr from mara into table itab1.

now loop at i_sub_file.

read table itab1 with key matnr = ( i_sub_file-idnrk Or i_sub_file-idnrk-matnr Or..)

if sy-subrc = 0.

entry exist.

else.

not exist.

endloop.

thanks & Regards,

Ruchi Tiwari

Read only

Former Member
0 Likes
857

Hi fill the ranges with ur 3 material numbers.

and use it in ur select query.

define a range for mat no.

ranges : r_matnr for mara-matnr.

read table or loop with i_sub_file.

r_matnr-sign = 'I'.

r_matnr-option = 'EQ'.

r_matnr-low = 'i_sub_file-matnr.

append r_matnr. clear r_matnr.

r_matnr-sign = 'I'.

r_matnr-option = 'EQ'.

r_matnr-low = 'i_sub_file-idnrk.

append r_matnr. clear r_matnr.

r_matnr-sign = 'I'.

r_matnr-option = 'EQ'.

r_matnr-low = 'i_sub_file-s_idnrk.

append r_matnr. clear r_matnr.

now in select.

select matnr from mara into table

i_mara2 where matnr in r_matnr.