REPORT ZPYLBMA128 MESSAGE-ID 25 LINE-SIZE 500 LINE-COUNT 65 NO STANDARD PAGE HEADING..
INCLUDE ZPYLBMA128_VARIABLES.
"SELECTION SCREEN STARTS=========================
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN: SKIP 1.
PARAMETERS : DSN LIKE FILENAME-FILEEXTERN DEFAULT '/home/HRD/UL/test zakat.prn'.
PARAMETERS : MAPNAME DEFAULT SY-UNAME LIKE RPTAXXXX-MAP_NAME.
PARAMETERS : TEST_RUN TYPE C AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK B1.
"SELECTION SCREEN ENDS=========================
"INITIALIZATION STARTS=========================
INITIALIZATION.
DSN+6(3) = SY-SYSID.
REPNAME = SY-REPID.
"INITIALIZATION ENDS=========================
"AT SELECTION-SCREEN CHECKING STARTS=========================
AT SELECTION-SCREEN ON DSN.
CLEAR: IDSN.
TRY.
OPEN DATASET DSN FOR INPUT IN TEXT MODE ENCODING NON-UNICODE. "UNI-CONV
IF SY-SUBRC NE 0.
MESSAGE E899(5A) WITH 'Error in opening file:'(E01) DSN.
ENDIF.
CATCH CX_SY_FILE_OPEN.
CLOSE DATASET DSN.
OPEN DATASET DSN FOR INPUT IN TEXT MODE ENCODING NON-UNICODE. "UNI-CONV
IF SY-SUBRC NE 0.
MESSAGE E899(5A) WITH 'DATA DOES NOT EXITS:'(E01) DSN.
ENDIF.
ENDTRY.
AT SELECTION-SCREEN.
IF TEST_RUN NE 'X'.
CALL FUNCTION 'HR_MAPNAME_VERIFY'
EXPORTING
MAPNAME = MAPNAME
REPORTNAME = REPNAME
IMPORTING
MAPNAME = MAPNAME.
ENDIF.
"AT SELECTION-SCREEN CHECKING ENDS=========================
"START-OF-SELECTION=========================
START-OF-SELECTION.
"BDC OPEN GROUP
IF TEST_RUN NE 'X'.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = MAPNAME
KEEP = 'X'
USER = SY-UNAME.
ENDIF.
**TO READ DATA FROM UNIX FILE
DO.
READ DATASET DSN INTO IDSN.
IF SY-SUBRC EQ 0.
"WRITE IDSN-SUBTY LEFT-JUSTIFIED TO IDSN-SUBTY.
CONDENSE IDSN-SUBTY.
APPEND IDSN.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET DSN.
**TO PROCESS RECORD BY RECORD
DESCRIBE TABLE IDSN LINES ILINE.
CHECK ILINE > 0.
CLEAR: ITAB[], ERRTAB[]."errtab AND ERROR_FLAG ARE not used as there is no checking as yet!
LOOP AT IDSN.
CLEAR: ERRTAB.
MOVE: IDSN-PERNR TO PERNR1.
ADD 1 TO NUMREC. "Current Record (Row) Number
****To validate PF No & IC/Passport No
PERFORM VALIDATE_PERNR.
****To assign data to ITAB
IF ERROR_FLAG <> 'X'.
PERFORM ASSIGN_DATA.
ENDIF.
IF ERROR_FLAG <> 'X'.
IF TEST_RUN NE 'X'.
PERFORM FILL-DYNPROS.
ENDIF.
******HASHING FOR ACCEPTED RECORDS
ADD: 1 TO HEAD_COUNT,
PERNR1 TO HASH_PERNR.
APPEND ITAB.
ELSE.
******HASHING FOR REJECTED RECORDS
ADD: 1 TO HEAD_COUNT_RJ,
PERNR1 TO HASH_PERNR_RJ.
ENDIF.
****HASHING FOR ALL RECORDS
ADD: 1 TO HEAD_COUNT_TT,
PERNR1 TO HASH_PERNR_TT.
ENDLOOP.
"**Close BDC session
IF TEST_RUN NE 'X'.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
FORMAT COLOR COL_GROUP ON INTENSIFIED OFF.
WRITE:/ 'Batch input session', MAPNAME, 'created'.
FORMAT COLOR COL_GROUP OFF INTENSIFIED OFF.
SKIP 2.
ENDIF.
**PRINT HASHING SUMMARY
PERFORM PRINT_HASHING_SUMMARY.
WRITE:/ 'Record(s) with errors'.
WRITE:/ '---------------------'.
WRITE:/2(10) 'Record no.' , 14(60)'Error' , 76(10) 'PF No', 88(11) 'Member Type', 101(4) 'Wage Type',
107(10) 'Start Date' , 119(8) 'End Date' , 129(14) 'Membership Fee' ,
145(10) ' Number' , 157(20) 'Unit' , 179(9) 'Payee Key'.
WRITE:/2(10) '----------' , 14(60)'-----' , 76(10) '-----', 88(11) '-----------', 101(4) '---------',
107(10) '----------' , 119(8) '--------' , 129(14) '--------------' ,
145(10) ' ------' , 157(20) '----' , 179(9) '---------'.
LOOP AT ERRTAB.
WRITE:/2(10) ERRTAB-NUMREC , 14(60) ERRTAB-MESSG, 76(10) ERRTAB-PERNR, 88(11) ITAB-SUBTY, 101(4) ITAB-LGART,
107(10) ITAB-BEGDA, 119(8) ITAB-ENDDA, 129(14) ITAB-BETRG,
145(10) ITAB-ANZHL, 157(20) ITAB-ZEINH, 179(9) ITAB-EMFSL.
"itab-icnum, "itab-mtgln.
ENDLOOP.
END-OF-SELECTION.
"END-OF-SELECTION=========================
"======================REPORTS STARTS
**PRINT FOOTER
PERFORM WRITE_FOOTER.
********************* REPORT HEADER *******************************
TOP-OF-PAGE.
PAGENO = ' '.
PERFORM WRITE_HEADER USING '0001' 'M' SY-DATUM
SPACE '100213' ' HRIS, HRD' PAGENO.
SKIP 2.
INCLUDE ZPULRIA001.
"======================REPORTS ENDS
INCLUDE ZPYLBMA128_FORMS.
"--------------------------------------------------------------------------------------------------------------
"--------------------------------------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include ZPYLBMA128_VARAIBLE
*&---------------------------------------------------------------------*
"DATA DECLARATION STARTS=========================
TABLES: PA0000, "HR Master Record: Infotype 0000 (Actions)
PA0001, "HR Master Record: Infotype 0001 (Org. Assignment)
PA0002, "HR Master Record: Infotype 0002 (Personal Data)
PA0185, "HR Master Record: Infotype 0185 [Identification] (SG)
T591S, "Subtype Texts (for Member Type Text)
T512T, "Wage Type Texts
T521B, "Payee Keys
T001, "Company Codes
SSCRFIELDS. "Fields on selection screens
** Table to hold all data row from flat file
DATA: BEGIN OF IDSN OCCURS 0,
PERNR(08) TYPE C, "PF No.
SUBTY(04) TYPE C, "Member Type (Sub-Type)
LGART(04) TYPE C, "Wage Type
BEGDA(08) TYPE C, "Start Date
ENDDA(08) TYPE C, "End Date
BETRG(13) TYPE C, "Membership Fee / Amount
ANZHL(10) TYPE C, "Number
ZEINH(20) TYPE C, "Unit
EMFSL(08) TYPE C, "Payee Key
" MTGLN(20) TYPE C, "Membership Number
" ICNUM(30) TYPE C, "New IC
END OF IDSN.
** Table to hold success data
DATA: BEGIN OF ITAB OCCURS 0,
PERNR LIKE P0000-PERNR, "PF No.
SUBTY LIKE RP50G-SUBTY, "Member Type (Sub-Type)
LGART LIKE P0057-LGART, "Wage Type
LGTXT LIKE T512T-LGTXT, "Wage Type Text*
BEGDA(10) TYPE C, "Start Date
ENDDA(10) TYPE C, "End Date
BETRG LIKE Q0057-BETRG, "Membership Fee
ANZHL LIKE P0057-ANZHL, "Number
ZEINH LIKE Q0057-EITXT, "Unit
EMFSL LIKE P0057-EMFSL, "Payee Key
EMFNA LIKE T521B-EMFNA, "Payee Key Text*
" STEXT LIKE T591S-STEXT, "Member Type Text
" MTGLN LIKE P0057-MTGLN, "Membership Number
" ICNUM LIKE P0185-ICNUM, "New IC
" CNAME LIKE P0002-CNAME, "Staff Name
END OF ITAB.
** Table to hold error data and error message
DATA: BEGIN OF ERRTAB OCCURS 0,
NUMREC TYPE I,
MESSG(60) TYPE C.
INCLUDE STRUCTURE ITAB.
DATA: END OF ERRTAB.
* Table for Batch Input
DATA: BEGIN OF BDCDATA OCCURS 20.
INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDCDATA.
DATA: HEAD_COUNT TYPE I,
HEAD_COUNT_RJ TYPE I,
HEAD_COUNT_TT TYPE I,
HASH_PERNR TYPE P,
HASH_PERNR_RJ TYPE P,
HASH_PERNR_TT TYPE P.
DATA: ILINE TYPE I,
NUMREC TYPE I, "Record (Row) Number
ERROR_FLAG TYPE C, "Error Flag
" BK_ICNUM(30) TYPE C, "Unformatted IC Number
PAGENO(1) TYPE C, "Page Number (Report)
" TDATE(10) TYPE C, "To hold formatted date
PERNR1 LIKE P0000-PERNR. "Personnel Number
" ICTYPE LIKE P0185-ICTYP, "Document Type
" STARTDT LIKE SY-DATUM. "Hiring Start Date
DATA: REPNAME LIKE SY-REPID.
"DATA DECLARATION ENDS=========================
"--------------------------------------------------------------------------------------------------------------
"--------------------------------------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include ZPYLBMA128_FORMS
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form assign_data
*&---------------------------------------------------------------------*
FORM ASSIGN_DATA.
CLEAR ERROR_FLAG.
MOVE-CORRESPONDING IDSN TO ITAB.
"**Retrieve Staff Name (Infotype 0002)
" SELECT SINGLE * FROM PA0002 WHERE PERNR EQ ITAB-PERNR.
" IF SY-SUBRC EQ 0.
" ITAB-CNAME = PA0002-CNAME. "Store Staff Name
" WRITE:/ PA0002-CNAME.
" ELSE.
" ERROR_FLAG = 'X'.
" MOVE-CORRESPONDING IDSN TO ERRTAB.
" ERRTAB-NUMREC = NUMREC.
" ERRTAB-MESSG = 'Staff Name not found'.
" APPEND ERRTAB. CLEAR ERRTAB.
" ENDIF.
"**Retrieve Member Type Text
" IF ERROR_FLAG NE 'X'.
" SELECT SINGLE * FROM T591S WHERE SPRSL EQ 'EN'
" AND INFTY = '0057'
" AND SUBTY = ITAB-SUBTY.
" IF SY-SUBRC EQ 0.
" ITAB-STEXT = T591S-STEXT.
" ELSE.
" ERROR_FLAG = 'X'.
" MOVE-CORRESPONDING IDSN TO ERRTAB.
" ERRTAB-NUMREC = NUMREC.
" ERRTAB-MESSG = 'Member Type not found'.
" APPEND ERRTAB. CLEAR ERRTAB.
" ENDIF.
" ENDIF.
"**Wage Type Text
" IF ERROR_FLAG NE 'X'.
" SELECT SINGLE * FROM T512T WHERE SPRSL EQ 'EN'
" AND MOLGA EQ '14'
" AND LGART = ITAB-LGART.
" IF SY-SUBRC EQ 0.
" ITAB-LGTXT = T512T-LGTXT.
" ELSE.
" ERROR_FLAG = 'X'.
" MOVE-CORRESPONDING IDSN TO ERRTAB.
" ERRTAB-NUMREC = NUMREC.
" ERRTAB-MESSG = 'Wage Type not found'.
" APPEND ERRTAB. CLEAR ERRTAB.
" ENDIF.
" ENDIF.
"**Payee Key Text
" IF ERROR_FLAG NE 'X'.
" SELECT * FROM T521B INTO TABLE WA_T521B WHERE EMFSL EQ ITAB-EMFSL.
" IF SY-SUBRC EQ 0.
" SORT WA_T521B BY ENDDA DESCENDING.
" LOOP AT WA_T521B.
" ITAB-EMFNA = WA_T521B-EMFNA. EXIT.
" ENDLOOP.
" ELSE.
" ERROR_FLAG = 'X'.
" MOVE-CORRESPONDING IDSN TO ERRTAB.
" ERRTAB-NUMREC = NUMREC.
" ERRTAB-MESSG = 'Wage Type not found'.
" APPEND ERRTAB. CLEAR ERRTAB.
" ENDIF.
" ENDIF.
ENDFORM. " assign_data
*&---------------------------------------------------------------------*
*& Form FILL-DYNPROS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL-DYNPROS .
PERFORM D1000.
PERFORM D2000.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'PA30'
TABLES
DYNPROTAB = BDCDATA.
ENDFORM. " FILL-DYNPROS
FORM D1000.
REFRESH BDCDATA.
CLEAR BDCDATA.
BDCDATA-PROGRAM = 'SAPMP50A'.
BDCDATA-DYNPRO = '1000'.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
**PF NO.
CLEAR BDCDATA.
BDCDATA-FNAM = 'RP50G-PERNR'.
BDCDATA-FVAL = IDSN-PERNR.
APPEND BDCDATA.
**INFOTYPE 0008
CLEAR BDCDATA.
BDCDATA-FNAM = 'RP50G-CHOIC'.
BDCDATA-FVAL = '0057'.
APPEND BDCDATA.
**SUBTYPE (Member Type)
CLEAR BDCDATA.
BDCDATA-FNAM = 'RP50G-SUBTY'.
BDCDATA-FVAL = IDSN-SUBTY.
APPEND BDCDATA.
CLEAR BDCDATA.
BDCDATA-FNAM = 'BDC_OKCODE'.
BDCDATA-FVAL = '=INS'.
APPEND BDCDATA.
ENDFORM. " d1000
*---------------------------------------------------------------------*
* FORM D2000
*---------------------------------------------------------------------*
FORM D2000.
CLEAR BDCDATA.
BDCDATA-PROGRAM = 'MP005700'.
BDCDATA-DYNPRO = '2000'.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
**START DATE
CLEAR BDCDATA.
BDCDATA-FNAM = 'P0057-BEGDA'.
"WRITE IDSN-BEGDA TO BDCDATA-FVAL DD/MM/YYYY.
CONCATENATE IDSN-BEGDA+6(2) '.' IDSN-BEGDA+4(2) '.' IDSN-BEGDA+0(4) INTO BDCDATA-FVAL.
APPEND BDCDATA.
**END DATE
CLEAR BDCDATA.
BDCDATA-FNAM = 'P0057-ENDDA'.
"WRITE IDSN-ENDDA TO BDCDATA-FVAL DD/MM/YYYY.
CONCATENATE IDSN-ENDDA+6(2) '.' IDSN-ENDDA+4(2) '.' IDSN-ENDDA+0(4) INTO BDCDATA-FVAL.
APPEND BDCDATA.
**Wage Type
CLEAR BDCDATA.
BDCDATA-FNAM = 'P0057-LGART'.
BDCDATA-FVAL = IDSN-LGART.
APPEND BDCDATA.
**Membership Fee
CLEAR BDCDATA.
BDCDATA-FNAM = 'Q0057-BETRG'.
BDCDATA-FVAL = IDSN-BETRG.
APPEND BDCDATA.
**Number
CLEAR BDCDATA.
BDCDATA-FNAM = 'P0057-ANZHL'.
BDCDATA-FVAL = IDSN-ANZHL.
APPEND BDCDATA.
**Unit
CLEAR BDCDATA.
BDCDATA-FNAM = 'Q0057-EITXT'.
BDCDATA-FVAL = IDSN-ZEINH.
APPEND BDCDATA.
**Payee Key
CLEAR BDCDATA.
BDCDATA-FNAM = 'P0057-EMFSL'.
BDCDATA-FVAL = IDSN-EMFSL.
APPEND BDCDATA.
"**Membership Number
" CLEAR BDCDATA.
" BDCDATA-FNAM = 'P0057-MTGLN'.
" BDCDATA-FVAL = IDSN-MTGLN.
" APPEND BDCDATA.
CLEAR BDCDATA.
BDCDATA-FNAM = 'BDC_OKCODE'.
BDCDATA-FVAL = '=UPD'.
APPEND BDCDATA.
ENDFORM. " d2000
*&---------------------------------------------------------------------*
*& Form print_hashing_summary
*&---------------------------------------------------------------------*
FORM PRINT_HASHING_SUMMARY.
SKIP 3.
WRITE: /20 'Accepted Records' COLOR COL_TOTAL,
40 'Rejected Records' COLOR COL_TOTAL,
60 ' Total Records' COLOR COL_TOTAL.
WRITE: /20 '----------------', 40 '----------------',
60 '----------------'.
WRITE: /02 'Head Count :',
20(13) HEAD_COUNT, 40(13) HEAD_COUNT_RJ,
60(13) HEAD_COUNT_TT.
WRITE: /02 'Hash Pernr :',
20(13) HASH_PERNR, 40(13) HASH_PERNR_RJ,
60(13) HASH_PERNR_TT.
SKIP 2.
ENDFORM. " print_hashing_summary
*&---------------------------------------------------------------------*
*& Form validate_pernr
*&---------------------------------------------------------------------*
FORM VALIDATE_PERNR.
DATA: RETCD, RETCD1.
ERROR_FLAG = SPACE.
**CHECK PERNR - PERSONNEL NUMBER
PERFORM CHECK_PERNR USING PERNR1 RETCD.
IF RETCD NE 0.
ERROR_FLAG = 'X'.
MOVE-CORRESPONDING IDSN TO ERRTAB.
ERRTAB-NUMREC = NUMREC.
ERRTAB-MESSG = 'PF number not found'.
APPEND ERRTAB. CLEAR ERRTAB.
ENDIF.
CHECK RETCD EQ 0.
" IF IDSN-ICNUM+6(1) EQ '-' AND IDSN-ICNUM+9(1) EQ '-'.
"****Subtype 'IC'
" ICTYPE = '01'.
" CONCATENATE IDSN-ICNUM+0(6) IDSN-ICNUM+7(2) IDSN-ICNUM+10(4)
" INTO BK_ICNUM.
" ELSE.
"****Subtype 'Passport'
" ICTYPE = '02'.
" MOVE IDSN-ICNUM TO BK_ICNUM.
" ENDIF.
" PERFORM VERIFY_DOCID USING PERNR1 ICTYPE BK_ICNUM RETCD1.
" IF RETCD1 NE 0.
" ERROR_FLAG = 'X'.
" MOVE-CORRESPONDING IDSN TO ERRTAB.
" ERRTAB-NUMREC = NUMREC.
" ERRTAB-MESSG = 'IC/Passport No. not found'.
" APPEND ERRTAB. CLEAR ERRTAB.
" ENDIF.
ENDFORM. " validate_pernr
FORM CHECK_PERNR USING PPERNR PRETCD.
**Check from Infortype 0000 (Action)
SELECT * FROM PA0000 WHERE PERNR EQ PPERNR. EXIT. ENDSELECT.
PRETCD = SY-SUBRC.
IF SY-SUBRC NE 0. EXIT. ENDIF.
**Check from Infotype 0001 (Organizational Assignment)
SELECT * FROM PA0001 WHERE PERNR EQ PPERNR. EXIT. ENDSELECT.
PRETCD = SY-SUBRC.
ENDFORM.
"--------------------------------------------------------------------------------------------------------------
"--------------------------------------------------------------------------------------------------------------
***INCLUDE ZPULRIA001 .
*----------------------------------------------------------------------
* Report header
*----------------------------------------------------------------------
FORM WRITE_HEADER USING VALUE(RBUKRS) VALUE(RTYPE) VALUE(RDATE)
VALUE(RTITL2) VALUE(RBRHCD) VALUE(RBRH)
RINDC.
DATA: CBUTXT(25), TITLEN TYPE I, OUTDATE(10), REPDATE(10).
DATA: BUKLEN TYPE I.
STATICS: CPAGNO(4).
IF RINDC = 'X'. CPAGNO = 0. RINDC = SPACE. ENDIF.
ADD 1 TO CPAGNO.
IF RBUKRS = 'G'.
CBUTXT = 'MAYBANK GROUP'.
ELSE.
PERFORM RE001 USING RBUKRS CBUTXT.
ENDIF.
CALL FUNCTION 'Z_CONV_DATE_TO_SLASH_FMT'
EXPORTING
IDATE = SY-DATUM
INDICATOR = '1'
IMPORTING
ODATE = OUTDATE.
CALL FUNCTION 'Z_CONV_DATE_TO_SLASH_FMT'
EXPORTING
IDATE = RDATE
INDICATOR = '1'
IMPORTING
ODATE = REPDATE.
* Line 1
TRANSLATE CBUTXT TO UPPER CASE.
TRANSLATE SY-TITLE TO UPPER CASE.
BUKLEN = STRLEN( CBUTXT ). BUKLEN = 32 - BUKLEN. BUKLEN = BUKLEN / 2.
TITLEN = STRLEN( SY-TITLE ). TITLEN = 69 - TITLEN.TITLEN = TITLEN / 2.
TITLEN = TITLEN + 34 - BUKLEN.
WRITE:/1 '1',2 CBUTXT.
WRITE AT TITLEN SY-TITLE.
* cpagno = sy-pagno. shift cpagno right deleting trailing space.
SHIFT CPAGNO RIGHT DELETING TRAILING SPACE.
WRITE:100 'RUN DATE :', 112 OUTDATE, 122 'PAGE:', 127 CPAGNO.
* Line 2
IF RTYPE = 'B'.
WRITE:/2 'BRANCH', 9 RBRHCD, 15 RBRH.
ELSEIF RTYPE = 'P'.
WRITE:/2 'P.AREA' , 9 RBRHCD, 17 RBRH.
ELSEIF RTYPE = 'R'.
WRITE:/2 'REGION' , 9 RBRHCD, 17 RBRH.
ELSEIF RTYPE = 'N'. WRITE /2 ' '. "Blank - don't have to display
ELSE.
WRITE:/2 'DEPT' , 9 RBRHCD, 17 RBRH.
ENDIF.
IF NOT RTITL2 IS INITIAL.
BUKLEN = STRLEN( RBRH ). BUKLEN = 36 - BUKLEN. BUKLEN = BUKLEN / 2.
TITLEN = STRLEN( RTITL2 ). TITLEN = 52 - TITLEN.TITLEN = TITLEN / 2.
TITLEN = TITLEN + 50 - BUKLEN.
WRITE AT TITLEN RTITL2.
WRITE: 100 'REPORT NO :', 115 SY-REPID.
WRITE:/51 'REPORT DATE :', 65 REPDATE.
ELSE.
WRITE: 51 'REPORT DATE :', 65 REPDATE.
WRITE: 100 'REPORT NO :', 115 SY-REPID.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------
* Read T001 to get company description
*----------------------------------------------------------------------
FORM RE001 USING VALUE(TBUKRS) TBUTXT.
CLEAR: TBUTXT, T001.
SELECT SINGLE * FROM T001 WHERE BUKRS EQ TBUKRS.
IF SY-SUBRC EQ 0. TBUTXT = T001-BUTXT. ENDIF.
ENDFORM.
*----------------------------------------------------------------------
* Report footer
*----------------------------------------------------------------------
FORM WRITE_FOOTER.
SKIP 2.
WRITE:/2 '*** END OF REPORT ***'.
ENDFORM.
INCLUDE ZPYLBMA128_VARIABLES.
"SELECTION SCREEN STARTS=========================
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN: SKIP 1.
PARAMETERS : DSN LIKE FILENAME-FILEEXTERN DEFAULT '/home/HRD/UL/test zakat.prn'.
PARAMETERS : MAPNAME DEFAULT SY-UNAME LIKE RPTAXXXX-MAP_NAME.
PARAMETERS : TEST_RUN TYPE C AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK B1.
"SELECTION SCREEN ENDS=========================
"INITIALIZATION STARTS=========================
INITIALIZATION.
DSN+6(3) = SY-SYSID.
REPNAME = SY-REPID.
"INITIALIZATION ENDS=========================
"AT SELECTION-SCREEN CHECKING STARTS=========================
AT SELECTION-SCREEN ON DSN.
CLEAR: IDSN.
TRY.
OPEN DATASET DSN FOR INPUT IN TEXT MODE ENCODING NON-UNICODE. "UNI-CONV
IF SY-SUBRC NE 0.
MESSAGE E899(5A) WITH 'Error in opening file:'(E01) DSN.
ENDIF.
CATCH CX_SY_FILE_OPEN.
CLOSE DATASET DSN.
OPEN DATASET DSN FOR INPUT IN TEXT MODE ENCODING NON-UNICODE. "UNI-CONV
IF SY-SUBRC NE 0.
MESSAGE E899(5A) WITH 'DATA DOES NOT EXITS:'(E01) DSN.
ENDIF.
ENDTRY.
AT SELECTION-SCREEN.
IF TEST_RUN NE 'X'.
CALL FUNCTION 'HR_MAPNAME_VERIFY'
EXPORTING
MAPNAME = MAPNAME
REPORTNAME = REPNAME
IMPORTING
MAPNAME = MAPNAME.
ENDIF.
"AT SELECTION-SCREEN CHECKING ENDS=========================
"START-OF-SELECTION=========================
START-OF-SELECTION.
"BDC OPEN GROUP
IF TEST_RUN NE 'X'.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = MAPNAME
KEEP = 'X'
USER = SY-UNAME.
ENDIF.
**TO READ DATA FROM UNIX FILE
DO.
READ DATASET DSN INTO IDSN.
IF SY-SUBRC EQ 0.
"WRITE IDSN-SUBTY LEFT-JUSTIFIED TO IDSN-SUBTY.
CONDENSE IDSN-SUBTY.
APPEND IDSN.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET DSN.
**TO PROCESS RECORD BY RECORD
DESCRIBE TABLE IDSN LINES ILINE.
CHECK ILINE > 0.
CLEAR: ITAB[], ERRTAB[]."errtab AND ERROR_FLAG ARE not used as there is no checking as yet!
LOOP AT IDSN.
CLEAR: ERRTAB.
MOVE: IDSN-PERNR TO PERNR1.
ADD 1 TO NUMREC. "Current Record (Row) Number
****To validate PF No & IC/Passport No
PERFORM VALIDATE_PERNR.
****To assign data to ITAB
IF ERROR_FLAG <> 'X'.
PERFORM ASSIGN_DATA.
ENDIF.
IF ERROR_FLAG <> 'X'.
IF TEST_RUN NE 'X'.
PERFORM FILL-DYNPROS.
ENDIF.
******HASHING FOR ACCEPTED RECORDS
ADD: 1 TO HEAD_COUNT,
PERNR1 TO HASH_PERNR.
APPEND ITAB.
ELSE.
******HASHING FOR REJECTED RECORDS
ADD: 1 TO HEAD_COUNT_RJ,
PERNR1 TO HASH_PERNR_RJ.
ENDIF.
****HASHING FOR ALL RECORDS
ADD: 1 TO HEAD_COUNT_TT,
PERNR1 TO HASH_PERNR_TT.
ENDLOOP.
"**Close BDC session
IF TEST_RUN NE 'X'.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
FORMAT COLOR COL_GROUP ON INTENSIFIED OFF.
WRITE:/ 'Batch input session', MAPNAME, 'created'.
FORMAT COLOR COL_GROUP OFF INTENSIFIED OFF.
SKIP 2.
ENDIF.
**PRINT HASHING SUMMARY
PERFORM PRINT_HASHING_SUMMARY.
WRITE:/ 'Record(s) with errors'.
WRITE:/ '---------------------'.
WRITE:/2(10) 'Record no.' , 14(60)'Error' , 76(10) 'PF No', 88(11) 'Member Type', 101(4) 'Wage Type',
107(10) 'Start Date' , 119(8) 'End Date' , 129(14) 'Membership Fee' ,
145(10) ' Number' , 157(20) 'Unit' , 179(9) 'Payee Key'.
WRITE:/2(10) '----------' , 14(60)'-----' , 76(10) '-----', 88(11) '-----------', 101(4) '---------',
107(10) '----------' , 119(8) '--------' , 129(14) '--------------' ,
145(10) ' ------' , 157(20) '----' , 179(9) '---------'.
LOOP AT ERRTAB.
WRITE:/2(10) ERRTAB-NUMREC , 14(60) ERRTAB-MESSG, 76(10) ERRTAB-PERNR, 88(11) ITAB-SUBTY, 101(4) ITAB-LGART,
107(10) ITAB-BEGDA, 119(8) ITAB-ENDDA, 129(14) ITAB-BETRG,
145(10) ITAB-ANZHL, 157(20) ITAB-ZEINH, 179(9) ITAB-EMFSL.
"itab-icnum, "itab-mtgln.
ENDLOOP.
END-OF-SELECTION.
"END-OF-SELECTION=========================
"======================REPORTS STARTS
**PRINT FOOTER
PERFORM WRITE_FOOTER.
********************* REPORT HEADER *******************************
TOP-OF-PAGE.
PAGENO = ' '.
PERFORM WRITE_HEADER USING '0001' 'M' SY-DATUM
SPACE '100213' ' HRIS, HRD' PAGENO.
SKIP 2.
INCLUDE ZPULRIA001.
"======================REPORTS ENDS
INCLUDE ZPYLBMA128_FORMS.
"--------------------------------------------------------------------------------------------------------------
"--------------------------------------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include ZPYLBMA128_VARAIBLE
*&---------------------------------------------------------------------*
"DATA DECLARATION STARTS=========================
TABLES: PA0000, "HR Master Record: Infotype 0000 (Actions)
PA0001, "HR Master Record: Infotype 0001 (Org. Assignment)
PA0002, "HR Master Record: Infotype 0002 (Personal Data)
PA0185, "HR Master Record: Infotype 0185 [Identification] (SG)
T591S, "Subtype Texts (for Member Type Text)
T512T, "Wage Type Texts
T521B, "Payee Keys
T001, "Company Codes
SSCRFIELDS. "Fields on selection screens
** Table to hold all data row from flat file
DATA: BEGIN OF IDSN OCCURS 0,
PERNR(08) TYPE C, "PF No.
SUBTY(04) TYPE C, "Member Type (Sub-Type)
LGART(04) TYPE C, "Wage Type
BEGDA(08) TYPE C, "Start Date
ENDDA(08) TYPE C, "End Date
BETRG(13) TYPE C, "Membership Fee / Amount
ANZHL(10) TYPE C, "Number
ZEINH(20) TYPE C, "Unit
EMFSL(08) TYPE C, "Payee Key
" MTGLN(20) TYPE C, "Membership Number
" ICNUM(30) TYPE C, "New IC
END OF IDSN.
** Table to hold success data
DATA: BEGIN OF ITAB OCCURS 0,
PERNR LIKE P0000-PERNR, "PF No.
SUBTY LIKE RP50G-SUBTY, "Member Type (Sub-Type)
LGART LIKE P0057-LGART, "Wage Type
LGTXT LIKE T512T-LGTXT, "Wage Type Text*
BEGDA(10) TYPE C, "Start Date
ENDDA(10) TYPE C, "End Date
BETRG LIKE Q0057-BETRG, "Membership Fee
ANZHL LIKE P0057-ANZHL, "Number
ZEINH LIKE Q0057-EITXT, "Unit
EMFSL LIKE P0057-EMFSL, "Payee Key
EMFNA LIKE T521B-EMFNA, "Payee Key Text*
" STEXT LIKE T591S-STEXT, "Member Type Text
" MTGLN LIKE P0057-MTGLN, "Membership Number
" ICNUM LIKE P0185-ICNUM, "New IC
" CNAME LIKE P0002-CNAME, "Staff Name
END OF ITAB.
** Table to hold error data and error message
DATA: BEGIN OF ERRTAB OCCURS 0,
NUMREC TYPE I,
MESSG(60) TYPE C.
INCLUDE STRUCTURE ITAB.
DATA: END OF ERRTAB.
* Table for Batch Input
DATA: BEGIN OF BDCDATA OCCURS 20.
INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDCDATA.
DATA: HEAD_COUNT TYPE I,
HEAD_COUNT_RJ TYPE I,
HEAD_COUNT_TT TYPE I,
HASH_PERNR TYPE P,
HASH_PERNR_RJ TYPE P,
HASH_PERNR_TT TYPE P.
DATA: ILINE TYPE I,
NUMREC TYPE I, "Record (Row) Number
ERROR_FLAG TYPE C, "Error Flag
" BK_ICNUM(30) TYPE C, "Unformatted IC Number
PAGENO(1) TYPE C, "Page Number (Report)
" TDATE(10) TYPE C, "To hold formatted date
PERNR1 LIKE P0000-PERNR. "Personnel Number
" ICTYPE LIKE P0185-ICTYP, "Document Type
" STARTDT LIKE SY-DATUM. "Hiring Start Date
DATA: REPNAME LIKE SY-REPID.
"DATA DECLARATION ENDS=========================
"--------------------------------------------------------------------------------------------------------------
"--------------------------------------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include ZPYLBMA128_FORMS
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form assign_data
*&---------------------------------------------------------------------*
FORM ASSIGN_DATA.
CLEAR ERROR_FLAG.
MOVE-CORRESPONDING IDSN TO ITAB.
"**Retrieve Staff Name (Infotype 0002)
" SELECT SINGLE * FROM PA0002 WHERE PERNR EQ ITAB-PERNR.
" IF SY-SUBRC EQ 0.
" ITAB-CNAME = PA0002-CNAME. "Store Staff Name
" WRITE:/ PA0002-CNAME.
" ELSE.
" ERROR_FLAG = 'X'.
" MOVE-CORRESPONDING IDSN TO ERRTAB.
" ERRTAB-NUMREC = NUMREC.
" ERRTAB-MESSG = 'Staff Name not found'.
" APPEND ERRTAB. CLEAR ERRTAB.
" ENDIF.
"**Retrieve Member Type Text
" IF ERROR_FLAG NE 'X'.
" SELECT SINGLE * FROM T591S WHERE SPRSL EQ 'EN'
" AND INFTY = '0057'
" AND SUBTY = ITAB-SUBTY.
" IF SY-SUBRC EQ 0.
" ITAB-STEXT = T591S-STEXT.
" ELSE.
" ERROR_FLAG = 'X'.
" MOVE-CORRESPONDING IDSN TO ERRTAB.
" ERRTAB-NUMREC = NUMREC.
" ERRTAB-MESSG = 'Member Type not found'.
" APPEND ERRTAB. CLEAR ERRTAB.
" ENDIF.
" ENDIF.
"**Wage Type Text
" IF ERROR_FLAG NE 'X'.
" SELECT SINGLE * FROM T512T WHERE SPRSL EQ 'EN'
" AND MOLGA EQ '14'
" AND LGART = ITAB-LGART.
" IF SY-SUBRC EQ 0.
" ITAB-LGTXT = T512T-LGTXT.
" ELSE.
" ERROR_FLAG = 'X'.
" MOVE-CORRESPONDING IDSN TO ERRTAB.
" ERRTAB-NUMREC = NUMREC.
" ERRTAB-MESSG = 'Wage Type not found'.
" APPEND ERRTAB. CLEAR ERRTAB.
" ENDIF.
" ENDIF.
"**Payee Key Text
" IF ERROR_FLAG NE 'X'.
" SELECT * FROM T521B INTO TABLE WA_T521B WHERE EMFSL EQ ITAB-EMFSL.
" IF SY-SUBRC EQ 0.
" SORT WA_T521B BY ENDDA DESCENDING.
" LOOP AT WA_T521B.
" ITAB-EMFNA = WA_T521B-EMFNA. EXIT.
" ENDLOOP.
" ELSE.
" ERROR_FLAG = 'X'.
" MOVE-CORRESPONDING IDSN TO ERRTAB.
" ERRTAB-NUMREC = NUMREC.
" ERRTAB-MESSG = 'Wage Type not found'.
" APPEND ERRTAB. CLEAR ERRTAB.
" ENDIF.
" ENDIF.
ENDFORM. " assign_data
*&---------------------------------------------------------------------*
*& Form FILL-DYNPROS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL-DYNPROS .
PERFORM D1000.
PERFORM D2000.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'PA30'
TABLES
DYNPROTAB = BDCDATA.
ENDFORM. " FILL-DYNPROS
FORM D1000.
REFRESH BDCDATA.
CLEAR BDCDATA.
BDCDATA-PROGRAM = 'SAPMP50A'.
BDCDATA-DYNPRO = '1000'.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
**PF NO.
CLEAR BDCDATA.
BDCDATA-FNAM = 'RP50G-PERNR'.
BDCDATA-FVAL = IDSN-PERNR.
APPEND BDCDATA.
**INFOTYPE 0008
CLEAR BDCDATA.
BDCDATA-FNAM = 'RP50G-CHOIC'.
BDCDATA-FVAL = '0057'.
APPEND BDCDATA.
**SUBTYPE (Member Type)
CLEAR BDCDATA.
BDCDATA-FNAM = 'RP50G-SUBTY'.
BDCDATA-FVAL = IDSN-SUBTY.
APPEND BDCDATA.
CLEAR BDCDATA.
BDCDATA-FNAM = 'BDC_OKCODE'.
BDCDATA-FVAL = '=INS'.
APPEND BDCDATA.
ENDFORM. " d1000
*---------------------------------------------------------------------*
* FORM D2000
*---------------------------------------------------------------------*
FORM D2000.
CLEAR BDCDATA.
BDCDATA-PROGRAM = 'MP005700'.
BDCDATA-DYNPRO = '2000'.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
**START DATE
CLEAR BDCDATA.
BDCDATA-FNAM = 'P0057-BEGDA'.
"WRITE IDSN-BEGDA TO BDCDATA-FVAL DD/MM/YYYY.
CONCATENATE IDSN-BEGDA+6(2) '.' IDSN-BEGDA+4(2) '.' IDSN-BEGDA+0(4) INTO BDCDATA-FVAL.
APPEND BDCDATA.
**END DATE
CLEAR BDCDATA.
BDCDATA-FNAM = 'P0057-ENDDA'.
"WRITE IDSN-ENDDA TO BDCDATA-FVAL DD/MM/YYYY.
CONCATENATE IDSN-ENDDA+6(2) '.' IDSN-ENDDA+4(2) '.' IDSN-ENDDA+0(4) INTO BDCDATA-FVAL.
APPEND BDCDATA.
**Wage Type
CLEAR BDCDATA.
BDCDATA-FNAM = 'P0057-LGART'.
BDCDATA-FVAL = IDSN-LGART.
APPEND BDCDATA.
**Membership Fee
CLEAR BDCDATA.
BDCDATA-FNAM = 'Q0057-BETRG'.
BDCDATA-FVAL = IDSN-BETRG.
APPEND BDCDATA.
**Number
CLEAR BDCDATA.
BDCDATA-FNAM = 'P0057-ANZHL'.
BDCDATA-FVAL = IDSN-ANZHL.
APPEND BDCDATA.
**Unit
CLEAR BDCDATA.
BDCDATA-FNAM = 'Q0057-EITXT'.
BDCDATA-FVAL = IDSN-ZEINH.
APPEND BDCDATA.
**Payee Key
CLEAR BDCDATA.
BDCDATA-FNAM = 'P0057-EMFSL'.
BDCDATA-FVAL = IDSN-EMFSL.
APPEND BDCDATA.
"**Membership Number
" CLEAR BDCDATA.
" BDCDATA-FNAM = 'P0057-MTGLN'.
" BDCDATA-FVAL = IDSN-MTGLN.
" APPEND BDCDATA.
CLEAR BDCDATA.
BDCDATA-FNAM = 'BDC_OKCODE'.
BDCDATA-FVAL = '=UPD'.
APPEND BDCDATA.
ENDFORM. " d2000
*&---------------------------------------------------------------------*
*& Form print_hashing_summary
*&---------------------------------------------------------------------*
FORM PRINT_HASHING_SUMMARY.
SKIP 3.
WRITE: /20 'Accepted Records' COLOR COL_TOTAL,
40 'Rejected Records' COLOR COL_TOTAL,
60 ' Total Records' COLOR COL_TOTAL.
WRITE: /20 '----------------', 40 '----------------',
60 '----------------'.
WRITE: /02 'Head Count :',
20(13) HEAD_COUNT, 40(13) HEAD_COUNT_RJ,
60(13) HEAD_COUNT_TT.
WRITE: /02 'Hash Pernr :',
20(13) HASH_PERNR, 40(13) HASH_PERNR_RJ,
60(13) HASH_PERNR_TT.
SKIP 2.
ENDFORM. " print_hashing_summary
*&---------------------------------------------------------------------*
*& Form validate_pernr
*&---------------------------------------------------------------------*
FORM VALIDATE_PERNR.
DATA: RETCD, RETCD1.
ERROR_FLAG = SPACE.
**CHECK PERNR - PERSONNEL NUMBER
PERFORM CHECK_PERNR USING PERNR1 RETCD.
IF RETCD NE 0.
ERROR_FLAG = 'X'.
MOVE-CORRESPONDING IDSN TO ERRTAB.
ERRTAB-NUMREC = NUMREC.
ERRTAB-MESSG = 'PF number not found'.
APPEND ERRTAB. CLEAR ERRTAB.
ENDIF.
CHECK RETCD EQ 0.
" IF IDSN-ICNUM+6(1) EQ '-' AND IDSN-ICNUM+9(1) EQ '-'.
"****Subtype 'IC'
" ICTYPE = '01'.
" CONCATENATE IDSN-ICNUM+0(6) IDSN-ICNUM+7(2) IDSN-ICNUM+10(4)
" INTO BK_ICNUM.
" ELSE.
"****Subtype 'Passport'
" ICTYPE = '02'.
" MOVE IDSN-ICNUM TO BK_ICNUM.
" ENDIF.
" PERFORM VERIFY_DOCID USING PERNR1 ICTYPE BK_ICNUM RETCD1.
" IF RETCD1 NE 0.
" ERROR_FLAG = 'X'.
" MOVE-CORRESPONDING IDSN TO ERRTAB.
" ERRTAB-NUMREC = NUMREC.
" ERRTAB-MESSG = 'IC/Passport No. not found'.
" APPEND ERRTAB. CLEAR ERRTAB.
" ENDIF.
ENDFORM. " validate_pernr
FORM CHECK_PERNR USING PPERNR PRETCD.
**Check from Infortype 0000 (Action)
SELECT * FROM PA0000 WHERE PERNR EQ PPERNR. EXIT. ENDSELECT.
PRETCD = SY-SUBRC.
IF SY-SUBRC NE 0. EXIT. ENDIF.
**Check from Infotype 0001 (Organizational Assignment)
SELECT * FROM PA0001 WHERE PERNR EQ PPERNR. EXIT. ENDSELECT.
PRETCD = SY-SUBRC.
ENDFORM.
"--------------------------------------------------------------------------------------------------------------
"--------------------------------------------------------------------------------------------------------------
***INCLUDE ZPULRIA001 .
*----------------------------------------------------------------------
* Report header
*----------------------------------------------------------------------
FORM WRITE_HEADER USING VALUE(RBUKRS) VALUE(RTYPE) VALUE(RDATE)
VALUE(RTITL2) VALUE(RBRHCD) VALUE(RBRH)
RINDC.
DATA: CBUTXT(25), TITLEN TYPE I, OUTDATE(10), REPDATE(10).
DATA: BUKLEN TYPE I.
STATICS: CPAGNO(4).
IF RINDC = 'X'. CPAGNO = 0. RINDC = SPACE. ENDIF.
ADD 1 TO CPAGNO.
IF RBUKRS = 'G'.
CBUTXT = 'MAYBANK GROUP'.
ELSE.
PERFORM RE001 USING RBUKRS CBUTXT.
ENDIF.
CALL FUNCTION 'Z_CONV_DATE_TO_SLASH_FMT'
EXPORTING
IDATE = SY-DATUM
INDICATOR = '1'
IMPORTING
ODATE = OUTDATE.
CALL FUNCTION 'Z_CONV_DATE_TO_SLASH_FMT'
EXPORTING
IDATE = RDATE
INDICATOR = '1'
IMPORTING
ODATE = REPDATE.
* Line 1
TRANSLATE CBUTXT TO UPPER CASE.
TRANSLATE SY-TITLE TO UPPER CASE.
BUKLEN = STRLEN( CBUTXT ). BUKLEN = 32 - BUKLEN. BUKLEN = BUKLEN / 2.
TITLEN = STRLEN( SY-TITLE ). TITLEN = 69 - TITLEN.TITLEN = TITLEN / 2.
TITLEN = TITLEN + 34 - BUKLEN.
WRITE:/1 '1',2 CBUTXT.
WRITE AT TITLEN SY-TITLE.
* cpagno = sy-pagno. shift cpagno right deleting trailing space.
SHIFT CPAGNO RIGHT DELETING TRAILING SPACE.
WRITE:100 'RUN DATE :', 112 OUTDATE, 122 'PAGE:', 127 CPAGNO.
* Line 2
IF RTYPE = 'B'.
WRITE:/2 'BRANCH', 9 RBRHCD, 15 RBRH.
ELSEIF RTYPE = 'P'.
WRITE:/2 'P.AREA' , 9 RBRHCD, 17 RBRH.
ELSEIF RTYPE = 'R'.
WRITE:/2 'REGION' , 9 RBRHCD, 17 RBRH.
ELSEIF RTYPE = 'N'. WRITE /2 ' '. "Blank - don't have to display
ELSE.
WRITE:/2 'DEPT' , 9 RBRHCD, 17 RBRH.
ENDIF.
IF NOT RTITL2 IS INITIAL.
BUKLEN = STRLEN( RBRH ). BUKLEN = 36 - BUKLEN. BUKLEN = BUKLEN / 2.
TITLEN = STRLEN( RTITL2 ). TITLEN = 52 - TITLEN.TITLEN = TITLEN / 2.
TITLEN = TITLEN + 50 - BUKLEN.
WRITE AT TITLEN RTITL2.
WRITE: 100 'REPORT NO :', 115 SY-REPID.
WRITE:/51 'REPORT DATE :', 65 REPDATE.
ELSE.
WRITE: 51 'REPORT DATE :', 65 REPDATE.
WRITE: 100 'REPORT NO :', 115 SY-REPID.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------
* Read T001 to get company description
*----------------------------------------------------------------------
FORM RE001 USING VALUE(TBUKRS) TBUTXT.
CLEAR: TBUTXT, T001.
SELECT SINGLE * FROM T001 WHERE BUKRS EQ TBUKRS.
IF SY-SUBRC EQ 0. TBUTXT = T001-BUTXT. ENDIF.
ENDFORM.
*----------------------------------------------------------------------
* Report footer
*----------------------------------------------------------------------
FORM WRITE_FOOTER.
SKIP 2.
WRITE:/2 '*** END OF REPORT ***'.
ENDFORM.
Post a Comment