‎2009 Nov 21 5:15 AM
Hello Experts...<br><br>
I HAVE SUCH SCENERIO....( please condider me as new in control break statement)....
<br><br>
<pre>
shipment number container type unit ocean freight
2030 20GO 1 30000
2030 20GO 1 30000
2030 42GO 2 30000
2030 45GO 2.25 30000
2030 45GO 2.25 30000
1998 20GO 1 15000
1998 42GO 2 15000
1998 42GO 2 15000
1998 45GO 2.25 15000 </pre><br><br>
OUTPUT SHOULD BE.....
<br><br><pre>
TOTAL UNIT FOR 2030 IS 1122.252.25 = 8.5
TOTAL UNIT FOR 1998 IS 122+2.25= 7.25
shipment number container type container count ocean freight container wise
2030 20GO 2 ( 30000 / 8.5 ) * 2 * 1
2030 42GO 1 ( 30000 / 8.5 ) * 1 * 2
2030 45GO 2 ( 30000 / 8.5 ) * 2 * 2.25
1998 20GO 1 ( 15000 / 7.27) * 1 * 1
1998 42GO 2 ( 15000/ 7.25 ) * 2 * 2
1998 45GO 1 ( 15000/ 7.25) * 1 * 2.25</pre><br><br>
I WRITE CODE BUT NOT WORKING PROPERLY...
<br><br>
<pre>LOOP AT it_name.
IF it_name-matkl = '20G0'.
z_unit = z_unit + 1.
ELSEIF it_name-matkl = '42G0'.
z_unit1 = z_unit1 + 2.
ELSEIF it_name-matkl = '45G0'.
z_unit2 = z_unit2 + '2.25'.
ENDIF.
AT END OF matkl.
z_unit_tot = z_unit + z_unit1 + z_unit2.
ENDAT.
AT END OF tknum.
it_total-con_tot = z_unit_tot.
it_total-tknum = it_name-tknum.
APPEND it_total.
CLEAR it_total.
CLEAR: z_unit_tot,z_unit,z_unit1,z_unit2 .
ENDAT.
ENDLOOP.
CLEAR z_count.
SORT it_final8 BY tknum matkl.
SORT it_final8 BY tknum .
LOOP AT it_name .
READ TABLE it_total WITH TABLE KEY tknum = it_name-tknum.
IF sy-subrc = 0.
IF it_name-add01 = 'CC'.
SELECT zzploffinaldeliv
add01
zzstuffingdate
matkl
lifnr
netwr
FROM zbrokrage INTO CORRESPONDING FIELDS OF TABLE it_cc
FOR ALL ENTRIES IN it_name
WHERE zzploffinaldeliv = it_name-zzploffinaldeliv AND
add01 = 'PP' AND
zzstuffingdate = it_name-zzstuffingdate AND
lifnr = it_name-lifnr.
READ TABLE it_final8 WITH KEY matkl = it_name-matkl.
IF sy-subrc = 0.
it_final-name1 = it_name-name1.
it_final-tplst = it_name-tplst.
it_final-matkl = it_name-matkl.
z_var = it_cc-netwr.
it_final-netwr = z_var.
z_count = z_count + 1.
AT END OF matkl.
*
it_final-tknum = it_name-tknum.
it_final-netwr = z_var.
it_final-exti1 = it_name-exti1.
it_final-zzstuffingdate = it_name-zzstuffingdate.
it_final-zzploffinaldeliv = it_name-zzploffinaldeliv.
it_final-add01 = it_name-add01.
it_final-matkl = it_name-matkl.
it_final-count = z_count.
z_test = z_count.
z_mat = it_name-matkl.
IF it_name-matkl = '20G0'.
z_count1 = z_unit_1 * z_count.
z_total = ( z_var / it_total-con_tot ) * z_count1 * z_unit.
ELSEIF it_name-matkl = '42G0'.
z_count2 = z_unit_2 * z_count.
z_total = ( z_var / it_total-con_tot ) * z_count2 * z_unit1.
ELSEIF it_name-matkl = '45G0'.
z_count3 = z_unit_3 * z_count.
z_total = ( z_var / it_total-con_tot ) * z_count3 * z_unit2.
ENDIF.
z_total = ( z_var / z_unit_tot ) * z_count.
z_brokrage = ( z_total * p_bra ) / 100.
it_final-tot_fr = z_total.
it_final-brokerage = z_brokrage.
APPEND it_final.
CLEAR it_final.
CLEAR z_count.
CLEAR z_count1.
CLEAR z_count2.
CLEAR z_count3.
CLEAR z_total.
CLEAR z_var.
ENDAT.
ENDIF.
*IF Z_COUNT LE 1.
EXIT.
ENDIF.
ENDIF.
ELSEIF it_name-add01 = 'PP'.
READ TABLE it_final8 WITH KEY matkl = it_name-matkl.
IF sy-subrc = 0.
it_final-name1 = it_name-name1.
it_final-tplst = it_name-tplst.
it_final-matkl = it_name-matkl.
z_var = it_name-netwr.
it_final-netwr = z_var.
z_count = z_count + 1.
AT END OF matkl.
*
it_final-tknum = it_name-tknum.
it_final-netwr = z_var.
it_final-exti1 = it_name-exti1.
it_final-zzstuffingdate = it_name-zzstuffingdate.
it_final-zzploffinaldeliv = it_name-zzploffinaldeliv.
it_final-add01 = it_name-add01.
it_final-matkl = it_name-matkl.
it_final-count = z_count.
z_test = z_count.
z_mat = it_name-matkl.
IF it_name-matkl = '20G0'.
z_count1 = z_unit_1 * z_count.
z_total = ( z_var / it_total-con_tot ) * z_count1.
ELSEIF it_name-matkl = '42G0'.
z_count2 = z_unit_2 * z_count.
z_total = ( z_var / it_total-con_tot ) * z_count2.
ELSEIF it_name-matkl = '45G0'.
z_count3 = z_unit_3 * z_count.
z_total = ( z_var / it_total-con_tot ) * z_count3.
ENDIF.
z_total = ( z_var / z_unit_tot ) * z_count.
z_brokrage = ( z_total * p_bra ) / 100.
it_final-tot_fr = z_total.
it_final-brokerage = z_brokrage.
APPEND it_final.
CLEAR it_final.
CLEAR z_count.
CLEAR z_count1.
CLEAR z_count2.
CLEAR z_count3.
CLEAR z_total.
CLEAR z_var.
ENDAT.
ENDIF.
*IF Z_COUNT LE 1.
EXIT.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDAT.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM it_final COMPARING ALL FIELDS.
</pre><br><br>
thanks<br>
sparsh
<br><br><br>Edited by: Matt on Nov 21, 2009 4:43 PM - formatted
‎2009 Nov 21 6:19 AM
‎2009 Nov 21 6:19 AM
‎2009 Nov 21 3:50 PM
Basic rule of programming. Select your data first. Then perform calculations on it. Then display it. Do not combine these actions, as it leads to complicated code that is hard to work with.
Your hard coding of 20G0 etc. is plain wrong. What will you do if another container type comes in? Will the program have to be rewritten?
Is this an exercise from your ABAP class?
A few hints. Once you've got your data into an internal table, calculate totals into an internal table, with two fields. SHIPMENT_NO and TOTAL_UNITS. Use this to keep track of the totals.
Make sure your input table is sorted by SHIPMENT_NUMBER CONTAINER_TYPE.
You should be able to get your output quite simply with a few passes through the data.
By the way. When posting code - only post the relevant parts. And certainly DON'T post commented out code! Also use a meaningful subject in future and DON'T post the same question more than once. DO read the Rules of Engagement before posting further.
matt
Edited by: Matt on Nov 21, 2009 4:51 PM
‎2009 Nov 23 5:29 AM
hi friend
The following code is depicted without the using of control break,
Thanks & Regards
Surender
it_tab1[] = it_tab[].
sort it_tab1 by shipment.
delete adjacent duplicates from it_tab1 comparing shipment.
loop at it_tab1 into wt_tab1 .
clear : wt_res.
read table it_tab transporting no fields with key shipment = wt_tab1-shipment binary search.
if sy-subrc eq 0.
loop at it_tab into wt_tab from sy-tabix.
if wt_tab-shipment ne wt_tab1-shipment.
exit.
endif.
wt_res-unit = wt_res-unit + wt_tab-unit.
flag = 1.
endloop.
if flag = 1.
wt_res-shipment = wt_tab1-shipment.
append wt_res to it_res.
clear flag.
endif.
clear: wt_tab,
wt_tab1,
endloop.