09-28-2007 7:22 AM
Hi,
I have the following requirement
I have a table with two columns Amount and Quantity
Amount Quantity
0 34
4 76
7 30
5 52
Here is the requirement
When there is 0 in Amount column in FIRST record, then I have to update Amount field by replacing index 1 value of Amount wthl index2 value of Amount
Index 2 value with Index 3 value etc and fill index n value with 9.99. AndQuantity should remain the same.
Output should look like this.
Amount Quantity
4 34
7 76
5 30
9.99 52
Can anyone help me on this. Thanks in advance.
-Padma
09-28-2007 7:36 AM
hi ,
please check this following coding ..
REPORT Z0322_UPGRATE.
data : begin of wa_sample,
amount type i,
quantity type i,
end of wa_sample.
data : s type i.
data : it_sample like table of wa_sample with header line,
it_sample1 like table of wa_sample with header line.
it_sample-amount = 0.
it_sample-quantity = 34.
append it_sample.
it_sample-amount = 4.
it_sample-quantity = 76.
append it_sample.
it_sample-amount = 7.
it_sample-quantity = 30.
append it_sample.
it_sample-amount = 5.
it_sample-quantity = 52.
append it_sample.
loop at it_sample.
write : / it_sample-amount , it_sample-quantity.
endloop.
write /: 'AFTER '.
loop at it_sample.
if sy-tabix <> 1.
it_sample1-amount = it_sample-amount.
it_sample1-quantity = s.
append it_sample1.
endif.
s = it_sample-quantity.
endloop.
loop at it_sample1.
write : / it_sample1-amount , it_sample1-quantity.
endloop.
send me if u get any error.
thanks,
baskaran.
09-28-2007 7:27 AM
Columns are not displayed with right space justification.
Actual table:
Amount Field contains
0
4
7
5
Output for Amound field should be
4
7
5
9.99
Actual Quantity Field values: should remain the same in the output as well
34
76
30
52
Thanks,
Padma
09-28-2007 7:32 AM
if say itab contains fields-amt and quan and ur itab has the values which u said-
data: itab2 like itab..
data: gv_quan.
clear gv_quan.
loop at itab.
if gv_quan is not initial.
itab2-amt = itab-amt.
itab2-quan = gv_quan.
append itab2.
clear gv_quan.
endif.
if itab-amt eq 0.
gv_quan = itab-quan.
continue.
endif.
endloop.
now ur itab2 will have the format u required..
hope this helps
09-28-2007 7:36 AM
hi ,
please check this following coding ..
REPORT Z0322_UPGRATE.
data : begin of wa_sample,
amount type i,
quantity type i,
end of wa_sample.
data : s type i.
data : it_sample like table of wa_sample with header line,
it_sample1 like table of wa_sample with header line.
it_sample-amount = 0.
it_sample-quantity = 34.
append it_sample.
it_sample-amount = 4.
it_sample-quantity = 76.
append it_sample.
it_sample-amount = 7.
it_sample-quantity = 30.
append it_sample.
it_sample-amount = 5.
it_sample-quantity = 52.
append it_sample.
loop at it_sample.
write : / it_sample-amount , it_sample-quantity.
endloop.
write /: 'AFTER '.
loop at it_sample.
if sy-tabix <> 1.
it_sample1-amount = it_sample-amount.
it_sample1-quantity = s.
append it_sample1.
endif.
s = it_sample-quantity.
endloop.
loop at it_sample1.
write : / it_sample1-amount , it_sample1-quantity.
endloop.
send me if u get any error.
thanks,
baskaran.
09-28-2007 8:17 AM