Top Banner
1 ABAP Basics III Northern Arizona University College of Business
33

1 ABAP Basics III Northern Arizona University College of Business.

Dec 14, 2015

Download

Documents

Ross Newson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 ABAP Basics III Northern Arizona University College of Business.

1

ABAP Basics III

Northern Arizona University

College of Business

Page 2: 1 ABAP Basics III Northern Arizona University College of Business.

2

Types

It is possible to define new data types.

These are known as user-defined types.

New types are defined using the Types statement.

Page 3: 1 ABAP Basics III Northern Arizona University College of Business.

3

Types

The syntax is identical to the Data statement.

Page 4: 1 ABAP Basics III Northern Arizona University College of Business.

4

Types

Types:

Bank_Acct(28) Type C.

Data:

Ckecking_Acct Type Bank_Acct.

Savings_Acct Type Bank_Acct.

Page 5: 1 ABAP Basics III Northern Arizona University College of Business.

5

Types

Types Begin of Demo_Type ,

D_ID Type I ,

D_Name(20) Type C ,

End of Demo_Type .

Data:

Old_Demo Type Demo_Type ,

New_Demo Type Demo_Type .

Page 6: 1 ABAP Basics III Northern Arizona University College of Business.

6

Formatting

Format Intensified .

Write ‘Whatever’ .

Format Reset .

Page 7: 1 ABAP Basics III Northern Arizona University College of Business.

7

Formatting

Format Inverse .

Write ‘Whatever’ .

Format Reset .

Page 8: 1 ABAP Basics III Northern Arizona University College of Business.

8

Formatting

Format Color 3 . “ 0-7

Write ‘Whatever’ .

Format Reset .

Page 9: 1 ABAP Basics III Northern Arizona University College of Business.

9

Arithmetic Operators

+ add- Subtract* multiply/ divide** exponentialDiv integer quotient of divisionMod integer remainder of division

Page 10: 1 ABAP Basics III Northern Arizona University College of Business.

10

Compute Statement

Compute Result = A + B .

Result = A + B .

Result = (A + B) / C .

Page 11: 1 ABAP Basics III Northern Arizona University College of Business.

11

Add Statement

Add 1 to Counter .or

Counter = Counter + 1 .

Add F1 then F2 until F9 giving Result .

Page 12: 1 ABAP Basics III Northern Arizona University College of Business.

12

Character Data – Offset & Length

Data:F1(6) Type C value ‘abcdef’ .F2(6) Type C value ‘ ‘ .

Move ‘x’ to F1+2 . “will space fillMove ‘x’ to F1+2(1) . “no space fillMove F1+0(3) to F2 .

Page 13: 1 ABAP Basics III Northern Arizona University College of Business.

13

Character Data – Shift

Data:F1(6) Type C value ‘abcdef’ .

Shift F1 . “shifts leftShift F1 circular .Shift F1 right .Shift F1 by 4 places .

Page 14: 1 ABAP Basics III Northern Arizona University College of Business.

14

Character Data – Replace

Data:

F1(7) Type C value ‘XXX-NAU’ .

Replace ‘XXX’ with ‘CBA’ into F1 .

The strings are case sensitive .

Page 15: 1 ABAP Basics III Northern Arizona University College of Business.

15

Character Data – Search

Data:

F1(7) Type C value ‘CBA-NAU’ .

Search F1 for‘CBA*’ .

Sy-subrc = 0 (match)

or 4 (no match).

Page 16: 1 ABAP Basics III Northern Arizona University College of Business.

16

Case Statement

The Case statement is used when there is a given set of values in a field .

Page 17: 1 ABAP Basics III Northern Arizona University College of Business.

17

Case Statement

Data Field1 Type I .Case Field1 .

When 1 .Write ‘The value is 1’ .

When 2 .Write ‘The value is 2’ .

When Others .Write ‘The value is greater than 2’ .

EndCase .

Page 18: 1 ABAP Basics III Northern Arizona University College of Business.

18

Case Statement

Data Field1(1) Type C .Case Field1 .

When ‘a’ .Write ‘The value is a’ .

When ‘b’ .Write ‘The value is b’ .

When Others .Write ‘The value is greater than b’ .

EndCase .

Page 19: 1 ABAP Basics III Northern Arizona University College of Business.

19

Case Statement

Case sy-subrc .

When 0 .

Write ‘The value is zero’ .

When Others .

Write ‘The value is not zero’ .

EndCase .

Page 20: 1 ABAP Basics III Northern Arizona University College of Business.

20

If Statement

If A = B .

Whatever = 0 .

EndIf .

Page 21: 1 ABAP Basics III Northern Arizona University College of Business.

21

If Statement

If A = B .

Whatever = 0 .

Else .

Whatever = 1 .

EndIf .

Page 22: 1 ABAP Basics III Northern Arizona University College of Business.

22

If Statement

If A < 50 .

Whatever = 0 .

ElseIf A = 50 .

Whatever = 1 .

Else .

Whatever = 2 .

EndIf .

Page 23: 1 ABAP Basics III Northern Arizona University College of Business.

23

Logical Operators

> GT< LT>= GE =><= LE =<= EQ<> NE ><

Page 24: 1 ABAP Basics III Northern Arizona University College of Business.

24

Logical Operators

Is InitialBetween value1 And value 2 CO contains onlyCA contains anyCS contains stringCP contains pattern

Page 25: 1 ABAP Basics III Northern Arizona University College of Business.

25

If Statement

If W_Field is Initial .

If Not ( W_Field is Initial ) .

If W_Field is between 10 and 20 .

Page 26: 1 ABAP Basics III Northern Arizona University College of Business.

26

If Statement

Data W_Field(6)type C Value ‘abcdef’ .

If W_Field CO ‘abcdef’ . “only

If W_Field CA ‘a’ . “any

IFW_Field CS ‘bc’ . “string

IFW_Field CP ‘*b+d*’ “pattern

Page 27: 1 ABAP Basics III Northern Arizona University College of Business.

27

Looping

Do Loop

While Loop

Loop

Page 28: 1 ABAP Basics III Northern Arizona University College of Business.

28

Do Loop

Used when a fixed number of iterations is known.

Do 10 times.

. . . . .

EndDo.

Page 29: 1 ABAP Basics III Northern Arizona University College of Business.

29

Do Loop

Data Cnt type I value 10 .

Do Cnt times.

Write: / ‘the loop count is: ‘, sy-index .

EndDo.

Page 30: 1 ABAP Basics III Northern Arizona University College of Business.

30

Sy-Index

Sy-Index automatically stores the loop pass number.

Page 31: 1 ABAP Basics III Northern Arizona University College of Business.

31

Do Loop - Exit

Data Cnt type I value 10 .

Do Cnt times.

Write: / ‘the loop count is: ‘, sy-index .

If sy-index = 5 .

Exit .

EndIf .

EndDo.

Page 32: 1 ABAP Basics III Northern Arizona University College of Business.

32

While Loop

Data: Cnt type I value 0 ,

Limit type I value 10 .

While Cnt < Limit .

Cnt = Cnt + 1 .

Write: / ‘the loop count is: ‘, Cnt .

EndWhile .

Page 33: 1 ABAP Basics III Northern Arizona University College of Business.

33

Loop

The Loop statement is used with internal tables.

Loop .

. . . . .

EndLoop .