sap ag csu chico mins298c abap/4 programming introduction to data types chapter 4 fall 1998
Post on 20-Dec-2015
218 views
TRANSCRIPT
![Page 1: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/1.jpg)
SAP AG
CSU Chico
MINS298c ABAP/4 Programming
Introduction to Data Types
Chapter 4
Fall 1998
![Page 2: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/2.jpg)
SAP AG
CSU Chico
Overview
Introduction
Declaration
Data Types
elementary
complex
Working with Data Types
![Page 3: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/3.jpg)
SAP AG
CSU Chico
Data Objects
Data Object
VariableFixed
? ?
![Page 4: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/4.jpg)
SAP AG
CSU Chico
Data Objects
Data Object
VariableFixed
Literals Constants
![Page 5: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/5.jpg)
SAP AG
CSU Chico
Fixed Data Objects (Constants and Literals)
CONSTANTS: company_name(3) type c value ‘SAP’.
Literals are inside quotes
WRITE: ‘Happiness is SAP’.
![Page 6: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/6.jpg)
SAP AG
CSU Chico
Hierarchy
Variable Data Objects
Table Record Field
Table is made up of Records(s) is made up of have a structure Field(s) is made up of characters have a type
![Page 7: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/7.jpg)
SAP AG
CSU Chico
Fields are Variables
may be declared at any point within the program
may use up to 30 characters in name
may use hyphen, but prefer dash for readability
may not use an ABAP reserved word
follow rules of scope definition
![Page 8: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/8.jpg)
SAP AG
CSU Chico
Normal Scope
ProgramDATA A, B, C
FormDATA X, Y, Z
FormDATA D, E, F
Write A Write F
Write AWrite F
Write AWrite F
According to normal rules of “scope,” whichWrite statements are legal and which are not?
Line
12
34
56
![Page 9: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/9.jpg)
SAP AG
CSU Chico
Data Types
User definedPre-defined
(p,i,f,c,n,d,t,x)
Elementary Structured
Structured type Table type
![Page 10: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/10.jpg)
SAP AG
CSU Chico
Data Types
User definedPre-defined
(p,i,f,c,n,d,t,x)
Elementary Structured
Structured type Table type
![Page 11: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/11.jpg)
SAP AG
CSU Chico
Pre-defined Types(with default length and value) Character Default Justify
c 1 space left n 1 ‘0’ left
Numbers i 4 0 right
p 8 0 right f 8 0.0 right
Date (d) 8 ‘00000000’ left
Time (t) 6 ‘000000’ left
Hexadecimal (x) 1 ‘00’ left
![Page 12: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/12.jpg)
SAP AG
CSU Chico
Data Types
User definedPre-defined
(p,i,f,c,n,d,t,x)
Elementary Structured
Structured type Table type
![Page 13: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/13.jpg)
SAP AG
CSU Chico
Three Ways to Declare Types
pre-defined elementary types
non-elementary types
existing fields
![Page 14: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/14.jpg)
SAP AG
CSU Chico
Types and Data Statement
DATA var[(length)] [TYPE type] [DECIMALS num] [VALUE init]
TYPES BEGIN OF rec-name
[fieldname]…
END OF rec-name
DATA var LIKE table-field [VALUE init]
![Page 15: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/15.jpg)
SAP AG
CSU Chico
Similar Declarations
Data: customer_name(25) type c,
vendor_name(25) type c.
TYPES name(25) type c.
DATA: customer_name type name,
vendor_name type name.
DATA: customer_name(25) type c,
vendor_name LIKE customer_name.
![Page 16: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/16.jpg)
SAP AG
CSU Chico
What are the defaults here?
What are the default type and length of ‘flag’ and of ‘my_number’?
DATA: flag, my_number.
What is contained in ‘c_alpha’ and ‘n_alpha’?
DATA: c_alpha(3) type c value ‘5’,
n_alpha(3) type n value ‘5’.
![Page 17: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/17.jpg)
SAP AG
CSU Chico
Character: C vs N
C = justifies left and has trailing blanks
N = justifies right and has leading zeroes
What happens with:
DATA: var-1(4) type c value ‘1234’,
var-2(4) type n value ‘1234’.
WRITE:/ var-1, var-2.
![Page 18: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/18.jpg)
SAP AG
CSU Chico
What are the defaults here?
What is contained in ‘c_alpha’ and ‘n_alpha’?
DATA: c_alpha(3) type c value ‘5’,
n_alpha(3) type n value ‘5’.
![Page 19: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/19.jpg)
SAP AG
CSU Chico
Numbers
i - cannot have explicit length
p - 15 digits, can explicitly define decimal places
DATA Dollars TYPE p DECIMALS 2.
f - handles exponential, subject to rounding errors
sometimes (1.0/3.0)*3.0 is not 1.0
![Page 20: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/20.jpg)
SAP AG
CSU Chico
Dates and Times
Date = d stored as YYYYMMDD with initial value of 00000000
Time = t stored as HHMMSS with 000000
Why store in this format?
![Page 21: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/21.jpg)
SAP AG
CSU Chico
Which is easier to sort?
01/01/58
01/20/58
01/01/60
12/01/97
01/20/00
19580101
19580120
19600101
19971201
20000120
![Page 22: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/22.jpg)
SAP AG
CSU Chico
Computations on Dates
DATA my_date LIKE sy-datum.
MOVE 19580420 to my_date.
my_date = my_date - 1.
Write:\ my_date.
Displays 19580419
![Page 23: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/23.jpg)
SAP AG
CSU Chico
Offset and Length Format
One may address sub-parts of elementary data objects by specifying the offset and length !!!
MOVE sy-datum+6(2) to hold_day
1 9 5 8 0 4 2 0
sy-datum(0) sy-datum(6)
![Page 24: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/24.jpg)
SAP AG
CSU Chico
Parameter Statement
Parameter statement creates a set of variable fields which are presented to the user for input on the selection screen.
PARAMETERS var TYPE type [DEFAULT value]
![Page 25: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/25.jpg)
SAP AG
CSU Chico
Data Types
User definedPre-defined
(p,i,f,c,n,d,t,x)
Elementary Structured
Structured type Table type
![Page 26: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/26.jpg)
SAP AG
CSU Chico
Records
records or structures are called field strings in ABAP
use BEGIN OF and END OF
nesting is allowed
use TYPES command
![Page 27: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/27.jpg)
SAP AG
CSU Chico
Field String Types
TYPES : BEGIN OF ADDRESS,
street(20) type c,
city(20) type c,
state(10) type c,
zip type I,
END OF ADDRESS.
How large (in characters) is the record ADDRESS?
![Page 28: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/28.jpg)
SAP AG
CSU Chico
Using Field String TypesTYPES : BEGIN OF ADDRESS,
street(20) type c,
city(20) type c,
state(10) type c,
zip type I,
END OF ADDRESS.
DATA: Old_Address TYPE Address,
New_Address TYPE Address.
MOVE Old_Address to New_Address.
![Page 29: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/29.jpg)
SAP AG
CSU Chico
Using Field String TypesTYPES : BEGIN OF ADDRESS,
street(20) type c,
city(20) type c,
state(10) type c,
zip type I,
END OF ADDRESS.
DATA: Old_Address TYPE Address,
New_Address TYPE Address.
Old_Address
Street City State Zip
Old_Address-Zip
Old_Address-City
![Page 30: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/30.jpg)
SAP AG
CSU Chico
Data Types
User definedPre-defined
(p,i,f,c,n,d,t,x)
Elementary Structured
Structured type Table type
![Page 31: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/31.jpg)
SAP AG
CSU Chico
Creating Tables
Use the occurs statement
not necessary to identify the amount, may use zero (0).
Format
TYPES tablename TYPE type OCCURS 0.
Example
TYPES Address_Table TYPE ADDRESS OCCURS 0.
Really creates the structurewhich will be allocated andmaintained dynamically.
![Page 32: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/32.jpg)
SAP AG
CSU Chico
Declarative Statements
DATA
TYPE
CONSTANTS
PARAMETERS
![Page 33: SAP AG CSU Chico MINS298c ABAP/4 Programming Introduction to Data Types Chapter 4 Fall 1998](https://reader030.vdocuments.net/reader030/viewer/2022032801/56649d535503460f94a2fb4b/html5/thumbnails/33.jpg)
SAP AG
CSU Chico
Assignments
Create program(s) to
demonstrate the justification difference between the n and c types
determine whether or not our system has a rounding error in the fixed point arithmetic
find the difference between the current date and your birthday
prove that one day before 01/01/98 is 12/31/97 using the ABAP date types
use the parameter statement to interactively ask for two dates and display the difference between them.