2

I'm trying to get a list of valid system status for the notification object, in order to not check all the notifications in the table, I want to execute the selection by checking only the last 2 years of data.

Maybe there is a better solution to my problem, but I'm still curious about this technical limitation. To my knowledge, the system status in SAP are kind of hardcoded and can't be determined per object via any table (SAP could add new system status any moment).

I tried to create the below CDS view, but the function dats_add_months can't be used in the where condition, is there a solution to that? Notice that 7.50 doesn't have session parameter for system date so I use an environment variable:

define view ZNOTIF_SYS_STATUS 
    with parameters sydat : abap.dats @<Environment.systemField: #SYSTEM_DATE
    as select distinct from qmel as notif
    inner join jest as notif_status on notif_status.objnr = notif.objnr
                                   and notif_status.inact = ''
    inner join tj02t as sys_status on sys_status.istat = notif_status.stat
                                  and sys_status.spras = $session.system_language
{
    key sys_status.txt04 as statusID,
        sys_status.txt30 as description
} where notif.erdat > dats_add_months($parameters.sydat, -12, '') //THIS CAN'T BE USED!!
6
  • It should work. the third parameter of dats_add_months should not be initial. right?
    – Haojie
    Apr 3, 2020 at 3:13
  • No, the third parameter is not the problem, I replaced it by initial date '00000000' but I still get the following syntax error: "Random expressions are not supported in a condition". Perhaps that's a 7.50 limitation?
    – RaTiO
    Apr 3, 2020 at 8:01
  • Try dats_add_months($parameters.sydat, -12, 'FAIL')
    – Haojie
    Apr 3, 2020 at 8:33
  • Still the same error :(
    – RaTiO
    Apr 3, 2020 at 8:46
  • I cannot further help. it works for me.
    – Haojie
    Apr 3, 2020 at 13:09

1 Answer 1

3

Putting built-in functions in RHS position of WHERE is supported only since 7.51 and you have 7.50 as you said. That is why it works for Haojie and not for you.

What can be done here? Possible option is CDS table function which consumes AMDP-class. Consider this sample:

Table function

@EndUserText.label: 'table_func months'
define table function ZTF_MONTHS
with parameters 
@Environment.systemField : #SYSTEM_DATE 
    p_datum : syst_datum
returns {

    mandt : abap.clnt;
    num   : qmnum;
    type  : qmart;
 }
implemented by method zcl_cds_qmel=>get_last_two_years;

AMDP

CLASS zcl_cds_qmel DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC.

  PUBLIC SECTION.
    INTERFACES if_amdp_marker_hdb.
    TYPES: tt_statuses TYPE STANDARD TABLE OF qmel.
    CLASS-METHODS get_last_two_years FOR TABLE FUNCTION ztf_months.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS zcl_cds_qmel IMPLEMENTATION.
  METHOD get_last_two_years BY DATABASE FUNCTION
          FOR HDB
          LANGUAGE SQLSCRIPT
          OPTIONS READ-ONLY.

    twoyrs := add_months (CURRENT_DATE,-12)

    RETURN SELECT mandt, qmnum AS num, qmart AS type FROM qmel WHERE erdat > twoyrs;
  ENDMETHOD.
  ENDCLASS.

It is very simplified compared to your original task but gives you the idea how to do this.

1
  • Thanks for the answer! Apparently I didn't read the proper release changes. Your solution is valid so I marked it as correct. But in my case I don't expose the CDS directly and I use ABAP SQL to read the data, so I will have to skip CDS this time.
    – RaTiO
    Apr 3, 2020 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.