‎2008 Jun 17 9:11 AM
Hello friends,
please give me a sample report program using logical database with explanation where logical databse used and how it works?
‎2008 Jun 17 9:16 AM
See the program given below, it uses logical database PNP.
************************************************************************
DESCRIPTION : TO GENERATE SIMPLE REPORT USING HR ABAP
LOGICAl DATABASE- PNP .
************************************************************************
REPORT Zdemop_HR_prog_1
LINE-SIZE 200 .
****************************
*Database Table
****************************
TABLES: PERNR, " Pernr structure for Logical database
PA0001, " Actions
PA0002. " Personnel Info
****************************
*Infotypes
****************************
INFOTYPES: 0001, " Actions
0002. " personnel info
****************************
*Variable Declaration
****************************
DATA: FORM_NAM LIKE P0001-ENAME,
V_AGE(5) TYPE C, "variable for calculating age in days
V_CTR1 TYPE I VALUE 0, "counter
V_CTR2 TYPE I VALUE 0, "counter
VAR(5) TYPE C , " variable to store btrtl
VAR1(5) TYPE C . " variable to store werks
*****************************
*Internal Table Decalartion
*****************************
DATA: BEGIN OF I_TAB1 OCCURS 0,
WERKS LIKE PA0001-WERKS, "personnel area
BTRTL LIKE PA0001-BTRTL, "personnel sub area
PERNR LIKE PA0001-PERNR, "employee number
ENAME LIKE PA0001-ENAME, "employee name
BEGDA LIKE PA0002-BEGDA, "employee join date
PERSG LIKE PA0001-PERSG, "employee group
PERSK LIKE PA0001-PERSK, "employee sub-group
PLANS LIKE PA0001-PLANS, "position
GBDAT LIKE P0002-GBDAT, "date of birth
END OF I_TAB1.
******************************
*START-OF-SELECTION
******************************
START-OF-SELECTION .
GET PERNR .
RP-PROVIDE-FROM-LAST P0001 SPACE PN-BEGDA PN-ENDDA . " Macro for IFT-0001
RP-PROVIDE-FROM-LAST P0002 SPACE PN-BEGDA PN-ENDDA . " Macro for IFT-0002
**--> Populate internal table
MOVE P0001-WERKS TO I_TAB1-WERKS .
MOVE P0001-BTRTL TO I_TAB1-BTRTL .
MOVE P0001-PERNR TO I_TAB1-PERNR .
MOVE P0001-ENAME TO I_TAB1-ENAME .
MOVE P0002-BEGDA TO I_TAB1-BEGDA .
MOVE P0001-PERSG TO I_TAB1-PERSG .
MOVE P0001-PERSK TO I_TAB1-PERSK .
MOVE P0001-PLANS TO I_TAB1-PLANS .
MOVE P0002-GBDAT TO I_TAB1-GBDAT .
**--> Append data to internal table
APPEND I_TAB1 .
CLEAR I_TAB1 . " Clear header I_TAB1
******************************
*END-OF-SELECTION
******************************
END-OF-SELECTION.
*****sorting the internal table on Personnel Area & Personnel Sub-Area
SORT I_TAB1 BY WERKS BTRTL.
******************************
*TOP_OF_PAGE
******************************
PERFORM TOP_OF_PAGE.
******************************
*Output Display
******************************
LOOP AT I_TAB1.
*for calculating the age in days
V_AGE = SY-DATUM - I_TAB1-GBDAT.
*control break on Personal Sub Area
AT NEW BTRTL .
IF SY-TABIX NE 1.
FORMAT COLOR COL_NORMAL ON.
WRITE:/5 'Total Number of Employees for personnel Sub-Area:',
VAR , 'is ',
V_CTR1.
CLEAR V_CTR1.
FORMAT COLOR OFF.
ENDIF.
ENDAT .
**Control Break on personnel Area
AT NEW WERKS.
IF SY-TABIX NE 1.
FORMAT COLOR COL_TOTAL ON.
WRITE:/5 'Total Number of Employees for Personal Area: ',
VAR1 ,'is ', V_CTR2. "color col_total.
CLEAR V_CTR2.
SKIP 1.
FORMAT COLOR OFF.
ENDIF.
ENDAT .
WRITE:/5 I_TAB1-PERNR, "personnel number
16 I_TAB1-ENAME, "emp name
47 I_TAB1-BEGDA, "join date
60 V_AGE, "age in days
74 I_TAB1-WERKS, "P area
84 I_TAB1-BTRTL, "P sub Area
94 I_TAB1-PERSG, "emp group
104 I_TAB1-PERSK, "emp sub group
114 I_TAB1-PLANS. "position
V_CTR1 = V_CTR1 + 1.
V_CTR2 = V_CTR2 + 1.
VAR = I_TAB1-BTRTL .
VAR1 = I_TAB1-WERKS .
ENDLOOP.
&----
*& Form top_of_page
&----
Header Output
----
----
FORM TOP_OF_PAGE.
FORMAT COLOR COL_HEADING ON.
WRITE:/5 'Employee',
16 'Employee',
47 'Join Date',
62 'Age',
74 'Personal',
84 'Personal',
94 'Employee',
104 'Employee',
114 'Position ',
/5 'Number',
16 'Name',
60 '(In Days)',
74 'Area',
84 'Sub-Area',
94 'Group',
104 'Sub-Group'.
FORMAT COLOR OFF.
SKIP 1.
ENDFORM. " top_of_page
Regards,
Joy.
‎2008 Jun 17 9:12 AM
Hi,
Please refer the link below:
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9b5e35c111d1829f0000e829fbfe/content.htm
Thanks,
Sriram Ponna.
‎2008 Jun 17 9:13 AM
hi check this..
Logical database
A logical database is a special ABAP/4 program which combines the contents of certain database tables. Using logical databases facilitates the process of reading database tables.
HR Logical Database is PNP
Main Functions of the logical database PNP:
Standard Selection screen
Data Retrieval
Authorization check
To use logical database PNP in your program, specify in your program attributes.
Standard Selection Screen
Date selection
Date selection delimits the time period for which data is evaluated. GET PERNR retrieves all records of the relevant infotypes from the database. When you enter a date selection period, the PROVIDE loop retrieves the infotype records whose validity period overlaps with at least one day of this period.
Person selection
Person selection is the 'true' selection of choosing a group of employees for whom the report is to run.
Sorting Data
· The standard sort sequence lists personnel numbers in ascending order.
· SORT function allows you to sort the report data otherwise. All the sorting fields are from infotype 0001.
Report Class
· You can suppress input fields which are not used on the selection screen by assigning a report class to your program.
· If SAP standard delivered report classes do not satisfy your requirements, you can create your own report class through the IMG.
Data Retrieval from LDB
1. Create data structures for infotypes.
INFOTYPES: 0001, "ORG ASSIGNMENT
0002, "PERSONAL DATA
0008. "BASIC PAY
2. Fill data structures with the infotype records.
Start-of-selection.
GET PERNR.
End-0f-selection.
Read Master Data
Infotype structures (after GET PERNR) are internal tables loaded with data.
The infotype records (selected within the period) are processed sequentially by the PROVIDE - ENDPROVIDE loop.
GET PERNR.
PROVIDE * FROM Pnnnn BETWEEN PN/BEGDA AND PN/ENDDA
If Pnnnn-XXXX = ' '. write:/ Pnnnn-XXXX. endif.
ENDPROVIDE.
Period-Related Data
All infotype records are time stamped.
IT0006 (Address infotype)
01/01/1990 12/31/9999 present
Which record to be read depends on the date selection period specified on the
selection screen. PN/BEGDA PN/ENDDA.
Current Data
IT0006 Address - 01/01/1990 12/31/9999 present
RP-PROVIDE-FROM-LAST retrieves the record which is valid in the data selection period.
For example, pn/begda = '19990931' pn/endda = '99991231'
IT0006 subtype 1 is resident address
RP-PROVIDE-FROM-LAST P0006 1 PN/BEGDA PN/ENDDA.
‎2008 Jun 17 9:13 AM
Hi mohan,
1. A logical database is in fact
a program only.
2. This LDB provides two main things :
a) a pre-defined selection screen
which handles all user inputs and validations
b) pre defined set of data
based upon the user selection.
3. So we dont have to worry about from
which tables to fetch data.
4. Moreover, this LDB Program,
handles all user-authorisations
and is efficient in all respects.
5. tcode is SLDB.
*----
1. To get a taste of it.
2. create a new z program.
3. while creating type PNP
in logical database field.
4. paste this code and execute.
REPORT ABC.
*----
infotypes : 0001.
TABLES : PERNR.
*----
GET PERNR.
WRITE 😕 PERNR-PERNR.
5. The selection screen which u see
is coming from logical database PNP program.
6. Execute
7. U will get a list of pernr.
-
SAPDBPNP
this is the main program of LDB PNP
which does the main work.
SAPDB + ldb name.
regards,
amit m.
‎2008 Jun 17 9:16 AM
See the program given below, it uses logical database PNP.
************************************************************************
DESCRIPTION : TO GENERATE SIMPLE REPORT USING HR ABAP
LOGICAl DATABASE- PNP .
************************************************************************
REPORT Zdemop_HR_prog_1
LINE-SIZE 200 .
****************************
*Database Table
****************************
TABLES: PERNR, " Pernr structure for Logical database
PA0001, " Actions
PA0002. " Personnel Info
****************************
*Infotypes
****************************
INFOTYPES: 0001, " Actions
0002. " personnel info
****************************
*Variable Declaration
****************************
DATA: FORM_NAM LIKE P0001-ENAME,
V_AGE(5) TYPE C, "variable for calculating age in days
V_CTR1 TYPE I VALUE 0, "counter
V_CTR2 TYPE I VALUE 0, "counter
VAR(5) TYPE C , " variable to store btrtl
VAR1(5) TYPE C . " variable to store werks
*****************************
*Internal Table Decalartion
*****************************
DATA: BEGIN OF I_TAB1 OCCURS 0,
WERKS LIKE PA0001-WERKS, "personnel area
BTRTL LIKE PA0001-BTRTL, "personnel sub area
PERNR LIKE PA0001-PERNR, "employee number
ENAME LIKE PA0001-ENAME, "employee name
BEGDA LIKE PA0002-BEGDA, "employee join date
PERSG LIKE PA0001-PERSG, "employee group
PERSK LIKE PA0001-PERSK, "employee sub-group
PLANS LIKE PA0001-PLANS, "position
GBDAT LIKE P0002-GBDAT, "date of birth
END OF I_TAB1.
******************************
*START-OF-SELECTION
******************************
START-OF-SELECTION .
GET PERNR .
RP-PROVIDE-FROM-LAST P0001 SPACE PN-BEGDA PN-ENDDA . " Macro for IFT-0001
RP-PROVIDE-FROM-LAST P0002 SPACE PN-BEGDA PN-ENDDA . " Macro for IFT-0002
**--> Populate internal table
MOVE P0001-WERKS TO I_TAB1-WERKS .
MOVE P0001-BTRTL TO I_TAB1-BTRTL .
MOVE P0001-PERNR TO I_TAB1-PERNR .
MOVE P0001-ENAME TO I_TAB1-ENAME .
MOVE P0002-BEGDA TO I_TAB1-BEGDA .
MOVE P0001-PERSG TO I_TAB1-PERSG .
MOVE P0001-PERSK TO I_TAB1-PERSK .
MOVE P0001-PLANS TO I_TAB1-PLANS .
MOVE P0002-GBDAT TO I_TAB1-GBDAT .
**--> Append data to internal table
APPEND I_TAB1 .
CLEAR I_TAB1 . " Clear header I_TAB1
******************************
*END-OF-SELECTION
******************************
END-OF-SELECTION.
*****sorting the internal table on Personnel Area & Personnel Sub-Area
SORT I_TAB1 BY WERKS BTRTL.
******************************
*TOP_OF_PAGE
******************************
PERFORM TOP_OF_PAGE.
******************************
*Output Display
******************************
LOOP AT I_TAB1.
*for calculating the age in days
V_AGE = SY-DATUM - I_TAB1-GBDAT.
*control break on Personal Sub Area
AT NEW BTRTL .
IF SY-TABIX NE 1.
FORMAT COLOR COL_NORMAL ON.
WRITE:/5 'Total Number of Employees for personnel Sub-Area:',
VAR , 'is ',
V_CTR1.
CLEAR V_CTR1.
FORMAT COLOR OFF.
ENDIF.
ENDAT .
**Control Break on personnel Area
AT NEW WERKS.
IF SY-TABIX NE 1.
FORMAT COLOR COL_TOTAL ON.
WRITE:/5 'Total Number of Employees for Personal Area: ',
VAR1 ,'is ', V_CTR2. "color col_total.
CLEAR V_CTR2.
SKIP 1.
FORMAT COLOR OFF.
ENDIF.
ENDAT .
WRITE:/5 I_TAB1-PERNR, "personnel number
16 I_TAB1-ENAME, "emp name
47 I_TAB1-BEGDA, "join date
60 V_AGE, "age in days
74 I_TAB1-WERKS, "P area
84 I_TAB1-BTRTL, "P sub Area
94 I_TAB1-PERSG, "emp group
104 I_TAB1-PERSK, "emp sub group
114 I_TAB1-PLANS. "position
V_CTR1 = V_CTR1 + 1.
V_CTR2 = V_CTR2 + 1.
VAR = I_TAB1-BTRTL .
VAR1 = I_TAB1-WERKS .
ENDLOOP.
&----
*& Form top_of_page
&----
Header Output
----
----
FORM TOP_OF_PAGE.
FORMAT COLOR COL_HEADING ON.
WRITE:/5 'Employee',
16 'Employee',
47 'Join Date',
62 'Age',
74 'Personal',
84 'Personal',
94 'Employee',
104 'Employee',
114 'Position ',
/5 'Number',
16 'Name',
60 '(In Days)',
74 'Area',
84 'Sub-Area',
94 'Group',
104 'Sub-Group'.
FORMAT COLOR OFF.
SKIP 1.
ENDFORM. " top_of_page
Regards,
Joy.
‎2008 Jun 17 9:53 AM
Hello friends,
Thanks for your quick response and also for your detailed answer.