Simple AMDP program for CRUD opertaions
Scenario - Create a report with selection screen to Create, Read, Update and Delete table data using AMDP.
I have used a custom table ZDLOAN for this requirement. The below is the information maintained in the table.
Below is the code implemented for AMDP class.
CLASS zvr30_amdp_crud DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_amdp_marker_hdb .
TYPES: BEGIN OF ty_read.
INCLUDE TYPE zdloan.
TYPES: END OF ty_read.
TYPES: tt_read TYPE TABLE OF ty_read.
METHODS: md_insert IMPORTING VALUE(ip_mandt) TYPE mandt
VALUE(ip_custid) TYPE int4
VALUE(ip_loanamt) TYPE int4
VALUE(ip_loandate) TYPE dats
VALUE(ip_duedate) TYPE dats
VALUE(ip_priority) TYPE char20
VALUE(ip_interest) TYPE int4 RAISING cx_amdp_execution_failed,
md_read IMPORTING VALUE(ip_mandt) TYPE mandt
EXPORTING VALUE(ep_read) TYPE tt_read,
md_update IMPORTING VALUE(ip_mandt) TYPE mandt
VALUE(ip_cust) TYPE int4
VALUE(ip_interest) TYPE int4,
md_delete IMPORTING VALUE(ip_mandt) TYPE mandt
VALUE(ip_cust) TYPE int4.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zvr30_amdp_crud IMPLEMENTATION.
METHOD md_insert BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT
USING zdloan.
DECLARE IT_LOAN table like ZDLOAN;
:IT_LOAN.INSERT( ( IP_MANDT, ip_custid, ip_loanamt, ip_loandate, ip_duedate, ip_priority, ip_interest ) );
ENDMETHOD.
METHOD md_read BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT OPTIONS READ-ONLY
USING zdloan.
ep_read = select * from zdloan where mandt = ip_mandt;
ENDMETHOD.
METHOD md_update BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT USING zdloan.
UPDATE zdloan set interest = ip_interest where mandt = ip_mandt and custid = ip_cust;
ENDMETHOD.
METHOD md_delete BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT USING zdloan.
DELETE FROM zdloan where mandt = ip_mandt and custid = ip_cust;
ENDMETHOD.
ENDCLASS.Below is the code implemented in the driver program.
REPORT zvr30_demoamdpcrudcon.
SELECTION-SCREEN begin of block b1 with frame TITLE T002.
PARAMETERS: p_create RADIOBUTTON GROUP rb1,
p_read RADIOBUTTON GROUP rb1,
p_update RADIOBUTTON GROUP rb1,
p_delete RADIOBUTTON GROUP rb1.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN begin of block b2 with FRAME TITLE T001.
PARAMETERS: p_custid type int4,
p_loan type int4,
p_loandt type dats,
p_duedt type dats,
p_priort type char20,
p_intrst type int4.
SELECTION-SCREEN end of block b2.
SELECTION-SCREEN begin of block b3 with FRAME TITLE T003.
parameters: up_cust type int4,
up_int type int4.
SELECTION-SCREEN end of block b3.
SELECTION-SCREEN begin of block b4 with FRAME TITLE T004.
parameters: dl_cust type int4.
SELECTION-SCREEN end of block b4.
INITIALIZATION.
T002 = 'CRUD Operation'.
T001 = 'Create data'.
T003 = 'Update data'.
T004 = 'Delete data'.
START-OF-SELECTION.
data(lo_amdp) = new zvr30_amdp_crud( ).
if p_create is not initial.
try.
lo_amdp->md_insert(
EXPORTING
ip_mandt = sy-mandt
ip_custid = p_custid
ip_loanamt = p_loan
ip_loandate = p_loandt
ip_duedate = p_duedt
ip_priority = p_priort
ip_interest = p_intrst
).
CATCH cx_amdp_execution_failed.
write: 'Error occured. Ket fields already exists'.
endtry.
elseif p_update is not INITIAL.
lo_amdp->md_update(
EXPORTING
ip_mandt = sy-mandt
ip_cust = up_cust
ip_interest = up_int
).
elseif p_delete is not INITIAL.
lo_amdp->md_delete(
EXPORTING
ip_mandt = sy-mandt
ip_cust = dl_cust
).
else.
lo_amdp->md_read(
EXPORTING
ip_mandt = sy-mandt
IMPORTING
ep_read = data(it_read)
).
if it_read is not INITIAL.
cl_demo_output=>display_data(
EXPORTING
value = it_read
name = 'Table Data'
* exclude =
* include =
).
endif.
endif.The selection screen looks as below.


Comments
Post a Comment