Sie sind auf Seite 1von 19

3/14/2014

ABAP Data Declarations |

ABAP Elementary Data Types


C: Character Text N: Numeric Text I: Integer D: Date

P: Packed #

T: Time

F: Floating Point #

X: Hexadecimal #

STRING

XSTRING

3/14/2014

ABAP Data Declarations |

ABAP Elementary Data Types (Contd.)


C: Character Text I: Integer D: Date

N: Numeric Text

P: Packed #

T: Time

F: Floating Point #

X: Hexadecimal #

STRING

XSTRING

3/14/2014

ABAP Data Declarations |

Declaring Variables
DATA: PLAYER(35) TYPE C, NICKNAME(35), POINTS TYPE I, GAMES TYPE I AVERAGE(5) TYPE P, STARTER, ACQUIRED TYPE D.

VALUE 10,

3/14/2014

ABAP Data Declarations |

Initial Values
C: (blank) N: zeroes I: zero D: 00000000

P: zero

T: 000000

F: zeroes

X: 00

The CLEAR statement sets a field back to its initial value, not its default value.
3/14/2014 ABAP Data Declarations | 5

Assigning Default Values


DATA: PLAYER(35) TYPE C, NICKNAME(35) POINTS TYPE I GAMES TYPE I AVERAGE(5) TYPE P STARTER ACQUIRED TYPE D

VALUE VALUE VALUE VALUE VALUE VALUE

Dr. J, 255, 10, 25.5, Yes, 19760610.

3/14/2014

ABAP Data Declarations |

Declaring Like Fields


DATA: PLAYER(35) TYPE C VALUE Julius Erving, NICKNAME(35), ACQUIRED TYPE D.

Use the LIKE addition to declare fields with the same format (i.e., data type and length)

DATA:

PLAYER(35) NICKNAME ACQUIRED

TYPE C VALUE Julius Erving, LIKE PLAYER, LIKE SY-DATUM.

3/14/2014

ABAP Data Declarations |

Declaring Constants
The VALUE addition is required.

CONSTANTS: TEAM1(20) TYPE C VALUE 76ers, TEAM2 TYPE TEAM1 VALUE Celtics, TOT_GAMES TYPE I VALUE 82.

If you attempt to change the value of a constant, a syntax error will occur.

3/14/2014

ABAP Data Declarations |

User-Defined Data Types


TYPES: NAME(35) TEAMS(20) DATA: PLAYER NICKNAME CONSTANTS: TEAM1 TEAM2 TYPE C, TYPE C. TYPE NAME VALUE Troy Aikman, TYPE PLAYER. TYPE TEAMS VALUE Cowboys, TYPE TEAM1 VALUE Packers.

A user-defined data type created with the TYPES statement is used to specify a fields data type in the TYPE addition of the DATA or CONSTANTS statements.

3/14/2014

ABAP Data Declarations |

Output for Numeric Fields


DATA: FLOAT PACK INT TYPE F TYPE P TYPE I VALUE 98.7654321E2, VALUE 12, VALUE 32. WRITE: / FLOAT, / FLOAT EXPONENT 1 DECIMALS 3, / FLOAT EXPONENT 0 DECIMALS 2, / PACK, / PACK DECIMALS 1, / INT DECIMALS 2. 9.876543210000000E+03 987.654E+01 9876.54 12 12.0 32.00

These fields are not aligned because of the different standard output lengths of the numeric type fields.

3/14/2014

ABAP Data Declarations |

10

Assigning Values to Fields


MOVE <value> TO <field>. [COMPUTE] <field> = <value or expression>. ADD <value> TO SUBTRACT <value> FROM MULTIPLY <field> BY DIVIDE <field> BY <field>. <field>. <value>. <value>.

DATA:

TITLE(25), SALARY TYPE P, CNVSALARY TYPE SALARY,

MOVE President TO TITLE. COMPUTE SALARY = 5000000. CNVSALARY = SALARY * 3. ADD 1000 TO SALARY.

