SAP/ABAP info: ABAP Tutorial
Writing on the screen
Source:

* Starting a line with star means,
* that it will be handled
* as a comment

* this line is for the formalities
* it must be included in all
* reports

report firstreport.

* lets write one line
write 'Something is written here'.

 
Result:
Something is written here


Writing five lines

* This line does what it says
do 5 times.

* / means new line
write / 'Line number:'.

* sy-index is the actual index
write sy-index.

* Do things 5 times until now
enddo.

 

Line number: 1
Line number: 2
Line number: 3
Line number: 4
Line number: 5

 
 
Variables

* Lets define a text variable
data var_text(10).
* And a numeric variable
data var_number type i.

var_text = ‘Apple’.

* Extend this variable
concatenate var_text ‘falls’
           ‘down’ into var_text.

write var_text.

var_number = 95.
add 20 to var_number.

write var_number.

 
 
Applefallsdown 115
 


Lazy programmers

* Some say programmers are lazy
* I don't necessary agree,
* but they certainly made life
* simpler for themselves.


write / 'Instead of writing'.
write / 'a write command'.
write / 'for each field,'.

write:/ 'you can use',
      / 'one colon(:)',
      / 'and instead of commands',
      / 'as many commas(,)',
      / 'as you want'.

 

Instead of writing
a write command
for each field,
you can use
one colon(:)
and instead of commands
as many commas(,)
as you want

 
Selection from database

select single * from t005t
       where spras = 'EN' and
             land1 = 'HU'.

* Write, what we got from the table
Write: t005t-land1,
       t005t-landx,
       t005t-nation.

 
 
HU Hungary Hungarian
 


Internal table

* Lets create an internal table
data: begin of i_tab occurs 0,
       text(10),
       num type I,
      end of i_tab.

i_tab-text = ‘Cats’.
i_tab-num = 5.
append i_tab.

i_tab-text = ‘Dogs’.
i_tab-num = 2.
append i_tab.

loop at i_tab.
write:/ i_tab-text, i_tab-num.
endloop.

 

Cats    5
Dogs    2

 
 
Full program: Add up two numbers
report addition.

* Get parameters
parameters: p_a(5),
            p_b(5).

data: var_c type i.

var_c = p_a + p_b.

write:/ p_a, ‘+’, p_b, ‘=’, var_c.
 
 



1 + 2 = 3
 

Full program: Nationalities
report nationalities.
tables: t005t.

* Lets create an internal table
* what looks like the table t005

data: i_tab like t005t occurs 0
            with header line.

select * from t005 into i_tab
         where spras = ‘EN’.

loop at i_tab.
  write:/ i_tab-land1,
  i_tab-landx,
  i_tab-natio.
endloop.
 
 



 
Published on zbalai.com in 2004.