ABAP Code Examples

Use logical database selection screen ABAP Code




*& TITLE: Use logical database selection screen
*&-------------------------------*
*& Report  ZLOGICAL_SELSCREEN
*&-------------------------------*
*& Simple ABAP code to demonstrate how to manipulate a logical database
*& selection screen. This is assigned and setup within menu option Goto->attributes.
*& You first need to assign a logical database such as PNP and then a HR report
*& category to determine which fields should be displayed.
*&
*& SAP ABAP report functionality used
*& **********************************
*& Use of HR logical database selection screen with standard ABAP report.
*& Set default time period/key date for HR locical database report
*& Set other defaults for HR logical database selection fields
*& Get SAP HR org structure based on user selection from tree structure
*&
*&-------------------------------*
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.

Text pool values



See other example ABAP Reports/Programs..