SAMPLE : how to create a alv report and a interactive button
12:41 AMREPORT ZSOLRMA047.
TYPE-POOLS: SLIS.
TABLES: PERNR, ZIT0762, PA0762, PA0761.
INFOTYPES : 0761, 0762, 9033, 0002, 0001.
*--------------------------------------------------------------------*
* Types
*--------------------------------------------------------------------*
TYPES: BEGIN OF TY_REPORT,
SKIP(1) TYPE C,
SEQNO TYPE I,
BUTXT TYPE T001-BUTXT, " Company name
PERNR TYPE P0761-PERNR, " PF No.
CNAME TYPE P0002-CNAME, " Name 2012 July 06
EXEDT TYPE P0762-BEGDA, " Exercise Date
CPLAN TYPE P0762-CPLAN, " Compensation Plan
CITEM TYPE P0762-CPLAN, " review item
EXENO TYPE P0762-EXENO, " No. of Shares Exercised
EXPRI TYPE P0762-EXPRI, " Option Price
CHKNO TYPE P0762-CHKNO, " Bank Draft/Cashier#s Order
EXETC TYPE P0762-EXETC, " Total Cost
PA0762 TYPE TEXT12, " PA0762 Status
ZIT0762 TYPE TEXT12, " ZIT0762 Status
REMARK TYPE C LENGTH 50, " Remarks
OBJPS TYPE PA0762-OBJPS,
* EXENO TYPE PA0762-EXENO,
SUBTY TYPE PA0762-SUBTY,
SPRPS TYPE PA0762-SPRPS,
BEGDA TYPE PA0762-BEGDA,
ENDDA TYPE PA0762-ENDDA,
SEQNR TYPE PA0762-SEQNR,
EXEON TYPE PA0762-EXEON,
EXEST TYPE PA0762-EXEST,
" gradt TYPE p0761-begda, " Grant Date
" begda TYPE p0762-begda, " Exercise Date
" pa0761 TYPE text12, " PA0761 Status
" cdsac_stat TYPE c LENGTH 50, " CDS Account Status
END OF TY_REPORT.
*--------------------------------------------------------------------*
* Variables
*--------------------------------------------------------------------*
DATA: T_REPORT TYPE STANDARD TABLE OF TY_REPORT WITH HEADER LINE INITIAL SIZE 0,
R_REPORT LIKE LINE OF T_REPORT,
R_P0762 TYPE P0762,
G_ERROR TYPE C,
R_ZIT0762 TYPE ZIT0762,
T_HEADER TYPE SLIS_T_LISTHEADER,
R_HEADER TYPE SLIS_LISTHEADER,
G_TOTAL_REC TYPE I,
G_ERROR_REC TYPE I,
G_EXPRI TYPE ECM_EXPRI,
" g_balance TYPE p0761-grano,
GV_PROCEED TYPE CHAR1,
GV_PA0762_BEGDA TYPE PA0762-BEGDA.
*--------------------------------------------------------------------*
* ALV
*--------------------------------------------------------------------*
DATA: R_FRAME TYPE SLIS_LAYOUT_ALV,
T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
T_SORT TYPE SLIS_T_SORTINFO_ALV,
T_EVENT TYPE SLIS_T_EVENT,
R_EVENT TYPE SLIS_ALV_EVENT,
G_REPID TYPE SY-REPID.
CONSTANTS: C_SUCCESSFUL TYPE TEXT12 VALUE 'Successful',
C_UNSUCCESSFUL TYPE TEXT12 VALUE 'Unsuccessful',
C_CHEQUE_NOT_RECEIVED TYPE CHAR2 VALUE '09',
C_PENDING_PAYMENT TYPE CHAR2 VALUE '02'.
*--------------------------------------------------------------------*
* Selection Screen
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK A1 WITH FRAME TITLE TEXT-001.
*SELECT-OPTIONS: s_rsu FOR pa0762-cplan NO INTERVALS, "RSU / SRSU Plan
* s_gradt FOR pa0761-begda NO INTERVALS NO-EXTENSION. "Grant Date
PARAMETERS: P_PRCDT TYPE BEGDA DEFAULT SY-DATUM OBLIGATORY. "Processing date
PARAMETERS: P_DAYS TYPE INTEGER DEFAULT 14 OBLIGATORY. "Number of days
SELECTION-SCREEN SKIP 1.
PARAMETERS: P_TEST TYPE C AS CHECKBOX DEFAULT 'X'. "Test Run
SELECTION-SCREEN END OF BLOCK A1.
*--------------------------------------------------------------------*
* Initialization
*--------------------------------------------------------------------*
INITIALIZATION.
G_REPID = SY-REPID.
*--------------------------------------------------------------------*
* START-OF-SELECTION.
*--------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM GET_EXERCISE_START_DATE CHANGING GV_PA0762_BEGDA.
GET PERNR.
CLEAR GV_PROCEED.
PERFORM F_VALIDATE_9033 CHANGING GV_PROCEED.
CLEAR: R_P0762, R_REPORT, P0762.
CASE GV_PROCEED.
WHEN 'X'.
PROVIDE * FROM P0762 BETWEEN GV_PA0762_BEGDA AND GV_PA0762_BEGDA."p_prcdt.
CASE P0762-EXEST. "Exercise Status
WHEN '02'. "Pending Payment
PERFORM PREPARE_P0762.
PERFORM PREPARE_REPORT.
R_REPORT-SEQNO = G_TOTAL_REC.
APPEND R_REPORT TO T_REPORT.
ENDCASE.
ENDPROVIDE.
ENDCASE.
END-OF-SELECTION.
READ TABLE T_REPORT INTO R_REPORT INDEX 1.
IF SY-SUBRC = 0.
PERFORM DISPLAY_REPORT.
ELSE.
MESSAGE S002(SY) WITH 'No record found'.
EXIT.
ENDIF.
*&---------------------------------------------------------------------*
*& Form prepare_p0762
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PREPARE_P0762.
CLEAR: G_EXPRI, R_P0762.
MOVE-CORRESPONDING P0762 TO R_P0762.
R_P0762-AEDTM = SY-DATUM.
R_P0762-UNAME = SY-UNAME.
R_P0762-BEGDA = P0762-BEGDA.
R_P0762-CPLAN = P0762-CPLAN.
IF P0762-EXPRI EQ '0.00' OR P0762-EXPRI IS INITIAL.
SELECT * FROM PA0761 WHERE CPLAN = P0762-CPLAN AND OBJPS = P0762-OBJPS AND PERNR = P0762-PERNR.
SELECT EXPRI FROM T71LTI03 INTO G_EXPRI WHERE CPLAN EQ P0762-CPLAN
AND BEGDA LE P0761-GRADT AND ENDDA GE P0761-GRADT.
ENDSELECT.
EXIT.
ENDSELECT.
ELSE.
G_EXPRI = R_P0762-EXPRI = P0762-EXPRI.
ENDIF.
R_P0762-CITEM = P0762-CITEM.
R_P0762-EXENO = P0762-EXENO.
R_P0762-CHKNO = P0762-CHKNO.
R_P0762-EXETC = P0762-EXETC.
ENDFORM. " prepare_p0762
FORM PREPARE_P0762_REPORT.
CLEAR: G_EXPRI, R_P0762.
SELECT SINGLE * FROM PA0762 WHERE PERNR EQ T_REPORT-PERNR AND
SUBTY EQ T_REPORT-SUBTY AND
OBJPS EQ T_REPORT-OBJPS AND
ENDDA EQ T_REPORT-ENDDA AND
SEQNR EQ T_REPORT-SEQNR.
MOVE-CORRESPONDING PA0762 TO R_P0762.
R_P0762-AEDTM = SY-DATUM.
R_P0762-UNAME = SY-UNAME.
R_P0762-BEGDA = T_REPORT-BEGDA.
R_P0762-CPLAN = T_REPORT-CPLAN.
IF T_REPORT-EXPRI EQ '0.00' OR T_REPORT-EXPRI IS INITIAL.
SELECT * FROM PA0761 WHERE CPLAN = T_REPORT-CPLAN AND OBJPS = T_REPORT-OBJPS AND PERNR = T_REPORT-PERNR.
SELECT EXPRI FROM T71LTI03 INTO G_EXPRI WHERE CPLAN EQ T_REPORT-CPLAN
AND BEGDA LE P0761-GRADT AND ENDDA GE P0761-GRADT.
ENDSELECT.
EXIT.
ENDSELECT.
ELSE.
G_EXPRI = T_REPORT-EXPRI = T_REPORT-EXPRI.
ENDIF.
R_P0762-CITEM = T_REPORT-CITEM.
R_P0762-EXENO = T_REPORT-EXENO.
R_P0762-CHKNO = T_REPORT-CHKNO.
R_P0762-EXETC = T_REPORT-EXETC.
ENDFORM. " prepare_p0762
*&---------------------------------------------------------------------*
*& Form UPDATE_ZIT0762
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_STATUS text
*----------------------------------------------------------------------*
FORM UPDATE_ZIT0762 USING P_STATUS.
CHECK P_TEST IS INITIAL.
DATA: R_RETURN TYPE BAPIRETURN1.
MOVE-CORRESPONDING PA0762 TO R_ZIT0762.
MOVE-CORRESPONDING R_P0762 TO R_ZIT0762.
R_ZIT0762-EXEDT = PA0762-BEGDA.
R_ZIT0762-EXPRI = G_EXPRI.
R_ZIT0762-EXEST = P_STATUS.
SELECT SINGLE EXFMV FROM ZFMVAL INTO R_ZIT0762-FMVVD WHERE DATUM EQ R_P0762-VESDT.
* INSERT INTO zit0762 VALUES r_zit0762.
* move-corresponding r_zit0762 to zit0762.
UPDATE ZIT0762
SET
EXEST = R_ZIT0762-EXEST
* 2012july18 changes to tag last changes by who and when
AEDTM = SY-DATUM
UNAME = SY-UNAME
* 2012july18 changes to tag last changes by who and when
WHERE
PERNR EQ R_ZIT0762-PERNR
AND EXEDT EQ R_ZIT0762-EXEDT
AND EXEON EQ R_ZIT0762-EXEON
AND CPLAN EQ R_ZIT0762-CPLAN
AND OBJPS EQ R_ZIT0762-OBJPS.
IF SY-SUBRC <> 0.
G_ERROR = 'X'.
G_ERROR_REC = G_ERROR_REC + 1.
R_REPORT-PA0762 = R_REPORT-ZIT0762 = C_UNSUCCESSFUL.
IF P_TEST IS INITIAL.
" Failed Update of ZIT0762
R_REPORT-REMARK = TEXT-E05.
ELSE.
" Failed Update of ZIT0762
CONCATENATE TEXT-S01 TEXT-E05 INTO T_REPORT-REMARK SEPARATED BY SPACE.
ENDIF.
" APPEND r_report TO t_report.
" CLEAR r_report.
ROLLBACK WORK.
CALL FUNCTION 'HR_EMPLOYEE_DEQUEUE'
EXPORTING
NUMBER = R_P0762-PERNR
IMPORTING
RETURN = R_RETURN.
ELSE.
COMMIT WORK AND WAIT.
R_REPORT-ZIT0762 = C_SUCCESSFUL.
R_REPORT-ZIT0762 = C_SUCCESSFUL.
ENDIF.
ENDFORM. " UPDATE_ZIT0762
*&---------------------------------------------------------------------*
*& Form UPDATE_INFOTYPE_0762
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM UPDATE_INFOTYPE_0762.
DATA: L_USER LIKE SY-UNAME,
R_RETURN TYPE BAPIRETURN1.
CALL FUNCTION 'HR_EMPLOYEE_ENQUEUE'
EXPORTING
NUMBER = R_P0762-PERNR
IMPORTING
RETURN = R_RETURN
LOCKING_USER = L_USER.
IF R_RETURN IS NOT INITIAL.
G_ERROR = 'X'.
G_ERROR_REC = G_ERROR_REC + 1.
R_REPORT-PA0762 = R_REPORT-ZIT0762 = C_UNSUCCESSFUL.
IF P_TEST IS INITIAL.
"PA0762 Locked by XXXXXXX
CONCATENATE TEXT-E03 L_USER INTO R_REPORT-REMARK SEPARATED BY SPACE.
ELSE.
"PA0762 Locked by XXXXXXX
CONCATENATE TEXT-S01 TEXT-E03 L_USER INTO R_REPORT-REMARK SEPARATED BY SPACE.
ENDIF.
APPEND R_REPORT TO T_REPORT.
CLEAR R_REPORT.
EXIT.
ENDIF.
CALL FUNCTION 'HR_INITIALIZE_BUFFER'
EXPORTING
PERNR = R_P0762-PERNR.
CALL FUNCTION 'HR_INFOTYPE_OPERATION'
EXPORTING
INFTY = '0762'
NUMBER = R_P0762-PERNR
SUBTYPE = R_P0762-SUBTY
OBJECTID = R_P0762-OBJPS
LOCKINDICATOR = R_P0762-SPRPS
VALIDITYEND = R_P0762-ENDDA
VALIDITYBEGIN = R_P0762-BEGDA
RECORDNUMBER = R_P0762-SEQNR
RECORD = R_P0762
"operation = 'INS'
OPERATION = 'MOD'
NOCOMMIT = 'X'
IMPORTING
RETURN = R_RETURN.
IF R_RETURN IS INITIAL.
R_REPORT-PA0762 = C_SUCCESSFUL.
IF P_TEST IS INITIAL.
"Successful Update of PA0762
R_REPORT-REMARK = TEXT-S02.
ELSE.
"Successful Update of PA0762
CONCATENATE TEXT-S01 TEXT-S02 INTO R_REPORT-REMARK SEPARATED BY SPACE.
ENDIF.
APPEND R_REPORT TO T_REPORT.
ELSE.
IF R_RETURN-TYPE EQ 'E'.
G_ERROR = 'X'.
G_ERROR_REC = G_ERROR_REC + 1.
R_REPORT-PA0762 = R_REPORT-ZIT0762 = C_UNSUCCESSFUL.
IF P_TEST IS INITIAL.
" Failed Update of PA0762
R_REPORT-REMARK = TEXT-E04.
ELSE.
" Failed Update of PA0762
CONCATENATE TEXT-S01 TEXT-E04 INTO R_REPORT-REMARK SEPARATED BY SPACE.
ENDIF.
APPEND R_REPORT TO T_REPORT.
CLEAR R_REPORT.
CALL FUNCTION 'HR_EMPLOYEE_DEQUEUE'
EXPORTING
NUMBER = R_P0762-PERNR
IMPORTING
RETURN = R_RETURN.
ENDIF.
ENDIF.
ENDFORM. " UPDATE_INFOTYPE_0762
*&---------------------------------------------------------------------*
*& Form PREPARE_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PREPARE_REPORT.
MOVE-CORRESPONDING P0762 TO R_REPORT.
R_REPORT-EXEDT = P0762-BEGDA.
PROVIDE CNAME FROM P0002 BETWEEN SY-DATUM AND SY-DATUM.
R_REPORT-CNAME = P0002-CNAME.
EXIT.
ENDPROVIDE.
PROVIDE BUKRS FROM P0001 BETWEEN SY-DATUM AND SY-DATUM.
SELECT BUTXT FROM T001 INTO R_REPORT-BUTXT WHERE BUKRS EQ P0001-BUKRS.
ENDSELECT.
ENDPROVIDE.
R_REPORT-EXPRI = G_EXPRI.
G_TOTAL_REC = G_TOTAL_REC + 1.
ENDFORM. "prepare_report
*&---------------------------------------------------------------------*
*& Form DISPLAY_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_REPORT .
PERFORM F_SET_FRAME USING R_FRAME.
PERFORM SET_FIELDCAT.
PERFORM F_SET_EVENT.
PERFORM F_SHOW.
ENDFORM. " DISPLAY_REPORT
*&---------------------------------------------------------------------*
*& Form F_SET_FRAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GT_FRAME text
*----------------------------------------------------------------------*
FORM F_SET_FRAME USING GT_FRAME TYPE SLIS_LAYOUT_ALV.
CLEAR GT_FRAME.
GT_FRAME-COLWIDTH_OPTIMIZE = 'X'.
GT_FRAME-WINDOW_TITLEBAR = SY-TITLE.
ENDFORM. " F_SET_FRAME
*&---------------------------------------------------------------------*
*& Form SET_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SET_FIELDCAT.
DATA: L_POS TYPE I.
CLEAR L_POS.
ADD 1 TO L_POS.
PERFORM F_CRTE_FCAT USING 'SKIP' 'Skip?' L_POS 'L'.
ADD 1 TO L_POS.
PERFORM F_CRTE_FCAT USING 'SEQNO' 'No.' L_POS 'L'.
ADD 1 TO L_POS.
PERFORM F_CRTE_FCAT USING 'BUTXT' TEXT-T01 L_POS 'L'.
"Company Name
ADD 1 TO L_POS.
PERFORM F_CRTE_FCAT USING 'PERNR' TEXT-T02 L_POS 'L'.
"PF No.
ADD 1 TO L_POS.
PERFORM F_CRTE_FCAT USING 'CNAME' TEXT-T03 L_POS 'L'.
"Name
ADD 1 TO L_POS.
PERFORM F_CRTE_FCAT USING 'EXEDT' TEXT-T04 L_POS 'L'.
"Exercise Date
ADD 1 TO L_POS.
PERFORM F_CRTE_FCAT USING 'CPLAN' TEXT-T05 L_POS 'L'.
"Offer changed from Compensation Plan
ADD 1 TO L_POS.
PERFORM F_CRTE_FCAT USING 'CITEM' TEXT-T06 L_POS 'L'.
"Tranche changed from Review Item
ADD 1 TO L_POS.
PERFORM F_CRTE_FCAT USING 'EXENO' TEXT-T07 L_POS 'L'.
"No. of Shares Exercised
ADD 1 TO L_POS.
PERFORM F_CRTE_FCAT USING 'EXPRI' TEXT-T08 L_POS 'L'.
"Option Price
ADD 1 TO L_POS.
PERFORM F_CRTE_FCAT USING 'EXETC' TEXT-T09 L_POS 'L'.
"Total Cost
ADD 1 TO L_POS.
PERFORM F_CRTE_FCAT USING 'CHKNO' TEXT-T10 L_POS 'L'.
"Bank Draft/Cashier's Order
* ADD 1 TO l_pos.
* PERFORM f_crte_fcat USING 'PA0762' text-t11 l_pos 'L'.
* " PA0762 Status
* ADD 1 TO l_pos.
* PERFORM f_crte_fcat USING 'ZIT0762' text-t12 l_pos 'L'.
* " ZIT0762 Status
ADD 1 TO L_POS.
PERFORM F_CRTE_FCAT USING 'REMARK' TEXT-T13 L_POS 'L'.
"Remarks
*
* ADD 1 TO l_pos.
* PERFORM f_crte_fcat USING 'EXEST' 'EXE STAT' l_pos 'L'.
* OBJPS TYPE PA0762-OBJPS,
* SUBTY TYPE PA0762-SUBTY,
* SPRPS TYPE PA0762-SPRPS,
* BEGDA TYPE PA0762-BEGDA,
* ENDDA TYPE PA0762-ENDDA,
* SEQNR TYPE PA0762-SEQNR,
* EXEON TYPE PA0762-EXEON,
* EXEST TYPE PA0762-EXEST,
ENDFORM. " SET_FIELDCAT
*&---------------------------------------------------------------------*
*& Form F_CRTE_FCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0879 text
* -->P_TEXT_T01 text
* -->P_L_POS text
* -->P_0882 text
*----------------------------------------------------------------------*
FORM F_CRTE_FCAT USING SI_TP_FIELDNAME TYPE SLIS_FIELDNAME
SI_TP_TEXT TYPE DD03P-SCRTEXT_L
SI_POS TYPE I
SI_DDICTXT TYPE DDICTXT.
DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
CLEAR LS_FIELDCAT.
IF SI_POS EQ 1.
LS_FIELDCAT-NO_ZERO = 'X'.
LS_FIELDCAT-CHECKBOX = 'X'.
LS_FIELDCAT-INPUT = 'X'.
ENDIF.
LS_FIELDCAT-COL_POS = SI_POS.
LS_FIELDCAT-FIELDNAME = SI_TP_FIELDNAME.
LS_FIELDCAT-SELTEXT_L = SI_TP_TEXT.
LS_FIELDCAT-DDICTXT = SI_DDICTXT.
APPEND LS_FIELDCAT TO T_FIELDCAT.
ENDFORM. "f_create_fcat
*&---------------------------------------------------------------------*
*& Form f_set_event
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM F_SET_EVENT.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = T_EVENT.
"Top of Page
READ TABLE T_EVENT WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
INTO R_EVENT.
IF SY-SUBRC = 0.
MOVE 'F_ALV_TOP_OF_PAGE' TO R_EVENT-FORM.
MODIFY T_EVENT FROM R_EVENT INDEX SY-TABIX.
ENDIF.
ENDFORM. "f_set_event
*&---------------------------------------------------------------------*
*& Form f_alv_top_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM F_ALV_TOP_OF_PAGE.
DATA: L_PROCESSED TYPE C LENGTH 5,
L_ERROR TYPE C LENGTH 5.
CLEAR T_HEADER.
L_PROCESSED = G_TOTAL_REC.
L_ERROR = G_ERROR_REC.
CLEAR R_HEADER.
R_HEADER-TYP = 'H'.
CONCATENATE SY-CPROG '-' SY-TITLE INTO R_HEADER-INFO SEPARATED BY SPACE.
APPEND R_HEADER TO T_HEADER.
CLEAR R_HEADER.
R_HEADER-TYP = 'S'.
R_HEADER-KEY = 'Date:'.
WRITE SY-DATUM TO R_HEADER-INFO.
APPEND R_HEADER TO T_HEADER.
CLEAR R_HEADER.
R_HEADER-TYP = 'S'.
R_HEADER-KEY = 'Time:'.
WRITE SY-UZEIT TO R_HEADER-INFO.
APPEND R_HEADER TO T_HEADER.
CLEAR R_HEADER.
R_HEADER-TYP = 'S'.
R_HEADER-KEY = 'Processed:'.
CONCATENATE L_PROCESSED 'record(s)' INTO R_HEADER-INFO SEPARATED BY SPACE.
APPEND R_HEADER TO T_HEADER.
CLEAR R_HEADER.
R_HEADER-TYP = 'S'.
R_HEADER-KEY = 'Error:'.
CONCATENATE L_ERROR 'record(s)' INTO R_HEADER-INFO SEPARATED BY SPACE.
APPEND R_HEADER TO T_HEADER.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = T_HEADER.
ENDFORM. "f_alv_top_of_page
*&---------------------------------------------------------------------*
*& Form F_SHOW
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F_SHOW .
CASE P_TEST.
WHEN 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
IS_LAYOUT = R_FRAME
IT_FIELDCAT = T_FIELDCAT[]
IT_EVENTS = T_EVENT[]
I_DEFAULT = 'X'
I_SAVE = 'A'
TABLES
T_OUTTAB = T_REPORT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
WHEN OTHERS.
DATA W_SELHIDE TYPE SLIS_SEL_HIDE_ALV.
W_SELHIDE-MODE = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_PF_STATUS_SET = 'SET_STAT'
IS_LAYOUT = R_FRAME
IT_FIELDCAT = T_FIELDCAT[]
IT_EVENTS = T_EVENT[]
I_SAVE = 'A'
TABLES
T_OUTTAB = T_REPORT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC NE 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDCASE.
ENDFORM. " F_SHOW
*&---------------------------------------------------------------------*
*& Form F_VALIDATE_9033
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GV_PROCEED text
*----------------------------------------------------------------------*
FORM F_VALIDATE_9033 CHANGING GV_PROCEED.
CLEAR GV_PROCEED.
TABLES PA9033.
SELECT * FROM PA9033 WHERE BEGDA LE SY-DATUM AND ENDDA GE SY-DATUM.
CASE P9033-METHD.
WHEN 01. "Self Funding
GV_PROCEED = 'X'.
EXIT.
ENDCASE.
ENDSELECT.
ENDFORM. " F_VALIDATE_9033
*&---------------------------------------------------------------------*
*& Form GET_EXERCISE_START_DATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GV_PA0762_BEGDA text
*----------------------------------------------------------------------*
FORM GET_EXERCISE_START_DATE CHANGING GV_PA0762_BEGDA.
CLEAR GV_PA0762_BEGDA.
* GV_PA0762_BEGDA = p_prcdt - p_days. "<-------- without checking working days
* CHECK working day of KL = MA
* The PA0762-BEGDA (Exercise Date) is "No. of Working Days" from "Processing Date" in the selection screen.
* get GV_PA0762_BEGDA
P_DAYS = P_DAYS * -1.
CALL FUNCTION 'BKK_ADD_WORKINGDAY'
EXPORTING
I_DATE = P_PRCDT
I_DAYS = P_DAYS
I_CALENDAR1 = 'ZE'"'MA'
"I_CALENDAR2 = 'MA'
IMPORTING
E_DATE = GV_PA0762_BEGDA
* E_RETURN =
.
ENDFORM. " GET_EXERCISE_START_DATE
*&---------------------------------------------------------------------*
*& Form DELETE_INFOTYPE_0762
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DELETE_INFOTYPE_0762 .
DATA: L_USER LIKE SY-UNAME,
R_RETURN TYPE BAPIRETURN1.
CALL FUNCTION 'HR_EMPLOYEE_ENQUEUE'
EXPORTING
NUMBER = R_P0762-PERNR
IMPORTING
RETURN = R_RETURN
LOCKING_USER = L_USER.
IF R_RETURN IS NOT INITIAL.
G_ERROR = 'X'.
G_ERROR_REC = G_ERROR_REC + 1.
T_REPORT-PA0762 = T_REPORT-ZIT0762 = C_UNSUCCESSFUL.
IF P_TEST IS INITIAL.
"PA0762 Locked by XXXXXXX
CONCATENATE TEXT-E03 L_USER INTO T_REPORT-REMARK SEPARATED BY SPACE.
ELSE.
"PA0762 Locked by XXXXXXX
CONCATENATE TEXT-S01 TEXT-E03 L_USER INTO T_REPORT-REMARK SEPARATED BY SPACE.
ENDIF.
"APPEND R_REPORT TO T_REPORT.
"CLEAR R_REPORT.
EXIT.
ENDIF.
CALL FUNCTION 'HR_INITIALIZE_BUFFER'
EXPORTING
PERNR = R_P0762-PERNR.
CALL FUNCTION 'HR_INFOTYPE_OPERATION'
EXPORTING
INFTY = '0762'
NUMBER = R_P0762-PERNR
SUBTYPE = R_P0762-SUBTY
OBJECTID = R_P0762-OBJPS
* lockindicator = r_p0762-sprps
VALIDITYEND = R_P0762-ENDDA
VALIDITYBEGIN = R_P0762-BEGDA
* recordnumber = r_p0762-seqnr
RECORD = R_P0762
OPERATION = 'DEL'
* nocommit = 'X'
IMPORTING
RETURN = R_RETURN.
IF R_RETURN IS INITIAL.
T_REPORT-PA0762 = C_SUCCESSFUL.
IF P_TEST IS INITIAL.
"Successful Update of PA0762
"t_report-REMARK = TEXT-S02.
ELSE.
"Successful Update of PA0762
"CONCATENATE TEXT-S01 TEXT-S02 INTO t_report-REMARK SEPARATED BY SPACE.
ENDIF.
"APPEND R_REPORT TO T_REPORT.
ELSE.
IF R_RETURN-TYPE EQ 'E'.
G_ERROR = 'X'.
G_ERROR_REC = G_ERROR_REC + 1.
T_REPORT-PA0762 = T_REPORT-ZIT0762 = C_UNSUCCESSFUL.
IF P_TEST IS INITIAL.
" Failed to Delete of PA0762
T_REPORT-REMARK = TEXT-E06.
ELSE.
" Failed Update of PA0762
CONCATENATE TEXT-S01 TEXT-E06 INTO T_REPORT-REMARK SEPARATED BY SPACE.
ENDIF.
" APPEND R_REPORT TO T_REPORT.
"CLEAR R_REPORT.
CALL FUNCTION 'HR_EMPLOYEE_DEQUEUE'
EXPORTING
NUMBER = R_P0762-PERNR
IMPORTING
RETURN = R_RETURN.
ENDIF.
ENDIF.
ENDFORM. " DELETE_INFOTYPE_0762
FORM SET_STAT USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'STANDARD' EXCLUDING RT_EXTAB.
ENDFORM. "SET_STAT
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
FORM USER_COMMAND USING FU_UCOMM LIKE SY-UCOMM
FU_SELFIELD TYPE SLIS_SELFIELD.
CASE FU_UCOMM.
WHEN 'PROCESS'. "TYPE STANDARD TABLE OF
*--------------------------------------------------------------------
*--------------------------------------------------------------------
LOOP AT T_REPORT.
*--------------------------------------------------------------------
CASE T_REPORT-REMARK.
WHEN ''.
*--------------------------------------------------------------------
CASE T_REPORT-SKIP.
WHEN 'X'.
T_REPORT-REMARK = 'Skipped'.
WHEN OTHERS.
PERFORM PREPARE_P0762_REPORT.
PERFORM UPDATE_ZIT0762 USING C_CHEQUE_NOT_RECEIVED.
IF R_REPORT-ZIT0762 = C_UNSUCCESSFUL.
T_REPORT-REMARK = 'ZIT0762 fail'.
ELSE.
PERFORM DELETE_INFOTYPE_0762.
IF G_ERROR IS INITIAL.
T_REPORT-EXEST = '09'. "(No Cheque Received)
T_REPORT-REMARK = 'Processed'.
ELSE.
T_REPORT-REMARK = 'PA0762 fail'.
PERFORM UPDATE_ZIT0762 USING C_PENDING_PAYMENT.
ENDIF.
ENDIF.
ENDCASE.
*--------------------------------------------------------------------
WHEN 'Skipped'. "do nothing
WHEN 'Processed'. "do nothing
ENDCASE.
*--------------------------------------------------------------------
MODIFY T_REPORT.
ENDLOOP.
*--------------------------------------------------------------------
*--------------------------------------------------------------------
P_TEST = 'X'. "Remove button
PERFORM REFRESH_REPORT.
WHEN OTHERS.
ENDCASE.
* READ TABLE t_report INTO r_report INDEX 1.
* IF sy-subrc = 0.
* PERFORM display_report.
* endif.
ENDFORM. " USER_COMMAND
*&---------------------------------------------------------------------*
*& Form REFRESH_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM REFRESH_REPORT .
PERFORM F_SET_FRAME USING R_FRAME.
* PERFORM set_fieldcat.
PERFORM F_SET_EVENT.
PERFORM F_SHOW.
LEAVE TO SCREEN 0.
ENDFORM. " REFRESH_REPORT
How to create a SFP (adobe) ABAP PART ONLY!
12:33 AM
*&---------------------------------------------------------------------*
*& Report Y_MARK_CREATE_PDF
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
* Modification
* Change by : Mark Chan San Choon Date :
* Requested by : TR # : HRDK9A0DNK
* Reason :
*&---------------------------------------------------------------------*
************************************************************************
REPORT Y_MARK_CREATE_PDF.
*--------------------------------------------------------------------*
* Type Pools
*--------------------------------------------------------------------*
TYPE-POOLS: SLIS.
*--------------------------------------------------------------------*
* Tables
*--------------------------------------------------------------------*
TABLES: PERNR.
*----------------------------------------------------------------------*
* Constants Declaration
*----------------------------------------------------------------------*
"ALV related.
CONSTANTS: GC_TOP_OF_PAGE(30) VALUE 'TOP_OF_PAGE',
GC_END_OF_LIST(30) VALUE 'END_OF_LIST'.
*--------------------------------------------------------------------*
* Data Declaration
*--------------------------------------------------------------------*
"ALV Stuff
DATA: GT_FC_SLIS TYPE SLIS_T_FIELDCAT_ALV,
GS_FC_SLIS TYPE LINE OF SLIS_T_FIELDCAT_ALV,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
GT_EVENT TYPE SLIS_T_EVENT,
GS_EVENT TYPE SLIS_ALV_EVENT,
GT_SORT TYPE SLIS_T_SORTINFO_ALV,
GS_SORT TYPE LINE OF SLIS_T_SORTINFO_ALV,
GV_TITLE TYPE LVC_TITLE,
GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
GT_LIST_END_OF_LIST TYPE SLIS_T_LISTHEADER.
TYPES:
BEGIN OF ELEMENT_PERSONAL_INFO,
BUMISTAT TYPE STRING,
GBORT TYPE GBORT,
GBDEP TYPE STRING,
GBLND TYPE STRING,
ICNEW TYPE ICNUM,
ICOLD TYPE ICOLD,
MARITALDATE TYPE BEGDA,
RELIGION TYPE STRING,
MARITAL TYPE STRING,
END OF ELEMENT_PERSONAL_INFO.
DATA LS_PERSONAL_INFO TYPE ELEMENT_PERSONAL_INFO.
*--------------------------------------------------------------------*
* Selection Screen
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-S01.
PARAMETERS: P_FOLDER TYPE STRING LOWER CASE.
SELECTION-SCREEN END OF BLOCK B1.
*----------------------------------------------------------------------*
* At Selection Screen
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON BLOCK B1.
IF SY-UCOMM NE 'UC1'.
IF P_FOLDER IS INITIAL.
* IF P_OFFLN IS NOT INITIAL AND P_FOLDER IS INITIAL AND P_TEST IS INITIAL AND P_ATTCH IS INITIAL.
MESSAGE 'Please key in File Path''.' TYPE 'E'.
ENDIF.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FOLDER.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE
CHANGING
SELECTED_FOLDER = P_FOLDER
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*--------------------------------------------------------------------*
* Start of Selection
*--------------------------------------------------------------------*
START-OF-SELECTION.
GET PERNR.
PERFORM GET_PERSONALINFO USING PERNR-PERNR.
PERFORM F_DOWNLOAD_PDF USING PERNR-PERNR.
END-OF-SELECTION.
*--------------------------------------------------------------------*
* MISC coding
*--------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form(S)
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form F_DOWNLOAD_PDF
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_PERNR_PERNR text
*----------------------------------------------------------------------*
FORM F_DOWNLOAD_PDF USING P_PERNR_PERNR.
DATA: LS_OUTPUTPARAMS TYPE SFPOUTPUTPARAMS.
DATA: LS_FORMOUTPUT TYPE FPFORMOUTPUT.
DATA: LV_FM_NAME TYPE RS38L_FNAM.
DATA: LS_DOCPARAMS TYPE SFPDOCPARAMS.
DATA: LV_MSG TYPE STRING.
"Get name of the generated function module
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
I_NAME = 'Z_PDF_PERSONAL_DETAILS'
IMPORTING
E_FUNCNAME = LV_FM_NAME.
"Set the output parameters.
LS_OUTPUTPARAMS-NODIALOG = 'X'.
LS_OUTPUTPARAMS-PREVIEW = ''.
LS_OUTPUTPARAMS-GETPDF = 'X'.
"Open print job
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
IE_OUTPUTPARAMS = LS_OUTPUTPARAMS
EXCEPTIONS
OTHERS = 1.
"Set the PDF to be dynamic and interactive.
LS_DOCPARAMS-FILLABLE = ''.
LS_DOCPARAMS-DYNAMIC = 'X'.
"Generate the PDF.
CLEAR LS_FORMOUTPUT.
CALL FUNCTION LV_FM_NAME
EXPORTING
/1BCDWB/DOCPARAMS = LS_DOCPARAMS
GPERNR = PERNR-PERNR
GBUMITAT = LS_PERSONAL_INFO-BUMISTAT
GBORT = LS_PERSONAL_INFO-GBORT
GBDEP = LS_PERSONAL_INFO-GBDEP
GBLND = LS_PERSONAL_INFO-GBLND
GICOLD = LS_PERSONAL_INFO-ICOLD
GICNEW = LS_PERSONAL_INFO-ICNEW
GRELIGION = LS_PERSONAL_INFO-RELIGION
GMARITAL = LS_PERSONAL_INFO-MARITAL
IMPORTING
/1BCDWB/FORMOUTPUT = LS_FORMOUTPUT
EXCEPTIONS
USAGE_ERROR = 1
SYSTEM_ERROR = 2
INTERNAL_ERROR = 3
OTHERS = 4.
CASE SY-SUBRC.
WHEN 0.
LV_MSG = 'Failed to generate Letter of Offer PDF.'.
WHEN OTHERS.
ENDCASE.
CHECK SY-SUBRC = 0.
"Close print job.
CALL FUNCTION 'FP_JOB_CLOSE'.
* download the pdf file
*--------------------------------------------------------------------*
DATA: LT_PDF_BIN TYPE TABLE OF X255.
DATA: LV_PDF_NAME TYPE STRING.
REFRESH: LT_PDF_BIN.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = LS_FORMOUTPUT-PDF
TABLES
BINARY_TAB = LT_PDF_BIN.
IF P_FOLDER IS NOT INITIAL.
CONCATENATE P_FOLDER '\PDF_FOR_' PERNR-PERNR '_' SY-DATUM '_' SY-UZEIT '.pdf' INTO LV_PDF_NAME.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = LV_PDF_NAME
FILETYPE = 'BIN'
TABLES
DATA_TAB = LT_PDF_BIN
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
CASE SY-SUBRC.
WHEN 0. LV_MSG = 'Successfully download Letter of Offer PDF.'.
WHEN OTHERS. LV_MSG = 'Failed to download Letter of Offer PDF.'.
ENDCASE.
ENDFORM. " F_DOWNLOAD_PDF
*&---------------------------------------------------------------------*
*& Form GET_PERSONALINFO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_PERNR_PERNR text
*----------------------------------------------------------------------*
FORM GET_PERSONALINFO USING P_PERNR_PERNR.
DATA LV_SEX TYPE STRING.
DATA LV_DOB TYPE BEGDA.
DATA LV_RETIRE TYPE BEGDA.
DATA LV_AGE TYPE I.
DATA LV_BUMI LIKE LS_PERSONAL_INFO-BUMISTAT.
DATA LV_GBORT LIKE LS_PERSONAL_INFO-GBORT.
DATA LV_GBDEP LIKE LS_PERSONAL_INFO-GBDEP.
DATA LV_GBLND LIKE LS_PERSONAL_INFO-GBLND.
DATA LV_NATIO TYPE NATIO.
DATA LV_ICNUM LIKE LS_PERSONAL_INFO-ICNEW.
DATA LV_ICOLD LIKE LS_PERSONAL_INFO-ICOLD.
DATA LV_RACE TYPE STRING.
DATA LV_RELIGION LIKE LS_PERSONAL_INFO-RELIGION.
DATA LV_MARITAL TYPE STRING.
DATA LV_MARITALDATE LIKE LS_PERSONAL_INFO-MARITALDATE.
DATA LV_MARRIEDSINCE TYPE C LENGTH 10.
DATA YY(4) TYPE C.
DATA MM(2) TYPE C.
DATA DD(2) TYPE C.
CALL FUNCTION 'Z_MCV001_PI_HEADER'
EXPORTING
UNAME = SY-UNAME
IMPORTING
GENDER = LV_SEX
DOB = LV_DOB
RETIRE = LV_RETIRE
AGE = LV_AGE
BUMI = LV_BUMI
GBORT = LV_GBORT
GBDEP = LV_GBDEP
GBLND = LV_GBLND
NATIO = LV_NATIO
ICOLD = LV_ICOLD
ICNUM = LV_ICNUM
RACE = LV_RACE
RELIGION = LV_RELIGION
MARITAL = LV_MARITAL
MARITALDATE = LV_MARITALDATE.
LS_PERSONAL_INFO-BUMISTAT = LV_BUMI.
LS_PERSONAL_INFO-GBORT = LV_GBORT.
LS_PERSONAL_INFO-GBDEP = LV_GBDEP.
LS_PERSONAL_INFO-GBLND = LV_GBLND.
LS_PERSONAL_INFO-ICOLD = LV_ICOLD.
LS_PERSONAL_INFO-ICNEW = LV_ICNUM.
LS_PERSONAL_INFO-RELIGION = LV_RELIGION.
* ls_personal_info-MARITAL = LV_MARITAL.
IF LV_MARITAL EQ 'Single'.
LS_PERSONAL_INFO-MARITAL = LV_MARITAL.
ELSE.
YY = LV_MARITALDATE+0(4).
MM = LV_MARITALDATE+4(2).
DD = LV_MARITALDATE+6(2).
CONCATENATE DD MM YY INTO LV_MARRIEDSINCE SEPARATED BY '.'.
CONCATENATE LV_MARITAL 'Since:' LV_MARRIEDSINCE INTO LV_MARITAL SEPARATED BY SPACE.
LS_PERSONAL_INFO-MARITAL = LV_MARITAL.
ENDIF.
ENDFORM. " GET_PERSONALINFO
*& Report Y_MARK_CREATE_PDF
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
* Modification
* Change by : Mark Chan San Choon Date :
* Requested by : TR # : HRDK9A0DNK
* Reason :
*&---------------------------------------------------------------------*
************************************************************************
REPORT Y_MARK_CREATE_PDF.
*--------------------------------------------------------------------*
* Type Pools
*--------------------------------------------------------------------*
TYPE-POOLS: SLIS.
*--------------------------------------------------------------------*
* Tables
*--------------------------------------------------------------------*
TABLES: PERNR.
*----------------------------------------------------------------------*
* Constants Declaration
*----------------------------------------------------------------------*
"ALV related.
CONSTANTS: GC_TOP_OF_PAGE(30) VALUE 'TOP_OF_PAGE',
GC_END_OF_LIST(30) VALUE 'END_OF_LIST'.
*--------------------------------------------------------------------*
* Data Declaration
*--------------------------------------------------------------------*
"ALV Stuff
DATA: GT_FC_SLIS TYPE SLIS_T_FIELDCAT_ALV,
GS_FC_SLIS TYPE LINE OF SLIS_T_FIELDCAT_ALV,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
GT_EVENT TYPE SLIS_T_EVENT,
GS_EVENT TYPE SLIS_ALV_EVENT,
GT_SORT TYPE SLIS_T_SORTINFO_ALV,
GS_SORT TYPE LINE OF SLIS_T_SORTINFO_ALV,
GV_TITLE TYPE LVC_TITLE,
GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
GT_LIST_END_OF_LIST TYPE SLIS_T_LISTHEADER.
TYPES:
BEGIN OF ELEMENT_PERSONAL_INFO,
BUMISTAT TYPE STRING,
GBORT TYPE GBORT,
GBDEP TYPE STRING,
GBLND TYPE STRING,
ICNEW TYPE ICNUM,
ICOLD TYPE ICOLD,
MARITALDATE TYPE BEGDA,
RELIGION TYPE STRING,
MARITAL TYPE STRING,
END OF ELEMENT_PERSONAL_INFO.
DATA LS_PERSONAL_INFO TYPE ELEMENT_PERSONAL_INFO.
*--------------------------------------------------------------------*
* Selection Screen
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-S01.
PARAMETERS: P_FOLDER TYPE STRING LOWER CASE.
SELECTION-SCREEN END OF BLOCK B1.
*----------------------------------------------------------------------*
* At Selection Screen
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON BLOCK B1.
IF SY-UCOMM NE 'UC1'.
IF P_FOLDER IS INITIAL.
* IF P_OFFLN IS NOT INITIAL AND P_FOLDER IS INITIAL AND P_TEST IS INITIAL AND P_ATTCH IS INITIAL.
MESSAGE 'Please key in File Path''.' TYPE 'E'.
ENDIF.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FOLDER.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE
CHANGING
SELECTED_FOLDER = P_FOLDER
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*--------------------------------------------------------------------*
* Start of Selection
*--------------------------------------------------------------------*
START-OF-SELECTION.
GET PERNR.
PERFORM GET_PERSONALINFO USING PERNR-PERNR.
PERFORM F_DOWNLOAD_PDF USING PERNR-PERNR.
END-OF-SELECTION.
*--------------------------------------------------------------------*
* MISC coding
*--------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form(S)
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form F_DOWNLOAD_PDF
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_PERNR_PERNR text
*----------------------------------------------------------------------*
FORM F_DOWNLOAD_PDF USING P_PERNR_PERNR.
DATA: LS_OUTPUTPARAMS TYPE SFPOUTPUTPARAMS.
DATA: LS_FORMOUTPUT TYPE FPFORMOUTPUT.
DATA: LV_FM_NAME TYPE RS38L_FNAM.
DATA: LS_DOCPARAMS TYPE SFPDOCPARAMS.
DATA: LV_MSG TYPE STRING.
"Get name of the generated function module
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
I_NAME = 'Z_PDF_PERSONAL_DETAILS'
IMPORTING
E_FUNCNAME = LV_FM_NAME.
"Set the output parameters.
LS_OUTPUTPARAMS-NODIALOG = 'X'.
LS_OUTPUTPARAMS-PREVIEW = ''.
LS_OUTPUTPARAMS-GETPDF = 'X'.
"Open print job
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
IE_OUTPUTPARAMS = LS_OUTPUTPARAMS
EXCEPTIONS
OTHERS = 1.
"Set the PDF to be dynamic and interactive.
LS_DOCPARAMS-FILLABLE = ''.
LS_DOCPARAMS-DYNAMIC = 'X'.
"Generate the PDF.
CLEAR LS_FORMOUTPUT.
CALL FUNCTION LV_FM_NAME
EXPORTING
/1BCDWB/DOCPARAMS = LS_DOCPARAMS
GPERNR = PERNR-PERNR
GBUMITAT = LS_PERSONAL_INFO-BUMISTAT
GBORT = LS_PERSONAL_INFO-GBORT
GBDEP = LS_PERSONAL_INFO-GBDEP
GBLND = LS_PERSONAL_INFO-GBLND
GICOLD = LS_PERSONAL_INFO-ICOLD
GICNEW = LS_PERSONAL_INFO-ICNEW
GRELIGION = LS_PERSONAL_INFO-RELIGION
GMARITAL = LS_PERSONAL_INFO-MARITAL
IMPORTING
/1BCDWB/FORMOUTPUT = LS_FORMOUTPUT
EXCEPTIONS
USAGE_ERROR = 1
SYSTEM_ERROR = 2
INTERNAL_ERROR = 3
OTHERS = 4.
CASE SY-SUBRC.
WHEN 0.
LV_MSG = 'Failed to generate Letter of Offer PDF.'.
WHEN OTHERS.
ENDCASE.
CHECK SY-SUBRC = 0.
"Close print job.
CALL FUNCTION 'FP_JOB_CLOSE'.
* download the pdf file
*--------------------------------------------------------------------*
DATA: LT_PDF_BIN TYPE TABLE OF X255.
DATA: LV_PDF_NAME TYPE STRING.
REFRESH: LT_PDF_BIN.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = LS_FORMOUTPUT-PDF
TABLES
BINARY_TAB = LT_PDF_BIN.
IF P_FOLDER IS NOT INITIAL.
CONCATENATE P_FOLDER '\PDF_FOR_' PERNR-PERNR '_' SY-DATUM '_' SY-UZEIT '.pdf' INTO LV_PDF_NAME.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = LV_PDF_NAME
FILETYPE = 'BIN'
TABLES
DATA_TAB = LT_PDF_BIN
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
CASE SY-SUBRC.
WHEN 0. LV_MSG = 'Successfully download Letter of Offer PDF.'.
WHEN OTHERS. LV_MSG = 'Failed to download Letter of Offer PDF.'.
ENDCASE.
ENDFORM. " F_DOWNLOAD_PDF
*&---------------------------------------------------------------------*
*& Form GET_PERSONALINFO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_PERNR_PERNR text
*----------------------------------------------------------------------*
FORM GET_PERSONALINFO USING P_PERNR_PERNR.
DATA LV_SEX TYPE STRING.
DATA LV_DOB TYPE BEGDA.
DATA LV_RETIRE TYPE BEGDA.
DATA LV_AGE TYPE I.
DATA LV_BUMI LIKE LS_PERSONAL_INFO-BUMISTAT.
DATA LV_GBORT LIKE LS_PERSONAL_INFO-GBORT.
DATA LV_GBDEP LIKE LS_PERSONAL_INFO-GBDEP.
DATA LV_GBLND LIKE LS_PERSONAL_INFO-GBLND.
DATA LV_NATIO TYPE NATIO.
DATA LV_ICNUM LIKE LS_PERSONAL_INFO-ICNEW.
DATA LV_ICOLD LIKE LS_PERSONAL_INFO-ICOLD.
DATA LV_RACE TYPE STRING.
DATA LV_RELIGION LIKE LS_PERSONAL_INFO-RELIGION.
DATA LV_MARITAL TYPE STRING.
DATA LV_MARITALDATE LIKE LS_PERSONAL_INFO-MARITALDATE.
DATA LV_MARRIEDSINCE TYPE C LENGTH 10.
DATA YY(4) TYPE C.
DATA MM(2) TYPE C.
DATA DD(2) TYPE C.
CALL FUNCTION 'Z_MCV001_PI_HEADER'
EXPORTING
UNAME = SY-UNAME
IMPORTING
GENDER = LV_SEX
DOB = LV_DOB
RETIRE = LV_RETIRE
AGE = LV_AGE
BUMI = LV_BUMI
GBORT = LV_GBORT
GBDEP = LV_GBDEP
GBLND = LV_GBLND
NATIO = LV_NATIO
ICOLD = LV_ICOLD
ICNUM = LV_ICNUM
RACE = LV_RACE
RELIGION = LV_RELIGION
MARITAL = LV_MARITAL
MARITALDATE = LV_MARITALDATE.
LS_PERSONAL_INFO-BUMISTAT = LV_BUMI.
LS_PERSONAL_INFO-GBORT = LV_GBORT.
LS_PERSONAL_INFO-GBDEP = LV_GBDEP.
LS_PERSONAL_INFO-GBLND = LV_GBLND.
LS_PERSONAL_INFO-ICOLD = LV_ICOLD.
LS_PERSONAL_INFO-ICNEW = LV_ICNUM.
LS_PERSONAL_INFO-RELIGION = LV_RELIGION.
* ls_personal_info-MARITAL = LV_MARITAL.
IF LV_MARITAL EQ 'Single'.
LS_PERSONAL_INFO-MARITAL = LV_MARITAL.
ELSE.
YY = LV_MARITALDATE+0(4).
MM = LV_MARITALDATE+4(2).
DD = LV_MARITALDATE+6(2).
CONCATENATE DD MM YY INTO LV_MARRIEDSINCE SEPARATED BY '.'.
CONCATENATE LV_MARITAL 'Since:' LV_MARRIEDSINCE INTO LV_MARITAL SEPARATED BY SPACE.
LS_PERSONAL_INFO-MARITAL = LV_MARITAL.
ENDIF.
ENDFORM. " GET_PERSONALINFO