3/14/2014

ABAP Data Declarations |

11

Arithmetic Expressions
Operators + - * / ** DIV and MOD Functions SQRT, EXP, LOG, SIN, COS, STRLEN, . . .

COUNTER = COUNTER + 1. SALARY = BASE * BONUS_PERCENT. LENGTH = STRLEN( NAME ). ANSWER = ( 10 + SQRT( NUM1 ) ) / ( NUM2 - 10 ).

Spacing is very important when using arithmetic expressions!!!

3/14/2014

ABAP Data Declarations |

12

Date Calculations in ABAP


DATA: DAYSOLD TYPE P, DOB TYPE D, TODAY TYPE SYDATUM.
DOB TODAY = 19621230. = SY-DATUM. Date fields store values as YYYYMMDD.

DAYSOLD = TODAY - DOB. WRITE: You are, DAYSOLD, days old.

You are 12410 days old.

3/14/2014

ABAP Data Declarations |

13

Declaring Fields with PARAMETERS


PARAMETERS: NUM TYPE I, NAME(20) DEFAULT AARON.

ADD 10 TO NUM. WRITE: / NUM, ----, NAME.

Selection Screen
3/14/2014 ABAP Data Declarations | 14

Selection Texts

These selection texts will be used on the selection screen instead of the parameter names.

Selection Screen With the parameter description


3/14/2014 ABAP Data Declarations | 15

Working with Field Symbols in ABAP


DATA: NUM TYPE I VALUE 12. FIELD-SYMBOLS: <F1>, <F2> TYPE I, <F3> TYPE NUM. ASSIGN: NUM TO <F1>, NUM TO <F2>, NUM TO <F3>. WRITE: / Line 1:, NUM, <F1>, <F2>, <F3>. <F1> = 32. WRITE: / Line 2:, NUM, <F1>, <F2>, <F3>. Line 1: 12 Line 2: 32 12 32 12 32 12 32 A field symbol is a pointer that assumes a fields address, not a fields value.

3/14/2014

ABAP Data Declarations |

16

Dynamic Assignment of Partial Strings


DATA: TEXT_LINE(30) VALUE ABCDEFGHIJK. FIELD-SYMBOLS <FSYMBOL>. ASSIGN TEXT_LINE+2(5) TO <FSYMBOL>. * this assigns 5 characters of text_line starting at * position 3 to the field string. WRITE: / Text Line =, TEXT_LINE. ULINE. WRITE: / Field Symbol=, <FSYMBOL>. ULINE.

<FSYMBOL> = 1234567890.
WRITE: / Field Symbol =, <FSYMBOL>. ULINE. WRITE: / Text Line =, TEXT_LINE.

3/14/2014

ABAP Data Declarations |

17

Dynamic Field Assignment


PARAMETERS FIELD(8) DEFAULT SY-UZEIT. FIELD-SYMBOLS <FSYMBOL>. ASSIGN (FIELD) TO <FSYMBOL>. IF SY-SUBRC = 0. WRITE: / The contents of field, FIELD, <FSYMBOL>. ELSE. WRITE: / Failure assigning field, FIELD, to field symbol. ENDIF.

FIELD

SY-UZEIT

Selection Screen

The contents of field SY-UZEIT 12:32:06


3/14/2014 ABAP Data Declarations |

List
18

Summary
DATA statement is used to declare a variable (or field) in an ABAP program "LIKE" and "TYPE" statements are used to declare fields with reference to other variables or fields CONSTANTS statement is used to declare a constant Text elements can be used to maintain a programs title and column headings,

selection texts, and text symbols. These text elements can be maintained in multiple languages A field symbol does not reserve space for the field, but points to the field ASSIGN statement associates a field to a field symbol at runtime The system carries out automatic type conversion if variables are not of the same type ABAP allows to display and change portions of a field by specifying an offset and length

3/14/2014

ABAP Data Declarations |

19

Das könnte Ihnen auch gefallen