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: 

Internal Tables

Former Member
0 Kudos

I have an internal table with 3 fields namely matnr,date & GR qty. Now from this internal table...i have to calculate the GR qty for each material based on dates and range of dates?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Chandra,

You can do this using the internal table control/events like AT NEW and SUM. Its not that difficult to build a logic.

Regards,

VJ

7 REPLIES 7

Former Member
0 Kudos

Hi Chandra,

You can do this using the internal table control/events like AT NEW and SUM. Its not that difficult to build a logic.

Regards,

VJ

Former Member
0 Kudos

Hi,

If you have a ALV report then all the totals / subtotals by specific fields can be done by the user using the toolbar options.

Else, you will have to use the AT NEW / ON CHANGE commands with in the Internal table LOOP and calculcate the totals manually.

Regards,

Ravi

Note : Please mark all the helpful answers

Former Member
0 Kudos

Hi

This you can do using control brake statments .

that is at new-endat, at first, at last etc

for every change in material you can sum up the quantites according to date

Thanks

Former Member
0 Kudos

Hi Chandra,

Try with this logic.

SORT itab BY date matnr.

LOOP AT itab INTO wa_itab.

SUM = SUM + wa_itab-gr_qty.

AT END OF date.

wa_itab_1-date = wa_itab-date.

wa_itab_1-matnr = wa_itab-matnr.

wa_itab_1-gr_qty = SUM.

APPEND wa_itab_1 TO new_itab.

CLEAR wa_itab_1.

CLEAR SUM.

ENDAT.

ENDLOOP.

Regards,

Prakashsingh

Message was edited by: Prakashsingh Mehra

Message was edited by: Prakashsingh Mehra

andreas_mann3
Active Contributor
0 Kudos

Hi,

or use an extra int. table(sumtab) to calculate sums:

loop at itab.
 move-corresponding itab to sumtab.
 collect sumtab. 
endloop.

Andreas

Former Member
0 Kudos

Hi!

Put control break AT END OF date inside the loop and inside it calculate the total by using SUM.

If ALV, just assign 'X' to subtotal/Total for the specified field.

Regards,

Sangeeta.

Former Member
0 Kudos

Hi Chandra,

You can build a logic inside the loop of your internal table.

Sort the internal table

Loop the table

Keep on summing the qty ( untill your date condition is satisfied ).

Once u reach the last material either move the data to another internal table or write ( as per your req ).

For the same logic u can use AT END ,, ENDAT control processing inside the loop.

Get a look of a small piece of code doing somewhat similar workout.

DATA : BEGIN OF matqty OCCURS 0,

matnr(5) TYPE c ,

date LIKE sy-datum,

qty TYPE i,

END OF matqty.

DATA : sum TYPE i.

matqty-matnr = '10001'.

matqty-date = '20060413'.

matqty-qty = 10.

APPEND matqty.

matqty-matnr = '10001'.

matqty-date = '20060412'.

matqty-qty = 20.

APPEND matqty.

matqty-matnr = '10001'.

matqty-date = '20060419'.

matqty-qty = 30.

APPEND matqty.

matqty-matnr = '10002'.

matqty-date = '20060413'.

matqty-qty = 10.

APPEND matqty.

matqty-matnr = '10002'.

matqty-date = '20060419'.

matqty-qty = 10.

APPEND matqty.

SORT matqty BY matnr.

LOOP AT matqty.

" Date Condition.

IF matqty-date < sy-datum.

sum = sum + matqty-qty.

ENDIF.

AT END OF matnr.

WRITE: / matqty-matnr , sum.

ULINE.

CLEAR SUM.

ENDAT.

ENDLOOP.

Give it a try and if helps please reward point and close thread.

Any doubt , Please reply.

Regards,

Mayank