‎2008 Jul 15 7:29 AM
Hi,
Can anyone tell me how to create a logical database? I am curious about it.
Thanks.
Awards will be provided.
Best regards,
Chris Gu
‎2008 Jul 15 7:31 AM
Hi Chris,
Check this link, you have step by step procedure:
http://help.sap.com/saphelp_nw70/helpdata/en/9f/db9bfa35c111d1829f0000e829fbfe/content.htm
Try to go thru this link also:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14239/create_ls.htm#SBYDB00300
Hope this helps you.
Regards,
Chandra Sekhar
‎2008 Jul 15 7:31 AM
Hi,
Go to Transaction SE36.There you Can Create Logical database.
Put the Name of the logical Database you want to Create.
Select STRUCTURE radiobutton and then press Create button.
Give the short text in Next Screen.
Then Click on Create Icon.
then save it.Give the Root Table name,text and Databse table in the Predefined input field.
Now Press create ICON.
A page is displayed with the structure and Table name at left side.
Now you can add more table which are related with the Root node by Right Clicking on the Root table and clicking 'INSERT NODES'
Now Save and activate the LDB.
Check this link-
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9bfa35c111d1829f0000e829fbfe/content.htm
http://articles.techrepublic.com.com/5100-10878_11-5034421.html
Regards,
Sujit
Regards,
Sujit
‎2008 Jul 15 7:31 AM
Hi Chris,
Check this link, you have step by step procedure:
http://help.sap.com/saphelp_nw70/helpdata/en/9f/db9bfa35c111d1829f0000e829fbfe/content.htm
Try to go thru this link also:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14239/create_ls.htm#SBYDB00300
Hope this helps you.
Regards,
Chandra Sekhar
‎2008 Jul 15 7:32 AM
hi
Plz refer to the link
http://articles.techrepublic.com.com/5100-10878_11-5034421.html
regards
Sumit Agarwal
‎2008 Jul 15 7:32 AM
Hi,
Refer to the following link.
http://saptechnical.com/Tutorials/ABAP/LDB/page1.htm
Hope it is usefull
Regards,
Jaya Vani
‎2008 Jul 15 7:33 AM
Hi,
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.
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.
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.
Creation of Logical database
Example of a Logical Database
Let us consider the logical database TEST_LDB.
Structure:
LFA1
LFB1
LFC1
BKPF
Selections in the Selection Include
SELECT-OPTIONS: slifnr FOR lfa1-lifnr,
sbukrs FOR lfb1-bukrs,
sgjahr FOR lfc1-gjahr,
sbelnr FOR bkpf-belnr.
Database Program
----
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
The PROGRAM statement has the addition DEFINING DATABASE test_ldb. This defines the database program as belonging to the logical database TEST_LDB.
You declare the node of the structure using the TABLESstatement. This creates the necessary interface work areas as table work areas. You can also use the NODES statement to define database tables as nodes. If a node of a logical database is not a database table, you must use the NODESstatement. The interface work areas are shared by the database program and the user, and so act as an interface for passing data. The term u201Cuseru201D here can mean either an executable program to which the logical database is linked, or the function module LDB_PROCESS.
The subroutines INIT and PBO initialize the selection screen.
In the PAI subroutine, you can include an authorization check for the user input on the selection screen. Plausibility or value range checks are also possible. If a check fails, you can write an error dialog. The corresponding field on the selection screen is then made ready for input again.
The PUT_node subroutines read the database tables according to the selection criteria entered by the user and trigger the relevant GET events. This program is intended only to show the essential structure of a logical database. It does not contain any refinements to improve response times. The order in which the subroutines are called is determined by the structure of the logical database.
Regards,
Sravanthi
‎2008 Jul 15 7:36 AM
Hi Chris,
Plz refer to the link below you will get the idea and t code for the same as also said by others is SE36:
http://help.sap.com/saphelp_46c/helpdata/en/9f/db9b5e35c111d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_46c/helpdata/en/9f/db9be035c111d1829f0000e829fbfe/content.htm
With luck,
Pritam.
‎2008 Jul 15 7:36 AM
‎2008 Jul 15 7:48 AM
Hi Chris.
I would like to suggest,
Logical Database - Functionality is to retrieve data from database and provide them to the application programs.
Provides a structure access.
[SDN - Reference for Effective use of Logical databases|;
[SDN - Reference for Use of LDB and Sample programs|;
Creating LDB - I suggest some references,
Transaction codes for creating LDB - SE36 or SLDB
[SAP HELP - Reference for creating a Logical database step by step|http://help.sap.com/saphelp_nw04s/helpdata/en/9f/db9bfa35c111d1829f0000e829fbfe/frameset.htm]
[SDN - Reference for "Possiblility for creating Two LDBs"|;
[SDN - Reference for creating a Logical database|;
Hope that's usefull.
Good Luck & Regards.
Harsh Dave
‎2008 Jul 15 8:04 AM
Transaction code for creating Logical db is se36.
Give the name as <ldbname>..
Specify the table names and the sub nodes according to your heirarchy.The root node used is zxxx_product and child node is zxxx_orders
The heirarchy used is ZXXX_PRODUCT---->ZXXX_ORDERS
write the below code under selections ...
Enable DYNAMIC SELECTIONS for selected nodes :
SELECTION-SCREEN DYNAMIC SELECTIONS FOR TABLE zxxx_product.
SELECTION-SCREEN DYNAMIC SELECTIONS FOR TABLE zxxx_orders.
Enable FIELD SELECTION for selected nodes :
SELECTION-SCREEN FIELD SELECTION FOR TABLE zxxx_product.
SELECTION-SCREEN FIELD SELECTION FOR TABLE zxxx_orders.
***User defined blocks :
****Root node
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001 .
SELECT-OPTIONS :
so_pname FOR zxxx_product-prname ,
so_pdelv FOR zxxx_product-prdeldate .
SELECTION-SCREEN END OF BLOCK b1 .
****Child node
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002 .
SELECT-OPTIONS :
so_odate FOR zxxx_orders-orddate ,
so_oqty FOR zxxx_orders-ordqty .
SELECTION-SCREEN END OF BLOCK b2 .
write the below code under include include DBZXX_PRODUCTTOP
TABLES : ZXXX_product, ZXXX_orders.
DATA : gt_root TYPE table of ZXXX_product ,
gt_chld TYPE table of ZXXX_orders .
write the below code under source code...
-
Call event GET Zxxx_PRODUCT
-
FORM put_zxxx_product.
TYPES : BEGIN OF ls_pid ,
prodid TYPE zxxx_product-prodid,
END OF ls_pid .
*
DATA : lt_pid TYPE ls_pid OCCURS 0 ,
lt_pid_tmp TYPE ls_pid OCCURS 0 .
STATICS lv_first_time VALUE 'X'.
STATICS ls_isroot_fields TYPE rsfs_tab_fields.
STATICS ls_isroot_where TYPE rsds_where.
STATICS ls_ischld_fields TYPE rsfs_tab_fields.
STATICS ls_ischld_where TYPE rsds_where.
IF lv_first_time EQ 'X'.
CLEAR lv_first_time.
*
o
+ Declarations for field selection for node Zxxx_PRODUCT ***
" move table name to the corresponding field
MOVE 'Zxxx_PRODUCT' TO ls_isroot_fields-tablename.
" Read values from selection screen
READ TABLE select_fields WITH KEY ls_isroot_fields-tablename
INTO ls_isroot_fields.
" move table name to the corresponding field
MOVE 'Zxxx_PRODUCT' TO ls_isroot_where-tablename.
" Read values from dynamic selection screen
READ TABLE dyn_sel-clauses WITH KEY ls_isroot_where-tablename
INTO ls_isroot_where.
*
o
+ Declarations for field selection for child node Zxxx_ORDERS ***
MOVE 'Zxxx_ORDERS' TO ls_ischld_fields-tablename.
READ TABLE select_fields WITH KEY ls_ischld_fields-tablename
INTO ls_ischld_fields.
MOVE 'Zxxx_ORDERS' TO ls_ischld_where-tablename.
READ TABLE dyn_sel-clauses WITH KEY ls_ischld_where-tablename
INTO ls_ischld_where.
"...Check whether entry is made in atleast one selection field:
IF NOT so_pname IS INITIAL OR
NOT so_pdelv IS INITIAL OR
NOT so_odate IS INITIAL OR
NOT so_oqty IS INITIAL OR
NOT ls_isroot_where-where_tab IS INITIAL OR
NOT ls_ischld_where-where_tab IS INITIAL .
"...Check whether entry is made in atleast one field in root node :
IF NOT so_pname IS INITIAL OR
NOT so_pdelv IS INITIAL OR
NOT ls_isroot_where-where_tab IS INITIAL .
SELECT prodid FROM Zxxx__product
INTO CORRESPONDING FIELDS OF TABLE lt_pid
WHERE prname IN so_pname AND
prdeldate IN so_pdelv AND
(ls_isroot_where-where_tab).
"...Check whether entry is made in atleast one field in child node:
IF NOT so_odate IS INITIAL OR
NOT so_oqty IS INITIAL OR
NOT ls_ischld_where-where_tab IS INITIAL AND
NOT lt_pid IS INITIAL.
SELECT prodid FROM Zxxx_orders
INTO CORRESPONDING FIELDS OF TABLE lt_pid_tmp
FOR ALL ENTRIES IN lt_pid
WHERE prodid = lt_pid-prodid AND
orddate IN so_odate AND
ordqty IN so_oqty AND
(ls_ischld_where-where_tab).
lt_pid = lt_pid_tmp.
ENDIF.
ELSEIF NOT so_odate IS INITIAL OR
NOT so_oqty IS INITIAL OR
NOT ls_ischld_where-where_tab IS INITIAL.
SELECT prodid FROM Zxxx_orders
INTO CORRESPONDING FIELDS OF TABLE lt_pid
WHERE orddate IN so_odate AND
ordqty IN so_oqty AND
(ls_ischld_where-where_tab).
ENDIF.
******lt_pid contains all the selections based product ids
******Now retrieve all the records with the corresponding product ids
CHECK NOT lt_pid IS INITIAL.
IF NOT ls_isroot_fields IS INITIAL.
SELECT (ls_isroot_fields-fields) FROM Zxxx_product
INTO CORRESPONDING FIELDS OF TABLE gt_root
FOR ALL ENTRIES IN lt_pid WHERE prodid = lt_pid-prodid.
ENDIF.
IF NOT ls_ischld_fields IS INITIAL AND
NOT gt_root IS INITIAL.
SELECT (ls_ischld_fields-fields) FROM Zxxx_orders
INTO CORRESPONDING FIELDS OF TABLE gt_chld
FOR ALL ENTRIES IN gt_root WHERE prodid = gt_root-prodid.
ENDIF.
LOOP AT gt_root INTO Zxxx_product.
PUT Zxxx_product.
ENDLOOP.
ENDIF.
ENDIF.
ENDFORM.
write the below code under
include DBZXXX_PRODUCTNXXX -->
include DBZXXX_PRODUCTN002 .
form put_zxxx_orders
LOOP AT gt_chld INTO zxxx_orders WHERE prodid = zxxx_product-prodid.
PUT ZXXX_ORDERS.
ENDLOOP.
endform.
now write a report program and call the ldb by its name using get
get <ldbname>.
Reward if this is useful.
Regards,
devi.
Edited by: Devi Raju on Jul 15, 2008 9:13 AM
‎2008 Nov 12 6:22 AM
Thanks all the guys.
I have the idea how to create it.
Cheers.
Chris