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

Summarize İnternal Table by specific two fields?

Former Member
0 Likes
2,283

Hi experts,

I have an internal table with 5 fields.

I have to summarize it by specific fields but ı dont know how to achieve

so any one please help me to succeed it

any help will be appreciate?

here is what I wanna achieve....

Regıo       Spart        PAFKT  PAFKT1      QUANTİTY

AN          09              KK          TT                        12

AN          09             RK           RR                       62         

AN         34              TK            KK                       78

AN         34              SK           RR                        99

AT          09              KK           KK                       44

AT          09             SK            TT                         55                  

AT         34              TK             RR                       66

AT         34              RK            TT                        77

...          ..                 ..              ..                          ..

...          ..                 ..              ..                          ..

...          ..                 ..              ..                          ..

I have 10 different regio and 2 different spart and 4 different pafkt      and 3 different pafkt1

I want to get total of like this and ı will use block alv to show the report at the end .

Block1( summarize for REGİO)

                09(spart1)                           34(spart2)                      

AN       74(12+62)                                 177(78+99)

AT       99(44+55)                                  143(66+77)

...

...

...

Block2 (Summarize for   PAFKT)

                             

              09(spart1)                          34(spart2)   

                  

KK       56(44+12)                                ........

TK        ...........                                   144(78+66)  

...

...

...

Block3(Summarize for PAFKT1)

             09(spart1)                          34(spart2)   

                  

TT       77(55+12)                                ........

RR        ...........                                   165(99+66)

...

...

)

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,668

hi,

i didnt use an alv block list befor, but reading this makes me think you get 1 separate table for each block (maybe the same table works as well) and give the layout settings (e.g. sort/sum by column xy)

http://www.google.de/imgres?imgurl=http%3A%2F%2Fimages.newtosap.info%2Falv_block_list.png&imgrefurl=...

regards

Stefan Seeburger

Hi experts,

I have an internal table with 5 fields.

I have to summarize it by specific fields but ı dont know how to achieve

so any one please help me to succeed it

any help will be appreciate?

here is what I wanna achieve....

Regıo       Spart        PAFKT  PAFKT1      QUANTİTY

AN          09              KK          TT                        12

AN          09             RK           RR                       62         

AN         34              TK            KK                       78

AN         34              SK           RR                        99

AT          09              KK           KK                       44

AT          09             SK            TT                         55                  

AT         34              TK             RR                       66

AT         34              RK            TT                        77

...          ..                 ..              ..                          ..

...          ..                 ..              ..                          ..

...          ..                 ..              ..                          ..

I have 10 different regio and 2 different spart and 4 different pafkt      and 3 different pafkt1

I want to get total of like this and ı will use block alv to show the report at the end .

Block1( summarize for REGİO)

                09(spart1)                           34(spart2)                      

AN       74(12+62)                                 177(78+99)

AT       99(44+55)                                  143(66+77)

...

...

...

Block2 (Summarize for   PAFKT)

                             

              09(spart1)                          34(spart2)   

                  

KK       56(44+12)                                ........

TK        ...........                                   144(78+66)  

...

...

...

Block3(Summarize for PAFKT1)

             09(spart1)                          34(spart2)   

                  

TT       77(55+12)                                ........

RR        ...........                                   165(99+66)

...

...

)

8 REPLIES 8
Read only

Former Member
0 Likes
1,669

hi,

i didnt use an alv block list befor, but reading this makes me think you get 1 separate table for each block (maybe the same table works as well) and give the layout settings (e.g. sort/sum by column xy)

http://www.google.de/imgres?imgurl=http%3A%2F%2Fimages.newtosap.info%2Falv_block_list.png&imgrefurl=...

regards

Stefan Seeburger

Read only

0 Likes
1,668

Hi Stefan

actually ım askıng the algorıth to succed to summarıze ın the way ı explaıned before

Using alv block is the final attemp for me.

I have make rıght summarizing and appen them there separate ınternal table.

so as I said ı need algoırth for it

thanks

best regards

Read only

0 Likes
1,668

Hi,

Please find the below approach. Hope it helps you.

  • Copy the internal table into four different table , example itab[] =itab1[].
  • sort first internal table by region spart
  • loop the internal table and use COLLECT statement
  • Follow the same approach for other requirement

Thanks

Read only

Former Member
0 Likes
1,668

Hi,

you can use aggregate function SUM to summarize your internal table and can display the result in different blocks using BLOCK LIST ALV.

here is an example of it.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

  EXPORTING

    I_CALLBACK_PROGRAM             = SY-REPID.

