Skip to Content
author's profile photo Former Member
Former Member

group by in internal table

I have records below in internaltable

"itab_Data"

bukrs,gsber,hkont, budata belnr

200 011A 12345678 2005/01/01 300000001

200 011A 12345678 2005/01/01 300000002

200 140b 12345678 2005/02/02 300000009

300 011A 12345678 2005/01/01 300000003

300 011A 12345678 2005/01/01 300000004

300 150b 12345678 2005/01/02 300000008

500 011A 12345678 2005/01/01 300000005

500 011A 12345678 2005/01/01 300000006

700 130b 12345678 2005/01/01 300000007

700 130b 12345678 2005/01/01 300000007

i want to group the records with respect to

gsber and hkont.

I want display as below.

200 011A 12345678 2005/01/01 300000001

200 011A 12345678 2005/01/01 300000002

300 011A 12345678 2005/01/01 300000003

300 011A 12345678 2005/01/01 300000004

500 011A 12345678 2005/01/01 300000005

500 011A 12345678 2005/01/01 300000006

700 130b 12345678 2005/01/01 300000007

700 130b 12345678 2005/01/01 300000007

200 140b 12345678 2005/02/02 300000009

300 150b 12345678 2005/01/02 300000008

how to do this.could you pls guide.

ambichan.

Add a comment
10|10000 characters needed characters exceeded

Related questions

5 Answers

  • Posted on Feb 06, 2005 at 12:57 PM

    What you need is <b>sort</b>

    Just sort your internal table by <b>hkont</b> you will get the desired result.

    sort itab_data by hkont .

    Regards

    Raja

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi

      I guess Durairaj meant

      SORT itab_data BY gsber hkont .

      If you want to use grouping (technically control level processing) features, you can utilize the following statements, too. They may be a bit difficult to implement. For more information you can refer to the SAP internal help by pressing F1.

      <b>AT NEW <field> .
      AT END OF <field> .
      AT FIRST .
      AT LAST .
      ON CHANGE OF <field> .</b>

      Regards,

      *--Serdar

  • author's profile photo Former Member
    Former Member
    Posted on Feb 07, 2005 at 06:01 AM

    HEY

    i have records listing like this.

    790 001A 12345678 0000/00/00

    200 001A 12345678 0000/00/00

    200 001A 12345678 2005/02/01 4000000005

    790 001A 12345678 2005/02/01 4000000004

    200 001A 12345678 2005/02/02 4000000004

    790 001A 12345678 2005/02/02 4000000003

    790 011A 12345678 0000/00/00

    200 011A 12345678 0000/00/00

    790 011A 12345678 2005/02/04 4000000005

    790 011A 12345678 2005/02/04 7000000001

    for each Date END, i have to put one horizontal

    line at report.

    i used below code for sample..its takes everyrecord

    and printing line.

    could you pls help me how to implement this event.

    loop at itab_data.

    write :/ itab_data-bukrs,

    itab_data-gsber,

    itab_data-hkont,

    itab_data-budat,

    itab_data-belnr.

    at end of budat.(date)

    write line.

    endat.

    at end of gsber.

    write line and calcuate sum.

    endat.

    endloop.

    here it wont work.?

    AT END OF BUDAT(date) and AT END Of GSBER event is not working

    in my report.

    ambichan.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hello Ambi,

      The order of the fields in your internal table is very important if you want to use the control levels with ease and efficiency.

      In your case, would it be possible for you to have GSBER and BUDAT as the first two fields in the internal table ? That would make things easier for you.

      If you cannot do that, then you will have to use ON CHANGE OF. The control level processing using AT...ENDAT is not going to be appropriate.

      Regards,

      Anand Mandalika.

  • Posted on Feb 07, 2005 at 07:41 AM

    Hi ambichan,

    Check out the below given link.

    /people/mark.finnern/blog/2004/08/10/spread-the-love

    Regards

    Raja

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 07, 2005 at 08:15 AM

    Hi chan,

    first sort your internal table like this.

    sort itab by field date.

    Then use below sample code..

    loop at itab.

    on change of field.

    ' Do printing required when new field comes.

    else.

    ' print records for this field value

    on change of date.

    ' print sum

    end on.

    endon.

    endloop.

    You can format your code like above given code.

    I hope it will help you.

    Bhavik

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 07, 2005 at 10:22 AM

    i am really struck up here..

    i have sorted table as

    sort itab_data by gsber hkont budat.

    and did code like this.

    loop at itab_data.

    perform list_detail.

    at end of budat.

    sum.

    perform checkpage.

    perform listtotal.

    endat.

    endloop.

    but "At end" is not working properly.

    how to trace this ...

    "on change" takes one record in advance with the group.

    not suiting my requirment.

    ambichan.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      Try <b>LOOP AT itab_data INTO wa_itab_data. ... ENDLOOP</b>, where wa_itab_data is declared as <b>LIKE LINE OF itab_data</b>.

      For debugging, place a breakpoint at SUM statement and double-click on wa_itab_data in debugger screen.

      Hope this helps.

      Regards

      Message was edited by: Shehryar Khan

      Message was edited by: Shehryar Khan

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.