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

[SAP ABAP] ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ” Standard, Sorted, Hashed table ์ด๋ž€?

by Jay Din 2025. 1. 2.
728x90
๋ฐ˜์‘ํ˜•

1. ํ…Œ์ด๋ธ”์˜ ์†์„ฑ ๋ฐ ์šฉ๋„ ์ •๋ฆฌํ‘œ

https://sapforbeginner.files.wordpress.com/2014/08/screen-shot-2014-08-31-at-6-35-25-pm.png

 

ํ…Œ์ด๋ธ” ์œ ํ˜• STANDARD TABLE SORTED TABLE HASHED TABLE
๊ตฌ์กฐ ๋น„์ •๋ ฌ, ์ˆœ์„œ๋Œ€๋กœ ๋ฐ์ดํ„ฐ ์ €์žฅ ํ‚ค๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ž๋™ ์ •๋ ฌ๋œ ํ…Œ์ด๋ธ” ํ‚ค ๊ธฐ๋ฐ˜์˜ ํ•ด์‹œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ ๋ฐ์ดํ„ฐ ์ €์žฅ
ํ‚ค ๊ธฐ๋ณธ์ ์œผ๋กœ ์ธ๋ฑ์Šค ํ‚ค ์œ ์ผํ•œ ๋น„๋ฐ€ ํ‚ค ๋˜๋Š” ๋น„์œ ์ผ ํ‚ค ๊ฐ€๋Šฅ ์œ ์ผํ•œ ๋น„๋ฐ€ ํ‚ค๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
์ ‘๊ทผ ๋ฐฉ์‹ ์ˆœ์ฐจ์  ๊ฒ€์ƒ‰(Linear Search) ์ด์ง„ ๊ฒ€์ƒ‰(Binary Search) ํ•ด์‹œ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ธฐ๋ฐ˜ ๊ฒ€์ƒ‰(O(1))
์„ฑ๋Šฅ ๋Œ€๋Ÿ‰ ๋ฐ์ดํ„ฐ์—์„œ ๋Š๋ฆผ ์ •๋ ฌ๋œ ๋ฐ์ดํ„ฐ ๊ฒ€์ƒ‰ ์‹œ ๋น ๋ฆ„ ๊ฐ€์žฅ ๋น ๋ฅธ ๊ฒ€์ƒ‰ ์†๋„ ์ œ๊ณต
๋ฐ์ดํ„ฐ ์‚ฝ์ž… ์‚ฝ์ž… ์ˆœ์„œ๋Œ€๋กœ ์ถ”๊ฐ€ ์‚ฝ์ž… ์‹œ ์ž๋™ ์ •๋ ฌ ํ•ด์‹œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ํ†ตํ•ด ์ €์žฅ
์ค‘๋ณต ํ—ˆ์šฉ ์ค‘๋ณต ํ—ˆ์šฉ ๊ฐ€๋Šฅ ํ‚ค ๊ธฐ์ค€์œผ๋กœ ์ค‘๋ณต ํ—ˆ์šฉ ๊ฐ€๋Šฅ ์ค‘๋ณต ํ—ˆ์šฉ ์•ˆ ๋จ
์‚ฌ์šฉ ์‚ฌ๋ก€ ์ˆœ์ฐจ์ ์ธ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ์ •๋ ฌ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค๋ฃฐ ๋•Œ ๊ณ ์† ๊ฒ€์ƒ‰, ์ค‘๋ณต์ด ์—†์–ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ
ํ•ต์‹ฌ ์š”์•ฝ ๋‹จ์ˆœ ๋ฐ์ดํ„ฐ ์ €์žฅ ๋ฐ ์ˆœ์ฐจ ์ฒ˜๋ฆฌ ์ •๋ ฌ๋œ ๋ฐ์ดํ„ฐ ๋ฐ ํšจ์œจ์ ์ธ ๊ฒ€์ƒ‰ ๊ณ ์† ๊ฒ€์ƒ‰ ๋ฐ ์œ ์ผ ํ‚ค๊ฐ€ ํ•„์š”ํ•  ๋•Œ

 

 

