Search
Search

itab

i have itab(lbkum,lgort....) with itab-lgort.

i need to collect all the lbkumfor specific lgort, and count the num of lbkum

how i do it in itab???

thanks

Former Memberreplied

hi,

no problem.i too observed our forum points are appearing as 0, so try it later time.

you no need to do sum manually.if you write the code, sap will do the sum of all numeric fields(i think) which are specifying the given condition.we can just use the values comes to the header line of that internal table.

*--further help from help.sap.com

<a href="http://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm">help on SUM in help.sap.com</a>

Within an AT...ENDAT block, you can calculate the contents of the numeric fields of the corresponding control level using the SUM statement.

SUM.

You can only use this statement within a LOOP. If you use SUM in an AT - ENDAT block, the system calculates totals for the numeric fields of all lines in the current line group and writes them to the corresponding fields in the work area (see example in ). If you use the SUM statement outside an AT - ENDAT block (single entry processing), the system calculates totals for the numeric fields of all lines of the internal table in each loop pass and writes them to the corresponding fields of the work area. It therefore only makes sense to use the SUM statement in AT...ENDAT blocks.

a small program on using SUM

DATA: BEGIN OF LINE,

COL1 TYPE C,

COL2 TYPE I,

COL3 TYPE I,

END OF LINE.

DATA ITAB LIKE HASHED TABLE OF LINE

WITH UNIQUE KEY COL1 COL2.

LINE-COL1 = 'A'.

DO 3 TIMES.

LINE-COL2 = SY-INDEX.

LINE-COL3 = SY-INDEX ** 2.

INSERT LINE INTO TABLE ITAB.

ENDDO.

LINE-COL1 = 'B'.

DO 3 TIMES.

LINE-COL2 = 2 * SY-INDEX.

LINE-COL3 = ( 2 * SY-INDEX ) ** 2.

INSERT LINE INTO TABLE ITAB.

ENDDO.

SORT ITAB.

LOOP AT ITAB INTO LINE.

WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.

AT END OF COL1.

SUM.

ULINE.

WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.

SKIP.

ENDAT.

AT LAST.

SUM.

ULINE.

WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.

ENDAT.

ENDLOOP.

The output is:

A 1 1

A 2 4

A 3 9

________________________________

A 6 14

B 2 4

B 4 16

B 6 36

________________________________

B 12 56

________________________________

• 18 70

*--

regards

srikanth

Message was edited by: Srikanth Kidambi

0 View this answer in context
View more on this topic or