All skills
secondsky avatar

/sap-abap-cds

@620a19a
by Eddiesecondsky/sap-skills456 stars
120

Comprehensive SAP ABAP CDS (Core Data Services) reference for data modeling, view development, and semantic enrichment. Use when creating CDS views or view entities, defining data models with annotations, working with associations and cardinality, implementing input parameters, using built-in functions, writing CASE expressions, implementing access control with DCL, handling CURR/QUAN data types, troubleshooting CDS errors, querying CDS views from ABAP, or displaying data with SALV IDA. Covers ABAP 7.4+ through ABAP Cloud.

Use this Skill: https://skilld.dev/gh/secondsky/sap-skills/sap-abap-cds

This session only. Nothing lands on disk.

templatesdcl-template.md

≈1.6k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Access Control (DCL) Template

Template for creating CDS access control definitions.


Basic DCL Template

@EndUserText.label: 'Access Control for <View Name>'
@MappingRole: true
define role <DCL_NAME> {
  grant select on <CDS_VIEW_NAME>
    where <condition>;
}

PFCG Authorization Template

@EndUserText.label: 'Access Control for Z_VIEW'
@MappingRole: true
define role Z_VIEW_DCL {
  grant select on Z_VIEW
    where (<cds_field>) = aspect pfcg_auth(
      <AUTH_OBJECT>,
      <AUTH_FIELD>,
      ACTVT = '03'
    );
}

Multiple Field Authorization

@EndUserText.label: 'Sales Organization Access Control'
@MappingRole: true
define role Z_SALES_DCL {
  grant select on Z_SALES_VIEW
    where (vkorg, vtweg, spart) = aspect pfcg_auth(
      V_VBAK_VKO,
      VKORG,
      VTWEG,
      SPART,
      ACTVT = '03'
    );
}

Combined Conditions Template

@EndUserText.label: 'Combined Access Control'
@MappingRole: true
define role Z_COMBINED_DCL {
  grant select on Z_VIEW
    where
      -- Authorization check
      (bukrs) = aspect pfcg_auth(F_BKPF_BUK, BUKRS, ACTVT = '03')

      -- Literal condition
      and status <> 'DELETED'

      -- Date condition
      and valid_to >= $session.system_date;
}

User-Based Access Template

@EndUserText.label: 'Own Records Only'
@MappingRole: true
define role Z_OWN_DATA_DCL {
  grant select on Z_USER_DATA
    where created_by ?= aspect user;
}

Note: ?= allows NULL values.


OR Condition Template

@EndUserText.label: 'Public or Own Records'
@MappingRole: true
define role Z_PUBLIC_OR_OWN_DCL {
  grant select on Z_DOCUMENTS
    where visibility = 'PUBLIC'
       or created_by ?= aspect user;
}

Multi-Level Authorization Template

@EndUserText.label: 'Multi-Level Authorization'
@MappingRole: true
define role Z_MULTILEVEL_DCL {
  grant select on Z_MATERIAL_DATA
    where
      -- Plant authorization
      (werks) = aspect pfcg_auth(M_MATE_WRK, WERKS, ACTVT = '03')

      -- Material type authorization
      and (mtart) = aspect pfcg_auth(M_MATE_MAR, MTART, ACTVT = '03');
}

Common Authorization Objects Reference

Finance

Object Fields Description
F_BKPF_BUK BUKRS, ACTVT Company code
F_BKPF_GSB GSBER, ACTVT Business area
F_BKPF_KOA KOART, ACTVT Account type
F_LFA1_BUK BUKRS, ACTVT Vendor company code
F_KNA1_BUK BUKRS, ACTVT Customer company code

Sales

Object Fields Description
V_VBAK_VKO VKORG, VTWEG, SPART, ACTVT Sales org/channel/division
V_VBAK_AAT AUART, ACTVT Order type
V_LIKP_VKO VKORG, VTWEG, ACTVT Delivery sales org

Materials

Object Fields Description
M_MATE_WRK WERKS, ACTVT Plant
M_MATE_MAR MTART, ACTVT Material type
M_MATE_MAN MTART, ACTVT Material maintenance

Controlling

Object Fields Description
K_CCA KOKRS, KOSTL, ACTVT Cost center
K_ORDER AUFNR, ACTVT Internal order
K_PCA KOKRS, PRCTR, ACTVT Profit center

Important: Authorization object names and fields may vary by SAP release and customization. Always verify the correct object name and fields in your system using transaction SU21 (Maintain Authorization Objects) before implementing DCL rules.

HR

Object Fields Description
P_ORGIN PERSA, PERSG, ACTVT Personnel area/group
PLOG OTYPE, INFTY, ACTVT HR master data

Activity Values (ACTVT)

Value Activity
01 Create
02 Change
03 Display
06 Delete
16 Execute
70 Administration

