‎2010 Feb 16 6:50 AM
Hi,
good day guys
i am getting a problem when iam doing the summing the values. Actually my itab got -ve values. Plz see my code, tell me is it wrong?
like:
>QTY Actsales Act cost
> -
- -
-
>1- 1000- 1000
>9 900 30-
>3- 300- 200
>8 100 200-
>Sort lt_machine_sales4 by ktgrm_d ascending.
loop at lt_machine_sales4 into lwa_out5.
at new ktgrm_d.
SUM.
if lwa_out5-sales_qty < 0.
lwa_out5-sales_qty = lwa_out5-sales_qty * -1. "qty values
endif.
if lwa_out5-act_sales_p < 0.
lwa_out5-act_sales_p = lwa_out5-act_sales_p * -1. "act sales
endif.
if lwa_out5-act_cos_p < 0 .
lwa_out5-act_cos_p = lwa_out5-act_cos_p * -1. "act costs
endif.
lwa_out5-ACT_GROSS_P = lwa_out5-act_sales_p - lwa_out5-act_cos_p.
lwa_out5-act_gross_perc_p = ( lwa_out5-act_gross_p / lwa_out5-act_sales_p ) * 100.
append lwa_out5 to lt_machine_sales5.
clear:lwa_out5.
endat.
endloop.
Regards
Edited by: Rob Burbank on Feb 16, 2010 2:26 PM
‎2010 Feb 16 6:58 AM
Hi Balaji,
First you are doing sum and then checking if it is negative or not.
at new ktgrm_d.
if lwa_out5-sales_qty < 0.
lwa_out5-sales_qty = lwa_out5-sales_qty * -1. "qty values
endif.
if lwa_out5-act_sales_p < 0.
lwa_out5-act_sales_p = lwa_out5-act_sales_p * -1. "act sales
endif.
if lwa_out5-act_cos_p < 0 .
lwa_out5-act_cos_p = lwa_out5-act_cos_p * -1. "act costs
endif.
SUM. " Keep it here
lwa_out5-ACT_GROSS_P = lwa_out5-act_sales_p - lwa_out5-act_cos_p.
lwa_out5-act_gross_perc_p = ( lwa_out5-act_gross_p / lwa_out5-act_sales_p ) * 100.
append lwa_out5 to lt_machine_sales5.
clear:lwa_out5.
endat.
Regards,
Swarna Munukoti
Edited by: Swarna Munukoti on Feb 16, 2010 7:58 AM
‎2010 Feb 16 6:58 AM
Hi Balaji,
First you are doing sum and then checking if it is negative or not.
at new ktgrm_d.
if lwa_out5-sales_qty < 0.
lwa_out5-sales_qty = lwa_out5-sales_qty * -1. "qty values
endif.
if lwa_out5-act_sales_p < 0.
lwa_out5-act_sales_p = lwa_out5-act_sales_p * -1. "act sales
endif.
if lwa_out5-act_cos_p < 0 .
lwa_out5-act_cos_p = lwa_out5-act_cos_p * -1. "act costs
endif.
SUM. " Keep it here
lwa_out5-ACT_GROSS_P = lwa_out5-act_sales_p - lwa_out5-act_cos_p.
lwa_out5-act_gross_perc_p = ( lwa_out5-act_gross_p / lwa_out5-act_sales_p ) * 100.
append lwa_out5 to lt_machine_sales5.
clear:lwa_out5.
endat.
Regards,
Swarna Munukoti
Edited by: Swarna Munukoti on Feb 16, 2010 7:58 AM
‎2010 Feb 16 7:01 AM
Hi,
good Morning Swarna
Its not working...Plz advice me
Sort lt_machine_sales4 by ktgrm_d ascending.
loop at lt_machine_sales4 into lwa_out5.
AT new ktgrm_d.
if lwa_out5-sales_qty < 0.
lwa_out5-sales_qty = lwa_out5-sales_qty * -1.
ENDIF.
SUM.
lwa_out5-ACT_GROSS_P = lwa_out5-act_sales_p - lwa_out5-act_cos_p.
lwa_out5-act_gross_perc_p = ( lwa_out5-act_gross_p / lwa_out5-act_sales_p ) * 100.
append lwa_out5 to lt_machine_sales5.
clear:lwa_out5.
endat.
endloop.
‎2010 Feb 16 7:09 PM
‎2010 Feb 17 6:05 AM
Hi,
Thank you for reply.
My itab got data like as below as
QTY sales cost
---- ------- --------
10 2000- 2000
20- 3000 1000-
20- 1000- 800-
10 2000 1000
iam using AT New when iam doing the subtot , at that time its gives the prob due to -ve values
so ive used the lwa_out5-sales_qty = lwa_out5-sales_qty * -1. but its doesnt work out. so ive removed the code. Pls see the code. and plz let me know how to overcome the prob
SORT lt_machine_sales4 BY ktgrm_d.
LOOP AT lt_machine_sales4 INTO lwa_out5.
AT NEW ktgrm_d.
SUM.
lwa_out5-act_gross_p = lwa_out5-act_sales_p - lwa_out5-act_cos_p.
lwa_out5-act_gross_perc_p = ( lwa_out5-act_gross_p / lwa_out5-act_sales_p ) * 100.
WRITE lwa_out5-act_gross_perc_p TO lwa_out5-act_gross_perc NO-SIGN LEFT-JUSTIFIED DECIMALS 1.
IF lwa_out5-act_gross_p < 0.
CONCATENATE lwa_out5-act_gross_perc '%-' INTO lwa_out5-act_gross_perc.
ELSE.
CONCATENATE lwa_out5-act_gross_perc '%' INTO lwa_out5-act_gross_perc.
ENDIF.
**************BUDGET CALCULATION FOR GROSS PROFIT & GROSS PROFIT PERCENTAGE.
lv_bud_gross_p = lwa_out5-bud_sales_p - lwa_out5-bud_cos_p.
lwa_out5-bud_gross_perc_p = ( lv_bud_gross_p / lwa_out5-bud_sales_p * 100 ).
IF lwa_out5-bud_gross_perc_p NE 0.
WRITE lwa_out5-bud_gross_perc_p TO lwa_out5-bud_gross_perc LEFT-JUSTIFIED.
CONCATENATE lwa_out5-bud_gross_perc '%' INTO lwa_out5-bud_gross_perc SEPARATED BY space.
ENDIF.
*****************************************************************************
clear:lwa_out5-matkl_d,
lwa_out5-matnr.
APPEND lwa_out5 TO lt_machine_sales5.
CLEAR:lwa_out5.
ENDAT.
ENDLOOP.
‎2010 Feb 17 6:24 AM
Hi
while using AT NEW control stmt, you should remember that, all the right side values of that field will be getting " ** ". So it is better to move the work area data into another workare before writting AT NEW stmt.
It will solve ur pb.
Regards
Srinivas K
‎2010 Feb 17 6:31 AM
Hi,
thank you for reply.
Plz check my code. is it right?
loop at lt_machine_sales into lwa_out5.
lwa_out1 = lwa_out5.
At new ktgrm_d.
sum.
append lwa_out1 to lt_machine_sales1.
endat.
endloop.
‎2010 Feb 17 6:34 AM
‎2010 Feb 17 7:17 AM
Hi,
good day
Still it snot working. plz see once in my code..any prob
SORT lt_machine_sales4 BY ktgrm_d.
CLEAR: lwa_out5,
lwa_out1.
LOOP AT lt_machine_sales4 INTO lwa_out5.
lwa_out1 = lwa_out5.
AT NEW ktgrm_d.
if lwa_out1-sales_qty < 0.
lwa_out1-sales_qty = lwa_out1-sales_qty * -1.
endif.
SUM.
lwa_out1-act_gross_p = lwa_out1-act_sales_p - lwa_out1-act_cos_p.
IF lwa_out1-act_sales_p IS NOT INITIAL.
lwa_out1-act_gross_perc_p = ( lwa_out1-act_gross_p / lwa_out1-act_sales_p ) * 100.
ENDIF.
WRITE lwa_out1-act_gross_perc_p TO lwa_out1-act_gross_perc NO-SIGN LEFT-JUSTIFIED DECIMALS 1.
IF lwa_out1-act_gross_p < 0.
CONCATENATE lwa_out1-act_gross_perc '%-' INTO lwa_out1-act_gross_perc.
ELSE.
CONCATENATE lwa_out1-act_gross_perc '%' INTO lwa_out1-act_gross_perc.
ENDIF.
**************BUDGET CALCULATION FOR GROSS PROFIT & GROSS PROFIT PERCENTAGE.
lv_bud_gross_p = lwa_out1-bud_sales_p - lwa_out1-bud_cos_p.
IF lwa_out1-bud_sales_p IS NOT INITIAL.
lwa_out1-bud_gross_perc_p = ( lv_bud_gross_p / lwa_out1-bud_sales_p * 100 ).
ENDIF.
IF lwa_out1-bud_gross_perc_p NE 0.
WRITE lwa_out1-bud_gross_perc_p TO lwa_out1-bud_gross_perc LEFT-JUSTIFIED.
CONCATENATE lwa_out1-bud_gross_perc '%' INTO lwa_out1-bud_gross_perc SEPARATED BY space.
ENDIF.
*****************************************************************************
CLEAR:lwa_out1-matkl_d,
lwa_out1-matnr.
APPEND lwa_out1 TO lt_machine_sales5.
CLEAR:lwa_out1.
ENDAT.
ENDLOOP.
Thank you
‎2010 Feb 17 7:30 AM
Hi Balaji,
The SUM stmt will not work in AT NEW contrl stmt. It can only be used in AT END or AT LAST only. Kindly look into help by pressing F1.
The statement SUM can only be specified within a loop starting with LOOP, and is only considered within a AT- ENDAT control structure.
Change the control stmt.
Regards
Srinivas K
‎2010 Feb 17 8:36 AM
@Kaudri - Are you sure that SUM will not work in At new and At end. ???
@OP-
AT NEW ktgrm_d.
SUM.
lwa_out5-act_gross_p = lwa_out5-act_sales_p - lwa_out5-act_cos_p.
lwa_out5-act_gross_perc_p = ( lwa_out5-act_gross_p / lwa_out5-act_sales_p ) * 100.
here when a new ktgrm_d is found it will consider both the -ve and +ve values for SUM.
After that there is no use of multiplying with -1.
A B
a 1
a 1-
a 2
a 3-
loop at itab
at new A.
sum = the value here is -1.
endat.
Here if you multiply the negative value with -1 the result will not be same.
endloop.
if you please explain what you exactly want then it will be easy to help you.
‎2010 Feb 17 8:47 AM
Hi
SUM statement wont work with AT NEW control Stament but it works with AT END control stmt.
[Desktop\untitled.bmp]
Regards,
Srinivas K
‎2010 Feb 17 8:52 AM
Hi,
Iam getting the report for Gross profit and GP % for sales.
In my report first iam displaying the Iteams wise.. as well every item displays the subtotal also.
Like:
Agency Categegory Machine sales cost GrossProfit GP % QTY
------------------------------------------------------------------------------------------------------
XYZ ABC Bajaj 100 80 20 80% 10
Subtot 100 80 20 80% 10
ABC Mot1 Indica 100 50 50 50% 50-
Maruthi 100 50 50 50% 50
Subtot 200 100 100 50% 100 "PROBLE IS HERE ITSNOT GETTING
------------------------------------------------------------------------------------------------------------
For the subtotal iam using the AT new based on agency.
hope uve understand my senario.
thank you
‎2010 Feb 17 9:02 AM
Hi Balaji,
I understand your scenario. For the subtotals it is better to you if use AT END OF statement. First try with this and let me know if you have any problem with that.
Regards
Srinivas K
‎2010 Feb 17 9:02 AM
Hi,
sorry for the before i didnt type very well.
I have used the at end of statement also . but stil its same the problem
‎2010 Feb 17 9:05 AM
Hi,
SORT lt_machine_sales4 BY ktgrm_d.
CLEAR: lwa_out5.
LOOP AT lt_machine_sales4 INTO lwa_out5.
AT end of ktgrm_d.
SUM.
lwa_out5-act_gross_p = lwa_out5-act_sales_p - lwa_out5-act_cos_p.
IF lwa_out5-act_sales_p IS NOT INITIAL.
lwa_out5-act_gross_perc_p = ( lwa_out5-act_gross_p / lwa_out5-act_sales_p ) * 100.
ENDIF.
WRITE lwa_out5-act_gross_perc_p TO lwa_out5-act_gross_perc NO-SIGN LEFT-JUSTIFIED DECIMALS 1.
IF lwa_out5-act_gross_p < 0.
CONCATENATE lwa_out5-act_gross_perc '%-' INTO lwa_out5-act_gross_perc.
ELSE.
CONCATENATE lwa_out5-act_gross_perc '%' INTO lwa_out5-act_gross_perc.
ENDIF.
**************BUDGET CALCULATION FOR GROSS PROFIT & GROSS PROFIT PERCENTAGE.
lv_bud_gross_p = lwa_out5-bud_sales_p - lwa_out5-bud_cos_p.
IF lwa_out5-bud_sales_p IS NOT INITIAL.
lwa_out5-bud_gross_perc_p = ( lv_bud_gross_p / lwa_out5-bud_sales_p * 100 ).
ENDIF.
IF lwa_out5-bud_gross_perc_p NE 0.
WRITE lwa_out5-bud_gross_perc_p TO lwa_out5-bud_gross_perc LEFT-JUSTIFIED.
CONCATENATE lwa_out5-bud_gross_perc '%' INTO lwa_out5-bud_gross_perc SEPARATED BY space.
ENDIF.
*****************************************************************************
CLEAR:lwa_out5-matkl_d,
lwa_out5-matnr.
APPEND lwa_out5 TO lt_machine_sales5.
CLEAR:lwa_out5.
ENDAT.
ENDLOOP.
Still itsnot working
‎2010 Feb 17 9:12 AM
Hi,
You missed again moving the workarea data into another workarea. If it is still unresolved reply me how is the ouput or error what you are getting.
Regards
Srinivas K
‎2010 Feb 17 9:22 AM
Hi,
sorry its not working if ive moved to another work area.
Subtotal is getting the last record of final itab.
Regards
‎2010 Feb 17 9:27 AM
It will work in any control break statements.
Have you tried.
types:begin of ty,
field1 type c,
field2 type i,
end of ty.
data:it type table of ty.
data:wa type ty.
wa-field1 = 'A'.
wa-field2 = '1'.
append wa to it.
wa-field1 = 'A'.
wa-field2 = '2'.
append wa to it.
loop at it into wa.
at new field1.
sum.
write wa-field2.
endat.
endloop.
‎2010 Feb 17 9:34 AM
LOOP.
PRINT THE ITEMS HERE.
AT END OF FIELD1.
SUM.
WTITE THE SUB TOT HERE
ENDAT.
ENDLOOP.
‎2010 Feb 17 9:39 AM
Hi,
thank you for the replying. its gr8
Actually first iam subtotaling then looping for the dipplaying for items disply and subtot displying.
SORT lt_machine_sales4 BY ktgrm_d.
CLEAR: lwa_out5.
LOOP AT lt_machine_sales4 INTO lwa_out5.
AT end of ktgrm_d.
SUM.
lwa_out5-act_gross_p = lwa_out5-act_sales_p - lwa_out5-act_cos_p.
IF lwa_out5-act_sales_p IS NOT INITIAL.
lwa_out5-act_gross_perc_p = ( lwa_out5-act_gross_p / lwa_out5-act_sales_p ) * 100.
ENDIF.
WRITE lwa_out5-act_gross_perc_p TO lwa_out5-act_gross_perc NO-SIGN LEFT-JUSTIFIED DECIMALS 1.
IF lwa_out5-act_gross_p < 0.
CONCATENATE lwa_out5-act_gross_perc '%-' INTO lwa_out5-act_gross_perc.
ELSE.
CONCATENATE lwa_out5-act_gross_perc '%' INTO lwa_out5-act_gross_perc.
ENDIF.
**************BUDGET CALCULATION FOR GROSS PROFIT & GROSS PROFIT PERCENTAGE.
lv_bud_gross_p = lwa_out5-bud_sales_p - lwa_out5-bud_cos_p.
IF lwa_out5-bud_sales_p IS NOT INITIAL.
lwa_out5-bud_gross_perc_p = ( lv_bud_gross_p / lwa_out5-bud_sales_p * 100 ).
ENDIF.
IF lwa_out5-bud_gross_perc_p NE 0.
WRITE lwa_out5-bud_gross_perc_p TO lwa_out5-bud_gross_perc LEFT-JUSTIFIED.
CONCATENATE lwa_out5-bud_gross_perc '%' INTO lwa_out5-bud_gross_perc SEPARATED BY space.
ENDIF.
*****************************************************************************
CLEAR:lwa_out5-matkl_d,
lwa_out5-matnr.
APPEND lwa_out5 TO lt_machine_sales5.
CLEAR:lwa_out5.
ENDAT.
ENDLOOP.
CLEAR: lwa_out1,
lwa_out5.
LOOP AT lt_machine_sales5 INTO lwa_out5. "for the subtotaling
LOOP AT lt_machine_sales INTO lwa_out1 WHERE ktgrm_d = lwa_out5-ktgrm_d. " here iteams displaying
APPEND lwa_out1 TO lt_machine_sales3.
CLEAR:lwa_out1.
ENDLOOP.
lwa_out5-ktgrm_d = 'SUBTOTAL'.
APPEND lwa_out5 TO lt_machine_sales3.
CLEAR:lwa_out5.
ENDLOOP.
Thank you brother
‎2010 Feb 17 10:14 AM
‎2010 Feb 17 10:19 AM
‎2010 Feb 17 10:30 AM
Hi,
A small favour. I need to delete the duplicate itams names but not subtotal text. for this one ive written like below.iam getting the first iteam Name but it deletes l subtotal text.. how to overcome this prob
*Refresh lt_machine_sales6.
*
*lt_machine_sales6[] = lt_machine_sales3[].
*clear:lwa_out5.
*Loop at lt_machine_sales6 into lwa_out5.
* Loop at lt_machine_sales3 into lwa_out5 where ktgrm_d = lwa_out5-ktgrm_d.
* if gv_ok = 'X'.
* clear: lwa_out5-ktgrm_d.
* endif.
* gv_ok = 'X'.
* Modify lt_machine_sales3 from lwa_out5.
* endloop.
* clear: gv_ok.
*endloop.
SUBTOTAL
Bomag
Bomag "from here
Bomag
Bomag
Bomag
Bomag
Bomag " to here
SUBTOTAL
Second Hands
SUBTOTAL
Second-hand
SUBTOTAL
Sullair
Sullair " from here
SUBTOTAL
Volvo
Volvo "From here
Volvo
Plz see my data as above as
regards
‎2010 Feb 17 7:28 AM
Hi Balaji,
To the best of my knowledge, SUM is only considered within AT END OF control structure. I think you need to modify your SUM statement. Do an F1 on SUM we got a good example there.
Regards,
Pranaam.
‎2010 Feb 17 10:35 AM
Hi all these problems can be solved by yourself. Do proper debugging from begining of loop to endloop.
‎2010 Feb 17 12:28 PM
Good dayBro
Ive got it but in other way.
first ive coverted in to the +ve values then ive used the At end of event
Thank you for being ans me.
Have a nice day.
Regards