Beruflich Dokumente
Kultur Dokumente
Reference materials
SAP Teach Yourself ABAP in 21 Days-SAMS.pdf
Contents
Objectives
Defining Constants
Defining Field Strings Defining Types Structured Types Summary Q&A
Contents
Objectives
Objectives
Use the TABLES statement to define field strings Understand the difference between field strings defined using DATA and using TABLES Understand the TYPES statement and use it to define your own data types
Contents
Defining Constants
Constants
value cannot be changed use the CONSTANTS statement 1 pre-defined constant: SPACE (same as the literal ) Syntax:
constants c1[(l)] [type t] [decimals d] value 'xxx'. constants c1 like cv value 'xxx'.
where:
c1 is the name of the constant. cv is the name of a previously defined constant or variable, or is the name of a field that belongs to a table or structure in the Data Dictionary. (l) is the internal length specification. t is the data type. d is the number of decimal places (used only with type p). 'xxx' is a literal that supplies the value of the constant.
Constants
constants c1(2) type c value 'AA'. constants c2 like c1 value 'BB'. constants error_threshold type i value 5. constants amalgamation_date like sy-datum value '19970305'.
Contents
Defining Field Strings
Field Strings
Field String:
~ structure in DDIC
Defined within ABAP/4 program
DATA Statement
Syntax:
data: begin of fs1, f1[(l)] [type t] [decimals d] [value 'xxx'], f2[(l)] [type t] [decimals d] [value 'xxx'], ... end of fs1. data begin of fs1. data f1[(l)] [type t] [decimals d] [value 'xxx']. data f2[(l)] [type t] [decimals d] [value 'xxx']. ... [include structure st1.] data end of fs1. data fs1 like fs2.
DATA Statement
where:
fs1 is the field string name. f1 and f2 are the fields (also called components) of the field string. fs2 is the name of a previously defined field string, or is the name of a table or structure in the Data Dictionary. (l) is the internal length specification. t is the data type. d is the number of decimal places (used only with type p). 'xxx' is a literal that supplies a default value. st1 is the name of a structure or table in the Data Dictionary.
DATA Statement
REPORT y_vu_0802. DATA: BEGIN OF totals_1, region(7) VALUE 'unknown', debits(15) TYPE p, count TYPE i, END OF totals_1, totals_2 LIKE totals_1. totals_1-debits = 100. totals_1-count = 10. totals_2-debits = 200. WRITE: / totals_1-region, totals_1-debits, totals_1-count, / totals_2-region, totals_2-debits, totals_2-count.
LIKE vs INCLUDE
REPORT y_vu_0806. DATA: BEGIN OF fs1, mylfa1 LIKE lfa1, extra_field(3) TYPE c, END OF fs1. REPORT y_vu_0805. DATA BEGIN OF fs1. INCLUDE STRUCTURE lfa1. DATA: extra_field(3) TYPE c, END OF fs1.
REPORT y_vu_0807. DATA: BEGIN OF fs1, c1 VALUE 'A', c2 VALUE 'B', c3 VALUE 'C', END OF fs1. WRITE: / fs1-c1, fs1-c2, fs1-c3, / fs1. fs1 = 'XYZ'. WRITE: / fs1-c1, fs1-c2, fs1-c3, / fs1.
TABLES Statement
Syntax:
tables fs1.
where:
fs1 is the field string name. A table or structure of the same name must exist in the Data Dictionary.
REPORT y_vu_0809. TABLES lfa1. lfa1-name1 = 'Bugsy'. lfa1-land1 = 'US'. WRITE: / lfa1-name1, lfa1-land1.
TABLES Statement
It defines a field string. It gives the program access to a database table of the same name, if one exists.
REPORT y_vu_0810. TABLES lfa1. SELECT * FROM lfa1 INTO lfa1 ORDER BY lifnr. WRITE / lfa1-lifnr. ENDSELECT.
Contents
Defining Types
Types
to define own data types base on existing data types Syntax:
types t1[(l)] [type t] [decimals d]. types t1 like v1.
where:
t1 is the type name. v1 is the name of a variable previously defined in the program, or is the name of a field that belongs to a table or structure in the Data Dictionary. (l) is the internal length specification. t is the data type. d is the number of decimal places (used only with type p).
TYPES statement
REPORT y_vu_0811. TYPES char2(2) TYPE c. DATA: v1 TYPE char2 VALUE 'AB', v2 TYPE char2 VALUE 'CD'.
WRITE: v1, v2.
american_sums-pay_outs = '9500.03'. "need quotes when literal contains a decimal italian_sums-lump_sums = 5141.
WRITE: / american_sums-pay_outs, / italian_sums-lump_sums.
Contents
Structured Types
Structured Types
Structured Type: a user-defined type with the definition of a field string to Reduce Redundancy and Make Maintenance Easier
REPORT y_vu_0813. TYPES: BEGIN OF address, street(25), city(20), region(7), country(15), postal_code(9), END OF address. DATA: customer_addr TYPE address, vendor_addr TYPE address, employee_addr TYPE address, shipto_addr TYPE address. customer_addr-street = '101 Memory Lane'. employee_addr-country = 'Transylvania'.
Contents
Summary
Summary
Field strings:
like DDIC structures define using DATA or TABLES statement
DATA: local or global visibility TABLES: global and external visibility
TYPES statement
define own data types User-defined types reduce redundancy and make maintenance easier.
Thank you!
Questions & Answers