[ABAP] AT FIRST / AT LAST / AT NEW / AT END OF / ON CHANGE OF
COL1(1) TYPE C | COL2(3) TYPE C | COL3 TYPE I | COL4(3) TYPE C |
---|---|---|---|
A | 001 | 10 | aaa |
A | 001 | 30 | aaa |
A | 001 | 20 | aab |
B | 002 | 0 | bbb |
B | 002 | 50 | bbb |
A | 002 | 50 | aaa |
μμ κ°μ μΈν°λν μ΄λΈ lt_tab, μ€νΈλμ³ ls_tab μ λ§λ€μλ€κ³ ν λ,
π AT FIRST / AT LAST
π AT FIRSTλ LOOPμ 맨 μ²μ ν λ²λ§, AT LASTλ LOOPμ 맨 λ§μ§λ§ ν λ²λ§ μ€ν
LOOP AT lt_tab INTO ls_tab.
AT FIRST.
WRITE: / 'AT FIRST'.
ENDAT.
WRITE: / ls_tab-col1, ls_tab-col2, ls_tab-col3, ls_tab-col4.
AT LAST.
WRITE: / 'AT LAST'.
ENDAT.
ENDLOOP.
κ²°κ³Ό)
AT FIRST
A 001 10 aaa
A 001 30 aaa
A 001 20 aab
B 002 0 bbb
B 002 50 bbb
A 002 50 aaa
AT LAST
π AT NEW / AT END OF
π AT NEWλ ν΄λΉ νλ ν¬ν¨ μ νλμ κ°μ΄ λ³κ²½λ λ, AT END OFλ ν΄λΉ νλ ν¬ν¨ μ νλμ κ°μ΄ λ³κ²½λκΈ° μ λ§μ§λ§ λ°μ΄ν°μμ μ€ν
π SORT κ²°κ³Όμ λ°λΌ κ°μ΄ λ¬λΌμ§
π SORT ν μ΄νμ νλλ μλ κ°μ κ΄κ³μμ΄ λ¬Έμλ κΈΈμ΄λ§νΌ *λ‘, μ«μλ 0μΌλ‘ μ±μμ§
βΆ lt_tabμ col1λ‘ SORT
A 001 10 aaa
A 001 30 aaa
A 001 20 aab
A 002 50 aaa
B 002 0 bbb
B 002 50 bbb
-
AT NEW (ν κ°μ νλλ‘ SORT)
SORT lt_tab BY col1. LOOP AT lt_tab INTO ls_tab. AT NEW col1. WRITE: / ls_tab-col1, ls_tab-col2, ls_tab-col3, ls_tab-col4. ENDAT. ENDLOOP.
κ²°κ³Ό)
A *** 0 *** B *** 0 ***
-
AT END OF (ν κ°μ νλλ‘ SORT)
SORT lt_tab BY col1. LOOP AT lt_tab INTO ls_tab. AT END OF col1. WRITE: / ls_tab-col1, ls_tab-col2, ls_tab-col3, ls_tab-col4. ENDAT. ENDLOOP.
κ²°κ³Ό)
A *** 0 *** B *** 0 ***
βΆ lt_tabμ col1 col2λ‘ SORT
A 001 10 aaa
A 001 30 aaa
A 001 20 aab
A 002 50 aaa
B 002 0 bbb
B 002 50 bbb
-
AT NEW (λ κ°μ νλλ‘ SORT)
SORT lt_tab BY col1 col2. LOOP AT lt_tab INTO ls_tab. AT NEW col2. WRITE: / ls_tab-col1, ls_tab-col2, ls_tab-col3, ls_tab-col4. ENDAT. ENDLOOP.
κ²°κ³Ό)
A 001 0 *** A 002 0 *** B 002 0 ***
-
AT END OF (λ κ°μ νλλ‘ SORT)
SORT lt_tab BY col1 col2. LOOP AT lt_tab INTO ls_tab. AT END OF col2. WRITE: / ls_tab-col1, ls_tab-col2, ls_tab-col3, ls_tab-col4. ENDAT. ENDLOOP.
κ²°κ³Ό)
A 001 0 *** A 002 0 *** B 002 0 ***
π ON CHANGE OF
π ON CHANGE OFλ AT NEW/AT ENDμλ λ€λ₯΄κ² ν΄λΉ νλ μ΄ν λͺ¨λ νλμ κ°μ΄ μ μμ μΌλ‘ μΆλ ₯λ¨
-
ν κ°μ νλλ‘ SORT
SORT lt_tab BY col1. LOOP AT lt_tab INTO ls_tab. ON CHANGE OF ls_tab-col1. WRITE: / ls_tab-col1, ls_tab-col2, ls_tab-col3, ls_tab-col4. ENDON. ENDLOOP.
κ²°κ³Ό)
A 001 10 aaa B 002 0 bbb
-
λ κ°μ νλλ‘ SORT
SORT lt_tab BY col1 col2. LOOP AT lt_tab INTO ls_tab. ON CHANGE OF ls_tab-col2. WRITE: / ls_tab-col1, ls_tab-col2, ls_tab-col3, ls_tab-col4. ENDAT. ENDLOOP.
κ²°κ³Ό)
A 001 10 aaa A 002 50 aaa