- Here we have created instance AMDP Method as highted as below
PUBLIC FINAL
CREATE PUBLIC.
PUBLIC SECTION.
"Add AMDP Class Interface
INTERFACES if_amdp_marker_hdb.
"Define Structure
TYPES: BEGIN OF lty_output,
SalesOrder TYPE vbeln_va,
OrderDate TYPE audat,
OrderType TYPE auart,
SalesOrg TYPE vkorg,
DistChannel TYPE vtweg,
Division TYPE spart,
END OF ltY_OUTPUT.
"Define table type
TYPES tt_output TYPE TABLE OF lty_output.
"Instance AMDP Method
METHODS: get_data_select_options IMPORTING VALUE(iv_mandt) TYPE mandt
VALUE(iv_where) TYPE string
EXPORTING VALUE(et_output) TYPE tt_output.
"Static AMDP Method
CLASS-METHODS: get_data IMPORTING VALUE(iv_mandt) TYPE mandt
EXPORTING VALUE(et_output) TYPE tt_output.
ENDCLASS.
CLASS zcl_amdp_demo_class IMPLEMENTATION.
METHOD get_data_select_options BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT OPTIONS READ-ONLY
USING VBAK.
et_output = select vbeln as SalesOrder,
audat as OrderDate,
auart as OrderType,
vkorg as SalesOrg,
vtweg as DistChannel,
spart as Division
from vbak
where mandt = :iv_mandt;
et_output = APPLY_FILTER ( :et_output, :iv_where );
ENDMETHOD.
METHOD get_data BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING vbak.
et_output = select vbeln as SalesOrder,
audat as OrderDate,
auart as OrderType,
vkorg as SalesOrg,
vtweg as DistChannel,
spart as Division
from vbak
where mandt = :iv_mandt;
ENDMETHOD.
ENDCLASS.
*& Report ZAMDP_PROGRAM_CALL
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zamdp_program_call.
TABLES vbak.
SELECT-OPTIONS: s_vbeln FOR vbak-vbeln,
s_auart FOR vbak-auart,
s_audat FOR vbak-audat.
"&...Convert Multiple Select-option to string format.
TRY.
DATA(lv_where) = cl_shdb_seltab=>combine_seltabs(
it_named_seltabs = VALUE #( ( name = 'SalesOrder' dref = REF #( s_vbeln[] ) )
( name = 'OrderType' dref = REF #( s_auart[] ) )
( name = 'OrderDate' dref = REF #( s_audat[] ) ) ) ).
CATCH cx_shdb_exception INTO DATA(lx_shdb_exe).
ENDTRY.
"&... We have instance AMDP method then we must create object for AMDP class and call AMDP method.
"&... Create Object
DATA(lo_amdp) = NEW zcl_amdp_demo_class( ).
"&... Call Instance AMDP method
lo_amdp->get_data_select_options( EXPORTING iv_mandt = sy-mandt
iv_where = lv_where
IMPORTING et_output = DATA(lt_output) ).
cl_demo_output=>display( data = lt_output
name = 'Sales Order Details' ).
- Note: IT_NAMED_SELTABS internal table Name column value must be same as field name in the AMDP method field name.
No comments:
Post a Comment