Application Development 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: 

Data Fetch in Internal Table

Former Member
0 Kudos

HI ALL,

i have a prob in displaying the records

i have got the records in the internal table. the records which r there in my criteria has the follw . strct.

matnr plant month stock

001 xxx 2 15

001 xxx 6 5

i m getting these values but i just wat the values like tis,

matnr plant apr may june jul aug sep

001 xxx 0 15 5

plzz help me out..

thanxx

Edited by: NILESH S. on Oct 3, 2008 1:56 PM

17 REPLIES 17

former_member182426
Active Contributor
0 Kudos

hi,

u declare two itabs. and in one itab store that matnr and remaining details.

and one more ITAB store that months Matnr, JAN, FEB,MAR,.....DEC.

while displaying.

Loop at itab1

read table itab2 with key itab2-matnr = itab1-matnr.

write: itab1-matnr, itab1-desc, itab2-mar,itab2-apr.....

endloop.

Regards,

Shankar.

Former Member
0 Kudos

Declare your table structure with 12 seperate month fields.

When you select your data, put the stock value of a month in the appropriate month field.

No need for 2 tables.

Edited by: Maen Anachronos on Oct 3, 2008 2:03 PM

0 Kudos

it will be very helpful if both these answers will be in detailed for...

thanx....

0 Kudos

Declare your table structure with 12 seperate month fields.

When you select your data, put the stock value of a month in the appropriate month field.

No need for 2 tables.

Edited by: Maen Anachronos on Oct 3, 2008 2:03 PM

i had tried this but for 1 material if i select 3 months it will be displayed 3 times in the table & so on the o/p screen....

0 Kudos

I don't know how your program looks like. But apparently your doing an append for each record found.

Select all months for a material, distribute the month values into their corresponding month field and then do an append.

0 Kudos

thats what i want in little details..

0 Kudos

>

> thats what i want in little details..

Select all months for a material, distribute the month values into their corresponding month field and then do an append.

0 Kudos

c im doing this...

i have foll. struct .

tell me where to place append

select a b c

select matnr......

select werks matnr lfmon ...

by if cond.

apr = the value.

i.e. sending values into corresponding months..

append itab.

endselect.

endselect

endselect.

if i placed apend after 1st endselect its giving me unwanted matnr...

so what to do now...?

0 Kudos

Hint: use sy-subrc after the first endselect.

Former Member
0 Kudos

Hi,

Create an internal table with header line say it_tabl2 with the fields as specified by you ie as matnr plant apr may june jul aug sep .

Say the internal table you have initially is it_table1 with header line. Do as follows

loop at it_table1.

it_tabl2-matnr = it_table1-matnr.

it_tabl2-plant = it_table1-plant.

case it_tabl2-month.

when '1'.

it_tabl2-jan = it_table1-stock.

when '2'.

it_tabl2-feb = it_table1-stock.

when '3'.

it_tabl2-mar = it_table1-stock.

....

.....

....

when '5'.

it_tabl2-may = it_table1-stock.

....

.....

...

endcase.

append it_tabl2-jan .

clear it_table1.

endloop.

Now display the contents of the internal table it_tabl2 in which ever way you want.

Hope this helps you.

Regards,

Murthy.

Edited by: pr murthy on Oct 3, 2008 2:08 PM

0 Kudos

sorry ,

its not correct its giving me only the first record...

0 Kudos

can i have the second option in details plz.....

0 Kudos

Dear Nilesh,

Why my code will give only first record correct. Its going to give result as I have written my logic inside a loop, not just for first record.

sorry ,
its not correct its giving me only the first record...

By the way I am not here to be judjed by you dear friend, I may not be able to get your requirement correct, but I am sure my code is going to work for your requirement. You must explaine if you think I did not get your requirement correct.

Regards,

Murthy.

Edited by: pr murthy on Oct 3, 2008 2:56 PM

vinod_vemuru2
Active Contributor
0 Kudos

Hi Nilesh,

No need to change ur whole logic. Check this code.


SORT itab BY matnr werks.
WRITE: /1 'matnr'
              20 ' plant'
             25 'Jan'
             35 'Feb
.
.
.
            135 'Dec'.
             may june jul aug sep  " Give the positions appropriately(As per ur field length)

LOOP AT itab INTO wa.
AT NEW werks.
WRITE: /1 wa-matnr,
              20 wa-werks.
ENDAT.
CASE wa-month.
WHEN '1'.
WRITE: 25 wa-stock.
WHEN '2'.
WRITE: 35 wa-stock.
.
.
.
WHEN '12'.
WRITE: 135 wa-stock.
ENDCASE.
ENDLOOP.

This surely solves ur problem.

Changed AT END OF to AT NEW:-)

Thanks,

Vinod.

Edited by: Vinod Reddy Vemuru on Oct 3, 2008 6:46 PM

Former Member
0 Kudos

the only prob with this solution is it is showing the 1st materail no 2 times for 2 months and showing both the values in the samr field of month (eg. may).

the remaining is working fine thanx.....a lot

0 Kudos

Hi Nilesh,

Since we are using the AT event wrt to plant(Werks) it is showing the material number more than once i.e once for the combination of material and plant. If u want to segregate the data at material level then use the AT END OF matnr instead of AT END OF werks.

U told quantity is printing at same month(May). For this either both plants has stock in May or u might be giving wrong positions in write statements. Check these and get back in case of any issues.

Thanks,

Vinod.

Former Member
0 Kudos

ok