Example: Parameters, Write, Data, If-else 28 April
REPORT Z930_PROG2.
*PARAMETERS p_x type i.
*PARAMETERS p_y type i.
PARAMETERS : p_x type i DEFAULT 10 OBLIGATORY,
p_y type i DEFAULT 20.
data gv_r1 type i.
data gv_r2 type i.
*gv_r1=p_x+p_y. "syntax error
gv_r1 = p_x + p_y.
gv_r2 = p_x - p_y.
*write 'sum of two numbers is ',gv_r1. "syntax error
write :/ 'sum of two numbers is ',gv_r1,
/ 'difference of two numbers is ',gv_r2.
uline. "underline
*format color 9. "syntax error
format color 3.
write :/ 'sum of two numbers is ',gv_r1.
if gv_r2 >= 0.
write :/ 'Difference of two numbers is ',gv_r2.
else.
write :/ 'Difference of two numbers is -' no-gap,gv_r2 no-sign LEFT-JUSTIFIED.
endif.
format color off.
Example: Constants
REPORT Z930_PROG3.
data gv_x type i value 10. "declaration and initialization
write :/ gv_x.
gv_x = 56.
write :/ gv_x.
uline.
*constants c_y type i. "syntax error
constants c_y type i value 20.
write :/ c_y.
*c_y = 24. "syntax error
1st May
Example: Selection Screen Radiobuttons
REPORT Z930_PROG4.
*PARAMETERS p_x type i.
*PARAMETERS p_y type i.
PARAMETERS : p_x type i DEFAULT 20 OBLIGATORY,
p_y type i DEFAULT 10 OBLIGATORY.
PARAMETERS : p_r1 RADIOBUTTON GROUP grp1,
p_r2 RADIOBUTTON GROUP grp1,
p_r3 RADIOBUTTON GROUP grp1 DEFAULT 'X',
p_r4 RADIOBUTTON GROUP grp1.
data gv_res type i.
if p_r1 = 'X'.
gv_res = p_x + p_y.
write :/ 'Sum of Two numbers is ',gv_res.
elseif p_r2 = 'X'.
gv_res = p_x - p_y.
if gv_res >= 0.
write :/ 'Difference of Two numbers is ',gv_res.
else.
write :/ 'Difference of Two numbers is -' no-gap,gv_res no-sign LEFT-JUSTIFIED.
endif.
elseif p_r3 = 'X'.
gv_res = p_x * p_y.
write :/ 'Product of Two numbers is ',gv_res.
*else. "(or)
elseif p_r4 = 'X'.
gv_res = p_x / p_y.
write :/ 'Division of two numbers is ',gv_res.
endif.
Example: Selection Screen Checkboxes
REPORT Z930_PROG5.
PARAMETERS : p_x type i,
p_y type i.
PARAMETERS : p_c1 as CHECKBOX default 'X',
p_c2 as CHECKBOX,
p_c3 as CHECKBOX default 'X',
p_c4 as CHECKBOX.
data gv_res type i.
if p_c1 = 'X'.
gv_res = p_x + p_y.
write :/ 'Sum of Two numbers is ',gv_res.
endif.
if p_c2 = 'X'.
gv_res = p_x - p_y.
if gv_res >= 0.
write :/ 'Difference of Two numbers is ',gv_res.
else.
write :/ 'Difference of Two numbers is -' no-gap,gv_res no-sign,
LEFT-JUSTIFIED.
endif.
endif.
if p_c3 = 'X'.
gv_res = p_x * p_y.
write :/ 'Product of Two numbers is ',gv_res.
endif.
if p_c4 = 'X'.
gv_res = p_x / p_y.
write :/ 'Division of two numbers is ',gv_res.
endif.
2nd May
Example: Data Types and System Fields
REPORT Z930_PROG6.
*data gv_x type i DECIMALS 2. "syntax error
data gv_x type i. "declaration
gv_x = 105. "assignment
write gv_x. "display
*gv_x = 123.45. "syntax error
gv_x = '123.45'.
write / gv_x.
gv_x = '123.87'.
write / gv_x.
uline.
data gv_y type p.
gv_y = '123.45'.
write / gv_y.
uline.
data gv_z type p DECIMALS 2.
gv_z = '123.45'.
write / gv_z.
uline.
data gv_m type c.
gv_m = 'Gensoft Technologies'.
write / gv_m.
uline.
data gv_k(10) type c. "array of characters
gv_k = 'Gensoft Technologies'.
write / gv_k.
uline.
data gv_r type string.
gv_r = 'Gensoft Technologies'.
write / gv_r.
uline.
data gv_r1 type d. "date-8 bytes
gv_r1 = sy-datum. "system field for application server current date
write / gv_r1. "ddmmyyyy
write /(10) gv_r1. "dd.mm.yyyy
write /(10) gv_r1 using EDIT MASK '__/__/____'. "dd/mm/yyyy
uline.
data gv_r2 type t. "time-6 bytes
gv_r2 = sy-uzeit. "system field for application server current time
write / gv_r2. "hhmmmss
write /(8) gv_r2. "hh:mm:ss
write /(8) gv_r2 using edit mask '__-__-__'. "hh-mm-ss
uline.
write / sy-repid. "current program name
write / sy-uname. "login user name
write / sy-pagno. "current page no
write / sy-dynnr. "current screen no
Example: Event handling on Selection Screen Radio Buttons
REPORT Z930_PROG7.
PARAMETERS : p_x type i DEFAULT 20,
p_y type i DEFAULT 10.
PARAMETERS : p_r1 RADIOBUTTON GROUP grp1 USER-COMMAND abc,
p_r2 RADIOBUTTON GROUP grp1,
p_r3 RADIOBUTTON GROUP grp1,
p_r4 RADIOBUTTON GROUP grp1.
at SELECTION-SCREEN ON RADIOBUTTON GROUP grp1.
* if sy-ucomm = 'abc'. "not satisfied as function code is always captured in upper case
if sy-ucomm = 'ABC'.
* message 'Selected the Radiobutton' type 'I'. "information msg
if p_r1 = 'X'.
message 'First Radiobutton selected' type 'I'.
elseif p_r2 = 'X'.
message 'Second Radiobutton selected' type 'I'.
elseif p_r3 = 'X'.
message 'Third Radiobutton selected' type 'I'.
elseif p_r4 = 'X'.
message 'Fourth Radiobutton selected' type 'I'.
endif.
endif.
3rd may
Example: Looping Statements, Continue and Exit statements
REPORT Z930_PROG8.
PARAMETERS p_x type i.
data : gv_y type i value 1,
gv_res type i.
write :/ 'While loop...'.
while gv_y <= 10.
gv_res = p_x * gv_y.
write :/ p_x,'*',gv_y,'=',gv_res.
gv_y = gv_y + 1.
endwhile.
uline.
gv_y = 1.
write :/ 'While loop...'.
while gv_y <= 10.
if gv_y ne 4.
gv_res = p_x * gv_y.
write :/ p_x,'*',gv_y,'=',gv_res.
endif.
gv_y = gv_y + 1.
endwhile.
uline.
gv_y = 1.
write :/ 'While loop...'.
while gv_y <= 10.
if gv_y eq 4.
gv_y = gv_y + 1.
continue.
endif.
gv_res = p_x * gv_y.
write :/ p_x,'*',gv_y,'=',gv_res.
gv_y = gv_y + 1.
endwhile.
uline.
write :/ 'DO...enddo..First Syntax..'.
gv_y = 1.
do.
gv_res = p_x * gv_y.
write :/ p_x,'*',gv_y,'=',gv_res.
gv_y = gv_y + 1.
if gv_y > 10.
exit.
endif.
enddo.
write :/ 'After do..enddo'.
uline.
write :/ 'DO...enddo..Second Syntax..'.
gv_y = 1.
do 10 times. "suitable for executing statements repeatedly for fixed no of times
gv_res = p_x * gv_y.
write :/ p_x,'*',gv_y,'=',gv_res.
gv_y = gv_y + 1.
enddo.
Example: Case-Endcase
REPORT Z930_PROG9.
PARAMETERS : p_x type i DEFAULT 10,
p_y type i DEFAULT 5,
p_ch type i.
data gv_res type i.
case p_ch.
when 1.
gv_res = p_x + p_y.
write :/ 'Sum is ',gv_res.
when 2.
gv_res = p_x - p_y.
write :/ 'Difference is ',gv_res.
when 3.
gv_res = p_x * p_y.
write :/ 'Product is ',gv_res.
when 4.
gv_res = p_x / p_y. "quotient
write :/ 'Division is ',gv_res.
when 5.
gv_res = p_x mod p_y. "remainder
write :/ 'Remainder is ',gv_res.
when others.
message 'Please enter choice as 1/2/3/4/5' type 'I'.
endcase.
Example: Check Statement
REPORT Z930_PROG10.
PARAMETERS p_x type i.
data gv_r type i.
gv_r = p_x mod 2.
write :/ 'Before checking condition...'.
check gv_r eq 0.
write :/ 'Even no'.
write :/ 'End of program'.
Example: Field-Symbols
REPORT Z930_PROG11.
data gv_r type i value 10.
*FIELD-SYMBOLS abc. "syntax error
FIELD-SYMBOLS <abc>. "capable of storing any type of data
write :/ 'Integer variable gv_r is ',gv_r,
/ 'Field Symbol <abc> is ',<abc>.
uline.
*<abc> = gv_r. "runtime error-error at assignment
assign gv_r to <abc>.
write :/ 'Integer variable gv_r is ',gv_r,
/ 'Field Symbol <abc> is ',<abc>.
uline.
gv_