Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

AT....ENDAT,

Former Member

Hi, Gurus

10 REPLIES 10
Read only

Former Member
0 Likes
1,405

HI,

You forgot to write the issue you are facing...

Read only

Former Member
0 Likes
1,405

Waiting for your question

Thanks,

Jayant

Read only

Former Member
0 Likes
1,405

hi

issue is incomplete

at ... endat is operation on internal table event which gets triggered at en of a pertiular pattern

shiva

Read only

Former Member
0 Likes
1,405

Hi, Gurus.

I have been trying to display the total number of units for each counter in my (sorted) internal table, it, using the above statement. My syntax doesn't seem to do the trick. For instance if the internal table with fields X,Y,Z contains:

X Y Z

1 A 100

2 A 200

3 B 100

4 C 50

5 C 65

I want it to display

A 300

B 100

C 115

Here, column Y is the counter and Z is the number of units. They are both not part of the key.

My code is as follows:

sort it ascending by counter.

loop at it.

at first.

write 'List of counters against number of units'.

endat.

at new counter.

clear total.

endat.

at end of counter.

add it-units to total.

write sy-uline.

write:/ it-counter, 20 total.

endat.

at last.

sum.

write: 'Total number of units for all counters:', it-units.

endat.

endloop.

Read only

0 Likes
1,405

Hi

Use Collect Statement

Example:

DATA: BEGIN OF seats, 
        carrid   TYPE sflight-carrid, 
        connid   TYPE sflight-connid, 
        seatsocc TYPE sflight-seatsocc, 
      END OF seats. 

DATA seats_tab LIKE HASHED TABLE OF seats 
               WITH UNIQUE KEY carrid connid. 

SELECT carrid connid seatsocc 
       FROM sflight 
       INTO seats. 
  COLLECT seats INTO seats_tab. 
ENDSELECT.

The collect statement will do the addition for numeric fields

Thanks & Regards

Srinivasu

Edited by: srinivasu bv on Nov 17, 2008 2:57 PM

Read only

0 Likes
1,405

You can do the same in this way also.

**-- Taking the condition that we only want to display the Materials in there latest stage.

**-- For the same we will compare the internal Table with there Material Number (what ever you say)

**-- and there stage number and delete the others.

**-- Before this Loop the Internal Table should be sorted in such a manner that Material

**-- and Stage Should be as below example.

Material Number Stage ---> Header Information.

000000000001 1

000000000001 2

000000000001 3

000000000012 1

000000000012 2

Loop at the Internal Table which has all the data that needs to be displayed.

loop at itab into wa.

Below Condition will work only once.

if wa2 is initial.

wa2 = wa.

endif.

if ( wa-material_number = wa2-material_number ) and ( wa-stage <> wa2-stage ).

In loop if the Material Number is same and stage is different than store the new

Information into the work area.

wa2 = wa.

else.

If new Material Number comes in Loop then our second work area will contain the

Details regarding the last stage of the Previous Material and that is what was needed.

Get the same information into Internal Table which is our Final Internal Table

and this needs to go to the Report Output.

append wa2 to itab2.

clear wa2.

wa2 = wa.

endif.

endloop.

Above is just a example. Just try to implement the same in your code.

Thanks

Jayant

Read only

0 Likes
1,405

coloumn Y has to be the first field of your internal table, otherwise hand it has no chance to work. On the other hand it would be simplier to code like this:

LOOP AT itab.
AT END of Y.
SUM. "Now you have summarized data in the work area based on Y
ENDAT.
ENDLOOP.

Read only

0 Likes
1,405

try this:

loop at itab into wa.

at end of y.

flag = 'X'.

endat.

if flag = 'X'

collect wa into itab1. "itab1 should have same structure as itab.

clear: wa, flag.

endif.

endloop.

regards,

padma

Read only

0 Likes
1,405

data: begin of itab,

end of itab.

Read only

0 Likes
1,405

Hi, Gurus,

I am glad to say I have learnt quite a lot from all your contributions. Your Assistance is greatly appreciated. The solution I found has to do with making the field in question be the first field in the internal table so that the AT...ENDAT statements can work.