[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
    

Categories:

SAP/ABAP