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

[SAP ABAP] TYPE ๊ณผ TYPE TABLE OF ๋ž€?

by Jay Din 2024. 7. 10.
728x90
๋ฐ˜์‘ํ˜•

TYPE ๊ณผ TYPE TABLE OF ์š”์•ฝ ์ •๋ฆฌ

TYPE ๋‹จ์ผ ๋ฐ์ดํ„ฐ ํ•ญ๋ชฉ(๋ณ€์ˆ˜ ๋˜๋Š” ๊ตฌ์กฐ์ฒด) ์„ ์–ธ
์˜ˆ: DATA: lv_carrid TYPE sflight-carrid.
TYPE TABLE OF ๋™์ผํ•œ ๊ตฌ์กฐ์˜ ์—ฌ๋Ÿฌ ํ–‰์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ” ์„ ์–ธ
์˜ˆ: DATA: lt_sflight TYPE TABLE OF sflight.

 

TYPE ์ด๋ž€?

TYPE ๊ตฌ๋ฌธ์€ ๋‹จ์ผ ๋ฐ์ดํ„ฐ ํ•ญ๋ชฉ(๋ณ€์ˆ˜ ๋˜๋Š” ๊ตฌ์กฐ์ฒด)์„ ์„ ์–ธํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

์ฆ‰, ๋ฐ์ดํ„ฐ ํƒ€์ž…์„ ์ง€์ •ํ•˜์—ฌ ๊ฐœ๋ณ„ ํ•„๋“œ๋‚˜ ๊ตฌ์กฐ์ฒด๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

 

์˜ˆ์ œ

DATA: lv_carrid TYPE sflight-carrid.  " ๋‹จ์ผ ๋ณ€์ˆ˜ ์„ ์–ธ
  • lv_carrid ๋Š” sflight ํ…Œ์ด๋ธ”์˜ carrid ํ•„๋“œ์™€ ๊ฐ™์€ ๋ฐ์ดํ„ฐ ํƒ€์ž…์„ ๊ฐ–๋Š” ๋‹จ์ผ ๋ณ€์ˆ˜์ž…๋‹ˆ๋‹ค.
TYPES: BEGIN OF ty_sflight,
         carrid TYPE sflight-carrid,
         connid TYPE sflight-connid,
         fldate TYPE sflight-fldate,
       END OF ty_sflight.

DATA: ls_sflight TYPE ty_sflight.  " ๊ตฌ์กฐ์ฒด ์„ ์–ธ
  • ty_sflight ๋ผ๋Š” ์ด๋ฆ„์˜ ๊ตฌ์กฐ์ฒด ํƒ€์ž…์„ ์ •์˜ํ•˜๊ณ , ์ด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ls_sflight ๋ผ๋Š” ๋‹จ์ผ ๊ตฌ์กฐ์ฒด ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค.

 

TYPE TABLE OF ์ด๋ž€?

TYPE TALBE OF ๊ตฌ๋ฌธ์€ ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ”์„ ์„ ์–ธํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

์ธํ„ฐ๋„ ํ…Œ์ด๋ธ”์€ ๋™์ผํ•œ ๊ตฌ์กฐ์˜ ์—ฌ๋Ÿฌ ํ–‰์„ ์ €์žฅํ•˜๋Š” ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ์ž…๋‹ˆ๋‹ค.

DATA: lt_sflight TYPE TABLE OF sflight.  " ํ…Œ์ด๋ธ” ์„ ์–ธ
  • lt_sflight ๋Š” sflight ํ…Œ์ด๋ธ”์˜ ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง„ ์—ฌ๋Ÿฌ ํ–‰์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ”์ž…๋‹ˆ๋‹ค.
TYPES: BEGIN OF ty_sflight,
         carrid TYPE sflight-carrid,
         connid TYPE sflight-connid,
         fldate TYPE sflight-fldate,
       END OF ty_sflight.

DATA: lt_sflight TYPE TABLE OF ty_sflight.  " ๊ตฌ์กฐ์ฒด ํ…Œ์ด๋ธ” ์„ ์–ธ
  • ty_sflight ๋ผ๋Š” ๊ตฌ์กฐ์ฒด ํƒ€์ž…์„ ์ •์˜ํ•˜๊ณ  ์ด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์—ฌ๋Ÿฌ ํ–‰์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ” lt_sflight ๋ฅผ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค.

 

TYPE ๊ณผ TYPE TABLE OF ์‚ฌ์šฉ ์˜ˆ์‹œ

๋‹ค์Œ์€ SFLIGHT ํ…Œ์ด๋ธ”์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹จ์ผ ๋ณ€์ˆ˜์™€ ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ”์— ์ €์žฅํ•˜๊ณ  ์ถœ๋ ฅํ•˜๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.

* ๋‹จ์ผ ๋ณ€์ˆ˜ ์„ ์–ธ
DATA: LV_CARRID TYPE SFLIGHT-CARRID.

* ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ” ์„ ์–ธ
DATA: LT_SFLIGHT TYPE TABLE OF SFLIGHT,
      WA_SFLIGHT TYPE SFLIGHT.

" ๋‹จ์ผ ๋ณ€์ˆ˜์— ๊ฐ’ ํ• ๋‹น
SELECT SINGLE CARRID
  INTO LV_CARRID
  FROM SFLIGHT
  WHERE CARRID = 'LH'.

" ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ”์— ๋ฐ์ดํ„ฐ ์ €์žฅ
SELECT *
  INTO TABLE LT_SFLIGHT
  FROM SFLIGHT
  WHERE CARRID = 'LH'.

" ๋‹จ์ผ ๋ณ€์ˆ˜ ์ถœ๋ ฅ
WRITE: / 'Single carrid:', LV_CARRID.

" ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ” ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ
LOOP AT LT_SFLIGHT INTO WA_SFLIGHT.
  WRITE: / WA_SFLIGHT-CARRID, WA_SFLIGHT-CONNID, WA_SFLIGHT-FLDATE.
ENDLOOP.

์‹คํ–‰ ํ™”๋ฉด

 

์ด ์˜ˆ์ œ๋ฅผ ํ†ตํ•ด TYPE ๊ณผ TYPE TABLE OF ์˜ ์ฐจ์ด์ ์„ ์ดํ•ดํ•˜๊ณ , ๊ฐ๊ฐ์˜ ๊ตฌ๋ฌธ์ด ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉ๋˜๋Š”์ง€ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

TYPE ์€ ๋‹จ์ผ ๋ฐ์ดํ„ฐ ํ•ญ๋ชฉ์„ ์„ ์–ธํ•œ๋Š”๋ฐ ์‚ฌ์šฉ๋˜๊ณ , TYPE TABLE OF ๋Š” ์—ฌ๋Ÿฌ ํ–‰์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ”์„ ์„ ์–ธํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

 

 

728x90
๋ฐ˜์‘ํ˜•