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

AT END (Values Group) Issue

muhammad_sohail
Participant
0 Likes
414

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
383

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.

2 REPLIES 2
Read only

Former Member
0 Likes
384

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

Read only

Former Member
0 Likes
383

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.