*&---------------------------------------------------------------------*
*& 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
Post a Comment