Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

SQLSCRIPT identifier must be declared CLIENT

hassin
Explorer

Hallo,

I'm trying to program a class where I use a CDS View as a source.

With a table function I would like to use the result in another CDS.

My problems started with the client handling and know I'm stuck with the client identifier.

After fixing one error after an other it feels like I'm running in circles.

That's why I hoped that someone could help me?

It would be great when you could check my programming (in attachment) and give me a feedback.

Kind regards

Hassin

---------------------CDS View-----------------------------------------------------------------------------------------------------------------------------------------------------
@AbapCatalog.sqlViewName: 'ZIBKAPA'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Basic View Arbeitsplätze Linien Kapazität Stichwerte'

@Analytics: { dataCategory: #DIMENSION }
@VDM.viewType: #BASIC
@ObjectModel.representativeKey: 'kunnr'
@Search.searchable: false
@ObjectModel.usageType.serviceQuality: #A
@ObjectModel.usageType.sizeCategory : #M
@ObjectModel.usageType.dataClass: #MASTER
@ClientHandling.algorithm: #SESSION_VARIABLE

@ClientHandling.type: #CLIENT_DEPENDENT

define view ZIB_KAPA as select from kapa 

{
    key kapid as Kapid,
    key versn as Versn,
    key datub as Datub,
    key tagnr as Tagnr,
    key schnr as Schnr,
    anzhl as Anzhl,
    begzt as Begzt,
    einzt as Einzt,
    endzt as Endzt,
    fabtg as Fabtg,
    kapaz as Kapaz,
    pause as Pause,
    ngrad as Ngrad,
    tprog as Tprog,
    wotag as Wotag,
    ang_min as AngMin,
    ang_max as AngMax
}


----------------------------------Table Function-----------------------------------------------------------------------------------------------------------------------------------------------
@EndUserText.label: 'Table Function für die Produktionslinien Planung'

//Mit dieser Annotation wird die Mandatenabhängigkeit deaktiviert. Ansonsten muss nach 'returns' immer als erstes der Mandant An-/Mitgegeben werden.
@ClientHandling.type: #CLIENT_INDEPENDENT

define table function ZTF_PROLINEDATE
    with parameters
//        @Environment.systemField: #CLIENT
        client1 : abap.clnt


  //Felder die von der Class erwartet werden. Felderanzahl und Datentyp muss auf beidne Seiten übereinstimmen.
returns
{
  mandt     : abap.clnt;
  KAPID     : abap.numc( 8 );
  DATUB_BIS : abap.dats;
  DATUV_VON : abap.dats;
  DIFF      : abap.int1;
  //  DATUM         : abap.dats;
  //  DAYS          : abap.int2;

}
implemented by method
  ZTF_CLASS_PROLINEDATE=>ZM_GET_PROLINEDATE;



--------------------------------------CLASS-------------------------------------------------------------------------------------------------------------------------------------------
CLASS ztf_class_prolinedate DEFINITION PUBLIC FINAL CREATE PUBLIC.

  PUBLIC SECTION.

    INTERFACES if_amdp_marker_hdb.

    TYPES:
      BEGIN OF vta_prolinedate,
        mandt     TYPE mandt,
        kapid     TYPE numc08,
        datub_bis TYPE dats,
        datum_von TYPE dats,
        diff      TYPE int1,
      END OF vta_prolinedate.
    TYPES:
      tt_prolinedate TYPE TABLE OF vta_prolinedate.

    CLASS-METHODS zm_get_prolinedate
*        FOR TABLE FUNCTION ztf_prolinedate.
      AMDP OPTIONS CDS SESSION CLIENT current
      IMPORTING
        VALUE(mandt) TYPE sy-mandt
      EXPORTING
        VALUE(ett_zic)   TYPE tt_prolinedate.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.


CLASS ZTF_CLASS_PROLINEDATE IMPLEMENTATION.
  METHOD zm_get_prolinedate
     BY DATABASE PROCEDURE "FUNCTION
     FOR HDB
     LANGUAGE SQLSCRIPT OPTIONS
     READ-ONLY USING zib_kapa.

    ett_zic = SELECT
                    mandt                           AS mandt,
                    kapid                           AS kapid,
                    datub                           AS datub_bis,
                    add_days
                        (to_date
                            ((SELECT MAX(inmax.datub)
                                from zib_kapa inmax
                                where inmax.datub < outmax.datub
                                and inmax.kapid = '10000007'),
                             'YYYYMMDD'),
                            1)
                    as datuv_von,
                    DAYS_BETWEEN
                        (to_date
                            ((SELECT MAX(inmax.datub)
                                from zib_kapa inmax
                                where inmax.datub < outmax.datub
                                and inmax.kapid = '10000007'),
                             'YYYYMMDD'),
                            datub)
                    as diff
                    FROM zib_kapa outmax
                    WHERE kapid = '10000007'
                    AND mandt = :client
                    GROUP BY mandt, kapid, datub;

  ENDMETHOD.
ENDCLASS.<br>
1 REPLY 1

Sandra_Rossi
Active Contributor
0 Kudos

So, you have:

  1. CDS view ZIB_KAPA = view on table KAPA
  2. Table function ZTF_PROLINEDATE = AMDP method which reads CDS view ZIB_KAPA
  3. You want to call the table function and pass parameter CLIENT1 = any client number you wish

What is your issue?