In this video, we will learn to Create, Read, Update and Delete (CRUD) using ABAP Report and Function Modules.
Prerequisite of this course:
Create, Read, Update & Delete – CRUD Operations in ABAP Report: https://gocoding.org/crud-operation-i...
SAP Tables: How to Create SAP ABAP Tables: https://gocoding.org/sap-tables/
Modularization Techniques in ABAP: https://gocoding.org/modularization-t...
ABAP Report Events: Reporting Events: https://gocoding.org/abap-report-even...
Source Code of Function Module:
Data: ls_emp type ZBARRY_EMP.
if flag = 'R'.
SELECT SINGLE * from ZBARRY_EMP into ls_emp where EMPID = EMPID.
If Sy-subrc = 0.
FNAME = ls_emp-FNAME.
LName = ls_emp-LName.
Phone = ls_emp-Phone.
MSG = 'Read is success'.
Endif.
ELSEIF flag = 'C'.
ls_emp-empid = empid.
ls_emp-FNAME = I_FNAME.
ls_emp-lname = I_lname.
ls_emp-phone = I_phone.
INSERT ZBARRY_EMP FROM ls_emp.
If Sy-subrc = 0.
MSG = 'Create is successful'.
else.
MSG = 'Create Failed'.
Endif.
Elseif Flag = 'U'.
UPDATE ZBARRY_EMP set phone = I_phone
where empid = empid.
If Sy-subrc = 0.
MSG = 'Update is successful'.
else.
MSG = 'Update Failed'.
Endif.
ELSEIF Flag = 'D'.
Delete from ZBARRY_EMP where empid = empid.
If Sy-subrc = 0.
MSG = 'Delete is successful'.
else.
MSG = 'Delete Failed'.
Endif.
Else.
MSG = 'No or invalid Flag Sent'.
ENDIF.
Code in ABAP Report:
REPORT ZBARRYEMP_REPORT.
Data: ls_emp type ZBARRY_EMP,
lv_MSG type char20.
PARAMETERS: p_empid TYPE int4,
p_flag type char1,
p_fname type char20,
p_lname type char20,
p_phone type char20.
CALL FUNCTION 'ZBARRYEMPLOYEE_FM'
EXPORTING
EMPID = p_empid
FLAG = p_flag
I_FNAME = p_fname
I_LNAME = p_lname
I_PHONE = p_phone
IMPORTING
FNAME = ls_emp-FNAME
LNAME = ls_emp-LNAME
PHONE = ls_emp-PHONE
MSG = lv_MSG.
ls_emp-empid = p_empid.
WRITE: 'The impored data is'.
WRITE:/3 ls_emp-empid, 20 ls_emp-fname,35 ls_emp-lname,70 ls_emp-phone.
WRITE: 'The message is', lv_MSG.