Lesson 5: SAP Development Mastery

Lesson 5: SAP Development Mastery


1. Custom ABAP CDS Annotations

  • Enhance CDS views with annotations for metadata-driven configurations.

  • Enable UI-specific behaviors and OData service generation.

  • Simplify integration with Fiori apps and APIs.


2. Event-Driven Programming in SAP

  • Triggers specific logic when predefined events occur.

  • Implements event handling with ABAP or SAPUI5.

  • Integrates seamlessly with workflows and backend processes.


3. SAP Security Concepts

  • Role-based authorization ensures controlled access to resources.

  • Uses Secure Network Communication (SNC) for data encryption.

  • Enforces strict authentication and authorization policies.


Code Example 1: Custom Annotation in CDS

@UI: {
  selectionField: [{ position: 10 }],
  lineItem: [{ position: 20 }]
}
define view ZSalesView as select from zsales {
  key id,
  customer,
  total_amount
}

Explanation

  1. Adds @UI annotations for Fiori application integration.

  2. Configures selection and line item behaviors.

  3. Exposes ZSalesView with metadata-driven behavior.


Code Example 2: ABAP Event Handler

CLASS zcl_event_handler DEFINITION.
  PUBLIC SECTION.
    EVENTS on_customer_save.
    METHODS handle_save FOR EVENT on_customer_save OF zcl_event_handler IMPORTING iv_customer_id TYPE zcustomer-id.
ENDCLASS.

CLASS zcl_event_handler IMPLEMENTATION.
  METHOD handle_save.
    WRITE: / 'Customer Saved:', iv_customer_id.
  ENDMETHOD.
ENDCLASS.

Explanation

  1. Declares and raises the on_customer_save event.

  2. Implements handle_save method to process the event.

  3. Outputs the saved customer ID dynamically.


Code Example 3: ABAP Role Check

AUTHORITY-CHECK OBJECT 'ZCUSTOMER_ROLE'
  ID 'ACTVT' FIELD '03'
  ID 'ZCUSTOMER_ID' FIELD lv_customer_id.
IF sy-subrc = 0.
  WRITE: / 'Authorization granted'.
ELSE.
  WRITE: / 'Access denied'.
ENDIF.

Explanation

  1. Verifies user access with AUTHORITY-CHECK.

  2. Checks the custom role ZCUSTOMER_ROLE.

  3. Grants or denies access based on the result.


Code Example 4: SAPUI5 Event Handling

onCustomerSave: function() {
  sap.m.MessageToast.show("Customer saved successfully!");
}
<Button text="Save" press="onCustomerSave"/>

Explanation

  1. Implements onCustomerSave event in SAPUI5 controller.

  2. Displays a success message on button press.

  3. Enhances user interaction with intuitive feedback.


Code Example 5: SNC Configuration in ABAP

DATA: lv_snc_name TYPE sncname VALUE 'p:CN=SAPServer,O=Company,C=US'.

SET PARAMETER ID 'SNC_PARTNERNAME' FIELD lv_snc_name.
WRITE: / 'SNC connection established with:', lv_snc_name.

Explanation

  1. Configures SNC parameters for secure communication.

  2. Uses SET PARAMETER ID for SNC partner setup.

  3. Establishes encrypted connections securely.