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

internal table question?

Former Member
0 Likes
1,115

Hi,

1)i have internal table with material ,plant , stlal fields.

for same material and plant ...stlal has different values.

so i have select the material and plant which has minimum stlal value.

please tell how to select the value ..or pls give me sample code.

2) i have internal table with material number and plant.

There may be more than on material for same plant.

so i have to pass material numbers and plant to other program based on plant wise.

please give me sample code ... other program has selection screen which has material number as selection option and plant as parameter.

i have to use submit statement for this condition.

please help by giving sample code

thanks

satish

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,087

Ans1. Suppose ur internal table name is itab containing 3 fields matnr,werks,stlal.Now u want the mat and plant with min stlal value.heres the code

sort itab by stlal descending.

read table itab into ls_tab index 1.

Now ls_tab is a work area which will contain the material and plant values which has min stlal value.

Ans2.

Declare a range table lt_matnr for all the material no corresponding to the plant.

Now

Loop at itab into ls_tab where plant = lv_plant.

ls_matnr-sign = 'I'.

ls_matnr-option='EQ'.

ls_matnr-low = ls_tab-matnr.

Append ls_matnr to lt_matnr.

Clear ls_matnr,ls_tab.

Endloop.

so now lt_matnr will contain all the matnr corresponding to each plant.

thanks,

ashish.

11 REPLIES 11
Read only

Former Member
0 Likes
1,088

Ans1. Suppose ur internal table name is itab containing 3 fields matnr,werks,stlal.Now u want the mat and plant with min stlal value.heres the code

sort itab by stlal descending.

read table itab into ls_tab index 1.

Now ls_tab is a work area which will contain the material and plant values which has min stlal value.

Ans2.

Declare a range table lt_matnr for all the material no corresponding to the plant.

Now

Loop at itab into ls_tab where plant = lv_plant.

ls_matnr-sign = 'I'.

ls_matnr-option='EQ'.

ls_matnr-low = ls_tab-matnr.

Append ls_matnr to lt_matnr.

Clear ls_matnr,ls_tab.

Endloop.

so now lt_matnr will contain all the matnr corresponding to each plant.

thanks,

ashish.

Read only

0 Likes
1,087

I have seen answer suggested by Ashish.

Question 2 is answered correctly.

For question 1

select matnr werks stlal into itab.

sort itab.

delete adjacent duplicates from itab comparing matnr werks.

This will delete duplicate entries from itab for each material and plat. As this is sorted ascending first record will contain min value for STLAL and this is your requirement.

In itab declaration, field sequence should be MATNR WERKS STLAL.

Read only

0 Likes
1,087

hi ashish d,

thanks for your answer...how to declare ranges can u pls given example...

thanks

satish

Read only

0 Likes
1,087

ranges: r_matnr for mara-matnr.

This is the way you declare ranges.

Read only

0 Likes
1,087

HI,

how to write full code..i m getting error..

ranges : ls_matnr for mara-matnr.

Loop at itab into ls_tab where plant = lv_plant.

ls_matnr-sign = 'I'.

ls_matnr-option='EQ'.

ls_matnr-low = ls_tab-matnr.

Append ls_matnr to lt_matnr.

Clear ls_matnr,ls_tab.

Endloop.

wt is ls_tab...wt is lv_plant..

can u pls explain..

please

thanks

satish

Read only

0 Likes
1,087

ranges : ls_matnr for mara-matnr.

Loop at itab into ls_tab where plant = lv_plant.

ls_matnr-sign = 'I'.

ls_matnr-option='EQ'.

ls_matnr-low = ls_tab-matnr.

Append ls_matnr.

Clear ls_matnr.

Endloop.

This will populate all material values to ranges LS_MATNR which you can pass to other program. It will act as a select option.

Read only

0 Likes
1,087

hi,

wr will we get the value of lv_plant ? in internal table of i have plant ,material number values..

please explain..i m fresher...i m doing one samll example ..please

Read only

Former Member
0 Likes
1,087

one more doubt

Read only

0 Likes
1,087

You have internal table with plant and material. One Plant can have multiple Material entries.

So for the Plant entry of internal table, you are populating all materials into ranges.

Read only

0 Likes
1,087

ya that is correct. How i will get the value of lv_plant from internal table.

thanks

satish

Read only

KN-Nampoothiry
Active Participant
0 Likes
1,087

Hi Dude,

as said above in all posts, once you sort the itab ascending based on the stlal value, the entry with the least stlal value is on top.

So use this.

data : wa_itab type itab. " To decalre a work area in case your itab has no header line.

then

sort itab asecnding by stlal.
read table itab into wa_itab index 1.
lv_palnt = wa_itab-plant

.

if your itab has header line then code chabges as :

sort itab asecnding by stlal.
read table itab  index 1.
lv_palnt = itab-plant.

Reward if useful.