2. Standard Table ์ด๋ž€

  1. ํŠน์ง•
    • ์ˆœ์ฐจ์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋˜๋ฉฐ, ์ •๋ ฌ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
    • ๋ฐ์ดํ„ฐ๋ฅผ ๊ฒ€์ƒ‰ํ•  ๋•Œ(์ธ๋ฑ์Šค ์ ‘๊ทผ) ์„ ํ˜•ํƒ์ƒ‰ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. 
      • ์„ ํ˜• ํƒ์ƒ‰: ๋ฐฐ์—ด์ด๋‚˜ ๋ฆฌ์ŠคํŠธ์˜ ์ฒ˜์Œ๋ถ€ํ„ฐ ๋๊นŒ์ง€ ํ•˜๋‚˜์”ฉ ๊ฐ’์„ ๋น„๊ตํ•˜๋ฉด์„œ ํƒ์ƒ‰ํ•˜๋Š” ๋ฐฉ๋ฒ•
    • ํ‚ค ๊ณ ์œ ์„ฑ (Key Uniqueness): Standard table์˜ ํ‚ค๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฆ‰, ๋ฐ์ดํ„ฐ ์ค‘๋ณต์ด ํ—ˆ์šฉ๋ฉ๋‹ˆ๋‹ค.
  2. ์ž‘๋™ ์›๋ฆฌ
    • ๋ฐ์ดํ„ฐ๊ฐ€ ์‚ฝ์ž…๋˜๋Š” ์ˆœ์„œ๋Œ€๋กœ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.
    • ๊ฒ€์ƒ‰ ์‹œ, ์ˆœ์ฐจ์ ์œผ๋กœ ๋ฐ์ดํ„ฐ ๋ ˆ์ฝ”๋“œ๋ฅผ ํ™•์ดํ•˜๋ฉฐ ๋ชฉํ‘œ ๋ฐ์ดํ„ฐ์— ๋„๋‹ฌํ•ฉ๋‹ˆ๋‹ค. (๊ฒ€์ƒ‰ ์‹œ๊ฐ„์ด ๋ฐ์ดํ„ฐ ํฌ๊ธฐ์— ๋น„๋ก€)
  3. ์‚ฌ์šฉ ์‹œ์ 
    • ๋ฐ์ดํ„ฐ๊ฐ€ ์ •๋ ฌ๋˜์ง€ ์•Š์•„๋„ ๋˜๊ณ , ์ˆœ์ฐจ์ ์ธ ์ฒ˜๋ฆฌ๊ฐ€ ํ•„์š”ํ•œ ๊ฒฝ์šฐ.
    • ๋ฐ์ดํ„ฐ ์–‘์ด ์ ์–ด ๊ฒ€์ƒ‰ ์†๋„๊ฐ€ ํฌ๊ฒŒ ์ค‘์š”ํ•˜์ง€ ์•Š์„ ๋•Œ.
  4. ์„ ์–ธ ๋ฐฉ๋ฒ•
    • ... STANDARD TABLE OF ... WITH EMPTY KEY
DATA: itab TYPE STANDARD TABLE OF mara WITH EMPTY KEY.

 

 