Example: Finance Document Access

@EndUserText.label: 'Finance Document Access Control'
@MappingRole: true
define role Z_FIN_DOC_DCL {
  grant select on Z_FINANCE_DOCUMENTS
    where
      -- Company code check
      (bukrs) = aspect pfcg_auth(F_BKPF_BUK, BUKRS, ACTVT = '03')

      -- Business area check (optional)
      and (gsber) ?= aspect pfcg_auth(F_BKPF_GSB, GSBER, ACTVT = '03')

      -- Only posted documents
      and posting_status = 'POSTED';
}

Example: Sales Order Access

@EndUserText.label: 'Sales Order Access Control'
@MappingRole: true
define role Z_SALES_ORDER_DCL {
  grant select on Z_SALES_ORDER
    where
      -- Sales organization structure
      (vkorg, vtweg, spart) = aspect pfcg_auth(
        V_VBAK_VKO,
        VKORG,
        VTWEG,
        SPART,
        ACTVT = '03'
      )

      -- Order type
      and (auart) ?= aspect pfcg_auth(V_VBAK_AAT, AUART, ACTVT = '03')

      -- Exclude cancelled orders
      and vbtyp <> 'K';
}

Example: Own Records with Admin Override

@EndUserText.label: 'User Tasks with Admin Access'
@MappingRole: true
define role Z_USER_TASKS_DCL {
  grant select on Z_USER_TASKS
    where
      -- Own tasks
      assigned_to ?= aspect user

      -- OR admin authorization
      or (admin_flag) = aspect pfcg_auth(Z_TASK_ADMIN, ADMIN, ACTVT = '03');
}

Testing Checklist

  • DCL name follows naming convention
  • @MappingRole: true is set
  • Correct CDS view name referenced
  • Authorization objects exist (check SU21)
  • Field names match CDS view exactly
  • Activity value appropriate (usually '03')
  • Test with authorized user
  • Test with unauthorized user
  • Test edge cases (NULL values)

Debugging

Check User Authorization (SU53)

After access denied, run SU53 to see missing authorization.

Authorization Trace (ST01)

  1. Start trace in ST01
  2. Execute query
  3. Analyze trace for auth checks

Verify DCL Assignment

" Check if DCL exists and is assigned to view
SELECT ddlname, as4local, as4vers
  FROM ddddlsrc
  WHERE ddlname = 'Z_VIEW_DCL'
  INTO TABLE @DATA(lt_dcl).

" Alternative: Check DCL source for specific view reference
SELECT ddlname, source
  FROM ddddlsrc
  WHERE source LIKE '%Z_CDS_VIEW%'
    AND ddlname LIKE '%_DCL'
  INTO TABLE @DATA(lt_dcl_refs).

Tip: In ADT, right-click the CDS view and select Open With → Dependency Analyzer to see associated DCL objects.

Source: SKILL.md on GitHub

1 warning15d4 checks · Risk SAFE
  • Gen Agent Trust Hub15d

    The skill provides comprehensive reference material, templates, and troubleshooting guides for SAP ABAP CDS development. It consists entirely of documentation and static templates without executable code. All external references point to official SAP resources and well-known community repositories.

  • Socket15d

    No alerts

  • Snyk15d

    Risk: LOW · No issues

  • Runlayer6mo

    5/12 files flagged

Signed by skilld at 620a19a. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 2 months ago
Other metadata
metadata
{
  "maintainer": "Eduard Jiglau",
  "maintainer_email": "hello@sap-ai-skills.com",
  "website": "https://sap-ai-skills.com",
  "version": "2.4.1",
  "last_verified": "2026-04-02",
  "abap_release": "7.4 SP8+ / 7.50+ / ABAP Cloud",
  "sources": [
    "https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/abencds.html",
    "https://github.com/SAP-samples/abap-cheat-sheets"
  ],
  "keywords": [
    "ABAP CDS",
    "Core Data Services",
    "CDS view",
    "CDS view entity",
    "define view",
    "DDL",
    "DCL",
    "annotations",
    "@AbapCatalog",
    "@AccessControl",
    "@EndUserText",
    "@Semantics",
    "@UI",
    "@Consumption",
    "@ObjectModel",
    "associations",
    "cardinality",
    "path expressions",
    "input parameters",
    "WITH PARAMETERS",
    "built-in functions",
    "CASE expression",
    "CAST",
    "session variables",
    "GROUP BY",
    "HAVING",
    "joins",
    "access control",
    "DEFINE ROLE",
    "pfcg_auth",
    "SALV IDA",
    "Eclipse ADT",
    "CDS annotations",
    "Fiori Elements",
    "OData",
    "RAP",
    "currencyCode",
    "unitOfMeasure",
    "SD_CDS_ENTITY105"
  ]
}

README badge

README badge for secondsky/sap-skills/sap-abap-cds