- In this Post will delete records from custom table using AMDP
CLASS zcl_amdp_demo_class DEFINITION
PUBLIC FINAL
CREATE PUBLIC.
PUBLIC SECTION.
"Add AMDP Class Interface
INTERFACES if_amdp_marker_hdb.
"Define Structure
TYPES: BEGIN OF lty_sales.
INCLUDE TYPE zms_sales_head.
TYPES END OF lty_sales.
"Define Internal Table
TYPES: tt_sales TYPE TABLE OF lty_sales.
"Static AMDP Method
CLASS-METHODS: InsertRec IMPORTING VALUE(iv_mandt) TYPE mandt
EXPORTING VALUE(et_sales) TYPE tt_sales
RAISING CX_AMDP_ERROR.
ENDCLASS.
CLASS zcl_amdp_demo_class IMPLEMENTATION.
METHOD insertrec BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT USING vbak zms_sales_head.
* DECLARE lt_sales_head table like ZMS_SALES_HEAD; //Define Internal table with same DB Table type
DECLARE lt_sales_head table ( mandt NVARCHAR(3),
vbeln "$ABAP.Type( vbeln_va )",
audat "$ABAP.Type( audat )",
auart "$ABAP.Type( auart )",
vkorg "$ABAP.Type( vkorg )",
vtweg "$ABAP.Type( vtweg )",
spart "$ABAP.Type( spart )",
vkbur "$ABAP.Type( vkbur )",
bstnk "$ABAP.Type( bstnk )",
bstdk "$ABAP.Type( bstdk )",
kunnr "$ABAP.Type( KUNAG )",
kunwe "$ABAP.Type( kunwe )",
erdat "$ABAP.Type( erdat )",
erzet "$ABAP.Type( erzet )",
ernam "$ABAP.Type( ernam )" );
lt_order = select top 5
mandt,
vbeln,
audat,
auart,
vkorg,
vtweg,
vkbur,
spart,
bstnk,
bstdk,
kunnr,
kunnr as kunwe
from vbak
where mandt = session_context( 'CLIENT' );
lt_sales_head = select cast(session_context( 'CLIENT' ) as nvarchar( 3 ) ) as mandt,
vbeln,
audat,
auart,
vkorg,
vtweg,
spart,
vkbur,
bstnk,
bstdk,
kunnr,
kunwe,
--current_date as ERDAT, //Get the Current Date as Date format
--cast( current_date as nvarchar(8) ) as erdat, //Current Date convert to 8 character
COALESCE( cast( to_nvarchar( current_date,'YYYYMMDD' ) as NVARCHAR(8) ), '00000000' ) as erdat,
to_nvarchar( current_time, 'HHMMSS' ) as erzet,
session_context( 'APPLICATIONUSER' ) as ernam
from :lt_order;
insert into zms_sales_head select * from :lt_sales_head;
delete from zms_sales_head where vbeln in ( select vbeln from :lt_sales_head );
et_sales = select * from :lt_sales_head;
ENDMETHOD.
ENDCLASS.
No comments:
Post a Comment