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

At New problem

former_member251546
Participant
0 Likes
2,254

Hi,

Good day guys.

Control break event problem. plz can any one help me

Iam dev the alv report. its fine. but client has chaged the req. He need the req is first i need to disply the total and then items details.

Like

-


Name Qty

boltes 30

boltes 10

10

10

so first ive summed the items and then appending items to final ita.

iam using nested loops. but its not working.

DATA : lwa_out1 TYPE zsalessm.

  • CLEAR: lwa_out5.

  • REFRESH: lt_machine_sales2,

  • lt_machine_sales4.

  • lt_machine_sales2[] = lt_machine_sales[].

  • SORT lt_machine_sales2 BY ktgrm_d.

  • SORT lt_machine_sales BY ktgrm_d.

*

  • LOOP AT lt_machine_sales INTO lwa_out5. " Here iam doing the total sum

  • AT NEW ktgrm_d.

  • SUM.

  • lwa_out5-sales_qty = lwa_out5-sales_qty * -1.

  • lwa_out5-act_sales_p = lwa_out5-act_sales_p * -1.

  • lwa_out5-act_cos_p = lwa_out5-act_cos_p * -1.

  • lwa_out5-act_gross_p = lwa_out5-act_gross_p * -1.

  • lwa_out5-act_gross_perc_P = lwa_out5-act_gross_perc_p * -1.

  • lwa_out5-netwr = lwa_out5-netwr * -1.

*

  • APPEND lwa_out5 TO lt_machine_sales4.

*

  • IF sy-subrc EQ 0.

  • LOOP AT lt_machine_sales2 INTO lwa_out1 where ktgrm_d = lwa_out5-ktgrm_d. " here iam appending the iteam details

*

  • APPEND lwa_out1 TO lt_machine_sales4.

  • clear:lwa_out1.

  • ENDLOOP.

  • ENDIF.

  • clear:lwa_out5.

  • ENDAT.

  • ENDLOOP.

Plz any one tell me how to do it?

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,207

Hi,

Are you not able to sum up the items or you are not able to append the items into new internal table.

Actually, you can do both the things in a single step.

Just loop at you internla table. Thn, use collect statement to sum up the items, at the same time before summing up you can append your work area to new internal table. So, it will solve both issues.

Thanks

Archana

25 REPLIES 25
Read only

Former Member
0 Likes
2,208

Hi,

Are you not able to sum up the items or you are not able to append the items into new internal table.

Actually, you can do both the things in a single step.

Just loop at you internla table. Thn, use collect statement to sum up the items, at the same time before summing up you can append your work area to new internal table. So, it will solve both issues.

Thanks

Archana

Read only

0 Likes
2,207

Hi,

Good day

Thank you. sorry for the disterb u. Generally for summing i did At New event.

If you dont mind, plz send sample code for it.

REgards

Read only

0 Likes
2,207

Hi,

You can do F1 on collect statement for more information. Refer to the below code:

LOOP AT lt_machine_sales INTO lwa_out5. " Here iam doing the total sum

 APPEND lwa_out1 TO " your new internal table.
 Collect lwa_out5 into lt_machine_sales4.
 clear:lwa_out1, lwa_out5.
ENDLOOP.

Thanks,

Archana

Read only

0 Likes
2,207

Hi,

good day archana

Ive follow ur code..but ive doubt

In my report, i need first total sum amount of Items then items list.

Here first you lwa_out1 appending new itab..

and then used the collet..

How its works?

LOOP AT lt_machine_sales INTO lwa_out5. " Here iam doing the total sum

APPEND lwa_out1 TO " your new internal table.

Collect lwa_out5 into lt_machine_sales4.

clear:lwa_out1, lwa_out5.

ENDLOOP.

Regards

Read only

0 Likes
2,207

Hi,

Collect statement will sum up the values based on unique values of key fields.

In my report, i need first total sum amount of Items then items list.

I am not able to understand what do actually mean by this? Can you explain with sample data?

