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

add multiple column of rows

hi i have an internal table itab it has following values.

empl_Id month expence1 expence2 expence3 expence4

259 jan 00 25 25 66

259 feb 30 11 00 22

259 feb 40 00 22 45

259 feb 40 00 26 10

259 mar 00 30 72 45

259 mar 25 88 32 55

259 apr 40 00 22 45

the final value of the internal table itab2 should be.

259 jan 00 25 25 66

259 feb 110 11 48 77

259 mar 25 118 104 110

259 apr 40 00 22 45

please suggest me how to write the code

Add a comment
10|10000 characters needed characters exceeded

Related questions

9 Answers

  • Best Answer
    Posted on Feb 25, 2009 at 12:26 PM
    LOOP AT itab.
    
    COLLECT itab.
    itab2 = itab.
    APPEND itab2.
    
    ENDLOOP.
    

    Pushpraj

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 25, 2009 at 12:25 PM

    hi there,

    use at end of event.

    search sdn with key word at end of.

    regards

    Edited by: BrightSide on Feb 25, 2009 1:57 PM

    Edited by: BrightSide on Feb 25, 2009 1:58 PM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 25, 2009 at 12:26 PM
    loop at itab.
     collect itab into itab2.
    endloop.
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 25, 2009 at 12:29 PM

    Hi,

    loop at itab into fs.

    at new month.

    sum.

    endat.

    at end of month.

    write : ...

    endat.

    endloop.

    This resolves ur issue

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 25, 2009 at 12:30 PM

    Hi,

    sort itab by employee_id month.

    Loop at itab.

    itab2-employeeid = itab-employeeid.

    itab2-month = itab-month.

    expense1 = expense1 + itab-expense1.

    expense2 = expense2 + itab-expense2.

    expense3 = expense3 + itab-expense3.

    expense4 = expense4 + itab-expense4.

    at end of month.

    itab2-expense1 = expense1.

    itab2-expense1 = expense2.

    itab2-expense1 = expense3.

    itab2-expense1 = expense4.

    clear: expense1, expense2,expense3,expense4.

    append itab2.

    end at.

    endloop.

    Regards,

    Venkatesh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 25, 2009 at 12:42 PM

    Hi Ajay,

    loop at  itab.
    write:/ itab-empl_id.
    at end of month.
    sum.
    write: 10 itab-month,
                 itab-exp1,
                 itab-exp2,
                 itab-exp3,
                 itab-exp4.
    endat.
    endloop.
    

    also try this......

    create itab2 of empl_id, month as character fields.

    loop at itab.
    itab2-emp = itab-emp.
    itab2-month = itab-month.
    itab2-exp1 = itab-exp.
    itab2-exp2 = itab-exp.
    itab2-exp3 = itab-exp.
    itab2-exp4 = itab-exp.
    collect itab2.
    endloop.
    

    Regards,

    Mdi.Deeba

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 25, 2009 at 12:43 PM

    Hi

    here im am assuming that your internal table is not with header line and

    the work area is wa1.Create another internal table of the same line type

    of the first one(ITAB1).

    Now loop through the internal table itab1 .

    loop at itab1 into wa1.
    COLLECT wa1 INTO itab2.
     endloop.

    Now your itab2 eill contains the values as follows

    259 jan 00 25 25 66
    259 feb 110 11 48 77
    259 mar 25 118 104 110
    259 apr 40 00 22 45

    What this statement does is,it will inserts contents of a work area wa to the

    itab2 by adding all the numeric fields with the same key.

    Try this.

    This defnitly will solve your problem.

    Regards

    Hareesh.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 25, 2009 at 12:44 PM

    Hi

    here im am assuming that your internal table is not with header line and

    the work area is wa1.Create another internal table of the same line type

    of the first one(ITAB1).

    Now loop through the internal table itab1 .

    loop at itab1 into wa1.
    COLLECT wa1 INTO itab2.
     endloop.

    Now your itab2 eill contains the values as follows

    259 jan 00 25 25 66
    259 feb 110 11 48 77
    259 mar 25 118 104 110
    259 apr 40 00 22 45

    What this statement does is,it will inserts contents of a work area wa to the

    itab2 by adding all the numeric fields with the same key.

    Try this.

    This defnitly will solve your problem.

    Regards

    Hareesh.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 25, 2009 at 12:45 PM

    Hi Ajay,

    Try following code.

    sort itab by empl_id month exp1 exp2 exp3 exp4.

    data: l_itab like itab,

    l_exp1 like itab-exp1,

    l_exp2 like itab-exp2,

    l_exp3 like itab-exp3,

    l_exp4 like itab-exp4.

    loop at itab.

    move itab to l_itab.

    l_exp1 = l_exp1 + l_itab-exp1 .

    l_exp2 = l_exp2 + l_itab-exp2 .

    l_exp3 = l_exp3 + l_itab-exp3 .

    l_exp4 = l_exp4 + l_itab-exp4 .

    at end of month.

    write : \1(10) l_itab-empl_id ,

    13(8) l_itab-month ,

    24(8) l_exp1 ,

    35(8) l_exp1 ,

    46(8) l_exp1 ,

    57(8) l_exp1 .

    ****Or populate ITAB2......as per your requirement.....

    clear : l_exp1,

    l_exp2,

    l_exp3,

    l_exp4.

    endat.

    endloop.

    Regards,

    Anil

    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.