๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿง‘‍๐Ÿ’ผ SAP/ABAP

[SAP ABAP] COMPARING ์ด๋ž€?

by Jay Din 2024. 12. 19.
728x90
๋ฐ˜์‘ํ˜•

1. COMPARING ์ด๋ž€?

COMPARING ์€ ABAP์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค๋ฃฐ ๋•Œ ํŠน์ • ํ•„๋“œ๋ฅผ ๋น„๊ตํ•˜๋Š” ๊ธฐ์ค€์œผ๋กœ ์ •ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ํ‚ค์›Œ๋“œ์ž…๋‹ˆ๋‹ค.

์‰ฝ๊ฒŒ ๋งํ•ด์„œ, ํ•„๋“œ ์ค‘์—์„œ "์ด๊ฑธ ๊ธฐ์ค€์œผ๋กœ ๋น„๊ตํ•˜๊ฒ ๋‹ค." ๋ผ๊ณ  ๋ช…์‹œ์ ์œผ๋กœ ์„ ์–ธํ•˜๋Š” ๊ฒ๋‹ˆ๋‹ค.

 

2. COMPARING ์‚ฌ์šฉ ์˜ˆ์‹œ

  1. ์ƒํ™ฉ:
    • ์ด๋ฆ„, ๋‚˜์ด, ์ฃผ์†Œ๊ฐ€ ํฌํ•จ๋œ ์นœ๊ตฌ๋“ค ๋ช…๋‹จ์ด ์žˆ์Šต๋‹ˆ๋‹ค.
    • ๊ทธ๋Ÿฐ๋ฐ "์ด๋ฆ„"์ด ์ค‘๋ณต๋œ ์• ๋“ค๋งŒ ์ง€์šฐ๊ณ  ์‹ถ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
  2. ๋น„๊ต ๊ธฐ์ค€:
    • ์ „์ฒด ์ •๋ณด๋ฅผ ๋‹ค ๋น„๊ตํ•˜์ง€ ์•Š๊ณ , '์ด๋ฆ„'๋งŒ ๋ณด๊ฒ ๋‹ค๊ณ  ์ •ํ•ฉ๋‹ˆ๋‹ค.
    • ๊ทธ๋Ÿด ๋•Œ, "COMPARING ์ด๋ฆ„"์ด๋ผ๊ณ  ํ•˜๋Š” ๊ฒ๋‹ˆ๋‹ค.
  3. ๊ฒฐ๊ณผ:
    • "COMPARING ์ด๋ฆ„"์„ ์‚ฌ์šฉํ•˜๋ฉด ์ด๋ฆ„๋งŒ ๊ธฐ์ค€์œผ๋กœ ์ค‘๋ณต๋œ ์• ๋“ค๋งŒ ๊ณจ๋ผ๋‚ด๊ฑฐ๋‚˜ ์ง€์šฐ๋Š” ์ž‘์—…์„ ์‰ฝ๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์•„๋ž˜๋Š” name ํ•„๋“œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ค‘๋ณต ์ œ๊ฑฐ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.

TYPES: BEGIN OF TY_FRIEND,
      NAME TYPE STRING,
      AGE TYPE I,
      CITY TYPE STRING,
  END OF TY_FRIEND.

DATA: LT_FRIENDS TYPE TABLE OF TY_FRIEND,
      WA_FRIEND TYPE TY_FRIEND.


" ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€
CLEAR WA_FRIEND.
WA_FRIEND-NAME = 'Anna'.
WA_FRIEND-AGE = 25.
WA_FRIEND-CITY = 'Seoul'.
APPEND WA_FRIEND TO LT_FRIENDS.

CLEAR WA_FRIEND.
WA_FRIEND-NAME = 'John'.
WA_FRIEND-AGE = 22.
WA_FRIEND-CITY = 'Incheon'.
APPEND WA_FRIEND TO LT_FRIENDS.

CLEAR WA_FRIEND.
WA_FRIEND-NAME = 'Anna'.
WA_FRIEND-AGE = 30.
WA_FRIEND-CITY = 'Busan'.
APPEND WA_FRIEND TO LT_FRIENDS.

" ์ด๋ฆ„(name)์„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•˜๊ณ  ์ค‘๋ณต ์ œ๊ฑฐ
SORT LT_FRIENDS BY NAME.
DELETE ADJACENT DUPLICATES FROM LT_FRIENDS COMPARING NAME.

" lt_friends ์ถœ๋ ฅ
LOOP AT LT_FRIENDS INTO WA_FRIEND.
  WRITE: / 'Name: ', WA_FRIEND-NAME,
        'Age: ', WA_FRIEND-AGE,
        'City: ', WA_FRIEND-CITY.
ENDLOOP.

 

๋งŒ์•ฝ ์œ„ ์ฝ”๋“œ์—์„œ name์œผ๋กœ ์ •๋ ฌ์„ ํ•ด์ฃผ์ง€ ์•Š์œผ๋ฉด ์ค‘๋ถ ์ œ๊ฑฐ๊ฐ€ ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์‹คํ–‰ ๊ฒฐ๊ณผ

 

3. COMPARING ์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ 

  1. ํ•„์š”ํ•œ ํ•„๋“œ๋งŒ ๋น„๊ต:
    • ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ๋น„๊ตํ•  ํ•„์š” ์—†์ด ํ•„์š”ํ•œ ํ•„๋“œ๋งŒ ๊ณจ๋ผ์„œ ํšจ์œจ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
  2. ์†๋„์™€ ์ •ํ™•์„ฑ:
    • ๋ถˆํ•„์š”ํ•œ ์ž‘์—…์„ ์ค„์—ฌ์„œ ๋” ๋น ๋ฅด๊ณ  ์ •ํ™•ํ•˜๊ฒŒ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

728x90
๋ฐ˜์‘ํ˜•