Thanks,

Archana

Read only

0 Likes
2,207

Hi,

Iam really sorry for confussing you.

He Needs the report first record displays Item total. and then displays iteams list. so. i worte the code as below as. but its not working.

My itab data looks like below.

Mtpos Ktgrm_d Des Value

Znam bomag xyz 10

Znam bomag fdfj 10

Nam bomag fjfff 20

znam volvo fdkfjkd 40

nam volvo erje 30

in my report i need to disply based on the ktgrm_d which is part name. No need to display the mt pos.

Iam doing the at new also based on ktgrm_d. so report should be like

Ktgrm_d Des Value

Bomag 40 "total values"

Bomag 10 "these are items

Bomag 10

Bomag 20

volvo 70 "total values

Volvo 40

volvo 30

Can you guide me plz. send me smaple code if uve time.

CLEAR: lwa_out5.

REFRESH: lt_machine_sales4.

DATA: lwa_out1 type zsalessm.

SORT lt_machine_sales BY ktgrm_d ascending.

LOOP AT lt_machine_sales INTO lwa_out5.

lwa_out1 = lwa_out5.

AT NEW ktgrm_d.

SUM.

lwa_out5-sales_qty = lwa_out5-sales_qty * -1.

lwa_out5-act_sales_p = lwa_out5-act_sales_p * -1.

lwa_out5-act_cos_p = lwa_out5-act_cos_p * -1.

lwa_out5-act_gross_p = lwa_out5-act_gross_p * -1.

lwa_out5-act_gross_perc_P = lwa_out5-act_gross_perc_p * -1.

lwa_out5-netwr = lwa_out5-netwr * -1.

APPEND lwa_out5 TO lt_machine_sales4.

clear:lwa_out5.

ENDAT.

Append lwa_out1 To lt_machine_sales4.

clear:lwa_out1.

ENDLOOP.

Read only

0 Likes
2,207

Hi,

What you can do is, first of all, lloop at your item internal table. New internal table will have only 3 columns i.e. Ktgrm_d Des Value.

Loop at itab1 into wa_itab.
 move-corrsponding wa_itab to wa_new_itab.
 Append wa_new_itab to i_new_itab.
 clear: wa_new_itab, wa_itab.
Endloop.

This table will contain all item level details with only required fields.

Now loop at this internal table.

Loop at i_new_itab into wa_new_itab.
 collect wa_new_itab into i_itab1.   " this will sum up your items based on Ktgrm_d.
 clear: wa_new_itab.
endloop.

Loop at i_new_itab into wa_new_itab.
   read table i_itab into wa_itab1 with key Ktgrm_d = wa_new_itab-Ktgrm_d.
   if sy-subrc eq 0.
    append wa_itab1 to i_final.
   endif.
  Append wa_new_itab to i_final.
Endloop.

Thanks,

Archana

Read only

0 Likes
2,207

hi,

Thank you.

I did the same wht u told but when the summing in the loop using collect. its not working.

Iam getting the all records from lt_machine_sales to lt_machine_sales4.

When we using collect, any resction need to follow or wht. . any sorting.

Loop at lt_machine_sales into lwa_out5.

collect lwa_out5 into lt_machine_sales4.

clear:lwa_out5.

endloop

Regards

Read only

0 Likes
2,207

Hi,

Can you please tell whether you need to display 'Des' column also?

Because i fell that column values are different even if Ktgrm_d column is same. So, it is not able to find any records with same combination of 'Ktgrm_d and Des' and that is why it is not summing it up.

If you don't want to display 'Des' coulmn, then remove that column as well from your internal table.

And let me know if collect is working or not.

Thansk,

Archana

Read only

former_member206377
Active Contributor
0 Likes
2,207

iam using nested loops. but its not working.

What is the issue you are facing?Are you getting any error/ data is not getting filled??

Read only

0 Likes
2,207

Data was filed.

Read only

0 Likes
2,207

Hi,