3. Sorted Table ์ด๋ž€?

  1. ํŠน์ง•
    • Sorted table์€ ๋ฐ์ดํ„ฐ๊ฐ€ ์‚ฝ์ž…๋  ๋•Œ ์ž๋™์œผ๋กœ ์ •๋ ฌ๋ฉ๋‹ˆ๋‹ค.
    • ๋ฐ์ดํ„ฐ์— ์ ‘๊ทผํ•  ๋•Œ ์ด์ง„ ํƒ์ƒ‰ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ๊ฒ€์ƒ‰ ์†๋„๋ฅผ ํ–ฅ์ƒ์‹œํ‚ต๋‹ˆ๋‹ค.
    • ํ‚ค ์ ‘๊ทผ (Key Access): Sorted table์—์„œ ๋ฐ์ดํ„ฐ์— ์•ก์„ธ์Šคํ•  ๋•Œ๋Š” ํ‚ค๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ์ง์ ‘์ ์ธ ์•ก์„ธ์Šค๊ฐ€ ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค. ์ด์ง„ ๊ฒ€์ƒ‰ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ์Šต๋‹ˆ๋‹ค.
    • ์ค‘๋ณต ํ‚ค ํ—ˆ์šฉ ์—ฌ๋ถ€๋ฅผ ์„ ํƒ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. (๊ธฐ๋ณธ๊ฐ’: ์ค‘๋ณต ํ—ˆ์šฉ ์•ˆ๋จ)
  2. ์ž‘๋™ ์›๋ฆฌ
    • ๋ฐ์ดํ„ฐ ์‚ฝ์ž… ์‹œ, ์ง€์ •๋œ ํ‚ค์— ๋”ฐ๋ผ ํ…Œ์ด๋ธ”์ด ์ •๋ ฌ๋ฉ๋‹ˆ๋‹ค.
    • ๊ฒ€์ƒ‰ ์‹œ, ์ด์ง„ ๊ฒ€์ƒ‰์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฒ€์ƒ‰ ์†๋„๊ฐ€ ๋น ๋ฆ…๋‹ˆ๋‹ค. (๊ฒ€์ƒ‰ ์‹œ๊ฐ„์€ O(log n))
  3. ์‚ฌ์šฉ ์‹œ์ 
    • ํ‚ค ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ๋œ ๋ฐ์ดํ„ฐ๊ฐ€ ํ•„์š”ํ•˜๊ฑฐ๋‚˜, ๊ฒ€์ƒ‰ ์†๋„๊ฐ€ ์ค‘์š”ํ•œ ๊ฒฝ์šฐ.
    • ์ค‘๋ณต ํ‚ค๊ฐ€ ํ—ˆ์šฉ๋˜๊ฑฐ๋‚˜ ๊ธˆ์ง€๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•  ๋•Œ.
  4. ์„ ์–ธ ๋ฐฉ๋ฒ•
    • ... SORTED TABLE OF ... WITH UNIQUE KEY ...
DATA: itab TYPE SORTED TABLE OF mara WITH UNIQUE KEY matnr.

 

 

4. Hash Table ์ด๋ž€?

  1. ํŠน์ง•
    • Hashed table์€ ํ•ด์‹œ ํ•จ์ˆ˜์— ์˜ํ•ด ์ƒ์„ฑ๋œ ํ•ด์‹œ ํ‚ค๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ํ…Œ์ด๋ธ”์ž…๋‹ˆ๋‹ค. 
    • ํ•ด์‹œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ ์ €์žฅ ๋ฐ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.
    • Hashed table์˜ ํ‚ค๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์ฆ‰, ๋™์ผํ•œ ํ•ด์‹œ ํ‚ค๋ฅผ ๊ฐ€์ง„ ๋‘ ๊ฐœ์˜ ํ•ญ๋ชฉ์ด ํ…Œ์ด๋ธ”์— ์กด์žฌํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ( Unique Key)
    • ์ค‘๋ณต ๋ฐ์ดํ„ฐ๊ฐ€ ์—†์œผ๋ฉฐ, ๊ฐ€์žฅ ๋น ๋ฅธ ๊ฒ€์ƒ‰ ์†๋„๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
  2. ์ž‘๋™ ์›๋ฆฌ
    • ๋ฐ์ดํ„ฐ ์‚ฝ์ž… ์‹œ, ํ‚ค ๊ฐ’์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•ด์‹œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ํ•ด์‹œ ๊ฐ’์„ ์ƒ์„ฑํ•˜์—ฌ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.
    • ๊ฒ€์ƒ‰ ์‹œ, ํ•ด์‹œ ๊ฐ’์„ ์ด์šฉํ•ด ์ง์ ‘ ํ•ด๋‹น ๋ฐ์ดํ„ฐ ์œ„์น˜๋กœ ์ ‘๊ทผํ•ฉ๋‹ˆ๋‹ค.
    • ๊ฒ€์ƒ‰ ์‹œ๊ฐ„์€ O(1), ๋ฐ์ดํ„ฐ ํฌ๊ธฐ์— ๊ด€๊ณ„์—†์ด ์ผ์ • ์‹œ๊ฐ„ ์†Œ์š”๋ฉ๋‹ˆ๋‹ค.
  3. ์‚ฌ์šฉ ์‹œ์ 
    • ๊ณ ์† ๊ฒ€์ƒ‰์ด ์š”๊ตฌ๋˜๋ฉฐ, ์ค‘๋ณต ๋ฐ์ดํ„ฐ๊ฐ€ ์—†์–ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ.
    • ๋Œ€๋Ÿ‰ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ๋ฐ ๋นˆ๋ฒˆํ•œ ์กฐํšŒ ์ž‘์—…์ด ์žˆ๋Š” ๊ฒฝ์šฐ.
  4. ์„ ์–ธ ๋ฐฉ๋ฒ•
    • ... TYPE HASH TABLE OF ... WITH UNIQUE KEY ...
