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

Control Break Statement

Hi,

I have a internal table with the following field:

material number line number qty

ABC 1 10

DEF 2 20

DEF 2 30

HJF 1 5

HJF 1 10

FGT 2 5

i try to group the records and sum the quantity by the line number field.

AT END OF LINE_NUMEBR.

..

ENDAT.

But, i found that the at end of statement get triggered on every record. How can i resolve it??

Regards,

Kit

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 04:09 AM

    Hi,

    before using this u just sort ur itab by material number.

    and use at end of matnr.

    SORT ITAB BY MATNR.

    and then use

    loop at itab.

    at end of matnr.

    .....

    endat.

    endloop.

    rgds,

    bharat.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 04:09 AM

    first sort the LINE_NUMEBR.

    sort itab by LINE_NUMEBR.

    after use at end.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 04:11 AM

    AT NEW:

    I have three fields in my itab namely f1, f2 and f3.

    the following are the records:

    f1.........f2.................f3...

    2.........3...................4

    2.........4...................5

    2........4....................6

    AT NEW or AT END of f3 will look all the fields to the left, if there is a change then it will trigger.

    For Example

    AT NEW f3 will treat all the lines as new lines

    AT NEW f2 will treat f1 and f2 as new lines.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 04:55 AM

    Hi Kit,

    This is kiran kumar.G.(working on SAP).I will understand ur problem.I will develop a small code for u.I will check that code it is executed sucessfully.plz check it once.

    If u satisfy with my answer plz give me REWARD POINTS.

    copy the below code and execute it.ur problem is solved.

    PLEASE THE "DISPLAY_DATA" FORM.There i develop a logic.

    CODE:

    ----


    • Tables

    ----


    tables:vbap.

    ----


    • Local Variables

    ----


    data: ltotal type i.

    ----


    • Internal Table

    ----


    data: begin of itab occurs 0,

    matnr like vbap-matnr,

    posnr like vbap-posnr,

    netpr like vbap-netpr,

    end of itab.

    ----


    • Selection Screen

    ----


    selection-screen : begin of block b1 with frame title text-001.

    select-options : s_matnr for vbap-matnr.

    selection-screen : end of block b1.

    ----


    • Initialization

    ----


    initialization.

    perform initial.

    ----


    • Fetch Data

    ----


    start-of-selection.

    perform fetch_data.

    ----


    • Display data

    ----


    end-of-selection.

    perform display_data.

    &----


    *& Form initial

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form initial .

    s_matnr-sign = 'I'.

    s_matnr-option = 'BT'.

    s_matnr-low = 'M-01'.

    s_matnr-high = 'M-20'.

    append s_matnr.

    endform. " initial

    &----


    *& Form fetch_data

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form fetch_data .

    Select matnr

    posnr

    netpr

    from vbap

    into table itab

    where matnr in s_matnr.

    endform. " fetch_data

    &----


    *& Form display_data

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form display_data .

    sort itab by matnr posnr.

    loop at itab.

    at first.

    write:/ 'MATNR', 20 'POSNR', 40 'NETPR'.

    endat.

    at new matnr.

    write:/ itab-matnr.

    endat.

    at new posnr.

    write:/20 itab-posnr.

    endat.

    write:/40 itab-netpr.

    ltotal = ltotal + itab-netpr.

    at end of posnr.

    write:/35 'TOTAL =', ltotal.

    clear ltotal.

    endat.

    endloop.

    endform. " display_data

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 04:59 AM

    Hi

    see this program you can understand very easily

    • Using AT FIRST , AT NEW, AT THE END OF , AT LAST.

    DATA: BEGIN OF ITAB OCCURS 0,
          F1 TYPE I,
          F2(6) TYPE C,
          F3(10) TYPE N,
          F4(16) TYPE P DECIMALS  2,
    
          END OF ITAB.
    
    
    DATA: SUB_TOT(10) TYPE P DECIMALS 3.
    
    **--1
    
    ITAB-F1 = 1.
    ITAB-F2 = 'ONE'.
    ITAB-F3 = 10.
    ITAB-F4 = '1000.00'.
    
    APPEND ITAB.
    CLEAR ITAB.
    
    ITAB-F1 = 1.
    ITAB-F2 = 'ONE'.
    ITAB-F3 = 20.
    ITAB-F4 = '2000.00'.
    
    
    APPEND ITAB.
    CLEAR ITAB.
    
    
    ITAB-F1 = 1.
    ITAB-F2 = 'ONE'.
    ITAB-F3 = 30.
    ITAB-F4 = '3000.00'.
    
    
    APPEND ITAB.
    CLEAR ITAB.
    
    *--2
    
    ITAB-F1 = 2.
    ITAB-F2 = 'TWO'.
    ITAB-F3 = 10.
    ITAB-F4 = '1000.00'.
    
    APPEND ITAB.
    CLEAR ITAB.
    
    
    ITAB-F1 = 2.
    ITAB-F2 = 'TWO'.
    ITAB-F3 = 20.
    ITAB-F4 = '2000.00'.
    
    
    APPEND ITAB.
    CLEAR ITAB.
    
    *-- 3
    
    ITAB-F1 = 3.
    ITAB-F2 = 'THREE'.
    ITAB-F3 = 10.
    ITAB-F4 = '1000.00'.
    
    
    APPEND ITAB.
    CLEAR ITAB.
    
    
    
    ITAB-F1 = 3.
    ITAB-F2 = 'THREE'.
    ITAB-F3 = 20.
    ITAB-F4 = '2000.00'.
    
    APPEND ITAB.
    CLEAR ITAB.
    
    
    SORT ITAB BY F1.
    
    LOOP AT ITAB.
    
    AT FIRST.
    WRITE: /35 ' MATERIAL DETAILS:'.
    ULINE.
    ENDAT.
    
    AT NEW F1.
    WRITE: / 'DETAILS OF MATERIAL:' COLOR 7  , ITAB-F1.
    ULINE.
    ENDAT.
    
    WRITE: / ITAB-F1, ITAB-F2, ITAB-F3, ITAB-F4.
    
    SUB_TOT = SUB_TOT + ITAB-F4.
    
    AT END OF F1.
    ULINE.
    WRITE: / 'SUB TOTAL :'  COLOR 3 INVERSE ON, SUB_TOT COLOR 3 INVERSE ON.
    CLEAR SUB_TOT.
    ENDAT.
    
    AT LAST.
    SUM.
    ULINE.
    WRITE: 'SUM:', ITAB-F4.
    ULINE.
    ENDAT.
    
    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 03, 2007 at 05:00 AM

    hi

    have a look at this code

    REPORT zinternaltable.

    TYPES:BEGIN OF itab,

    num TYPE i,

    name(10) TYPE c,

    amt type i,

    END OF itab.

    DATA : wa_itab TYPE itab,

    it_itab TYPE STANDARD TABLE OF itab.

    DATA : v_lines TYPE i.

    wa_itab-num = 1.

    wa_itab-name = 'nag'.

    wa_itab-amt = 1000.

    append wa_itab TO it_itab.

    wa_itab-num = 1.

    wa_itab-name = 'nag'.

    wa_itab-amt = 2000.

    append wa_itab TO it_itab.

    wa_itab-num = 1.

    wa_itab-name = 'nag'.

    wa_itab-amt = 1500.

    append wa_itab TO it_itab.

    wa_itab-num = 2.

    wa_itab-name = 'sri'.

    wa_itab-amt = 500.

    append wa_itab tO it_itab.

    wa_itab-num = 2.

    wa_itab-name = 'sri'.

    wa_itab-amt = 600.

    append wa_itab TO it_itab.

    wa_itab-num = 2.

    wa_itab-name = 'sri'.

    wa_itab-amt = 700.

    append wa_itab TO it_itab.

    wa_itab-num = 3.

    wa_itab-name = 'ganesh'.

    wa_itab-amt = 1200.

    append wa_itab TO it_itab.

    wa_itab-num = 3.

    wa_itab-name = 'ganesh'.

    wa_itab-amt = 1300.

    append wa_itab TO it_itab.

    wa_itab-num = 3.

    wa_itab-name = 'ganesh'.

    wa_itab-amt = 1400.

    append wa_itab TO it_itab.

    wa_itab-num = 4.

    wa_itab-name = 'suresh'.

    wa_itab-amt = 900.

    append wa_itab TO it_itab.

    wa_itab-num = 4.

    wa_itab-name = 'suresh'.

    wa_itab-amt = 300.

    append wa_itab TO it_itab.

    sort it_itab.

    LOOP AT it_itab INTO wa_itab.

    at first.

    write :/ 'details of sales order:'.

    uline.

    endat.

    at new num.

    write :/ 'serial num:', wa_itab-num.

    uline.

    endat.

    WRITE :/ wa_itab-num , wa_itab-name , wa_itab-amt.

    at end of num.

    uline.

    sum.

    write :/ 'total amount:',wa_itab-amt.

    uline.

    endat.

    *

    at last.

    sum.

    uline.

    write:/ 'grand total:',wa_itab-amt.

    endat.

    ENDLOOP.

    describe table it_itab lines v_lines.

    WRITE:/'no of records :', v_lines.

    reward if u find useful

    Regards

    Nagesh.Paruchuri

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 06:30 AM

    Hey Kit,

    Just try to use 'COLLECT' on the Internal table rather than using AT END.

    and then u get Qty Summed up with refrence to MAterial Number and Line number as follows.

    ABC 1 10

    DEF 2 50

    HJF 1 15

    FGT 2 5

    Then U can use this data as per ur requirement.

    Add a comment
    10|10000 characters needed characters exceeded

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.