04_sap - defining data in abap
DESCRIPTION
SAMS PPT SAP ABAPTRANSCRIPT
SAP - Defining Data in ABAP/4, Part 1
Contents
• Objectives
• Elements of ABAP/4 Syntax
• Defining Data Objects
• Summary
• Q&A
Contents
Objectives
Objectives
• Understand the elements of ABAP/4 syntax.
• Describe the concept of data objects and their visibility.
• Use literals and understand how to code each type.
• Define and use constants.
• Use the data statement to define variables and field strings.
• Understand ABAP/4 data types, and be able to identify the character and numeric data types.
• Understand the ABAP/4 definition of common DDIC data types.
Contents
Elements of ABAP/4 Syntax
Elements of ABAP/4 Syntax
• 1 ABAP/4 program = 1-n statements• 1 statement = 1-n words separated by space(s)• The 1st word: keyword• statement ends with punctuation mark (dot)• A statement can include 1-n additions
select * from ztxlfa1 where lifnr > '0000001050' order by lifnr. write: \ ztxlfa1-lifnr, ztxlfa1-name1, ztxlfa1-land1.endselect.
-Keywords: select, write, endselect-Additions: where, order by
Elements of ABAP/4 Syntax
• A statement:– can begin in any column– any number of lines– to continue on another line break between any
2 words• ABAP/4 code is not case sensitive.
select * from ztxlfa1 where lifnr > '0000001050' order by lifnr. write: \ ztxlfa1-lifnr, ztxlfa1-name1, ztxlfa1-land1. endselect.
Contents
Defining Data Objects
Data Objects
• Data Objects: memory locations to hold data while running
• 2 types:– modifiable:
• variables• field strings (~ structures)• and internal tables (~ arrays)
– non-modifiable:• literals• constants
Data Objects
• 3 levels of visibility: from where in prog., data object is accessible.– Local: from inside the subroutine– Global: from anywhere within the
program– External: from outside of the program
by another program
Literals• Literal: a non-modifiable data object.• 4 types:
– character string:• 'Hello SAP world‘• 'Caesar''s tail‘ Caesar's tail
– numeric• 256, -99, ’10.5’
– floating-point: '<mantissa>E<exponent>‘• '9.99E9', '-10E-32', '+1E09'
– hexadecimal:• character string (0-9, A-F)• must be an even number of characters in the string• must be in uppercase• '00', 'A2E5', 'F1F0FF'
Literals
Variables
• 2 statements are commonly used to define variables:– data• variables can be declared for the program• variables are assigned to a data type and can have
defaults
– parameters• like data statement• the parameters are displayed as input fields on a
selection screen.
DATA statement
• Syntax:– data v1[(l)] [type t] [decimals d] [value 'xxx'].– data v1 like v2 [value 'xxx'].
• where:– v1 is the variable name. – v2 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). – 'xxx' is a literal that supplies a default value.
DATA statement
Examples of Variables Defined with the DATA Statement
1 data f1(2) type c.2 data f2 like f1.3 data max_value type i value 100.4 data cur_date type d value '19980211'.
• default length: depends on the data type• default data type: c (character)• default initial value: 0, (for data type c: blank)• cannot use a variable to supply a default value.
ABAP/4 Data Types
• Character Data Types• Numeric Data Types
Character Data Types
• N – Numeric text:– hold unsigned positive integer in character– used as unique identifiers: document no, account no…
• D – Date & T – Time:– stored internally as YYYYMMDD & HHMMSS– ex: current date sy-datum, current time sy-uzeit
Numeric Data Types
• Packed decimal: (L*2) – 1 digits, L-length in bytes
Mapping DDIC Data Types to ABAP/4 Data Types
PARAMETERS statement• The maximum length is 8• can use a variable to supply a default value.• Syntax:
– parameters p1[(l)] [type t] [decimals d] ...– parameters p1 like v1 ...... [default 'xxx'] [obligatory] [lower case] [as checkbox]
[radiobutton group g].• where:
– p1 is the parameter name. – v1 is the name of a previously defined variable or parameter, 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 or previously defined variable that supplies a default value.
PARAMETERS statement
parameters p1(2) type c.parameters p2 like p1.parameters max_value type i default 100.parameters cur_date type d default '19980211' obligatory.parameters cur_date like sy-datum default sy-datum obligatory.
PARAMETERS statement
Examplereport ztx0706.parameters: p1(15) type c, p2 like p1 obligatory lower case, p3 like sy-datum default sy-datum, cb1 as checkbox, cb2 as checkbox, rb1 radiobutton group g1 default 'X', rb2 radiobutton group g1, rb3 radiobutton group g1.write: / 'You entered:', / ' p1 =', p1, / ' p2 =', p2, / ' p3 =', p3, / ' cb1=', cb1, / ' cb2=', cb2, / ' rb1=', rb1, / ' rb2=', rb2, / ' rb3=', rb3.
Parameter Labels
• In ABAP/4 Editor: GotoText ElementsSelection Texts
LIKE addition
• F1 help: from Documentation in data element• F4 help: from check table– obtain a list of valid values– the value entered is NOT validated against the
check table.• field label: obtained from the Data Dictionary
Contents
Summary
Summary• An ABAP/4 program, statement, keyword.• A data object is a memory location that contains data during
the runtime of the program.– non-modifiable: literals and constants.– modifiable: variables, field strings, and internal tables.
• Data objects have 3 levels of visibility: local, global, and external.– indicates from where the data object is accessible.
• Literals are data that is hard-coded in your program.• Data types: character and numeric.
– Character: c, n, d, t, and x– Numeric: i, p, and f
• data and parameters statements.• parameter input field labels: menu path Goto->Text Elements.