Unit 4 - Basic ABAP statements, ABAP Structures and ABAP Logical Expressions
04_SAP - Defining Data in ABAP
-
Upload
varaprasadp -
Category
Documents
-
view
66 -
download
10
description
Transcript of 04_SAP - Defining Data in ABAP
![Page 1: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/1.jpg)
SAP - Defining Data in ABAP/4, Part 1
![Page 2: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/2.jpg)
Contents
• Objectives
• Elements of ABAP/4 Syntax
• Defining Data Objects
• Summary
• Q&A
![Page 3: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/3.jpg)
Contents
Objectives
![Page 4: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/4.jpg)
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.
![Page 5: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/5.jpg)
Contents
Elements of ABAP/4 Syntax
![Page 6: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/6.jpg)
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
![Page 7: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/7.jpg)
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.
![Page 8: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/8.jpg)
Contents
Defining Data Objects
![Page 9: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/9.jpg)
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
![Page 10: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/10.jpg)
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
![Page 11: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/11.jpg)
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'
![Page 12: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/12.jpg)
Literals
![Page 13: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/13.jpg)
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.
![Page 14: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/14.jpg)
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.
![Page 15: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/15.jpg)
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.
![Page 16: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/16.jpg)
ABAP/4 Data Types
• Character Data Types• Numeric Data Types
![Page 17: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/17.jpg)
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
![Page 18: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/18.jpg)
Numeric Data Types
• Packed decimal: (L*2) – 1 digits, L-length in bytes
![Page 19: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/19.jpg)
Mapping DDIC Data Types to ABAP/4 Data Types
![Page 20: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/20.jpg)
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.
![Page 21: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/21.jpg)
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.
![Page 22: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/22.jpg)
PARAMETERS statement
![Page 23: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/23.jpg)
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.
![Page 24: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/24.jpg)
Parameter Labels
• In ABAP/4 Editor: GotoText ElementsSelection Texts
![Page 25: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/25.jpg)
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
![Page 26: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/26.jpg)
Contents
Summary
![Page 27: 04_SAP - Defining Data in ABAP](https://reader033.fdocuments.net/reader033/viewer/2022051312/54618d13af7959a4058b45cc/html5/thumbnails/27.jpg)
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.