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

Summarization In an Internal table- Smartforms

Former Member
0 Likes
1,481


Hello Experts,

I have the following requirement.

I have a internal table with 10 fields of which am displaying only 6 fields in my maintable of smartform. Now in my internal table structure i have the last two fields as MATNR and MATKL.

Now the 6 fields am displaying on main table are

1) Item no

2)description

3)QTY

4)some integer value1

5)some integer value2

6)some integer value3

Now based on the combination of matnr and matkl i must add the line items in the item table.

Conditions,

Item no, description can be taken from the first line item, rest all fields must be added.

Can you help me on acheiving this requirement.

Am very thankful to your immediate response

Thanks

Loki

1 ACCEPTED SOLUTION
Read only

former_member1716
Active Contributor
0 Likes
1,433

Hi Lokeshwari,

I hope you got the answer

If not you can try this code below, it will work i have checked

Do the following steps before you use the code,

Make the field matnr (Whichever field you want to use as a condition for summarization) as first field in your structure,

Also create one extra internal table as final which will hold your summarized value and use that table to display.

Define other data as we used in the code,

after that use the code below,

   LOOP AT it_item1 INTO wa_item1.

  AT NEW matnr.     

    G_flag1 = 1.
  ENDAT.


  IF G_flag1 is NOT INITIAL.
    wa_final-item     = wa_item1-item.
    wa_final-desc    = wa_item1-item.
  CLEAR G_flag1.
  ENDIF.

    wa_final-qty         =  wa_final-qty+ wa_item1-qty.
    wa_final-intvalue1 gwa_final-intvalue1+  gwa_item1-intvalue1.
    wa_final-intvalue2 gwa_final-intvalue2+  gwa_item1-intvalue2.
    wa_final-intvalue3 gwa_final-intvalue3+  gwa_item1-intvalue3.


at END OF matnr.
   G_flag2 = 1.
   ENDAT.


   IF G_flag2 is NOT INITIAL.
     APPEND wa_final TO it_final.
    CLEAR wa_final.
    CLEAR G_flag2.
   ENDIF.


ENDLOOP.

" Am using Flag value inside "at new" and "at end of" because variables will be holding only junk value inside these control break statements.

Hope you got this logic, Please get back if you have any issues in understanding the code

Thanks,

Satish

13 REPLIES 13
Read only

former_member1716
Active Contributor
0 Likes
1,433

Hi Lokeswari,

Why dont you try using At new, At last functionalities

Thanks,

Satishi

Read only

VijayaKrishnaG
Active Contributor
0 Likes
1,433

Hi Mohan,

You can use COLLECT Statement.

LOOP HEAD_TAB.

     WA_ITEM = WA_HEAD. "(required fields)

     COLLECT WA_ITEM TO ITEM_TAB.

ENDLOOP.

Here except 4,5,6 and 7 remaining all are Char fields. So, these fields will be simulated with respect to non numeric fields.

Hope you understand.

regards,

Vijay

Read only

thangam_perumal
Contributor
0 Likes
1,433

Hi Lokeshwari,

                       with help of your collect statements we can achieve your requirements.

here data type of field should be specified below type.

data: begin of wa,

matnr(20) type c,

matkl(20) type c,

Item_no(6) type c ,

description(40) type c

QTY type n,

some integer value1 type n,

some integer value2 type n,

some integer value3 type n,

end of wa.

data : itab like wa occurs 0.

loop at itab into wa.

collect wa to itab.

endloop.

Regards,

Thangam.P

Read only

Former Member
0 Likes
1,433

Hello All Please understand the condition that i have to maintain,

For every line item having same material number and material group i have to sum up the fields.

Hope i explained my requirement clearly

Thanks,

loki

Read only

0 Likes
1,433

Hi,

Have you tried COLLECT?

If you are having data as below,

MAT1 MATGRP1 20 50 10

MAT1 MATGRP1 10 10 20

MAT1 MATGRP1 30 20 40

MAT1 MATGRP1 40 50 50

