Skip to Content
This blogs explains how to display the HRFORMS in PDF format from the BSP Application.   *Note:* I hope, this topic remains unresolved one so far. If there are any similar posts on this topic, please let me know, I will pull this one off.   Let’s take the scenario of displaying the current Payslip for given employee. The payslip period and employee number are hardcoded in the program itself just for demo.   Let’s look at the output of the BSP Application before we get into the technical details. *Prerequisite: *You need to know the driver program of HRFORMS & parameters to call the driver program.

 

*Development Steps:*

 

  • Create the BSP Application with page name called “HRFORMS”.

 

  • *Layout code:**OnInitialization:* * event handler for data retrieval CONSTANTS: C_DATASETNAME(6) TYPE C VALUE ‘HRFORM’, C_REPORTID(40) TYPE C VALUE ‘/1PYXXFO/ZUS_PAYSLIP’. DATA: IT_PARAMS TYPE TABLE OF RSPARAMS, WA_PARAMS TYPE RSPARAMS, PRINTPARAMETERS TYPE PRI_PARAMS, SPL_ID TYPE RSPOID, LISTNAME TYPE SYPLIST, IT_SPOOLREQ TYPE TABLE OF RSPORQ, WA_SPOOLREQ TYPE RSPORQ. FIELD-SYMBOLS TYPE X. DATA: NUMBER TYPE PERNR_D VALUE ‘4545885’, PDF_TABLE TYPE TEXT_LINE_TAB, CONTENT TYPE TLINE, STRFILE_CONTENT TYPE STRING, FILE_XCONTENT TYPE XSTRING, LEN TYPE I, CACHED_RESPONSE TYPE REF TO IF_HTTP_RESPONSE, GUID TYPE GUID_32, MIMETYPE TYPE STRING, JOBNUMBER TYPE BTCJOBCNT, JOBNAME TYPE BTCJOB. REFRESH PDF_TABLE. *Set parameters for HRFORMS Driver program REFRESH IT_PARAMS. * Set the Personnel number WA_PARAMS-SIGN = ‘I’. WA_PARAMS-OPTION = ‘EQ’. WA_PARAMS-SELNAME = ‘PNPPERNR’. WA_PARAMS-LOW = NUMBER. APPEND WA_PARAMS TO IT_PARAMS. WA_PARAMS-SELNAME = ‘P_NOSTAT’. WA_PARAMS-LOW = ‘X’. APPEND WA_PARAMS TO IT_PARAMS. WA_PARAMS-SELNAME = ‘PNPBEGDA’. WA_PARAMS-LOW = ‘20081101’. APPEND WA_PARAMS TO IT_PARAMS. WA_PARAMS-SELNAME = ‘PNPENDDA’. WA_PARAMS-LOW = ‘20081130’. APPEND WA_PARAMS TO IT_PARAMS. * Get print parameters CONCATENATE C_DATASETNAME SY-UZEIT INTO LISTNAME. CALL FUNCTION ‘GET_PRINT_PARAMETERS’ EXPORTING DATA_SET = C_DATASETNAME EXPIRATION = ‘1’ IMMEDIATELY = SPACE LIST_NAME = LISTNAME NEW_LIST_ID = ‘X’ NO_DIALOG = ‘X’ MODE = ‘BATCH’ IMPORTING OUT_PARAMETERS = PRINTPARAMETERS EXCEPTIONS OTHERS = 4. CONCATENATE SY-UNAME ‘HR_PAYSLIP’ INTO JOBNAME. CALL FUNCTION ‘JOB_OPEN’ EXPORTING JOBNAME = JOBNAME IMPORTING JOBCOUNT = JOBNUMBER EXCEPTIONS CANT_CREATE_JOB = 1 INVALID_JOB_DATA = 2 JOBNAME_MISSING = 3 OTHERS = 4. * Call report in background mode SUBMIT (C_REPORTID) WITH SELECTION-TABLE IT_PARAMS TO SAP-SPOOL SPOOL PARAMETERS PRINTPARAMETERS WITHOUT SPOOL DYNPRO VIA JOB JOBNAME NUMBER JOBNUMBER AND RETURN. IF SY-SUBRC = 0. COMMIT WORK. CALL FUNCTION ‘JOB_CLOSE’ EXPORTING JOBCOUNT = JOBNUMBER JOBNAME = JOBNAME STRTIMMED = ‘X’ EXCEPTIONS CANT_START_IMMEDIATE = 1 INVALID_STARTDATE = 2 JOBNAME_MISSING = 3 JOB_CLOSE_FAILED = 4 JOB_NOSTEPS = 5 JOB_NOTEX = 6 LOCK_FAILED = 7 OTHERS = 8. IF SY-SUBRC <> 0. * Error RETURN. ENDIF. ELSE. * Error RETURN. ENDIF. * Generate PDF File DO. CALL FUNCTION ‘RSPO_FIND_SPOOL_REQUESTS’ EXPORTING RQ0NAME = C_DATASETNAME RQ2NAME = LISTNAME TABLES SPOOLREQUESTS = IT_SPOOLREQ EXCEPTIONS OTHERS = 0. READ TABLE IT_SPOOLREQ INTO WA_SPOOLREQ INDEX 1. IF SY-SUBRC EQ 0. SPL_ID = WA_SPOOLREQ-RQIDENT. CALL FUNCTION ‘CONVERT_OTFSPOOLJOB_2_PDF’ EXPORTING SRC_SPOOLID = SPL_ID NO_DIALOG = ‘ ‘ TABLES PDF = PDF_TABLE EXCEPTIONS ERR_NO_OTF_SPOOLJOB = 1 ERR_NO_SPOOLJOB = 2 ERR_NO_PERMISSION = 3 ERR_CONV_NOT_POSSIBLE = 4 ERR_BAD_DSTDEVICE = 5 USER_CANCELLED = 6 ERR_SPOOLERROR = 7 ERR_TEMSEERROR = 8 ERR_BTCJOB_OPEN_FAILED = 9 ERR_BTCJOB_SUBMIT_FAILED = 10 ERR_BTCJOB_CLOSE_FAILED = 11. IF SY-SUBRC NE 0. *Error EXIT. ENDIF. EXIT. ” Exit from do..enddo loop ELSE. * Spool not updated, Try again ENDIF. ENDDO. LOOP AT PDF_TABLE INTO CONTENT. ASSIGN CONTENT TO CASTING TYPE X. CONCATENATE FILE_XCONTENT INTO FILE_XCONTENT IN BYTE MODE. ENDLOOP. * Assign the MIME Type. MIMETYPE = ‘application/pdf’. LEN = XSTRLEN( FILE_XCONTENT ). * Display PDF CREATE OBJECT CACHED_RESPONSE TYPE CL_HTTP_RESPONSE EXPORTING ADD_C_MSG = 1. LEN = XSTRLEN( FILE_XCONTENT ). CACHED_RESPONSE->SET_DATA( DATA = FILE_XCONTENT LENGTH = LEN ). CACHED_RESPONSE->SET_HEADER_FIELD( NAME = IF_HTTP_HEADER_FIELDS=>CONTENT_TYPE VALUE = MIMETYPE ). CACHED_RESPONSE->SET_STATUS( CODE = 200 REASON = ‘OK’ ). CACHED_RESPONSE->SERVER_CACHE_EXPIRE_REL( EXPIRES_REL = 180 ). CALL FUNCTION ‘GUID_CREATE’ IMPORTING EV_GUID_32 = GUID. CONCATENATE RUNTIME->APPLICATION_URL ‘/’ GUID INTO DISPLAY_URL. CL_HTTP_SERVER=>SERVER_CACHE_UPLOAD( URL = DISPLAY_URL RESPONSE = CACHED_RESPONSE ).     *Page attribute:*    0.1. This conclude the development steps.   0.1. If you want to check the spool request, goto Tcode SP01
To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Alvaro Tejada Galindo
    Hi Raja:

    Nice blog -:) But, why your using Spool to generate the PDF? I belive that HRFORMS just like SMARTFORMS can be turned into PDF by using…FM “CONVERT_OTF”…It would be a better and cleaner solution…Please correct me if I’m wrong -;)

    Greetings,
    Blag.

    (0) 
    1. Raja Thangamani Post author
      Hi Alvaro,

      Thanks for the comments.

      Regarding your question:
      Yes, you will get the generated function module for HRFORMS to get the OTF which is same like Smartforms.

        But if you look at the Form Interface of the Generated FM, there is a parameter called “HRDATA” and populating the HRDATA will be very hard by the calling (custom) program. This HRDATA parameter is set of infoDim.

      So calling this generated FM to get the OTF is not as easy in case of HRFORMS as compare to smartform.

        For each HRFORMS, there is a generated driver programmer which takes care of populating the HRDATA. So I felt calling the generated report & reading the spool was the easy way.

      If you know any other better solution, please let me know…

      Thanks
      Raja

      (0) 

Leave a Reply