DATA: itab TYPE HASHED TABLE OF mara WITH UNIQUE KEY matnr.

 

5. ํ…Œ์ด๋ธ” ์œ ํ˜• ์„ ํƒ ๊ฐ€์ด๋“œ

  • STANDARD TABLE
    • ๋Œ€๋Ÿ‰ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ๊ฐ€ ์•„๋‹Œ ๊ฐ„๋‹จํ•œ ์ˆœ์ฐจ์  ์ฒ˜๋ฆฌ๊ฐ€ ํ•„์š”ํ•œ ๊ฒฝ์šฐ.
    • ๋ฐ์ดํ„ฐ ๊ฒ€์ƒ‰ ๋นˆ๋„๊ฐ€ ๋‚ฎ๊ฑฐ๋‚˜, ๋ฐ์ดํ„ฐ ์‚ฝ์ž… ์ˆœ์„œ๊ฐ€ ์ค‘์š”ํ•œ ๊ฒฝ์šฐ.
  • SORTED TABLE
    • ๋ฐ์ดํ„ฐ๊ฐ€ ํ•ญ์ƒ ์ •๋ ฌ๋œ ์ƒํƒœ๋กœ ์œ ์ง€๋˜์–ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ.
    • ๊ฒ€์ƒ‰ ๋ฐ ์ •๋ ฌ์ด ๋นˆ๋ฒˆํ•œ ์ž‘์—….
    • ์ค‘๋ณต ํ‚ค๋ฅผ ํ—ˆ์šฉํ•˜๊ฑฐ๋‚˜ ์ œํ•œํ•  ํ•„์š”๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ.
  • HASHED TABLE
    • ๋Œ€๋Ÿ‰ ๋ฐ์ดํ„ฐ์—์„œ ๊ณ ์† ๊ฒ€์ƒ‰์ด ํ•„์ˆ˜์ ์ผ ๋•Œ.
    • ์ค‘๋ณต ๋ฐ์ดํ„ฐ๊ฐ€ ํ—ˆ์šฉ๋˜์ง€ ์•Š์œผ๋ฉฐ, ํ•ญ์ƒ ๊ณ ์œ ํ•œ ํ‚ค๊ฐ€ ์กด์žฌํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ.

 

6. Standard, Sorted, Hashed table ์‚ฌ์šฉ ์˜ˆ์ œ

" ๋ณ€์ˆ˜ ์„ ์–ธ
TYPES: BEGIN OF TY_MARA,
        MATNR TYPE MATNR,   " ์ž์žฌ ๋ฒˆํ˜ธ
        MAKTX TYPE MAKTX,   " ์ž์žฌ ์„ค๋ช…
      END OF TY_MARA.

DATA: STANDARD_ITAB TYPE STANDARD TABLE OF TY_MARA,
      SORTED_ITAB TYPE SORTED TABLE OF TY_MARA WITH UNIQUE KEY MATNR,
      HASHED_ITAB TYPE HASHED TABLE OF TY_MARA WITH UNIQUE KEY MATNR.

