💬Personal website: [Mango Personal Diary]​​​​
💬Original address: SAP ABAP - data type (2) [Detailed explanation of TYPES custom data type] - Mango Personal Log (wyz-math.cn)
💂 About the author: King THUNDER, a blogger who loves finance and taxation, SAP ABAP programming and sharing. Currently studying in Jiangxi Normal University as a sophomore major in accounting, and at the same time serving as an ABAP development consultant for Hanshuoyun (Guangdong) Technology Co., Ltd. In my study and work, I usually use the back-end development language ABAP and SQL to complete the task, and I have in-depth research on SAP enterprise management system, SAP ABAP development and database.
💅Article Summary: This article continues to give an in-depth explanation of the user-defined data type TYPES in ABAP! A more detailed introduction to the global data dictionary type will be explained in detail in the next chapter [Data Dictionary]!
🤟A Word of the Day: The edge of a sword comes from sharpening, and the fragrance of plum blossoms comes from bitter cold.
in the previous article
SAP ABAP - Data Types (1) [Summary and Classification of Data Types]
Introduced the summary and classification of data types in SAP ABAP. We know the three types of data types in ABAP. This article follows the previous article and continues to give an in-depth explanation of the user-defined data type TYPES in ABAP! About the global data dictionary type A more detailed introduction will be explained in the next chapter[Data Dictionary]!
Table of contents
Refer to predefined data type definitions
Refer to the global data dictionary type definition
Refer to the database table field definition
Refer to data element definition
Refer to the component definition in the data dictionary structure
Refer to class/interface definition
Redefine with reference to the user-defined data type
Refer to predefined data type definitions
Refer to the global data dictionary type definition
Refer to the database table field definition
Refer to data element definition
Refer to the component definition in the data dictionary structure
Refer to the data dictionary structure definition
Refer to class/interface definition
Redefine with reference to the user-defined data type
Define internal table types (standard tables, sorted tables, hash tables)
Refer to the global data dictionary type definition
Refer to the database table definition
Refer to the data dictionary table type definition
Define internal table types with reference to the data dictionary structure
Redefine with reference to the user-defined data type
Redefinition with reference to the custom structure type
Redefinition with reference to the custom internal table type
define a single type
Refer to predefined data type definitions
TYPES:CHAR_10 TYPE CHAR10, "10 bit string CHAR_20 TYPE C LENGTH 20, "20 bit string P_8_2 TYPE P LENGTH 8 DECIMALS 2. "16 digit variable, two decimal places
Refer to the global data dictionary type definition
The following lists the most common sample codes for defining common single types with reference to global data dictionary types:
-
Refer to the database table field definition
TYPES:ZCARRID TYPE SFLIGHT-CARRID, ZCONNID TYPE SFLIGHT-CONNID, ZFLDATE TYPE SFLIGHT-FLDATE, ZPRICE TYPE SFLIGHT-PRICE.
The database table sflight is as follows:
-
Refer to data element definition
TYPES:ZCARRID TYPE S_CARR_ID, ZCONNID TYPE S_CONN_ID, ZFLDATE TYPE S_DATE, ZPRICE TYPE S_PRICE.
The data elements used are defined in the above database table sflight:
-
Refer to the component definition in the data dictionary structure
TYPES: ZFIELDNAME TYPE /EACA/O_CHAR_T-FIELDNAME.
The data dictionary structure/EACA/O_CHAR_T is as follows:
Data dictionary structure/EACA/O_CHAR_T
-
Refer to class/interface definition
TYPES:WCL_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER, WCL_ALV TYPE REF TO CL_GUI_ALV_GRID.
Redefine with reference to the user-defined data type
The following sample code first selects one of the above-mentioned examples to define user-defined types, and then defines the same type with reference to the user-defined types respectively, with the suffix [_copy], showing how to redefine with reference to user-defined data types:
*First make a custom data type: TYPES:CHAR_10 TYPE CHAR10, ZCARRID TYPE SFLIGHT-CARRID, ZCONNID TYPE S_CONN_ID, ZFIELDNAME TYPE /EACA/O_CHAR_T-FIELDNAME, WCL_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER. *Then refer to the data types defined above to define: TYPES:CHAR_10_COPY TYPE CHAR_10, ZCARRID_COPY TYPE ZCARRID, ZCONNID_COPY TYPE ZCONNID, ZFIELDNAME_COPY TYPE ZFIELDNAME, WCL_CONTAINER_COPY TYPE WCL_CONTAINER.
Define the structure type
Refer to predefined data type definitions
TYPES:BEGIN OF TY_CLASS, TEA_NAME TYPE C LENGTH 10, TEA_ID TYPE N LENGTH 8, STU_NAME TYPE C LENGTH 10, STU_ID TYPE N LENGTH 8, END OF TY_CLASS.
Refer to the global data dictionary type definition
The following lists the most common sample codes for defining structure types with reference to global data dictionary types:
-
Refer to the database table field definition
TYPES:BEGIN OF TY_SFLIGHT, ZCARRID TYPE SFLIGHT-CARRID, ZCONNID TYPE SFLIGHT-CONNID, ZFLDATE TYPE SFLIGHT-FLDATE, ZPRICE TYPE SFLIGHT-PRICE, END OF TY_SFLIGHT.
The database table sflight is as follows:
-
Refer to data element definition
TYPES:BEGIN OF TY_SFLIGHT, ZCARRID TYPE S_CARR_ID, ZCONNID TYPE S_CONN_ID, ZFLDATE TYPE S_DATE, ZPRICE TYPE S_PRICE, END OF TY_SFLIGHT.
-
Refer to the component definition in the data dictionary structure
TYPES:BEGIN OF TY_/EACC/YS_WA_JOURNAL, ZPST_DAT TYPE /EACC/YS_WA_JOURNAL-PST_DAT, ZACC_SYSTEM TYPE /EACC/YS_WA_JOURNAL-ACC_SYSTEM, ZBUS_TRANS_CAT TYPE /EACC/YS_WA_JOURNAL-BUS_TRANS_CAT, ZITEM_CAT TYPE /EACC/YS_WA_JOURNAL-ITEM_CAT, ZJOURNAL TYPE /EACC/YS_WA_JOURNAL-JOURNAL, END OF TY_/EACC/YS_WA_JOURNAL.
The data dictionary structure /EACC/YS_WA_JOURNAL is as follows:
Data dictionary structure/EACC/YS_WA_JOURNAL
-
Refer to the data dictionary structure definition
TYPES:TY_/EACC/YS_WA_JOURNAL TYPE /EACC/YS_WA_JOURNAL.
-
Refer to class/interface definition
TYPES:BEGIN OF TY_ALV, WCL_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER, WCL_ALV TYPE REF TO CL_GUI_ALV_GRID, END OF TY_ALV.
Redefine with reference to the user-defined data type
The following sample code first selects one of the above-mentioned examples to define user-defined types, and then defines the same type with reference to the user-defined types respectively, with the suffix [_copy], showing how to redefine with reference to user-defined data types:
TYPES:BEGIN OF TY_TEST, TEA_NAME TYPE C LENGTH 10, ZCARRID TYPE SFLIGHT-CARRID, ZCONNID TYPE S_CONN_ID, ZPST_DAT TYPE /EACC/YS_WA_JOURNAL-PST_DAT, GS_/EACC/YS_WA_JOURNAL TYPE /EACC/YS_WA_JOURNAL, WCL_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER, END OF TY_TEST. TYPES: TY_TEST_COPY TYPE TY_TEST."Refer to custom structure TY_TEST redefine
Define internal table types (standard tables, sorted tables, hash tables)
Refer to the global data dictionary type definition
The following lists the most common example codes for defining table types with reference to the global data dictionary type: the three table types of internal tables will be explained in more detail in the subsequent chapter [Internal Tables]!
-
Refer to the database table definition
*Define standard table types TYPES: TY_TAB_SFLIGHT TYPE TABLE OF SFLIGHT , TY_TAB_SFLIGHT1 TYPE STANDARD TABLE OF SFLIGHT , TY_TAB_SFLIGHT2 TYPE TABLE OF SFLIGHT WITH NON-UNIQUE KEY CARRID CONNID FLDATE, TY_TAB_SFLIGHT3 TYPE STANDARD TABLE OF SFLIGHT WITH NON-UNIQUE KEY CARRID CONNID FLDATE. *Define sort table type TYPES: TY_TAB_SFLIGHT4 TYPE SORTED TABLE OF SFLIGHT , TY_TAB_SFLIGHT5 TYPE SORTED TABLE OF SFLIGHT WITH UNIQUE KEY CARRID CONNID FLDATE, TY_TAB_SFLIGHT6 TYPE SORTED TABLE OF SFLIGHT WITH NON-UNIQUE KEY CARRID CONNID FLDATE. *Define the hash table type TYPES: TY_TAB_SFLIGHT7 TYPE HASHED TABLE OF SFLIGHT , TY_TAB_SFLIGHT8 TYPE HASHED TABLE OF SFLIGHT WITH UNIQUE KEY CARRID CONNID FLDATE.
-
Refer to the data dictionary table type definition
TYPES: TY_TAB_HRPERNR TYPE HRAHQ_PERNR_TABLE .
PS: [TYPE] is followed by the global table type (standard table, sorted table, hash table), so there is no need to use the [TYPE [STANDARD|SORTED|HASHED] TABLE OF] statement
-
Define internal table types with reference to the data dictionary structure
*Define standard table types TYPES: TY_TAB_/EACC/YS_WA_JOURNAL TYPE TABLE OF /EACC/YS_WA_JOURNAL , TY_TAB_/EACC/YS_WA_JOURNAL1 TYPE STANDARD TABLE OF /EACC/YS_WA_JOURNAL , TY_TAB_/EACC/YS_WA_JOURNAL2 TYPE TABLE OF /EACC/YS_WA_JOURNAL WITH NON-UNIQUE KEY PST_DAT ACC_SYSTEM BUS_TRANS_CAT. TY_TAB_/EACC/YS_WA_JOURNAL3 TYPE STANDARD TABLE OF /EACC/YS_WA_JOURNAL WITH NON-UNIQUE KEY PST_DAT ACC_SYSTEM BUS_TRANS_CAT. *Define sort table type TYPES: TY_TAB_/EACC/YS_WA_JOURNAL4 TYPE SORTED TABLE OF /EACC/YS_WA_JOURNAL , TY_TAB_/EACC/YS_WA_JOURNAL5 TYPE SORTED TABLE OF /EACC/YS_WA_JOURNAL WITH UNIQUE KEY PST_DAT ACC_SYSTEM BUS_TRANS_CAT, TY_TAB_/EACC/YS_WA_JOURNAL6 TYPE SORTED TABLE OF /EACC/YS_WA_JOURNAL WITH NON-UNIQUE KEY PST_DAT ACC_SYSTEM BUS_TRANS_CAT. *Define the hash table type TYPES: TY_TAB_/EACC/YS_WA_JOURNAL7 TYPE HASHED TABLE OF /EACC/YS_WA_JOURNAL , TY_TAB_/EACC/YS_WA_JOURNAL8 TYPE HASHED TABLE OF /EACC/YS_WA_JOURNAL WITH UNIQUE KEY PST_DAT ACC_SYSTEM BUS_TRANS_CAT.
The data dictionary structure /EACC/YS_WA_JOURNAL is as follows:
Data dictionary structure/EACC/YS_WA_JOURNAL
Redefine with reference to the user-defined data type
The following lists two sample codes for redefining the table type with reference to the custom data type: one method is to redefine the table type with reference to the custom structure, and the other method is to redefine the table type with reference to the custom table type
-
Redefinition with reference to the custom structure type
*Define standard table types TYPES:BEGIN OF TY_CLASS, TEA_NAME TYPE C LENGTH 10, TEA_ID TYPE N LENGTH 8, STU_NAME TYPE C LENGTH 10, STU_ID TYPE N LENGTH 8, END OF TY_CLASS. *Define standard table types TYPES: TY_TAB_CLASS TYPE TABLE OF TY_CLASS , TY_TAB_CLASS1 TYPE STANDARD TABLE OF TY_CLASS , TY_TAB_CLASS2 TYPE TABLE OF TY_CLASS WITH NON-UNIQUE KEY TEA_ID STU_ID, TY_TAB_CLASS3 TYPE STANDARD TABLE OF TY_CLASS WITH NON-UNIQUE KEY TEA_ID STU_ID. *Define sort table type TYPES: TY_TAB_CLASS4 TYPE SORTED TABLE OF TY_CLASS , TY_TAB_CLASS5 TYPE SORTED TABLE OF TY_CLASS WITH UNIQUE KEY TEA_ID STU_ID, TY_TAB_CLASS6 TYPE SORTED TABLE OF TY_CLASS WITH NON-UNIQUE KEY TEA_ID STU_ID. *Define the hash table type TYPES: TY_TAB_CLASS7 TYPE HASHED TABLE OF TY_CLASS , TY_TAB_CLASS8 TYPE HASHED TABLE OF TY_CLASS WITH UNIQUE KEY TEA_ID STU_ID.
-
Redefinition with reference to the custom internal table type
*Define the structure first TYPES:BEGIN OF TY_CLASS, TEA_NAME TYPE C LENGTH 10, TEA_ID TYPE N LENGTH 8, STU_NAME TYPE C LENGTH 10, STU_ID TYPE N LENGTH 8, END OF TY_CLASS. *Define standard table types TYPES: TY_TAB_CLASS TYPE STANDARD TABLE OF TY_CLASS WITH NON-UNIQUE KEY TEA_ID STU_ID, TY_TAB_CLASS_COPY TYPE TY_TAB_CLASS ."Refers to defined standard table types TY_TAB_CLASS redefine *Define sort table type TYPES: TY_TAB_CLASS1 TYPE SORTED TABLE OF TY_CLASS WITH NON-UNIQUE KEY TEA_ID STU_ID, TY_TAB_CLASS2 TYPE SORTED TABLE OF TY_CLASS WITH UNIQUE KEY TEA_ID STU_ID, TY_TAB_CLASS_COPY1 TYPE TY_TAB_CLASS1, "Refers to a defined sort table type TY_TAB_CLASS1 redefine TY_TAB_CLASS_COPY2 TYPE TY_TAB_CLASS1. "Refers to a defined sort table type TY_TAB_CLASS2 redefine *Define the hash table type TYPES: TY_TAB_CLASS3 TYPE HASHED TABLE OF TY_CLASS WITH UNIQUE KEY TEA_ID STU_ID, TY_TAB_CLASS_COPY3 TYPE TY_TAB_CLASS3 . "Refer to the defined hash table type TY_TAB_CLASS3 redefine