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: 

grouping fields of a internal table into another internal table

Former Member
0 Kudos

Hi

I've two internal tables and a want put in second the adition of items of the first.

when record of zzpernr is last, i want put the SUM of records for this zzpernr.

I've this code but the result give me al items.

LOOP AT it_execucao.
    ltabix2 = ltabix2 + 1.
    ltabix  = sy-tabix.
    at END OF zzpernr.
      SELECT SINGLE cname FROM pa0002 INTO it_final-cname
          WHERE pernr = it_execucao-zzpernr.
      it_final-zzpernr = it_execucao-zzpernr.
      it_final-nlinhas_exec = ltabix2.
      APPEND it_final.
     CLEAR ltabix2.
    endat.


ENDLOOP.

Can somebody help me ? Thanks

1 ACCEPTED SOLUTION

former_member242255
Active Contributor
0 Kudos

please use ON-CHANGE of instead of at-end..

6 REPLIES 6

former_member242255
Active Contributor
0 Kudos

please use ON-CHANGE of instead of at-end..

faisal_altaf2
Active Contributor
0 Kudos

Hi,

You can use

at end of zzpernr.
   sum.
   append wa to it.
endat.

for this your zzpernr must be left most field,

Please Reply if any Issue,

Kind Regards,

Faisal

Former Member
0 Kudos

Sort your table on zzpernr then use on change.

Former Member
0 Kudos

Hi,

Could you please describe the structure of the internal table it_execucao?

If zzpernr field is the first field, then, AT END OF logic will work fine...

But if it is not the first field of the internal table it_execucao, then use ON CHANGE OF zzpernr...

Best Regards,

Suresh

0 Kudos

Hi,

SORT it_first by ZZPPNNR.

loop at it_first into wa_first.

move corresponding records wa_first to wa_sum.

wa_second-sum = wa_first-sum + wa_second-sum .

at end of zzppnnr.

append wa_sum to it_second.

clear : wa_sum.

endat.

clear : wa_first.

endloop.

Regards,

Surya kiran

faisal_altaf2
Active Contributor
0 Kudos

Hi,

Test the following Sample Report Hope will Solve out your problem,

REPORT zfsl_sdn_test.

TYPES: BEGIN OF ty_it,
  mm(10),
  amount TYPE i,
  END OF ty_it.

DATA: it_mm1 TYPE STANDARD TABLE OF ty_it WITH HEADER LINE,
      it_mm2 TYPE STANDARD TABLE OF ty_it WITH HEADER LINE.

it_mm1-mm = 'AAA'.
it_mm1-amount = 10.
APPEND it_mm1 TO it_mm1.

it_mm1-mm = 'BBB'.
it_mm1-amount = 10.
APPEND it_mm1 TO it_mm1.

it_mm1-mm = 'AAA'.
it_mm1-amount = 10.
APPEND it_mm1 TO it_mm1.

SORT it_mm1 BY mm.

LOOP AT it_mm1.

  APPEND it_mm1 TO it_mm2.

  AT END OF mm.
    SUM.
    it_mm1-mm = 'Sub Tot'.
    APPEND it_mm1 TO it_mm2.
  ENDAT.

  AT LAST.
    SUM.
    it_mm1-mm = 'Grand Tot'.
    APPEND it_mm1 TO it_mm2.
  ENDAT.

ENDLOOP.

LOOP AT it_mm2.
  WRITE: / it_mm2-mm, it_mm2-amount.
ENDLOOP.

Kind Regards,

Faisal