Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

logical database

Former Member
0 Kudos

hello experts,

I want to know about logical database and to create logical database...how to use logcal database in se38...help me please..

9 REPLIES 9

Former Member
0 Kudos

Logical reasons to create logical databases in SAP

SAP comes loaded with all the extras. Among the extras that are most helpful to IT managers are all the access routines needed to pull any business object that managers can think of out of SAP databases. However, SAP has not thought of everything where your particular applications are concerned. SAP organizes its standard database tables to service business units based on conventional business applications. It’s likely your business requires something new, perhaps even something exotic. In that case, you will need to create a new database, using information from different places. Basically, you need a logical database. You need to create a virtual business data object repository consisting of a new kind of record or table that suits your purposes. In addition, the repository should be composed of information that is actually stored in a number of different locations, none of them necessarily logically associated with one another. Let’s take a closer look at creating logical databases.

A case for a logical database

Suppose my company manufactures widgets of the most obscure variety, and they are components of other widgets. I sell my widgets as raw material for the more sophisticated widgets built by others, but in some cases I actually partner with other manufacturers in creating yet another class of widget. Now, in my world, I consequently have customers who are also partners. I sell to them and I partner with them in manufacturing and distribution. Also, I need an application that uses both of these dual-use relationships.

Essentially, I have a customer database and a partner database. Neither contains records that are structured to contain the identifying particulars of the other. Thus, I need a hybrid database that gives me tables detailing these hybrid relationships. What can I do? I can go the long way around and write a new database, pulling information from both and creating new objects with a customized program that I write by hand. However, this process is cumbersome and contains maintenance issues. On the other hand, I can use SAP’s logical database facility, create my logical database in a couple of minutes, and have no maintenance issues at all.

Logical database structures

There are three defining entities in an SAP logical database. You must be clear on all three in order to create and use one.

  • Table structure: Your logical database includes data from specified tables in SAP. There is a hierarchy among these tables defined by their foreign keys (all known to SAP), and you are going to define a customized relationship between select tables. This structure is unique and must be defined and saved.

  • Data selection: You may not want or need every item in the referenced tables that contributes to your customized database. There is a selection screen that permits you to pick and choose.

  • Database access programming: Once you’ve defined your logical database, SAP will generate the access subroutines needed to pull the data in the way you want it pulled.

Creating your own logical database

ABAP/4 (Advanced Business Application Programming language, version 4) is the language created by SAP for implementation and customization of its R/3 system. ABAP/4 comes loaded with many predefined logical databases that can construct and table just about any conventional business objects you might need in any canned SAP application. However, you can also create your own logical databases to construct any custom objects you care to define, as your application requires in ABAP/4. Here’s a step-by-step guide:

1. Call up transaction SLDB (or transaction SE36). The path you want is Tools | ABAP Workbench | Development | Programming Environment | Logical Databases. This screen is called Logical Database Builder.

2. Enter an appropriate name in the logical database name field. You have three options on this screen: Create, Display, and Change. Choose Create.

3. You’ll be prompted for a short text description of your new logical database. Enter one. You’ll then be prompted to specify a development class.

4. Now comes the fun part! You must specify a root node, or a parent table, as the basis of your logical database structure. You can now place subsequent tables under the root table as needed to assemble the data object you want. You can access this tree from this point forward, to add additional tables, by selecting that root node and following the path Edit | Node | Create. Once you’ve saved the structure you define in this step, the system will generate the programming necessary to access your logical database. The best part is you don’t have to write a single line of code.

Watch out!

The use of very large tables will degrade the performance of a logical database, so be aware of that trade-off. Remember that some tables in SAP are very complex, so they will be problematic in any user-defined logical database.

Declaring a logical database

Here’s another surprising feature of logical databases: You do not assign them in your ABAP/4 Code. Instead, the system requires that you specify logical databases as attributes. So when you are creating a report, have your logical database identifier (the name you gave it) on hand when you are defining its attributes on the Program Attributes screen. The Attributes section of the screen (the lower half) will include a Logical database field, where you can declare your logical database.

Logical databases for increasing efficiency

Why else would you want to create a logical database? Consider that the logical databases already available to you begin with a root node and proceed downward from there. If the data object you wish to construct consists of items that are all below the root node, you can use an existing logical database program to extract the data, then trim away what you don’t want using SELECT statements—or you can increase the speed of the logical database program considerably by redefining the logical database for your object and starting with a table down in the chain. Either way, you’ll eliminate a great deal of overhead.

refer the links

http://help.sap.com/saphelp_46c/helpdata/en/9f/db9b5e35c111d1829f0000e829fbfe/content.htm

http://www.sap-basis-abap.com/sapta003.htm

regards,

srinivas

<b>*reward for useful answers*</b>

former_member198270
Active Contributor
0 Kudos

Hi Manjula ,

Logical databases are programs that does useful tasks like data fetch, Authorization check on behalf of thep program to which you attach them.

Some of the Tasks of LDB's.

Reading the same data for several programs.

The individual programs do not then need to know the exact structure of the relevant database tables (and especially not their foreign key relationships). Instead, they can rely on the logical database to read the database entries in the right order during the GET event.

Defining the same user interface for several programs.

Logical databases have a built-in selection screen. Therefore, all of the programs that use the logical database have the same user interface.

Central authorization checks

Authorization checks for central and sensitive data can be programmed centrally in the database to prevent them from being bypassed by simple application programs.

Improving Performance

If you want to improve response times, logical databases permit you to take a number of measures to achieve this (for example, using joins instead of nested SELECT statements). These become immediately effective in all of the application programs concerned and save you from having to modify their source code.

The data fetch happend with the PUT_XXXX subrotuines in the Logical database programs.

Example:

----


  • DATABASE PROGRAM OF THE LOGICAL DATABASE TEST_LDB

----


PROGRAM sapdbtest_ldb DEFINING DATABASE test_ldb.

TABLES: lfa1,

lfb1,

lfc1,

bkpf.

----


  • Initialize selection screen (process before PBO)

----


FORM init.

....

ENDFORM. "INIT

----


  • PBO of selection screen (always before selection

  • screen

----


FORM pbo.

....

ENDFORM. "PBO

----


  • PAI of selection screen (process always after ENTER)

----


FORM pai USING fname mark.

CASE fname.

WHEN 'SLIFNR'.

....

WHEN 'SBUKRS'.

....

WHEN 'SGJAHR'.

....

WHEN 'SBELNR'.

....

ENDCASE.

ENDFORM. "PAI

----


  • Call event GET LFA1

----


FORM put_lfa1.

SELECT * FROM lfa1

WHERE lifnr IN slifnr.

PUT lfa1.

ENDSELECT.

ENDFORM. "PUT_LFA1

----


  • Call event GET LFB1

----


FORM put_lfb1.

SELECT * FROM lfb1

WHERE lifnr = lfa1-lifnr

AND bukrs IN sbulrs.

PUT lfb1.

ENDSELECT.

ENDFORM. "PUT_LFB1

----


  • Call event GET LFC1

----


FORM put_lfc1.

SELECT * FROM lfc1

WHERE lifnr = lfa1-lifnr

AND bukrs = lfb1-bukrs

AND gjahr IN sgjahr.

PUT lfc1.

ENDSELECT.

ENDFORM. "PUT_LFC1

----


  • Call event GET BKPF

----


FORM put_bkpf.

SELECT * FROM bkpf

WHERE bukrs = lfb1-bukrs

AND belnr IN sbelnr

AND gjahr IN sgjahr.

PUT bkpf.

ENDSELECT.

ENDFORM. "PUT_BKPF

Please Reward Points If helpful.

Regards,

Amber S

Former Member
0 Kudos

hi,

Logical Databases

Logical databases are special ABAP programs that retrieve data and make it available to application programs. The most common use of logical databases is still to read data from database tables by linking them to executable ABAP programs.

However, from Release 4.5A, it has also been possible to call logical databases using the function module LDB_PROCESS. This allows you to call several logical databases from any ABAP program, nested in any way. It is also possible to call a logical database more than once in a program, if it has been programmed to allow this. This is particularly useful for programs with type 1.

Logical databases contain Open SQL statements that read data from the database. You do not therefore need to use SQL in your own programs. The logical database reads the program, stores them in the program if necessary, and then passes them line by line to the application program or the function module LDB_PROCESS using an interface work area.

Logical Databases - Views of Data

A logical database provides a particular view of database tables in the R/3 System. It is always worth using logical databases if the structure of the data that you want to read corresponds to a view available through a logical database.

The data structure in a logical database is hierarchical. Many tables in the R/3 System are linked to each other using foreign key relationships. Some of these dependencies form tree-like hierarchical structures. Logical databases read data from database tables that are part of these structures.

Former Member
0 Kudos

Hi Manjula,

chk this

Former Member
0 Kudos

Hi,

Logical Database - SE36

A logical database is a special ABAP/4 program which combines the contents of certain database tables. You can link a logical database to an ABAP/4 report program as an attribute. The logical database then supplies the report program with a set of hierarchically structured table lines which can be taken from different database tables.

Reading a SAP standard logical database in your ABAP/4 program.

start-of-selection.

  • get is equal to select * from....

get mdkp.

check field-name.

get mdtb.

check field-name

end-of-selection.

A logical database is, in SAP terms, nothing more than a stored retrieval plan for the information needed to build your app’s business objects. You have several tools at your disposal here: a view of the data within the source database, the specifics of how the data will be accessed from the source database, and a screen that allows you to specify the data’s selection criteria.

You can fine-tune the access methods of your logical database as you please, until the reports and user dialogs in your appear as fast as it is possible for them to be. And you can store your work, meaning that this well-tuned, rapid access is now available for other apps to make use of. (In fact, any change to a logical database will immediately take effect in all apps using it.)

Hope it was useful.

Thanks,

Sandeep.

Former Member
0 Kudos

Hi,

A logical database is a special ABAP/4 program which combines the contents of certain database tables. You can link a logical database to an ABAP/4 report program as an attribute. The logical database then supplies the report program with a set of hierarchically structured table lines which can be taken from different database tables.

Advantages of Logical database -

1) No need of programming for retrieval , meaning for data selection

2) Easy to use standard user interface, have check completeness of user input.

Disadvantages

1) Fast in case of lesser no. of tables But if the table is in the lowest level of hierarchy, all upper level tables should be read so performance is slower.

GO THROUGH LINKS -

http://www.sap-basis-abap.com/saptab.htm

http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9bfa35c111d1829f0000e829fbfe/content.htm

http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9b5e35c111d1829f0000e829fbfe/frameset.htm

http://help.sap.com/saphelp_nw04/helpdata/en/c6/8a15381b80436ce10000009b38f8cf/frameset.htm

Structure

The structure of a logical database determines the database tables which it can access. It adopts the hierarchy of the database tables defined by their foreign key relationships. This also controls the sequence in which the tables are accessed.

Tasks of Logical Databases

As well as allowing you to read data from the database, logical databases also allow you to program other tasks centrally, making your application programs less complicated. They can be used for the following tasks:

• Reading the same data for several programs.

The individual programs do not then need to know the exact structure of the relevant database tables (and especially not their foreign key relationships). Instead, they can rely on the logical database to read the database entries in the right order during the GET event.

• Defining the same user interface for several programs.

Logical databases have a built-in selection screen. Therefore, all of the programs that use the logical database have the same user interface.

• Central authorization checks

Authorization checks for central and sensitive data can be programmed centrally in the database to prevent them from being bypassed by simple application programs.

• Improving performance

If you want to improve response times, logical databases permit you to take a number of measures to achieve this (for example, using joins instead of nested SELECT statements). These become immediately effective in all of the application programs concerned and save you from having to modify their source code.

Selection Part

The selection part of the logical database defines input fields for selecting data. The runtime environment displays these on the selection screen when you run an executable program linked to the logical database. The corresponding fields are also available in the ABAP program, allowing you, for example, to change their values to insert default values on the selection screen.

Database Program

The database program of a logical database is a container for special subroutines, in which the data is read from the database tables. These subrotuines are called by the reporting processor in the runtime environment in a predefined sequence.

Regards,

Priyanka.

0 Kudos

Hi,

Goto transaction ABAPDOCU,

There in KEYWORD help type Logical databases.

In the result check the Logical Databases in Subject area.

There you will get a link to know everything about logical databases.

Regards,

Sesh

Former Member
0 Kudos

Hi ,

Logical Database - SE36

A logical database is a special ABAP/4 program which combines the contents of certain database tables. You can link a logical database to an ABAP/4 report program as an attribute. The logical database then supplies the report program with a set of hierarchically structured table lines which can be taken from different database tables.

Reading a SAP standard logical database (DB M - MRP Documents) in your ABAP/4 program.

start-of-selection. 

* get is equal to select * from.... 
get mdkp. 
   check field-name. 

get mdtb. 
   check field-name 

end-of-selection.


Creating a Logical Database

To create a new logical database, you should follow the procedure below. The Logical Database Builder then saves you work by using components that you have already defined to generate proposals for other components. Some of the most important attributes of a logical database are set when you define its structure. When you have defined the structure, the Logical Database Builder automatically generates a proposal for the selection include. The system then generates an input mask for the database program, based on the structure of the logical database and the selections.

These generated proposals allow you to create a working logical database quickly. However, you must program refinements such as authorization checks and performance optimization yourself.

Procedure for Creating a Logical Database

Enter a name on the initial screen of the Logical Database Builder and choose Create.

A dialog box appears. Enter a short text. You can change this later by choosing Extras ® Short text or Administration info.

Once you have entered the short text, you must define the root node of the logical database. Enter the node name and its attributes. There are three different types of nodes:

§ Database tables. The table must be active in the ABAP Dictionary. Tables always have a flat structure. The name of the node must correspond with the name of the table.

§ Data types from the ABAP Dictionary: The node may refer to any data type in the ABAP Dictionary. The node name and the name of the data type do not have to be the same. You can use deep data types as nodes.

§ Data types from type groups: The node can also refer to a data type from a type group in the ABAP Dictionary. Enter the name of the type group in the corresponding field. You must choose Other types before specifying this type. Data types in type groups were the forerunners of real data types in the ABAP Dictionary. Wherever possible, you should use ABAP Dictionary data types. They have all of the semantic properties of their underlying data elements. This is useful, for example, when you use a logical database to create ABAP Queries.

You can use the Text from Dictionary function to adopt the text stored in the ABAP Dictionary for the relevant table or data type.

The structure editor of the Logical Database Builder appears. On the left is the name of the root node, followed by a code for the node type: T for a database table, S for a ABAP Dictionary type, and C for a type from a type group. The new logical database now has a structure with a single node.

You can now extend the structure as described in Editing the Structure.

If you choose Next screen (right arrow in the application toolbar), a screen appears on which you can enter a search help for the logical database as described under Editing Search Helps.

If you choose Next screen (right arrow in the application toolbar), a dialog box appears, asking you whether the system should generate the selections for the logical database. When you have confirmed the dialog box, a list appears, on which you can select all of the nodes that you want to use for field selections or dynamic selections. The fields that you select are included in the source code generated by the system for the selection include.

The generated selection include is displayed in the ABAP Editor. You can change it as described in Editing Selections.

If you choose Next screen (right arrow in the application toolbar), a dialog box appears, asking you whether the system should generate the database program for the logical database. The database program is generated from the structure and the selection include. It has a modular structure, consisting of several include programs and all of the necessary subroutines, with proposals for the statements that will read the data.

The generated database program is displayed in the ABAP Editor. You can change it as described in Editing the Database Program.

If you repeatedly choose Previous screen (left arrow in the application toolbar), you can display and change the general attributes of the logical database.

Finally, you can maintain optional selection texts and documentation.

rewards pts if found usefull

Regards

Sathish

former_member235056
Active Contributor
0 Kudos

Hi,

----


  • DATABASE PROGRAM OF THE LOGICAL DATABASE TEST_LDB

----


PROGRAM sapdbtest_ldb DEFINING DATABASE test_ldb.

TABLES: lfa1,

lfb1,

lfc1,

bkpf.

----


  • Initialize selection screen (process before PBO)

----


FORM init.

....

ENDFORM. "INIT

----


  • PBO of selection screen (always before selection

  • screen

----


FORM pbo.

....

ENDFORM. "PBO

----


  • PAI of selection screen (process always after ENTER)

----


FORM pai USING fname mark.

CASE fname.

WHEN 'SLIFNR'.

....

WHEN 'SBUKRS'.

....

WHEN 'SGJAHR'.

....

WHEN 'SBELNR'.

....

ENDCASE.

ENDFORM. "PAI

----


  • Call event GET LFA1

----


FORM put_lfa1.

SELECT * FROM lfa1

WHERE lifnr IN slifnr.

PUT lfa1.

ENDSELECT.

ENDFORM. "PUT_LFA1

----


  • Call event GET LFB1

----


FORM put_lfb1.

SELECT * FROM lfb1

WHERE lifnr = lfa1-lifnr

AND bukrs IN sbulrs.

PUT lfb1.

ENDSELECT.

ENDFORM. "PUT_LFB1

----


  • Call event GET LFC1

----


FORM put_lfc1.

SELECT * FROM lfc1

WHERE lifnr = lfa1-lifnr

AND bukrs = lfb1-bukrs

AND gjahr IN sgjahr.

PUT lfc1.

ENDSELECT.

ENDFORM. "PUT_LFC1

----


  • Call event GET BKPF

----


FORM put_bkpf.

SELECT * FROM bkpf

WHERE bukrs = lfb1-bukrs

AND belnr IN sbelnr

AND gjahr IN sgjahr.

PUT bkpf.

ENDSELECT.

ENDFORM. "PUT_BKPF

Regards,

Ameet