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

control level statement

hii all,

i have a internal table in which data is coming like this

VBELN LFIMG

20000018 50,000

80003370 1,000

80003371 5,000

80003371 5,000

80003371 4,000

80003371 4,000

80003372 10,000

80003373 10,000

80003375 4,000

80003375 5,000

80003375 4,000

80003375 3,000

80003376 2,000

80003376 4,000

80003376 4,000

80003376 5,000

80003377 5,000

80003377 6,000

80003377 4,000

80003377 7,000

80003378 1,000

80003378 5,000

80003378 6,000

80003378 7,000

80003379 7,000

80003379 4,000

80003379 3,000

80003379 5,000

80003380 1,000

80003380 1,000

80003380 2,000

80003380 1,000

80003381 2,000

80003381 3,000

80003381 1,000

80003381 1,000

80003382 2,000

80003382 3,000

80003382 1,000

80003382 1,000

80003383 3,000

80003383 2,000

80003383 2,000

80003383 1,000

80003384 5,000

80003384 6,000

80003384 6,000

80003384 7,000

80003385 3,000

80003385 3,000

80003385 5,000

80003385 6,000

80003386 3,000

80003386 6,000

both fields coming from lips.

now i want count vbeln when:

vbeln is not change:

and correponding values of lfimg would be added

and display.

the OUTPUT SHOULD BE:

vbeln lfimg no. of records

20000018 50,000 1

80003370 1,000 1

80003371 18000 4

80003372 10,000 1.

and so on.....................

please provide me the suitable code.

thanks

babbal.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 22, 2008 at 06:05 PM

    Hi,

    Try this..

    DATA: v_count type i.

    DATA: wa LIKE LINE OF ITAB.

    • Make sure the VBELN is the first column in your internal table ITAB.

    SORT ITAB BY VBELN.

    LOOP AT ITAB INTO WA.

    V_COUNT = V_COUNT + 1.

    AT END OF VBELN.

    SUM.

    WA_FINAL-VBELN = WA-VBELN.

    WA_FINAL-LFIMG = WA-LFIMG.

    WA_FINAL-COUNT = V_COUNT.

    • Move the records to the final internal table.

    APPEND WA_FINAL TO ITAB_FINAL.

    • Clear the count.

    CLEAR: V_COUNT.

    ENDAT.

    ENDLOOP.

    **ITAB_FINAL will have the consolidated records

    Thanks

    Naren

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 22, 2008 at 06:06 PM

    Hello,

    VBELN is a character field and lfimg is a quantity field.

    Create one more internal table with 3 fields, first 2 should be vbeln and lfimg.

    Let the 3rd field be an integer field - say count. Set this value to 1 for every first occurence.

    For every subsequent occurence of the vbeln, just use the collect statement.

    Please make sure you always have 1 in the count so that when you use the collect statement 1 gets added to the previous value.

    I have done this in the past and worked for me perfectly. Give it a try.

    cheers,

    Sushil Joshi

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 22, 2008 at 06:13 PM

    Hi,

    try the below code:

    data:

    w_count type i,

    w_rec_change type c.

    data:

    begin of i_final occurs 0,

    vbeln like vbap-vbeln,

    lfimg like likp-lfimg,

    count type i,

    end of i_final.

    sort itab by vbeln.

    clear w_count.

    loop at itab.

    clear w_rec_change.

    w_count = w_count + 1.

    move itab-vbeln to i_final-vbeln.

    i_final-lfimg = i_final-lfimg + itab-lfimg.

    at end of vbeln.

    w_rec_change = 'X'.

    endat.

    if w_rec_change eq 'X'.

    move w_count to i_final-count.

    append i_final.

    clear i_final.

    clear w_count.

    endif.

    endloop.

    Thanks.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 23, 2008 at 03:38 AM

    Hi,

    Try this code.

    Sort itab by vbeln

    Loop at itab into wa_itab.

    Sum = sum + lfimg.

    Cnt = cnt + 1.

    At end of vbeln

    Wa_itab2-vbeln = wa_itab1-vbeln.

    Wa_itab2-lfimg = sum.

    Wa_itab2-count = cnt.

    append wa_itab2 to itab2.

    clear: sum,

    cnt.

    Endat.

    u2026u2026u2026u2026u2026u2026u2026..

    Endloop.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 23, 2008 at 04:00 AM

    Hope this helps,

    Lets say, you have your original data in itab1.

    And you are trying to fill up itab2.

    Loop at itab1 .
      itab2-vbeln = itab1-vbeln.
      itab2-lfimg = itab1-lfimg.
      itab2-count = 1.
      collect itab2.
    endloop.

    Just realized, sushil suggested the same thing.

    Edited by: RK on Jul 23, 2008 6:02 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 23, 2008 at 04:10 AM

    hi babbal,

    check the code snippet given Sharin..

    it works..

    Regards ..

    Raju Mummidi

    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.