This blog describes the option to download payslip of each employee in separate PDF files to application server. In the case of smartform, the payslip of each employee will be printed in each page of smart form output. The function module illustrated below will handle the process of downloading payslip to application server. You can call it in your custom program.
FUNCTION ZPYSLP_PDF_DWNLD_APP_SRV.
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_FORMNAME) TYPE CHAR30
*" REFERENCE(I_FILENAME) TYPE STRING
*" REFERENCE(I_PRESENTATION) TYPE CHAR1 OPTIONAL
*" REFERENCE(I_APPLICATION) TYPE CHAR1 DEFAULT 'X'
*" REFERENCE(IT_FINAL) TYPE ZTT_PAYSLIP
*" REFERENCE(I_DATE) TYPE CHAR20
*" EXCEPTIONS
*" ERROR_PRESENTATION_SERVER
DATA: FNAM TYPE RS38L_FNAM, "FORM NAME
CONTROL_PARAMETERS TYPE SSFCTRLOP, "CONTROL PARAMETERS
OUTPUT_OPTIONS TYPE SSFCOMPOP, "OUTPUT OPTIONS
JOB_OUTPUT_INFO TYPE SSFCRESCL,
DOCTAB_ARCHIVE TYPE DOCS OCCURS 0,
BIN_FILESIZE(132) TYPE C,
WA_DATA TYPE TLINE,
E_DATA_OTF TYPE TABLE OF TLINE,
LV_JOB_OUTPUT_INFO TYPE SSFCRESCL,
LV_LINES TYPE I,
LV_COUNT(1) TYPE N,
LT_PAYSLIP TYPE ZTT_PAYSLIP,
WA_FINAL TYPE ZST_PAYSLIP,
LV_FILENAME TYPE STRING,
LV_APPFILE TYPE STRING.
CLEAR LV_LINES.
DESCRIBE TABLE IT_FINAL LINES LV_LINES. “FINAL INTERNAL TABLE IN SMARTFORM
DO.
LV_COUNT = LV_COUNT + 1.
CLEAR: WA_FINAL, LT_PAYSLIP, LV_FILENAME, LV_APPFILE.
REFRESH LT_PAYSLIP.
IF LV_COUNT LE LV_LINES.
READ TABLE IT_FINAL INTO WA_FINAL INDEX LV_COUNT.
IF SY-SUBRC EQ 0.
APPEND WA_FINAL TO LT_PAYSLIP.
ENDIF.
ELSE.
EXIT.
ENDIF.
IF I_PRESENTATION = 'X'.
CONCATENATE 'PAYSLIP' WA_FINAL-PERNR '.PDF' INTO LV_FILENAME.
LV_APPFILE = LV_FILENAME.
CONCATENATE I_FILENAME LV_FILENAME INTO LV_FILENAME.
ENDIF.
IF I_APPLICATION = 'X'. "FILE NAME IN APPLICATION SERVER
CLEAR LV_FILENAME.
CONCATENATE I_FILENAME '/PAYSLIP' WA_FINAL-PERNR '.PDF' INTO LV_FILENAME.
ENDIF.
*--INITIALIZE THE CONTROL PARAMETERS
CONTROL_PARAMETERS-NO_OPEN = 'X'.
CONTROL_PARAMETERS-NO_CLOSE = 'X'.
CONTROL_PARAMETERS-NO_DIALOG = 'X'.
CONTROL_PARAMETERS-GETOTF = 'X'.
*--INITIALIZE OUTPUT OPTIONS
OUTPUT_OPTIONS-TDDEST = 'LOCL'.
*--GET THE SMART FORM F.M NAME
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = I_FORMNAME
IMPORTING
FM_NAME = FNAM
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3.
*--OPEN THE SMARTFORM
CALL FUNCTION 'SSF_OPEN'
EXPORTING
* ARCHIVE_PARAMETERS =
USER_SETTINGS = ' '
* MAIL_SENDER =
* MAIL_RECIPIENT =
* MAIL_APPL_OBJ =
OUTPUT_OPTIONS = OUTPUT_OPTIONS
CONTROL_PARAMETERS = CONTROL_PARAMETERS
* IMPORTING
* JOB_OUTPUT_OPTIONS =
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
* IMPLEMENT SUITABLE ERROR HANDLING HERE
ENDIF.
*--START SMARTFORM
CALL FUNCTION FNAM
EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
CONTROL_PARAMETERS = CONTROL_PARAMETERS
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
OUTPUT_OPTIONS = OUTPUT_OPTIONS
USER_SETTINGS = ' '
PAY_COMP = LT_PAYSLIP
DATE = I_DATE
* IMPORTING
* DOCUMENT_OUTPUT_INFO =
* JOB_OUTPUT_INFO =
* JOB_OUTPUT_OPTIONS =
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5.
*--CLOSE THE SMARTFORM
CALL FUNCTION 'SSF_CLOSE'
IMPORTING
JOB_OUTPUT_INFO = JOB_OUTPUT_INFO
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
OTHERS = 4.
*--CONVERT TO THE SMARTFORM OTF OUTPUT TO THE PDF
CALL FUNCTION 'CONVERT_OTF_2_PDF'
* EXPORTING
* USE_OTF_MC_CMD = 'X'
IMPORTING
BIN_FILESIZE = BIN_FILESIZE
TABLES
OTF = JOB_OUTPUT_INFO-OTFDATA
DOCTAB_ARCHIVE = DOCTAB_ARCHIVE
LINES = E_DATA_OTF
EXCEPTIONS
ERR_CONV_NOT_POSSIBLE = 1
ERR_OTF_MC_NOENDMARKER = 2
OTHERS = 3.
IF I_PRESENTATION = 'X'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = LV_FILENAME
FILETYPE = 'BIN'
TABLES
DATA_TAB = E_DATA_OTF
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.
IF SY-SUBRC EQ 0.
* RAISE ERROR_PRESENTATION_SERVER.
ENDIF.
ELSEIF I_APPLICATION = 'X'.
OPEN DATASET LV_FILENAME FOR OUTPUT IN BINARY MODE.
IF SY-SUBRC = 0.
LOOP AT E_DATA_OTF INTO WA_DATA.
TRANSFER WA_DATA TO LV_FILENAME.
ENDLOOP.
CLOSE DATASET LV_FILENAME.
ELSE.
WRITE : / 'OPERATING SYSTEM COULD NOT OPEN FILE'.
ENDIF.
ENDIF.
ENDDO.
ENDFUNCTION.
CALL FUNCTION MODULE IN CUSTOM PROGRAM (Driver program for SmartForm)
CALL FUNCTION 'ZFM_PYSLP_PDF_DWNLD_APP_SRV'
EXPORTING
I_FORMNAME = 'ZSF_PAYSLIP' “SMARTFORM NAME
I_FILENAME = '/ABCD/PYSLP' “LOCATION IN APPLICATION SERVER
* I_PRESENTATION =
I_APPLICATION = 'X'
IT_FINAL = IT_FINAL “FINAL INTERNAL TABLE IN SMARTFORM
I_DATE = LV_DATE
* EXCEPTIONS
* ERROR_PRESENTATION_SERVER = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* IMPLEMENT SUITABLE ERROR HANDLING HERE
ENDIF.