2009 Jul 16 10:56 AM
Dear All,
I have itab2 which is filled (as debugged) with btext and persk. I want to group values on the basis of btext. I m using the following (AT END) method. but the values or not gonn'a to be grouped and in sum_itab these are displayed separately not in group.
Kindly someone pls. help me what is the mistake which i m doing in following statements.
SORT itab2 BY btext.
LOOP AT itab2.
sum_itab-btext = itab2-btext.
sum_itab-persk = itab2-persk.
IF ( sum_itab-persk EQ '01' ).
counter1 = counter1 + 1.
ELSEIF ( sum_itab-persk EQ '02' ).
counter2 = counter2 + 1.
AT END OF btext.
sum_itab-counter_1 = counter1.
sum_itab-counter_2 = counter2.
sum_itab-sum_count = sum_itab-counter1 + sum_itab-counter2.
APPEND sum_itab.
CLEAR: sum_itab,
counter1,
counter2,
ENDAT.
CLEAR: itab2,
sum_itab.
ENDLOOP.
2009 Jul 16 11:02 AM
hi Sohail,
in itab2 btext should be the first field.I guess this was the main Reason.
I have just corrected the syntatical errors in your code.
SORT itab2 BY btext.
LOOP AT itab2.
sum_itab-btext = itab2-btext.
sum_itab-persk = itab2-persk.
IF ( sum_itab-persk EQ '01' ).
counter1 = counter1 + 1.
ELSEIF ( sum_itab-persk EQ '02' ).
counter2 = counter2 + 1.
endif.
AT END OF btext.
sum_itab-counter_1 = counter1.
sum_itab-counter_2 = counter2.
sum_itab-sum_count = sum_itab-counter1 + sum_itab-counter2.
APPEND sum_itab.
CLEAR: sum_itab,
counter1,
counter2.
ENDAT.
CLEAR: itab2,sum_itab.
ENDLOOP.Regards
Sajid
Edited by: shaik sajid on Jul 16, 2009 12:03 PM
Dear All,
I have itab2 which is filled (as debugged) with btext and persk. I want to group values on the basis of btext. I m using the following (AT END) method. but the values or not gonn'a to be grouped and in sum_itab these are displayed separately not in group.
Kindly someone pls. help me what is the mistake which i m doing in following statements.
SORT itab2 BY btext.
LOOP AT itab2.
sum_itab-btext = itab2-btext.
sum_itab-persk = itab2-persk.
IF ( sum_itab-persk EQ '01' ).
counter1 = counter1 + 1.
ELSEIF ( sum_itab-persk EQ '02' ).
counter2 = counter2 + 1.
AT END OF btext.
sum_itab-counter_1 = counter1.
sum_itab-counter_2 = counter2.
sum_itab-sum_count = sum_itab-counter1 + sum_itab-counter2.
APPEND sum_itab.
CLEAR: sum_itab,
counter1,
counter2,
ENDAT.
CLEAR: itab2,
sum_itab.
ENDLOOP.
2009 Jul 16 11:02 AM
hi Sohail,
in itab2 btext should be the first field.I guess this was the main Reason.
I have just corrected the syntatical errors in your code.
SORT itab2 BY btext.
LOOP AT itab2.
sum_itab-btext = itab2-btext.
sum_itab-persk = itab2-persk.
IF ( sum_itab-persk EQ '01' ).
counter1 = counter1 + 1.
ELSEIF ( sum_itab-persk EQ '02' ).
counter2 = counter2 + 1.
endif.
AT END OF btext.
sum_itab-counter_1 = counter1.
sum_itab-counter_2 = counter2.
sum_itab-sum_count = sum_itab-counter1 + sum_itab-counter2.
APPEND sum_itab.
CLEAR: sum_itab,
counter1,
counter2.
ENDAT.
CLEAR: itab2,sum_itab.
ENDLOOP.Regards
Sajid
Edited by: shaik sajid on Jul 16, 2009 12:03 PM
2009 Jul 16 11:20 AM
Hi,
Your code works fine for me. I think you have declared your type declaration in a different manner. Your field *btext' has to be the first field in the internal table declaration. Only then, the AT END OF will be triggered correctly. Otherwise, it will be triggered for every row. I think that's ther reason why your data does not seem to be getting grouped. Check the following code.
DATA: BEGIN OF itab2 OCCURS 0,
btext(10) TYPE c, "<- Check this
persk(10) TYPE c,
END OF itab2.
DATA: BEGIN OF sum_itab OCCURS 0,
btext(10) TYPE c,
persk(10) TYPE c,
counter_1 TYPE i,
counter_2 TYPE i,
sum_count TYPE i,
END OF sum_itab.
DATA: counter1 TYPE i,
counter2 TYPE i.
itab2-btext = 'A'. itab2-persk = '01'.
APPEND itab2.
itab2-btext = 'A'. itab2-persk = '02'.
APPEND itab2.
itab2-btext = 'A'. itab2-persk = '03'.
APPEND itab2.
itab2-btext = 'B'. itab2-persk = '03'.
APPEND itab2.
SORT itab2 BY btext.
LOOP AT itab2.
sum_itab-btext = itab2-btext.
sum_itab-persk = itab2-persk.
IF ( sum_itab-persk EQ '01' ).
counter1 = counter1 + 1.
ELSEIF ( sum_itab-persk EQ '02' ).
counter2 = counter2 + 1.
ENDIF.
AT END OF btext.
sum_itab-counter_1 = counter1.
sum_itab-counter_2 = counter2.
sum_itab-sum_count = sum_itab-counter_1 + sum_itab-counter_2.
APPEND sum_itab.
CLEAR: sum_itab,
counter1,
counter2.
ENDAT.
CLEAR: itab2,
sum_itab.
ENDLOOP.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |