Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Naveen_n
Explorer
1,096

Definition: 

A Logical Database (LDB) in SAP ABAP is a special type of data retrieval tool that provides a structured method to access and read data from related database tables using predefined hierarchies. It allows developers to define a standard way of fetching data without manually writing complex SELECT queries, making reporting and data retrieval more efficient and consistent. 

Introduction: 

Logical Databases play a vital role in traditional ABAP reporting, especially when working with standard reports, selection screens, and data hierarchies. They encapsulate the logic of data selection, allowing ABAP programs to access complex datasets through a simplified interface. 

This blog provides a step-by-step guide to help you create a Logical Database from scratch in SAP ABAP. Whether you're new to SAP or looking to refresh your skills, this guide will walk you through the key components, including structure definition, selection screen setup, database program logic, and how to link it with an ABAP report. By the end, you'll have a fully functional logical database ready for use in custom reporting. 

Open transaction SE36, enter a logical database name, click 'Create', and provide a short description. 

Naveen_n_0-1746512664167.png

Naveen_n_1-1746512664170.png

Naveen_n_2-1746512664173.png

Naveen_n_3-1746512664175.png

If the node type is a database table, the root node name must match the table name. For dictionary types, this is not required. 

Naveen_n_4-1746512664176.png

Naveen_n_5-1746512664177.png

Right-click the root node and select Insert Node. 

Naveen_n_6-1746512664178.png

Create a new node for the sales header as per your requirement. 

Naveen_n_7-1746512664180.png

Repeat the previous steps. 

Naveen_n_8-1746512664182.png

Then save it, click on 'Selection', and confirm by selecting 'Yes'. 

Naveen_n_9-1746512664183.png

Naveen_n_10-1746512664183.png

Select the required nodes for dynamic selection and click Transfer. 

Naveen_n_11-1746512664184.png

Write select option names in the generated code, then save and activate. 

Naveen_n_12-1746512664186.png

Click the back button, then select 'Source Code' and click 'Yes' 

Naveen_n_13-1746512664187.png

Naveen_n_14-1746512664188.png

Double-click on include LDBNXXX. 

Naveen_n_15-1746512664189.png

Here, we can see the include program for each table. Double-click to uncomment the respective SELECT query. 

Naveen_n_16-1746512664190.png

This is for KNA1 table. 

Naveen_n_17-1746512664191.png

This is for VBAK table. 

Naveen_n_18-1746512664193.png

This is for VBAP table. 

Naveen_n_19-1746512664194.png

In the report using the Logical Database, include the following statement to print the output 

Naveen_n_20-1746512664195.png

Naveen_n_21-1746512664195.png

In the Description tab, you must provide the Logical Database name. 

Naveen_n_22-1746512664196.png

REPORT ZNA_RP_LDB2. 
NODES: kna1,vbak, vbap. 
GET kna1. 
  FORMAT COLOR 5 ON. 
  WRITE: / 'Customer Information'. 
  WRITE: / kna1-kunnr, kna1-name1, kna1-name2, kna1-land1. 
  FORMAT COLOR OFF. 
  FORMAT COLOR 4 ON. 
  WRITE: / 'Sales order header details Respected to given customer'. 
  FORMAT COLOR OFF. 
GET vbak. 
  WRITE: / Vbak-vbeln, vbak-kunnr. 
  FORMAT COLOR 3 ON. 
WRITE: / 'Sales Order line item details based on customer and sales order'.
  FORMAT COLOR OFF. 
GET vbap. 
  WRITE: / vbap-vbeln, vbap-posnr, vbap-matnr. 

Here we need to pass values. 

Naveen_n_23-1746512664197.png

Here we get all the respected output. 

Naveen_n_24-1746512664198.png

 

Conclusion: 

Creating a Logical Database in SAP ABAP simplifies data retrieval and enhances the efficiency of custom reporting. By following this step-by-step guide, you now have the knowledge to design, implement, and utilize a Logical Database for your own SAP applications. Logical Databases not only streamline data access but also ensure consistency and reduce the complexity of your ABAP programs. With this foundational understanding, you can now take full advantage of this powerful tool to build more efficient and maintainable reports in SAP. 

3 Comments
Sandra_Rossi
Active Contributor

IMPORTANT to say first: the Logical Database technology is obsolete since 2000, it's not recommended, it's not vital and according to me it's efficiently replaced by the powerful CDS views.

It's completely dead.

Your blog post will help people who need to maintain legacy code based on logical database (rare except maybe HR?), so thank you for them.

Jelena_Perfiljeva
Active Contributor

Had to check the calendar and date on this post to make sure we haven't fallen into some kind of time-bending hole.

I've started in SAP around 2005. Logical DBs have already been obsolete at that time. I know what these are but thankfully, never had to deal with one myself, as an ABAPer. Why on Earth would someone need instructions to create a new LDB in 2025? 😱 This is bonkers.

Readers, please never do this.

Jelena_Perfiljeva_0-1747159963910.jpeg

 

marcfbe
Participant
0 Kudos

Hi Naveen

thanks for putting together this blog. It’s an older topic but nicely done! 
I would love to chat. If you get a chance, send me a message 

Best

Marc