Skip to Content

How can I write unit test for table function&AMDP?

Hello,

In our project, we use table function&AMDP to add sequence numbers for our CDS view.

@ClientHandling.type: #CLIENT_DEPENDENT
@ClientHandling.algorithm: #SESSION_VARIABLE
@VDM.viewType: #COMPOSITE
@VDM.private: true
@EndUserText.label: 'Add a Sequence Number for Each Group'


define table function P_AddSqncNumberTableFunction
  with parameters
    @Environment.systemField: #CLIENT
    P_SAPClient : vdm_v_sap_client
  returns
{
  mandt : vdm_v_sap_client;
  PaymentPlanUUID : abap.raw(16);
  PaymentRunDate : dats;
  PayingCompanyCode : abap.char(4);
  NumberOfTrendPeriod : abap.dec(9);
  TrendSequenceNumber : abap.int8;
}
implemented by method CL_FAP_PPS_ADD_SQNCNUMBER_AMDP=>ADD_SEQUENCSE_NUM_DATA;
CLASS cl_fap_pps_add_sqncnumber_amdp DEFINITION
  PUBLIC
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES if_amdp_marker_hdb.

    CLASS-METHODS:
      ADD_SEQUENCSE_NUM_DATA FOR TABLE FUNCTION P_AddSqncNumberTableFunction.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS cl_fap_pps_add_sqncnumber_amdp IMPLEMENTATION.

  METHOD ADD_SEQUENCSE_NUM_DATA
    BY DATABASE FUNCTION
    FOR HDB
    LANGUAGE SQLSCRIPT
    USING P_PaymentProposalSimlnAggrgn.

    add_trendseqnum_results =
      SELECT DISTINCT
             :P_SAPClient          as mandt,
             PaymentPlanUUID       as PaymentPlanUUID,
             PaymentRunDate        as PaymentRunDate,
             PayingCompanyCode     as PayingCompanyCode,
             SumOfInvoices         as NumberOfTrendPeriod,
             ROW_NUMBER() OVER ( PARTITION BY PaymentPlanUUID,PayingCompanyCode ORDER BY PaymentRunDate ASC ) as TrendSequenceNumber
        FROM P_PaymentProposalSimlnAggrgn
        WHERE
            mandt = :P_SAPClient;

    RETURN
      SELECT mandt,
             PaymentPlanUUID,
             PaymentRunDate,
             PayingCompanyCode,
             NumberOfTrendPeriod,
             TrendSequenceNumber
        FROM :add_trendseqnum_results
        WHERE
            mandt = :P_SAPClient;

  ENDMETHOD.

ENDCLASS.

But When i try to write UT to cover these files, I didn't know how to do it?

CDS test double doesn't support table function.

I try to use Avalon like this: AMDP Test Framework AVALON.pptx

But I can't call the function in the AMDP like

CL_FAP_PPS_ADD_SQNCNUMBER_AMDP->ADD_SEQUENCSE_NUM_DATA

Because CL_FAP_PPS_ADD_SQNCNUMBER_AMDP is the implementation of a table function.

The method "ADD_SEQUENCSE_NUM_DATA" is defined as an implementation of a CDS table function and cannot be called directly from ABAP programs.

I also try to write test case like Notes on AVALON based testing

but it run into some error when i try to call function cl_avalon_cds_test_environment=>create

I also noticed Sandra Rossi's answer in How to test cds table function?

But it seems that this solution only covers the table function and needs to create an additional CDS view.

what should I do to write unit test for table function & AMDP?

Thank you in advance

Best Regards

Yao, Pengfei

Add a comment
10|10000 characters needed characters exceeded

Related questions

0 Answers

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.