Collect makes this as

MAT1 MATGRP1 100 130 120. I think, this is what you required.

-Vijay

Read only

0 Likes
1,433

yes you are right, but i may also have MAT2MATGRP2, MAT3MATGRP3 will it work for all conditions?

Can you please also specify the syntax for collect ?

Read only

0 Likes
1,433

Hi Mohan,

Yes it will workout for all materials and groups.

Already I mentioned the syntax and sample in my first reply. Generally when we are moving data from one table to another we use APPEND WA TO ITAB at the end of loop, instead of APPEND use COLLECT WA INTO ITAB.

And also go through this link for clear syntax and example code.

ABAP Keyword Documentation

-Vijay

Read only

thangam_perumal
Contributor
0 Likes
1,433

Hi Lokeshwari,

                     DATA: BEGIN OF seats,
        carrid   TYPE sflight-carrid,
        connid   TYPE sflight-connid,
        seatsocc TYPE sflight-seatsocc,
      END OF seats.

DATA seats_tab LIKE HASHED TABLE OF seats
               WITH UNIQUE KEY carrid connid.

SELECT carrid connid seatsocc
       FROM sflight
       INTO seats.
  COLLECT seats INTO seats_tab.
ENDSELECT.



let me know know still facing the problem.



Regards,

Thangam.P

Read only

former_member1716
Active Contributor
0 Likes
1,434

Hi Lokeshwari,

I hope you got the answer

If not you can try this code below, it will work i have checked

Do the following steps before you use the code,

Make the field matnr (Whichever field you want to use as a condition for summarization) as first field in your structure,

Also create one extra internal table as final which will hold your summarized value and use that table to display.

Define other data as we used in the code,

after that use the code below,

   LOOP AT it_item1 INTO wa_item1.

  AT NEW matnr.     

    G_flag1 = 1.
  ENDAT.


  IF G_flag1 is NOT INITIAL.
    wa_final-item     = wa_item1-item.
    wa_final-desc    = wa_item1-item.
  CLEAR G_flag1.
  ENDIF.

    wa_final-qty         =  wa_final-qty+ wa_item1-qty.
    wa_final-intvalue1 gwa_final-intvalue1+  gwa_item1-intvalue1.
    wa_final-intvalue2 gwa_final-intvalue2+  gwa_item1-intvalue2.
    wa_final-intvalue3 gwa_final-intvalue3+  gwa_item1-intvalue3.


at END OF matnr.
   G_flag2 = 1.
   ENDAT.


   IF G_flag2 is NOT INITIAL.
     APPEND wa_final TO it_final.
    CLEAR wa_final.
    CLEAR G_flag2.
   ENDIF.


ENDLOOP.

" Am using Flag value inside "at new" and "at end of" because variables will be holding only junk value inside these control break statements.

Hope you got this logic, Please get back if you have any issues in understanding the code

Thanks,

Satish

Read only

0 Likes
1,433

Hi Satish,

Thanks for the reply, Your code worked

Also i thank all others who contributed for my query.

Thanks,

lokeshwari

Read only

0 Likes
1,433

Glad that you got the solution

Read only

0 Likes
1,433

hiiii alll,

          if i have 1 field which i dnt want to collect like rate whos value must b same throughout...

for eg..

total_diamnd_stn     discription      no_of_stn     diamnd_rate     total_val

.22                         round              22               120                   = 120*.22

.32                         crt_round         12               150                   =150*.32

.45                         round              2                120                    =120*.45

.85                        crt_round          8                150                    =150*.85

now i want to club all the columns, but the diamnd_rate column also gets clubed, which i want only 120 and 150 correspondly...

output like below...

total_diamnd_stn     discription      no_of_stn     diamnd_rate     total_val

      .67                   round                    24          120                    120*.67

    1.17               crt_round               20          150                    150*1.17

plz help......

thank u..

Read only

0 Likes
1,433

Hi Priyanka,

Make DIAMND_RATE column type as C (CHAR) and try.

Regards,

Vijay