Basic Program in Abap
Basic Program in Abap
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