0% found this document useful (0 votes)
233 views

Employee Details Report Using Logical Database - PNP

This ABAP report code extracts employee details from SAP HR using infotypes and displays it in an interactive ALV grid. It defines a structure to hold the extracted data, performs data extraction using subroutines that call various SAP functions, processes the extracted data, and displays it using the ALV function module.

Uploaded by

Ayaz Ahmed Shaik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
233 views

Employee Details Report Using Logical Database - PNP

This ABAP report code extracts employee details from SAP HR using infotypes and displays it in an interactive ALV grid. It defines a structure to hold the extracted data, performs data extraction using subroutines that call various SAP functions, processes the extracted data, and displays it using the ALV function module.

Uploaded by

Ayaz Ahmed Shaik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Selection screen:

Run

Following is the source code that will work .


*&---------------------------------------------------------------------*

*& Author: Pavan Golesar (Zapper)

*& Dated: 17th Feb 2015

*& Module: SAP HR

*& Subject: Employee Details Report using infotype (HR ABAP report)

*&---------------------------------------------------------------------*

*& CREATE A STRUCTURE OF FOLLOWING SPEC WITH THE NAME AS 'ZHR_EMP_STRUC'.

*----------------------------------------------------------------------*

*PERNR 1 Types PERSNO NUMC 8 0 Personnel number

*ENAME 1 Types ZENAME CHAR 20 0 Employee name - zapper

*DOJ 1 Types ZDOJ DATS 8 0 Date of birth

*DOB 1 Types GBDAT DATS 8 0 Date of Birth

*DESIG 1 Types ZDESIG CHAR 20 0 Desig

*DEPT 1 Types ZDEPT CHAR 20 0 Department

*AGE 1 Types ZAGE1 NUMC 3 0 Age

*----------------------------------------------------------------------*

REPORT ZAP_EMP_DETAILS_REPORT.

*-- TABLES WORKAREA.

TABLES: PERNR.

*-- INFOTYPES DECLARATION.

INFOTYPES: 0001, 0002 .

*-- DEFINE SCREEN

SELECTION-SCREEN:BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.


SELECT-OPTIONS: S_PERNR FOR PERNR-PERNR ,

S_PERSG FOR PERNR-PERSG ,

S_PERSK FOR PERNR-PERSK ,

S_ABKRS FOR PERNR-ABKRS .

SELECTION-SCREEN:END OF BLOCK B1 .

*-- DATA OBJECTS

DATA: WA_FINAL TYPE ZHR_EMP_STRUC ,

IT_FINAL TYPE STANDARD TABLE OF ZHR_EMP_STRUC ,

DESIG(20) ,

DEPT(20) ,

AGE TYPE I .

*-- EXTRACTION LOGIC

START-OF-SELECTION.

GET PERNR . " LDB WILL FETCH DATA FROM RESPECTIVE INFOTYPES BASED ON SELECTION PROVIDED

CHECK PERNR-PERNR IN S_PERNR AND

PERNR-PERSG IN S_PERSG AND

PERNR-PERSK IN S_PERSK AND

PERNR-ABKRS IN S_ABKRS .

*-- SUBROUTINES.

IF SY-SUBRC EQ 0 .

PERFORM GET_DATA.

ENDIF.
END-OF-SELECTION. "LAST RECORD PROCESS

PERFORM PROCESS_DATA .

PERFORM DISPLAY_DATA .

*&---------------------------------------------------------------------*

*& Form GET_DATA

*&---------------------------------------------------------------------*

* EXTRACT THE DATA

*----------------------------------------------------------------------*

FORM GET_DATA .

SELECT SINGLE PLSTX

FROM T528T

INTO DESIG

WHERE ( PLANS = PERNR-PLANS AND OTYPE = 'S' AND SPRSL = 'EN' ).

SELECT SINGLE ORGTX

FROM T527X

INTO DEPT

WHERE ORGEH = PERNR-ORGEH .

WA_FINAL-PERNR = PERNR-PERNR .

WA_FINAL-ENAME = P0001-SNAME .

WA_FINAL-DOJ = P0001-BEGDA .

WA_FINAL-DOB = P0002-GBDAT .

WA_FINAL-DESIG = DESIG .
WA_FINAL-DEPT = DEPT .

*-- NOW GET THE AGE IN YEARS(NOT IN MONTHS)

CALL FUNCTION 'HR_RU_AGE_YEARS'

EXPORTING

PERNR = PERNR-PERNR

BSDTE = SY-DATUM

IMPORTING

VALUE = AGE

EXCEPTIONS

RECORD_NOT_FOUND = 1

STRANGE_BIRTH_DATE = 2

OTHERS = 3.

*-- ERROR HANDLING VIA EXCEPTIONS

IF SY-SUBRC EQ 2.

MESSAGE 'Unable to process your query' TYPE 'E'.

ELSEIF SY-SUBRC EQ 1.

MESSAGE 'Sorry, Record not found!' TYPE 'E'.

ELSEIF SY-SUBRC EQ 0.

WA_FINAL-AGE = AGE .

APPEND WA_FINAL TO IT_FINAL.

ENDIF.

ENDFORM. " GET_DATA

*&---------------------------------------------------------------------*

*& Form PROCESS_DATA

*&---------------------------------------------------------------------*
* processing the employee details

*----------------------------------------------------------------------*

FORM PROCESS_DATA .

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

PERCENTAGE = 100

TEXT = 'EMPLOYEE DETAILS'.

ENDFORM. " PROCESS_DATA

*&---------------------------------------------------------------------*

*& Form DISPLAY_DATA

*&---------------------------------------------------------------------*

* Displaying the report

*----------------------------------------------------------------------*

FORM DISPLAY_DATA .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_STRUCTURE_NAME = 'ZHR_EMP_STRUC'

TABLES

T_OUTTAB = IT_FINAL.

ENDFORM. " DISPLAY_DATA

*-- Cheers , Enjoy Coding 

You might also like