*   I_CALLBACK_PF_STATUS_SET       = ' '

*   I_CALLBACK_USER_COMMAND        = ' '

*   IT_EXCLUDING                   =

         .

SELECT SUM( QUANTITY ) SPART REGIO FROM TABLENAME INTO TABLE ITAB1 GROUP BY REGIO SPART

SELECT SUM( QUANTITY ) SPART PAFKT FROM TABLENAME INTO TABLE ITAB2 GROUP BY REGIO PAFKT

SELECT SUM( QUANTITY ) SPART PAFKT1 FROM TABLENAME INTO TABLE ITAB3 GROUP BY REGIO PAFKT1

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

    EXPORTING

      IS_LAYOUT                        = V_LAYOUT

      IT_FIELDCAT                      = IT_FCAT1

      I_TABNAME                        = 'ITAB1'

      IT_EVENTS                        = IT_EVENTS1

*     IT_SORT                          =

*     I_TEXT                           = ' '

    TABLES

      T_OUTTAB                         = ITAB1

   EXCEPTIONS

     PROGRAM_ERROR                    = 1

     MAXIMUM_OF_APPENDS_REACHED       = 2

     OTHERS                           = 3

            .

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

    EXPORTING

      IS_LAYOUT                        = V_LAYOUT

      IT_FIELDCAT                      = IT_FCAT2

      I_TABNAME                        = 'ITAB2'

      IT_EVENTS                        = IT_EVENTS2

*     IT_SORT                          =

*     I_TEXT                           = ' '' '

    TABLES

      T_OUTTAB                         = ITAB2

   EXCEPTIONS

     PROGRAM_ERROR                    = 1

     MAXIMUM_OF_APPENDS_REACHED       = 2

     OTHERS                           = 3

            .

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

  EXPORTING

    IS_LAYOUT                        = V_LAYOUT

    IT_FIELDCAT                      = IT_FCAT3

    I_TABNAME                        = 'ITAB3'

    IT_EVENTS                        = IT_EVENTS3

*   IT_SORT                          =

*   I_TEXT                           = '' ' '

  TABLES

    T_OUTTAB                         = ITAB3

EXCEPTIONS

   PROGRAM_ERROR                    = 1

   MAXIMUM_OF_APPENDS_REACHED       = 2

   OTHERS                           = 3

        .

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'

* EXPORTING

*   I_INTERFACE_CHECK             = ' '

*   IS_PRINT                      =

*   I_SCREEN_START_COLUMN         = 0

*   I_SCREEN_START_LINE           = 0

*   I_SCREEN_END_COLUMN           = 0

*   I_SCREEN_END_LINE             = 0

* IMPORTING

*   E_EXIT_CAUSED_BY_CALLER       =

*   ES_EXIT_CAUSED_BY_USER        =

* EXCEPTIONS

*   PROGRAM_ERROR                 = 1

*   OTHERS                        = 2

       .

Read only

0 Likes
1,668

select sum is for database table ı guess it wont work for me

I already fetch the datas ınto ınternal table

Read only

0 Likes
1,668

I would suggest you to store the summarized data into 3 different internal tables instead of storing the data into an internal table and summarizing the internal table.

Read only

0 Likes
1,668

Before summarizing ım fetching data with inner join so ıt wıll be dıffıcult for me to fetch data wıth summarizing...

here is my join...

is it possible to use inner join and summarize( select sum ) at the same time???

select a~vbeln

        a~audat

        a~auart

        a~kunnr

        b~fksak

        c~posnr

        c~matnr

        c~netwr

        c~spart

        c~kwmeng

        c~ernam

        c~netpr

        c~cmpre

        d~regio

*       e~pafkt

*       e~vtext

    from vbak as a

                inner join vbuk  as b on a~vbeln = b~vbeln

                inner join vbap  as c on a~vbeln = c~vbeln

                inner join kna1  as d on a~kunnr = d~kunnr

*               inner join knvk  as e on a~kunnr = e~kunnr and

*                                        e~name1 = 'SATIŞ TEMSİLCİSİ'

*               inner join tpfkt as e on e~pafkt = e~pafkt and

*                                        f~spras = 'TR'

     into corresponding fields of table it_final

   where a~audat in p_audat and

         a~auart in p_auart.






Read only

former_member1716
Active Contributor
0 Likes
1,668

I would request you go through the above links it gives a clear picture of ALV block, also for filling the internal table you could use control break statements. There so many discussuions in the forum on how to deal with control break statments, Please have a look at them.

Please get back if you queries.

regards,

Satish