No need for nested loop.You can do the achieve the same by putting the detailed item level append after the AT ENDAT block.

Pls look at the below sample.

LOOP AT lt_machine_sales INTO lwa_out5.

lwa_out = lwa_out5.

AT NEW ktgrm_d.

SUM.

lwa_out5-sales_qty = lwa_out5-sales_qty * -1.

lwa_out5-act_sales_p = lwa_out5-act_sales_p * -1.

lwa_out5-act_cos_p = lwa_out5-act_cos_p * -1.

lwa_out5-act_gross_p = lwa_out5-act_gross_p * -1.

lwa_out5-act_gross_perc_P = lwa_out5-act_gross_perc_p * -1.

lwa_out5-netwr = lwa_out5-netwr * -1.

APPEND lwa_out5 TO lt_machine_sales4.

ENDAT.

APPEND lwa_out TO lt_machine_sales4.

ENDLOOP.

Regards,

Vignesh.

Read only

0 Likes
2,207

hi

While using at new. Following is the standard functionality:

say itab1 has field F1, F2, F3.

So in when you give

loop at itab1.

at new F2.

UR logic

endat.

endloop.

If the value of F1 changes and F2 is still the same. It will execute the At new logic.(i.e. if value of any of pramaters upto current paramter changed the At new Logic will be executed).

Please check if this is working fine.

Hoping it helps..

Regards,

Komal

Read only

0 Likes
2,207

hi,

Thank you vignaswaran. ur right 100% coding. but i dont know ,At New event is not working.

when iam summing the Qty, Act sales, Act cost..and etc.. these r not summing.

When i was debugging..its not -ve value lke 123-

thats why ive taken values one which the fields are getting the -ve like "lwa_out5-sales_qty = lwa_out5-sales_qty * -1."

But still there is prob. its not summing

Thank you

Regards

Read only

0 Likes
2,207

Hi,

I am not sure ..how is your internal table is declared.If you are using KTGRM_D alone for summing the line,then make sure you declare KTGRM_D as a first field in the internal table .You are already sorted the intenral table by KTGRM_D .That is fine.

Thanks,

Vigneswaran.

Read only

0 Likes
2,207

hi,

Iam sorry i didnt tell you.

In the internal table there is first field Mt_pos.

Mt_pos got two values Znarm , NORM. But in my report mt-pos will not be displayed.

If ive sorted the based on mt_pos. its diffecult to summed the Items.

My itab Data is like below

Mtpos ktgrm_d values

znarm ind 10

znarm ind 10

norm ind 10

norm ind 10

znarm aus 10

znarm aus 10

REgards

Raghu

Read only

0 Likes
2,207

Hi,

Since you have not put KTGRM_D as a first field in internal table ,the control break statement AT NEW did not summ up correctly.

These are the two basic steps need to be followed before using control break statement.

1.The field(s) to be considered for summing up the line should be on the left hand side of the internal table.

2.The internal table should be sorted by those field(s).

Since the first condition is not satisfied in your case,the summation is going wrong.Put KTGRM_D field as a first field in internal table and then check your output.It should summ up correctly.

Thanks,

Vigneswaran .

Read only

0 Likes
2,207

Its not summing rightly. Can u plz send the solution plz

Regards

Read only

0 Likes
2,207

Hi,

check out the below code.If you still say it is not summing up correclty,then just show me the actual content of the itab and also the summarized value you get.


Data:beging of  lwa_out5,
        KTGRM_d type c,
        Mtpos type posnr,
        qty1 type ..,
        qty2 type .
        end of lwa_out5,

lt_machine_sales like standard table of lwa_out5.
lt_machine_sales2 like standard table of lwa_out5.

 CLEAR: lwa_out5.
 REFRESH: lt_machine_sales2,
