Javascript required
Skip to content Skip to sidebar Skip to footer

How to Use Logical Database in Abap Program

Simple ABAP code to demonstrate how to manipulate a logical database selection screen which is assigned and setup within menu option Goto->properties.

This example SAP ABAP HR report implements the following functionality:

Use of HR logical database selection screen with standard ABAP report.
Set default time period/key date for HR logical database report.
Set other defaults for HR logical database selection fields.
Get SAP HR org structure based on user selection from the tree structure.

To create this report you first need to assign a logical database such as PNP within the report properties (Goto->properties)
abap-hr-selection-screen-properties

Then you can add a HR report category to determine which fields should be displayed, just leave it blank for the default ones
abap hr report category

Then Ensure you include the NODES statement to instruct you report to use the logical database

NODES: Pernr.

Your selection screen will then look somthing like this
abap-hr-selection-screen

Full ABAP code listing for HR selection screen report

*&-------------------------------* *& Simple ABAP code to demonstrate how to manipulate a logical database selection screen.  *&-------------------------------* REPORT ZREP_LOGICAL_DB.  NODES: pernr.  SELECTION-SCREEN BEGIN OF block block_qual WITH FRAME title text-002. Parameters:       p_full type c as CHECKBOX DEFAULT 'X',                   p_none type c as CHECKBOX DEFAULT ' '. SELECTION-SCREEN END OF block block_qual.   *Data Declaration *---------------- data: r_objid type range of hrp1001-objid. data: wa_objid like line of r_objid.  data: wa_stat2    like line of pnpstat2,       wa_persg    like line of pnppersg,       wa_pnpobjid like line of pnpobjid.  data: objec_tab type STANDARD TABLE OF objec,       it_dept   type STANDARD TABLE OF objec,       wa_objtab like line of objec_tab,       struc_tab type STANDARD TABLE OF STRUC,       wa_struc  like line of struc_tab,       ld_orgeh  type orgeh.  *********************************************************************** *INITIALIZATION. INITIALIZATION. * Setting the radio button values directly here does not work and * setting them via the AT SELECTION-SCREEN OUTPUT resets them everytime * the screen is reloaded. See  PNPTIMED code below *PNPTIMR6 = ' '. *PNPTIMR1 = 'X'.  * Set time period default when using a logical database and report * catagory (Goto->Attributes)   PNPTIMED = 'D'.  "Sets default to Today *D     =     Today *M     =     Current month *Y     =     Current year *P     =     To current date *F     =     From today (from current date)   *Set default for other screen fields assigned via logical database *report catagory   wa_stat2-option = 'EQ'.   wa_stat2-sign   = 'I'.   wa_stat2-low    = 3.   APPEND wa_stat2 to pnpstat2.    wa_persg-option = 'EQ'.   wa_persg-sign   = 'I'.   wa_persg-low    = 'E'.   APPEND wa_persg to pnppersg.   ************************************************************************ *AT SELECTION-SCREEN OUTPUT. AT SELECTION-SCREEN OUTPUT. *This will set these values as below, but will do it every time the *screen is reloaded, including when you enter and leave a screen *field selection dialog *PNPTIMR6 = ' '. *PNPTIMR1 = 'X'.   ************************************************************************ *AT SELECTION-SCREEN AT SELECTION-SCREEN.   if p_full is INITIAL and p_none is INITIAL.     message E003(zp) with 'Please select at least 1 option'.   endif.   ************************************************************************ * START-OF-SELECTION START-OF-SELECTION.  *GET PERNR  "Use if you want to use logical database functionality  *Use Org. Unit tree selection with normal ABAP report code   loop at pnpobjid into wa_pnpobjid.     refresh: objec_tab.     ld_orgeh = wa_pnpobjid-low.     read table it_dept into  wa_objtab with key objid = ld_orgeh.     if sy-subrc ne 0. CALL FUNCTION 'RH_PM_GET_STRUCTURE'         EXPORTING           plvar           = '01'   "p0000-plvar           otype           = 'O'  "0001-otype           objid           = ld_orgeh           begda           = sy-datum           endda           = sy-datum           status          = '1'           wegid           = 'SBESX'   "ORGEH           77aw_int        = ' '           AUTHY           = ' '         TABLES           objec_tab       = objec_tab *         STRUC_TAB       = struc_tab         EXCEPTIONS           not_found       = 1           ppway_not_found = 2           others          = 3.       LOOP AT objec_tab INTO wa_objtab WHERE otype EQ 'O'.         APPEND wa_objtab to it_dept.  "objid       ENDLOOP.       sort it_dept by objid.     endif.   endloop.        

See other example ABAP Reports/Programs..

How to Use Logical Database in Abap Program

Source: https://www.se80.co.uk/training-education/logical-database-selection-screen/