-
[Data Type] ABAP dictionary's typeSAP/Abap 2022. 1. 11. 15:25
[Abap dictionary]
Abap dictionary는 program의 global data type으로 table, structure, data element가 존재하고, 이와 같은 abap dictionary는 모든 프로그램에서 data type으로 선언하여 사용할 수 있다.
1) Abap dictionary 조회 [t-code: se11]
- SFLIGHT data table의 CARRID field에 해당하는 data element 조회하기
SFLIGHT 테이블 CARRID 필드의 data element는 S_CARR_ID이며, 해당 element는 길이 3의 type c로 구성된다.
2) Table, view를 이용한 type 선언
Database table과 view를 참고하여 구조체(structure) 및 인터널 테이블(internal table)을 선언할 수 있다.
또한, table의 특정 필드만을 참고하여 데이터를 선언할 수 있다.- SFLIGHT 테이블에서 CARRID가 'AA'인 데이터 한건 조회하기
-
REPORT ZA02_15. DATA : gs_sflight TYPE sflight. SELECT SINGLE * FROM sflight into gs_sflight WHERE carrid = 'AA'. WRITE :/ gs_sflight-carrid, gs_sflight-connid, gs_sflight-fldate, gs_sflight-price, gs_sflight-currency, gs_sflight-planetype.
-
- SFLIGHT 테이블에서 CARRID, CONNID, FLDATE 필드를 참고하여 변수 선언하기
-
REPORT ZA02_16. DATA : gv_carrid TYPE sflight-carrid, gv_connid TYPE sflight-connid, gv_fldate TYPE sflight-fldate. gv_carrid = 'AA'. gv_connid = '0017'. gv_fldate = sy-datum. WRITE :/ gv_carrid, / gv_connid, / gv_fldate.
-
3) Data type을 이용한 type 선언
- Data element 타입을 참고하는 타입과 변수 선언하기
-
REPORT ZA02_17. TYPES : t_carrid TYPE s_carr_id. " Data element를 참조하는 type선언 DATA : gs_carrid1 TYPE s_carr_id, " Data element를 참조하는 data선언 gs_carrid2 TYPE t_carrid. gs_carrid1 = 'AA '. gs_carrid2 = 'AB '. WRITE :/ 'Carrid1 :', gs_carrid1, / 'Carrid2 :', gs_carrid2.
-
- Structure를 이용한 type 선언: 여러 table간 조합이 필요한 경우 사용된다.
- COL1, COL2, COL3 3개의 필드를 갖는 구조체(ZSTURC) 생성 [t-code: se11]
- 위에서 선언한 abap dictionary structure를 참조하는 변수 선언
REPORT ZA02_18. DATA : gs_str TYPE zstruct. gs_str-col1 = '1'. gs_str-col2 = 'Structure'. gs_str-col3 = 'ABAP Dictionary Test'. WRITE :/ gs_str-col1, gs_str-col2, gs_str-col3.
- 위에서 선언한 abap dictionary structure를 참조하는 변수 선언
- COL1, COL2, COL3 3개의 필드를 갖는 구조체(ZSTURC) 생성 [t-code: se11]
4) Type group을 이용한 type 선언
- Type group 생성 [t-code: se11]
- 위에서 생성한 type pool을 참조하는 변수 선언
REPORT ZA02_19. DATA : gv_tgrp1 TYPE ztgrp_typ1, gv_tgrp2 TYPE ztgrp_typ2. gv_tgrp1 = 'Type group'. gv_tgrp2-col1 = 'Test'. gv_tgrp2-col2 = 7. WRITE :/ gv_tgrp1, gv_tgrp2-col1, gv_tgrp2-col2, ztgrp_name.
5) Abap dictionary type VS Abap type
Predefined type을 이용하여 자주 사용되는 type은 Abap dictionary type으로 생성되어 있고, 해당 type간에 차이점은 없다.
즉, 밑의 두개의 명령어는 같은 의미를 같는다DATA gv_f1(10) TYPE c.
DATA gv_f2. TYPE char10.- 자주 사용하는 Abap dictionary type
Abap dictionary type Abap type ACCP N(6) CHARN C(N) CLNT C(3) CUKY C(5) CURR n, m P((n+1)/2) DECIMAL m DEC n, m P((n+1)/2) DECIMAL m DATS D(8) FLTP F(8) INT1 X(1) INT2 X(2) INT4 X(4) LANG C(1) NUMC n N(n) PREC X(2) QUAN n, m P((n+1)/2) DECIMAL m RAW n X(n) TIMS T(6) UNIT C(n) VARC n C(n) LRAW X(n) LCHR C(n) STRING STRING
'SAP > Abap' 카테고리의 다른 글
[Open SQL & Native SQL] Overview (0) 2022.01.11 [Data Type] Assigning value & 기타변수 선언 (0) 2022.01.11 [Data Type] Program's local type (0) 2022.01.11 [Data Type] Predefined ABAP Type: Other types (0) 2022.01.10 [Data Type] Predefined ABAP Type: Numeric type (0) 2022.01.10 - SFLIGHT 테이블에서 CARRID가 'AA'인 데이터 한건 조회하기