lt_machine_sales4.
 lt_machine_sales2] = lt_machine_sales[.
 SORT lt_machine_sales2 BY ktgrm_d.
 SORT lt_machine_sales BY ktgrm_d.

LOOP AT lt_machine_sales INTO lwa_out5. 
lwa_out = lwa_out5.
AT NEW ktgrm_d.
SUM.
lwa_out5-sales_qty = lwa_out5-sales_qty * -1.
lwa_out5-act_sales_p = lwa_out5-act_sales_p * -1.
lwa_out5-act_cos_p = lwa_out5-act_cos_p * -1.
lwa_out5-act_gross_p = lwa_out5-act_gross_p * -1.
lwa_out5-act_gross_perc_P = lwa_out5-act_gross_perc_p * -1.
lwa_out5-netwr = lwa_out5-netwr * -1.

APPEND lwa_out5 TO lt_machine_sales4.

ENDAT.

APPEND lwa_out TO lt_machine_sales4.
ENDLOOP.

Thanks,

Vigneswaran.

Read only

0 Likes
2,207

hi,

Ive declared the data as below as

DATA: lwa_out1 type zsalessm.
  DATA: lwa_out5 type zsalessm.
: DATA  : lt_machine_sales4  TYPE TABLE OF zsalessm.
DATA  : lt_machine_sales  TYPE TABLE OF zsalessm.


And coding
SORT lt_machine_sales BY ktgrm_d ascending.

  LOOP AT lt_machine_sales INTO lwa_out5.
    lwa_out1 = lwa_out5.
    AT NEW ktgrm_d.
      SUM.
      lwa_out5-sales_qty = lwa_out5-sales_qty * -1.
      lwa_out5-act_sales_p = lwa_out5-act_sales_p * -1.
      lwa_out5-act_cos_p = lwa_out5-act_cos_p * -1.
      lwa_out5-act_gross_p = lwa_out5-act_gross_p * -1.
      lwa_out5-act_gross_perc_P = lwa_out5-act_gross_perc_p * -1.
      lwa_out5-netwr      = lwa_out5-netwr * -1.
      APPEND lwa_out5 TO lt_machine_sales4.
      clear:lwa_out5.
     ENDAT.

     Append lwa_out1 To lt_machine_sales4.
     clear:lwa_out1.


  ENDLOOP.

I think, except data dec, remaining everything is same. I told you how my data wil looks like. if you dont mind, can u send << request for personal information removed >> . so i can send the print screen of dubug itab data.

Thank you very much for supporting

regards

Moderator message - Please use code tags to format your code

Edited by: Rob Burbank on Feb 8, 2010 2:19 PM

Read only

0 Likes
2,207

Hi,

No need to worry about in which order the output fields is going to be displayed.In output,you can change the order of the fields displayed like any way and it does not necessarry be in same order like intenal table declaration.

So in your internal table declaration,instead of refering ZSALESMM structure,declare individual fields with the order mentioned in previous post.It should work.I dont think a any other better way than that.

Thanks,

Vignesh.

Read only

0 Likes
2,207

Do you really need to resolve this issue with ABAP code?

Have you tried to create and save an ALV Grid display variant which includes subtotals/totals? These totals can be displayed before the entries they summarise.

Mike

Edited by: Mike Morgan on Feb 8, 2010 5:41 PM

Read only

0 Likes
2,207

If this is a report you want to create, simply use "reuse_alv_list_display" or "reuse_alv_grid_display" and pass the internal table to the function module and display ur report., the user can use various operations on the OUTPUT displayed by using the Graphical Items on the display Page,.

eg: there is subtotal icon, grand total icon, sort icon's, list choose icon, export to presentation server icons, etc

sap has provided many things predefined use them to ur will........

Cheers,

Shravs

Read only

0 Likes
2,207

i mean explain to the user the various advantages of using graphical user display...............

Hope it helps u find a solution cheaply...........

Read only

0 Likes
2,207

Balaji,

After the "AT NEW ktgrm_d.", you also need to add this statement:

READ TABLE lt_machine_sales INTO lwa_out5 INDEX SY-TABIX.

This is needed if you access the fields defined after ktgrm_d.

Thanks,

Bhanu