ABAP Chapter 2

    

Report Statement Write & Format Statement Flow Control in ABAP Manipulating Character Data Report Driven : Page Report (List Header)

List Processing

Report Header Report Listing (Body)

Report Statement

Syntax EPORT <report name> [NO STANDARD PAGE HEADING] [LINE-SIZE no of columns] [LINE-COUNT no of lines[(no of footer)

EPORT ztest1 NO STANDARD PAGE HEADING. EPORT ztest LINE-SIZE 132 LINE-COUNT 65(2
sy-linsz

Text Element : Title&Headers
Report ztest. Write ‘Hello World’.

 Text Element

Title and Headers This is test program by Prapoj List Header Column Header
Column #1 Column #2

Creating Lists

ABAP statement that create list
  

WRITE SKIP ULINE

The complete report list will appears automatically at the end of the processing block

List Buffer
Dialog WP TaskHandler
ABAP Processor
List Buffer

Local Memory
Memory Space

Dynpro Processor

WRITE,SKIP ,ULINE

DB Interface

WRITE Statement

* Write data

WRITE ‘Hello World’. WRITE: ‘OK’, ‘Test data’. WRITE: /15(10) ‘ABCDEFGHIJKLMNOPQ’. WRITE /20 ‘Test data’.

Breaking to a New Line

Write data WRITE: / ‘First Line’, ‘Data 1’, / ‘Second Line’, ‘Data 2’, /(20) ‘Third Line’, ‘Data 3’, /35 ‘Fourth Line’, ‘Data 4’.
sycolno

Text Symbol

Report ztest. Write: Text-001,

 Text Element
 Text Symbols  Text Symbol 001 002 Text Text 1 Text 2

Text-002.

Text Symbol
write: write: write: write: write: / / / / /

Text-00 Text-00 Text-00 Text-00 Text-00

Column Position
DATA colno type I value 10. write: /5 ‘Hello’, at colno ‘World’. write: at /colno ‘OK’.

Options of the WRITE Statement

* Write Syntax
WRITE var [NO-ZERO] [NO-SIGN] [NO-GROUPING] [NO-GAP] [DECIMALS no of decimals]

Suppressing Blanks(NO-ZERO)
* No Zero
DATA: number(10) TYPE N VALUE 23. WRITE: number, number NO-ZERO.

Suppressing Number(+ / -) Sign
* No Sign
DATA: v_integer TYPE I VALUE -1. WRITE: v_integer, v_integer NO-SIGN.

NO-GROUPING
* No grouping

DATA: v_integer TYPE I VALUE 120000. WRITE: v_integer, v_integer NO-GROUPING

NO-GAP
* No gap
WRITE: ‘Hello’ NO-GAP, ‘World’.

DECIMALS
* Decimals DATA: v_pack TYPE P DECIMALS 4 VALUE ‘1234.5678’. WRITE: v_pack, v_pack DECIMALS 2.

Formatting Options
* * * * Format options of WRITE statement LEFT-JUSTIFIED for Integer data RIGHT-JUSTIFIED for Character data CENTERED

test Data tmp1(20) value ‘test’. WRITE: tmp1 CENTERED.

Inserting Blank Lines(SKIP)
*Skip Statement SKIP. WRITE: ‘Hello World’, sy-linno. SKIP. WRITE: ‘Test 1’. SKIP 5. WRITE: ‘Test 2’. SKIP TO LINE 20. WRITE ‘This is line 20’.

Inserting Horizontal Lines(ULINE)
* Uline WRITE: WRITE: ULINE ULINE. WRITE: ULINE ‘Hello World’. /5(35) sy-uline, sy-vline. /5(35). / ‘This is an underline’. /(18).

Frame
uline: /(45). write: /1 sy-vline, 'Column #1', 15 sy-vline, 'Column #2', 30 sy-vline, 'Column #3', 45 sy-vline. uline: /(45).

Exercise I
sy-uzeit

sy-datum

FORMAT Statement
FORMAT [INTENSIFIED] [INTENSIFIED OFF] [COLOR <color>] [COLOR OFF] [HOTSPOT ON] [HOTSPOT OFF] [RESET]

FORMAT Statement FORMAT COLOR 1. WRITE: / ‘Hello World’, ‘Test’ FORMAT COLOR OFF.

COLOR

7

FORMAT COLOR
COLOR COLOR COLOR COLOR COLOR COLOR COLOR COLOR col_heading. col_normal. col_total. col_key. col_positive. col_negative. col_group. col_background. “color 1 “color 2 “color 3 “color “color 5 “color 6 “color 7 “color off

ORMAT ORMAT ORMAT ORMAT ORMAT ORMAT ORMAT ORMAT

Exercise I

Include Program
  

You can create a program with program type include program in the program attribute Include program do not have to have an introductory statement During the syntax check and during program generation by the ABAP compiler, the INCLUDE statement is replaced by the source text of the defined include program

REPORT ztest1. INCLUDE zinclude1. …

Include Program : Data tmp(10). ZINCLUDE1
Data tmp1 type i. Data tmp2 type p. Data tmp3.

REPORT ztest2. INCLUDE zinclude …

Symbols and Icons

Display Icon or Symbol in List CLUDE <LIST>. RITE: / ‘Phone :’, SYM_PHONE AS SYMBOL. RITE: / ‘Alarm :’, ICON_ALARM AS ICON. RITE: / ‘Green Light :’, ICON_GREEN_LIGHT AS ICON HOTS RMAT HOTSPOT ON. WRITE: / ‘Hello ABAP’, ’Hi!’. RMAT HOTSPOT OFF.

Flow Control in ABAP

Flow Control in ABAP

Branching ==> IF, CASE.  Looping ==> DO, WHILE.

IF Statement
IF <Condition>. <Statement Block> ELSEIF <Condition>. <Statement Block> ELSEIF <Condition>. <Statement Block> ELSE. <Statement Block> ENDIF.

IF Statement
IF

sy-mandt = ‘100’. WRITE: / ‘This is Production Client’. ELSEIF sy-mandt = ‘800’. WRITE: / ‘This is Development Client’. ELSE. WRITE: / ‘This is Test Client’. ENDIF.

CASE Statement
CASE <field>. WHEN <value1>. <Statement Block> WHEN <value2>. <Statement Block> ... WHEN OTHERS. <Statement Block> ENDCASE.

CASE Statement
CASE sy-mandt. WHEN ‘100’. WRITE: / ‘Production Client’. WHEN ‘800’. WRITE: / ‘Development Client’. WHEN OTHERS. WRITE: / ‘Test Client’. ENDCASE.

DO Statement
DO. WRITE sy-index. IF sy-index = 3. EXIT. ENDIF. WRITE: sy-index. ENDDO.

CONTINUE Statement
DO 5 TIMES. IF sy-index = 3. CONTINUE. ENDIF. WRITE: sy-index. ENDDO.

CHECK Statement
DO 4 TIMES. CHECK sy-index BETWEEN 2 AND 3. WRITE: sy-index. ENDDO.

WHILE Statement

DATA: count TYPE I value 1. WHILE count <> 4. WRITE: sy-index. count = count + 1. ENDWHILE.

Logical Expressions
>,GT <,LT >=, =>, GE <=, =<, LE =, EQ <>, ><, NE BETWEEN value1 AND value2 IS INITIAL

Arithmetic Operators
+ , - , * , / , ** DIV MOD Example : 9 / 2 = 4.5 9 DIV 2 = 4.0 9 MOD 2 = 1 SQRT( 2 ) = 1.41 2 ** 4 = 16

Character String Operator
if if if if if ‘AABB’ ‘ABCD’ ‘AXCZ’ ‘ABCD’ ‘ABCD’ co ‘AB’. F co ‘ABC’. T ca ‘AB’. F ca ‘XYZ’. T cp ‘+B*’.
T

Manipulating Character Data

Manipulating Character Data
* Substrings with offsets DATA tmp(10) VALUE ‘ABCDEFGHIJ’. DEFGHIJ DATA tmp1(2). BCDE WRITE: tmp+3(7), ABCDEFGH tmp+1(4), tmp+0(8), HIJ tmp+7(3). MOVE tmp+4(2) TO tmp1.

SHIFT Statement
* SHIFT Statement DATA tmp(5) VALUE ‘12345’. 2345_ SHIFT tmp. 345__ SHIFT tmp BY 2 PLACES. SHIFT tmp BY 2 PLACES CIRCULAR. 34512 345__ SHIFT tmp UP TO ‘3’. SHIFT SHIFT SHIFT SHIFT tmp tmp tmp tmp

UP TO ‘3’ RIGHT. __123 UP TO ‘3’ RIGHT CIRCULAR. 45123 RIGHT DELETING TRAILING SPACE. LEFT DELETING LEADING SPACE.

SHIFT

* Shift DATA name(30) VALUE ‘Alexander Bill Charl SHIFT name UP TO ‘Bill’. WRITE: / name.
Bill Charles

SEARCH(Non Case* Search DATA tmp(5) VALUE ‘ABCDE’. SEARCH tmp FOR ‘C’. DATA tmp1(10) VALUE ‘Till Bill’. SEARCH tmp1 FOR ‘Bill’. IF SY-SUBRC = 0. WRITE: / SY-FDPOS. ENDIF.

sensitive)

TRANSLATE
* Translate DATA tmp(5) VALUE ‘abc ‘. TRANSLATE tmp TO UPPER CASE. TRANSLATE tmp TO LOWER CASE. TRANSLATE tmp USING ‘ 0’. TRANSLATE tmp USING ‘ 0aA’.

REPLACE
* Replace DATA tmp(20) VALUE ‘I was a boy’. REPLACE ‘was’ WITH ‘am’ INTO tmp. IF sy-subrc = 0. write ‘Replace OK’. ELSE. write ‘Cannot find data to be replaced’. ENDIF.

Removing Spaces(CONDENSE)
* Condense DATA: tmp(20) VALUE ‘I am a CONDENSE tmp. I am a boy CONDENSE tmp NO-GAPS.
Iamaboy

boy’.

Concatenation String(CONCATENATE)

* Concatenate DATA: tmp1(2) VALUE ‘AB’, ABCDE tmp2(3) VALUE ‘CDE’, tmp3(10). CONCATENATE tmp1 tmp2 INTO tmp3. CONCATENATE tmp1 tmp2 INTO tmp3 SEPARATED BY
AB CDE

‘ ‘.

Split

* Split
DATA: name(30) value ‘David, John, Peter’, one(10), two(10), three(30). split name at ‘,’ into one two three.

Working with Date Variables
* Date DATA today TYPE D. today = sy-datum. syWRITE: today, datum+0(4) ‘Year :’ , today+0(4), ‘Month :’, today+4(2), ‘Day :’ , today+6(2).

WRITE … TO …
DATA: today TYPE D, tmp(10). today = sy-datum. tmp = today. WRITE tmp. WRITE today TO tmp. WRITE tmp. CLEAR today. WRITE today NO-ZERO TO tmp. WRITE tmp.

Invalid Date
DATA: today TYPE D. today = ‘20061321’. today = today + 0. if today is initial. write: / ‘invalid date’. else. write: / today. endif.

Built-in Functions
 

ABAP provides a lot of built-in functions A Built-in function calculates a return value from an argument
    

abs = Absolute value of argument sign = +/- sign of argument sqrt = Square root strlen = Number of characters in arg xstrlen = Number of bytes in arg

STRLEN Built-in Function
DATA: tmp(20) VALUE ‘Test String’, count TYPE I. count = strlen( tmp ). WRITE count.

STRLEN Built-in Function Example
DATA: tmp(20) VALUE ‘xxax’, cntlen TYPE I. cntlen = strlen( tmp ). cntlen = cntlen – 2. if tmp+cntlen(1) = ‘a’. “cntlen >= 0 write: / ‘OK’. endif.

WRITE ‘
*If we need the word like this I’m a boy WRITE: ‘I’’m a boy’.

Exercise

Create program to display current month in text for example October

Report Driven : Page Report

Application Driven Programming
REPORT ztest. DATA: today TYPE D. today = ‘20061321’. today = today + 0. IF today IS INITIAL. WRITE: / ‘invalid date’. ELSE. WRITE: / today. ENDIF.

Event Driven Programming
REPORT ztest. DATA today TYPE D. TOP-OF-PAGE. <ABAP statement> END-OF-PAGE. <ABAP statement> START-OF-SELECTION. <ABAP statement>

Report Driven List Header

PORT ztest NO STANDARD PAGE HEADIN P-OF-PAGE. FORMAT COLOR 1. WRITE: /5 ‘User Name’, 25 ‘Program Name’. ULINE. ART-OF-SELECTION. WRITE: /5 sy-uname, 25 sy-repid.

Report Driven Page Footer
REPORT ztest no standard page heading LINE-COUNT 10(2). TOP-OF-PAGE. FORMAT COLOR 1. WRITE: / ‘Page :’, sy-pagno. ULINE. END-OF-PAGE. ULINE. WRITE: / ‘To be continue on next page…’ . START-OF-SELECTION. DO 20 TIMES. WRITE: / sy-index. ENDDO.

TOP-OF-PAGE
REPORT ztest no standard page heading. TOP-OF-PAGE. FORMAT COLOR 1. WRITE: / 'Report Header'. ULINE. START-OF-SELECTION. DO 100 TIMES. WRITE: / sy-index. ENDDO.

ABAP Program Structure
Report ztest. *Data declaration data ... data begin of ... *Top-of-Page event top-of-page. *End-of-Page event end-of-page. *Start-of-selection Start-of-selection.

ABAP Practice

Exercise II

sy-datum

sy-uzeit sy-repid

syuname

Sign up to vote on this title
UsefulNot useful