*&---------------------------------------------------------------------* *& Report _DEMO_BASIC_02_ABAP_TYPES *& *&---------------------------------------------------------------------* *& Description: *& Declarations of various data types in ABAP. *& • constants *& • variables using elementary ABAP types: characters, numbers, ... *& • structures *& • internal tables (with DDIC reference) *& *& Technical description: *& SAP rules to follow when creating data object name: *& • Variable name must begin with character (a-z) *& • Variable name can contain up to 30 characters *& • Name can contain alphanumeric characters and underscore ( _ ) *& • Name can not contain reserved ABAP statement names *& *& More Information: *& - https://help.sap.com/saphelp_nw70/helpdata/en/fc/eb2fd9358411d1829f0000e829fbfe/frameset.htm *& *&---------------------------------------------------------------------* *& Change log: *& Date Author Action *& xxxx-xx-xx ABAP_ACADEMY Created *& *&---------------------------------------------------------------------* REPORT _demo_basic_02_abap_types. *-----------------------------------" * DECLARATIONS "------------------------------ " CONSTANTS are usually defined at the beginning of declaration of all " variables. " Declare maximum integer value " Declare minimum integer value " Declare float value for Pi constant " Declare packed value for Pi "------------------------------ " DEFINING VARIABLES FROM PREDEFINED ABAP TYPES " The following data types are predefined in the R/3 System kernel, and " are visible in all ABAP programs. You can use predefined types to " define local data types and objects in a program and to specify the " type of interface parameters and field symbols. "------------------------------ " ELEMENTARY DATA OBJECTS WITH FIXED LENGTH - NUMERIC TYPES " INTEGER " 4-byte integer between -2147483648 and 2147483647. The length for this data " type is limited to 10 places. " Usability: counters, numbers of items, indexes, time periods, ... " Non-integer results of arithmetic operations (e.g. fractions) are rounded, " not truncated. " Define integer variable " Define integer variable with default value 5 " FLOATING POINT NUMBER " The length (including decimal places) is set to 16 places for this data type. " Since type F data is internally converted to a binary system, rounding errors " can occur. Although the ABAP processor tries to minimize these effects, you " should not use type F data if high accuracy is required. Instead, use type P data. " Define float variable " PACKED NUMBER " Arithmetic operations with decimal number " thousands. A DEC field has a maximum length of 31 places. " Define packed number " Define packed number with 2 decimal places "------------------------------ " ELEMENTARY DATA OBJECTS WITH FIXED LENGTH - CHARACTER TYPES " CHARACTER FIELD " Character string, which may contain alphanumeric characters " Define character variable " Define character variable with length 255 " NUMERIC TEXT FIELD " Long character field in which only numbers can be entered. The length of this " field is limited to a maximum of 255 places. " Define numeric variable " DATE FIELD " Format: YYYYMMDD. The output template can be defined with the user profile. " Define date variable in format yyyymmdd " Define date variable in display format " TIME FIELD " The length is set to 6 places for this data type. The format is HHMMSS. The " template for input and output has the form ‘__.__.__’. " Define time variable in format yyyymmdd " Define time variable in display format "------------------------------ " HEXADECIMAL TYPE " The remaining non-numeric type - X - always interprets individual bytes in " memory. One byte is represented by a two-digit hexadecimal display. The fields " with this type are called hexadecimal fields. " Define hexadecimal variable "------------------------------ " ELEMENTARY DATA OBJECTS WITH VARIABLE LENGTH " STRING " A string is a sequence of characters with variable length. A string can contain " any number of alphanumeric characters. The length of a string is the number of " characters multiplied by the length required for the internal representation of " a single character. " Define string variable " XSTRING " A byte string is a hexadecimal type with variable length. It can contain any " number of bytes. The length of a byte string is the same as the number of bytes. " Define xstring variable "------------------------------ " CUSTOM LOCAL TYPES " It is a good habit to define local types right after constants definition. " We define it here just to be consistent in explanation of ABAP types " Local type based on eleámentary ABAP type " Define packed number type with 2 decimal places " Local custom structure type " Define local structure type with following 3 fields: " - field1 contains character type " - field2 contains local packed number type with 2 decimal places, defined in step above " - field1 contains date type " Local structure from global database table structure " Define local structure type from global database table DD02L " Define local table type from custom local structure " Define local table type from global database table structure "------------------------------ " COMPLEX VARIABLES " Declare structure variable containing previously defined local structure type " Declare structure variable containing structure from global database table DD02L " Declare internal table, containing previously defined local structure type " Declare internal table, containing structure from global database table DD02L *-----------------------------------" * MAIN LOGIC FORMAT COLOR = col_heading. WRITE: / 'DATE and TIME'. SKIP. FORMAT COLOR = col_background. " Output: 'Today is: ' " Fill in the following variables WRITE: / 'Date (30 days ago) - type D: ', gv_date. WRITE: / 'Date (30 days ago) - type SYDATUM: ', gv_sydatum. " Output: 'Actual time is: