Lesson 9: Advanced Development and Optimization in SAP

Lesson 9: Advanced Development and Optimization in SAP


1. ABAP RESTful Application Programming (RAP) Advanced Scenarios

  • RAP supports draft handling for transactional applications.

  • Enables authorization checks using CDS annotations and behavior definitions.

  • Simplifies debugging with seamless integration in ABAP Development Tools.


2. SAP Workflow and Automation with APIs

  • Automates tasks by invoking workflow APIs.

  • Manages dynamic task routing using SAP Gateway services.

  • Ensures efficient workflow orchestration across systems.


3. SAP Performance Tuning with SQL Trace

  • SQL Trace (ST05) analyzes database calls in ABAP programs.

  • Identifies long-running queries and optimizes table joins.

  • Enables better indexing for improved execution times.


Code Example 1: RAP Draft Handling

define behavior for ZOrderView alias Order
  implementation in class ZCL_ORDER_HANDLER unique
{
  draft;
  lock;
  create;
}

Explanation

  1. Configures draft handling and locking for RAP entity ZOrderView.

  2. Allows data save without finalizing creation.

  3. Associates draft behavior with ZCL_ORDER_HANDLER.


Code Example 2: Workflow Task Creation Using API

DATA: lv_task_id TYPE swr_struct-task_id.

CALL FUNCTION 'SAP_WAPI_CREATE_WORKITEM'
  EXPORTING
    task    = 'TS12300001'
    objtype = 'ORDER'
  IMPORTING
    workitem_id = lv_task_id.

Explanation

  1. Creates a workflow task using SAP_WAPI_CREATE_WORKITEM.

  2. Associates the task with a specific object type.

  3. Returns the generated task ID for tracking.


Code Example 3: ABAP SQL Trace Execution

DATA: lt_trace TYPE TABLE OF st05_trace.

CALL FUNCTION 'ST05_START_TRACE'.
SELECT * FROM zcustomer INTO TABLE lt_trace.
CALL FUNCTION 'ST05_STOP_TRACE'.

Explanation

  1. Starts SQL Trace using the ST05_START_TRACE function.

  2. Executes a database query on the zcustomer table.

  3. Stops the trace for further analysis.


Code Example 4: Dynamic Workflow Task Routing

DATA: lv_user TYPE sy-uname.

CALL FUNCTION 'RH_DYNAMIC_AGENT_ASSIGN'
  EXPORTING
    task        = 'TS12300002'
    agent_user  = lv_user.

Explanation

  1. Dynamically assigns a workflow task to a user.

  2. Uses RH_DYNAMIC_AGENT_ASSIGN for task routing.

  3. Simplifies task delegation based on runtime conditions.


Code Example 5: RAP Authorization Check

define behavior for ZProductView alias Product
  implementation in class ZCL_PRODUCT_HANDLER unique
{
  authorization master ( instance = CDS ZAuthInstance );
}

Explanation

  1. Implements RAP authorization checks for ZProductView.

  2. Links instance-based authorization with CDS ZAuthInstance.

  3. Ensures secure access control in transactional scenarios.