Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data...

18
Introduction ABAP Fields and Variables

description

Slide 3 Field Naming Field names must begin with a letter or underscore character Subsequent characters can be digits 30 character maximum variable length Avoid special characters Don’t use anything but an underscore Don’t use a dash for reasons you will discover shortly Cannot be reserved words

Transcript of Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data...

Page 1: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Introduction ABAP Fields and Variables

Page 2: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 2

Fields (Introduction) In ABAP, fields (or data objects) are

named locations in memory Variables store data that might change Constants store data that does not

change As before, fields are declared with the

DATA keyword

KEEP IN MIND THAT ABAP IS A ‘BUSINESS’ PROGRAMMING LANGUAGE

Page 3: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 3

Field Naming Field names must begin with a letter or

underscore character Subsequent characters can be digits 30 character maximum variable length Avoid special characters

Don’t use anything but an underscore Don’t use a dash for reasons you will

discover shortly Cannot be reserved words

Page 4: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 4

Fields (Characteristics) They nave a name A defined length And a data type And possibly a length And possibly an initial value

Page 5: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 5

Fields (Primary Data Types)

Page 6: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 6

Data Types and the ABAP Dictionary ABAP data types and ABAP dictionary

data types are not exactly the same Dictionary types map to more simple

ABAP types See handout

Page 7: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 7

Numeric Data Types (1) Integer numbers are whole number

having a value range between -2**31 to 2**31-1 Results are rounded not truncated

Floating point numbers (data type F) are similar to IEEE floating point numbers They are converted to a binary value and

are subject to rounding error

Page 8: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 8

Numeric Data Types (2) Packed numbers (data type P) use an

internal SAP format The size is program defined between 1 and

16 bits Each digit occupies 4 bits

So two decimal digits are packed into one byte

Up to 14 digits allowed after the decimal point

Make sure that fixed-point arithmetic is set. otherwise values are treated as integers

P fields are slow

Page 9: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 9

Declaring Variables (1) The DATA statement declares a variable Syntax:

DATA VARNAME TYPE DATATYPE [VALUE INITIALVALUE].

Example: Declare an integer having an initial value

of 5.

DATA IntValue1 TYPE I VALUE 5.

Page 10: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 10

Packed Numbers (Example)

DATA packed16 TYPE P LENGTH 7 DECIMALS 2.packed16 = '12121219.12'.WRITE packed16. Produces

Page 11: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 11

LIKE Declare a variable having the dame

data type as another variable Makes it easier to change data types

DATA demo16instance1 LIKE packed16.DATA demo16instance2 LIKE packed16.

Page 12: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 12

Arithmetic Operators are as usual +, -, /, * Use DIV for integer division and MOD for

integer remainder THERE MUST BE A BLANK CHARACTER

BEFORE AND AFTER THE ‘=‘ SIGN AND BETWEEN ARITHMETIC OPERATORS AND PARENTHESIS

Page 13: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 13

Arithmetic (Type Conversion) Looks like any other arithmetic

expression (plus the space requirements)

SAP calls this compatible and convertible data types Compatible types have the same data

type, field type, … Comparable types are converted using

conversion rules (See handout)

Page 14: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 14

Type Coercion (1) The following produces “1” because the

result is rounded to an int

Page 15: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 15

Type Coercion (2) Floating point data (F, P) are rounded

and converted to integers Floating point numbers are rounded

when converted to packed values When converting character fields to

numbers, the source field must contain a valid number

More about dates later

Page 16: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 16

Numeric Overflow Outcome

Page 17: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 17

System Fields System fields are constants defined by

the system SY-SUBRC – return code of a procedure SY-UNAME – logon name of the user SY-DATUM – current date SY-UZEIT – current type SY-TCODE – current transaction code

Page 18: Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.

Slide 18

Constants The CONSTANTS statement declares a

constant

CONSTANTS pi TYPE P LENGTH 15 DECIMALS 14 VALUE '3.14159'.