DATA: WA TYPE TY_MARA.

" ๋ฐ์ดํ„ฐ ์‚ฝ์ž… (STANDARD TABLE)
WA-MATNR = '1001'.
WA-MAKTX = 'Screw'.
APPEND WA TO STANDARD_ITAB.

" ๋ฐ์ดํ„ฐ ์‚ฝ์ž… (SORTED TABLE)
WA-MATNR = '1002'.
WA-MAKTX = 'Bolt'.
INSERT WA INTO TABLE SORTED_ITAB.

" ๋ฐ์ดํ„ฐ ์‚ฝ์ž… (HASHED TABLE)
WA-MATNR = '1003'.
WA-MAKTX = 'Nut'.
INSERT WA INTO TABLE HASHED_ITAB.


" STANDARD TABLE ์ˆœ์ฐจ ํƒ์ƒ‰  ๋ฐ ์ถœ๋ ฅ
CLEAR WA.
READ TABLE STANDARD_ITAB INTO WA WITH KEY MATNR = '00'.
IF SY-SUBRC = 0.
  WRITE: / 'STANDARD TABLE ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ:',
         / 'MATNR:', WA-MATNR,
         / 'MAKTX:', WA-MAKTX.
ELSE.
  WRITE: / 'STANDARD TABLE์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.'.
ENDIF.


" SORTED TABLE ์ด์ง„ ํƒ์ƒ‰ ๋ฐ ์ถœ๋ ฅ
CLEAR WA. WRITE: / '-'.
READ TABLE SORTED_ITAB INTO WA WITH KEY MATNR = '1002'.
IF SY-SUBRC  = 0.
  WRITE: / 'SORTED TABLE ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ: ',
          / 'MATNR: ', WA-MATNR,
          / 'MAKTX: ', WA-MAKTX.
ELSE.
  WRITE: / 'SORTED TABLE์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.'.
ENDIF.


" HASHED TABLE ํ•ด์‹œ ํƒ์ƒ‰ ๋ฐ ์ถœ๋ ฅ
CLEAR WA. WRITE: / '-'.
READ TABLE HASHED_ITAB INTO WA WITH KEY MATNR = '1003'.
IF SY-SUBRC = 0.
  WRITE:  / 'HASHED TABLE ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ: ',
          / 'MATNR: ', WA-MATNR,
          / 'MAKTX: ', WA-MAKTX.
ELSE.
  WRITE: / 'HASHED TABLE์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.'.
ENDIF.
  1. ํ…Œ์ด๋ธ” ์ •์˜
    • standard_itab: ๋ฐ์ดํ„ฐ๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ์ €์žฅ.
    • sorted_itab: matnr ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ๋œ ์ƒํƒœ๋กœ ์ €์žฅ.
    • hashed_itab: matnr๋ฅผ ํ•ด์‹œ ํ‚ค๋กœ ์‚ฌ์šฉํ•˜๋Š” ํ…Œ์ด๋ธ”.
  2. ๋ฐ์ดํ„ฐ ์‚ฝ์ž…
    • ๊ฐ ํ…Œ์ด๋ธ”์— ์ƒ˜ํ”Œ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฝ์ž…ํ•ฉ๋‹ˆ๋‹ค.
  3. ๋ฐ์ดํ„ฐ ๊ฒ€์ƒ‰
    • READ TABLE ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ ํ…Œ์ด๋ธ”์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฒ€์ƒ‰.
    • ๊ฒ€์ƒ‰ ์„ฑ๊ณต ์—ฌ๋ถ€๋Š” ์‹œ์Šคํ…œ ๋ณ€์ˆ˜ sy-subrc๋กœ ํ™•์ธ:
      • sy-subrc = 0: ๊ฒ€์ƒ‰ ์„ฑ๊ณต.
      • ๊ทธ ์™ธ: ๊ฒ€์ƒ‰ ์‹คํŒจ.

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

728x90
๋ฐ˜์‘ํ˜•