Skip to Content

Use of inserting record with sy-tabix in at new and at end

Hi all,

I have some logical issue while using at new and at end of concept .

My requirement, calculated record will insert on the at end of section.

Pls see my code here.

IT2[] = IT1[] " it contains more than 50 records.

sort it1 by date plant material type

sort it2 by date plant material type

my input it1,

date plant material type

19072016 A X sale

19072016 A X stock

19072016 B X stock

19072016 C X sale

19072016 C X stock

loop at it1 into wa1

at new matnr.

clear : wa1.

end at.

if wa1-type = 'stock'

wa1-st = value.

else

wal1-sa = value.

endif.

at end matnr.

if wa1-type = 'sale'

sal1-sa =value.

else

wa1-st = value.

endif.

wa1-cal = wa1-st / wa1-sal.

sy tab = sy tab + 1.

insert wa1 to it2 index into sy tabix.

Here, same material have sale and stock means, loop will executed twice and record will inserted third place.

another material only have sale or stock means, loop will executed once and record to be inserted on fifth place.

the above two scenario will come next records.

How it can be achieved. Please help.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Jul 19, 2016 at 07:37 PM

    As Matthew suggested, simply running this through debugger should explain how AT... events work. You'll also see in debugger that inside AT... ENDAT only certain fields have values and others are replaced with the asterisks. These events are tricky.

    I didn't get how sy-tabix is involved here exactly or even what are you trying to achieve, sorry. It does seem like you rather need COLLECT but it's not really clear what's the goal here. You might want to clarify.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 19, 2016 at 08:03 AM

    Your program won't work in any sensible way, since loop at it1 into wa1 causes WA1 to contain exactly the next record in all parts, every time. Your updates in the loop will all be lost.

    You must run it in the debugger - then you can see how the data changes, step by step.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 20, 2016 at 06:14 AM

    Hi,

    May I know why you are clearing the wa1 at new matnr? (Instead you can copy wa1 to a temporary wok area wa2)

    Because after that statement you have few more lines.At the line if wa1-type = 'stock' the wa1 is empty.

    Correct me if I am wrong.

    Regards,

    Priyanka.

    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.