SAP

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
⤢ Open full site

Calculate Shortest Path Using a GRAPH Procedure

Learn how to use a GRAPH Procedure to calculate shortest paths on the Street Network.

Overview

You will learn

  • How to define the required Table Type for the database procedure
  • How to create a GRAPH procedure for shortest path calculation
  • How to use anonymous blocks approach for shortest path calculation
Thomas Jung T Thomas Jung August 21, 2026
Created on July 26, 2021
Contributors

More from Thomas Jung

See all 226 tutorials by Thomas Jung →

Prerequisites

Prerequisites

Steps

Intro

Once you have defined a Graph Workspace, you can run openCypher(*) queries for pattern matching workload or create GRAPH procedures for network analysis. In this tutorial you will learn how to create a database procedure that uses the built-in function to calculate a shortest path between two vertices. This includes three steps:

  • Define the required Table Type for database procedure
  • Create a GRAPH procedure for shortest path calculation
  • Run a GRAPH code using anonymous blocks

Step 1 Define the required Table Type for database procedure

If you are familiar with SAP HANA database procedures using SQLScript, you already know how to handle table-like results. A clean way to do this is defining and using TABLE TYPES. The same approach is valid for GRAPH procedures. Our TABLE TYPE TT_SPOO_EDGES describes the structure of the path result. It includes the ID of the edge and the ORDER in which the edges are traversed.

First you need to create a TABLE TYPE that describes the output table of the procedure, containing ID, SOURCE, TARGET, EDGE_ORDER (BIGINT), and length (DOUBLE). Execute this statement:

SQL
CREATE TYPE "TT_SPOO_EDGES" AS TABLE (
    "ID" NVARCHAR(5000), "SOURCE" BIGINT, "TARGET" BIGINT, "EDGE_ORDER" BIGINT, "length" DOUBLE)
;
Step 2 Create a GRAPH procedure for shortest path calculation
+
Step 3 Run a GRAPH code using anonymous blocks
+
Step 4 Test yourself
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 4
1. Define the required Table Type for database procedure 2. Create a GRAPH procedure for shortest path calculation 3. Run a GRAPH code using anonymous blocks 4. Test yourself