Convert Report Program to PDF file

Hi All,
I need example of converting Report program to PDF file.
I am beginner so please give simple example to understand it properly ..
Please write the description along with the code so that i can understand it...
no long long programs please.
Thanks.
Raj

Hi,
report zabap_2_pdf.
*-- Enhancements: only allow to be run with variant.  Then called
*-- program will be transparent to users
*-- TABLES
tables:
  tsp01.
*-- STRUCTURES
data:
  mstr_print_parms like pri_params,
  mc_valid(1)      type c,
  mi_bytecount     type i,
  mi_length        type i,
  mi_rqident       like tsp01-rqident.
*-- INTERNAL TABLES
data:
  mtab_pdf    like tline occurs 0 with header line,
  mc_filename like rlgrap-filename.
*-- SELECTION SCREEN
parameters:
  p_repid like sy-repid, " Report to execute
  p_linsz like sy-linsz default 132, " Line size
  p_paart like sy-paart default 'X_65_132'.  " Paper Format
start-of-selection.
concatenate 'c:'
            p_repid
            '.pdf'
  into mc_filename.
*-- Setup the Print Parmaters
  call function 'GET_PRINT_PARAMETERS'
   exporting
     authority= space
     copies   = '1'
     cover_page                   = space
     data_set = space
     department                   = space
     destination                  = space
     expiration                   = '1'
     immediately                  = space
     in_archive_parameters        = space
     in_parameters                = space
     layout   = space
     mode     = space
     new_list_id                  = 'X'
     no_dialog= 'X'
     user     = sy-uname
   importing
     out_parameters               = mstr_print_parms
     valid    = mc_valid
   exceptions
     archive_info_not_found       = 1
     invalid_print_params         = 2
     invalid_archive_params       = 3
     others   = 4.
*-- Make sure that a printer destination has been set up
*-- If this is not done the PDF function module ABENDS
  if mstr_print_parms-pdest = space.
    mstr_print_parms-pdest = 'LOCL'.
  endif.
*-- Explicitly set line width, and output format so that
*-- the PDF conversion comes out OK
  mstr_print_parms-linsz = p_linsz.
  mstr_print_parms-paart = p_paart.
  submit (p_repid) to sap-spool without spool dynpro
                   spool parameters mstr_print_parms
                   via selection-screen
                   and return.
*-- Find out what the spool number is that was just created
  perform get_spool_number using sy-repid
             sy-uname
    changing mi_rqident.
*-- Convert Spool to PDF
  call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
    exporting
      src_spoolid= mi_rqident
      no_dialog  = space
      dst_device = mstr_print_parms-pdest
    importing
      pdf_bytecount                  = mi_bytecount
    tables
      pdf        = mtab_pdf
    exceptions
      err_no_abap_spooljob           = 1
      err_no_spooljob                = 2
      err_no_permission              = 3
      err_conv_not_possible          = 4
      err_bad_destdevice             = 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
      others     = 12.
call function 'DOWNLOAD'
     exporting
          bin_filesize            = mi_bytecount
          filename                = mc_filename
          filetype                = 'BIN'
     importing
          act_filename            = mc_filename
     tables
          data_tab                = mtab_pdf.
*       FORM get_spool_number *
*       Get the most recent spool created by user/report              *
*  -->  F_REPID               *
*  -->  F_UNAME               *
*  -->  F_RQIDENT             *
form get_spool_number using f_repid
     f_uname
                changing f_rqident.
  data:
    lc_rq2name like tsp01-rq2name.
  concatenate f_repid+0(8)
              f_uname+0(3)
    into lc_rq2name separated by '_'.
  select * from tsp01 where  rq2name = lc_rq2name
  order by rqcretime descending.
    f_rqident = tsp01-rqident.
    exit.
  endselect.
  if sy-subrc ne 0.
    clear f_rqident.
  endif.
endform." get_spool_number
Regards
Sudheer

Similar Messages

  • How to convert the output of the report (program) to PDF file , Please HELP

    Good Morning, ALL
    I have done a small program in ABAP that lets the employee enters his information. Once the emplyee enters the information and executes the program, I want the result to be saved in a PDF file (in any kind of format). I did try to do this action BUT I couldn't. ( ABAP Beginner LOL ).
    This is the code ( The main thing ):
    SELECTION-SCREEN BEGIN OF BLOCK Yours WITH FRAME TITLE text-001.
    PARAMETERS: NAME(15) TYPE C OBLIGATORY lower case,
                CITY LIKE NAME OBLIGATORY ,
                DATE LIKE SY-DATUM DEFAULT SY-DATUM   MODIF ID ZZZ,
                ID# TYPE C LENGTH 9,
                PHONE TYPE C LENGTH 10.
    SKIP 4.
    SELECTION-SCREEN END OF BLOCK Yours.
    SELECTION-SCREEN BEGIN OF BLOCK More WITH FRAME TITLE text-002.
    PARAMETERS: MALE RADIOBUTTON GROUP G1 DEFAULT 'X',
                FEMALE RADIOBUTTON GROUP G1.
    SELECTION-SCREEN END OF BLOCK More.
    SELECTION-SCREEN BEGIN OF BLOCK Details WITH FRAME TITLE text-003.
    PARAMETERS: P_DATE TYPE DATUM,
                Locate TYPE C LENGTH 30.
    SELECTION-SCREEN END OF BLOCK Details.
    AT SELECTION-SCREEN OUTPUT.
      LOOP AT SCREEN.
        IF SCREEN-GROUP1 = 'ZZZ'.
          SCREEN-INPUT = '0'.
          MODIFY SCREEN.
        ENDIF.
      ENDLOOP.
    Any useful help will be appreciated, THANK YOU

    Hi
    Try the below code.
    REPORT ztest_notepad.
    "Variables
    DATA:
       l_lay         TYPE pri_params-paart,
       l_lines       TYPE pri_params-linct,
       l_cols        TYPE pri_params-linsz,
       l_val         TYPE c,
       l_no_of_bytes TYPE i,
       l_pdf_spoolid LIKE tsp01-rqident,
       l_jobname     LIKE tbtcjob-jobname,
       l_jobcount    LIKE tbtcjob-jobcount,
       spoolno       TYPE tsp01-rqident.
    *Types
    TYPES:
       t_pripar      TYPE pri_params,
       t_arcpar      TYPE arc_params.
    "Work areas
    DATA:
       lw_pripar     TYPE t_pripar,
       lw_arcpar     TYPE t_arcpar.
    DATA:
       it_t100       TYPE t100  OCCURS 0 WITH HEADER LINE,
       it_pdf        TYPE tline OCCURS 0 WITH HEADER LINE.
    "Start-of-selection.
    START-OF-SELECTION.
      l_lay   = 'X_65_132'.
      l_lines = 65.
      l_cols  = 132.
      "Read, determine, change spool print parameters and archive parameters
      CALL FUNCTION 'GET_PRINT_PARAMETERS'
        EXPORTING
          in_archive_parameters  = lw_arcpar
          in_parameters          = lw_pripar
          layout                 = l_lay
          line_count             = l_lines
          line_size              = l_cols
          no_dialog              = 'X'
        IMPORTING
          out_archive_parameters = lw_arcpar
          out_parameters         = lw_pripar
          valid                  = l_val
        EXCEPTIONS
          archive_info_not_found = 1
          invalid_print_params   = 2
          invalid_archive_params = 3
          OTHERS                 = 4.
      IF l_val  space AND sy-subrc = 0.
        lw_pripar-prrel = space.
        lw_pripar-primm = space.
        NEW-PAGE PRINT ON
          NEW-SECTION
          PARAMETERS lw_pripar
          ARCHIVE PARAMETERS lw_arcpar
          NO DIALOG.
      ENDIF.
      "Get data
      SELECT *
      FROM t100
      INTO TABLE it_t100
      UP TO 100 ROWS
      WHERE sprsl = sy-langu.
      " Writing to Spool
      LOOP AT it_t100.
        WRITE:/ it_t100.
      ENDLOOP.
      NEW-PAGE PRINT OFF.
      CALL FUNCTION 'ABAP4_COMMIT_WORK'.
      spoolno = sy-spono.
      "Convert spool to PDF
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
        EXPORTING
          src_spoolid   = spoolno
          no_dialog     = ' '
        IMPORTING
          pdf_bytecount = l_no_of_bytes
          pdf_spoolid   = l_pdf_spoolid
          btc_jobname   = l_jobname
          btc_jobcount  = l_jobcount
        TABLES
          pdf           = it_pdf.
      "Download PDF file C Drive
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename = 'C:\itab_to_pdf.pdf'
          filetype = 'BIN'
        TABLES
          data_tab = it_pdf
    Hope this helps you.

  • Page format problem while converting spool job to PDF file

    Hi,
    I convert the sapscript from spoollist to pdf with the FM CONVERT _ OTFSPOOLJOB _ 2 _ PDF giving the spool id but I can not get the file properly. It adds a raigth margin to the PDF file.
    Should I call aany other FM to format the PDF file ?
    Thanks.
    Utku.

    Hi,
    I have executed the report and the PDF file has the right margin.
    In the properties of PDF file it says PDF version 1.3 (Acrobat 4.x) and Page Size 11.69 in x 11.69 in
    Also I open the PDF file with Acrobat 5.0
    Thanks.
    Utku.

  • Convert word document to PDF file in SAP

    Hello experts,
    I've been searching around to get some code examples to upload a word document and convert it into a PDF file and then store it in unix. I hope one of you can help me, because many explanations and threads exist, but I did not get wiser reading them...
    I don't want to use 3rd party tools to do the conversion, but do it directly in SAP with abap coding and if necessary spool processing.
    System details:
    SAP ECC 6.0 (unicode system)
    SAP_ABA     700     0014     SAPKA70014     Cross-Application Component
    SAP_BASIS     700     0014     SAPKB70014     SAP Basis Component
    Thanks in advance!
    Regards,
    Danny

    Hi,
    You can get the spool no from transaction SP01 and later use this spool no to convert the word document to PDF
    using the function module CONVERT_OTFSPOOLJOB_2_PDF and give the import parameter as ur spool id.
    once the doc gets converted to PDF u can use CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
    to get the path where the file is to be saved and later give the path to function module GUI_DOWNLOAD to download the file.
    or else u can manually execute the following reports:
    RSTXPDFT4  (give the spool no. as input)
    RSPO0068  (give the word doc with its full path as input)
    Hope that helps u
    Regards,
    Radhika

  • Convert PO in to PDF file

    Hi,
    Can anybody help me to configure system to convert PO in to PDF file.
    Thanks,
    Sanjana

    Hi jain,
    When using external mail, the following basic settings are required:
    1. You must maintain an e-mail address in the address in the vendor master.
    2. The same applies to your own user master. You also have to specify an e-mail address there in order to identify the sender.
    • Note that it is not possible to change the e-mail address of the vendor via the SAP purchase order transaction (ME21N, ME22N, and so on).
    • The system only uses the e-mail address of the vendor that is maintained in the vendor master!
    3. For the output type for default values, a communication strategy needs to be maintained in the Customizing that supports the e-mail. You can find the definition of the communication strategy in the Customizing via the following path: (SPRO -> IMG -> SAP Web Application Server -> Basic Services -> Message Control -> Define Communication Strategy). As a default, communication strategy CS01 is delivered. This already contains the necessary entry for the external communication. Bear in mind that without a suitable communication strategy it is not possible to communicate with a partner via Medium 5 (external sending).
    4. Use the standard SAP environment (program 'SAPFM06P', FORM routine 'ENTRY_NEU' and form 'MEDRUCK') as the processing routines.
    5. In the condition records for the output type NEU (for example, Transaction MN04), use medium '5' (External send). Then in Transaction M/34 for the output type NEU add the medium '5' (External send) in Partner functions & Processing routines.
    6.Then Create a PO…Go to Messages>select the output type & medium '5' (External send). Then communication method > Comm Strategy “CS01”. Remoce Print immediately if it is ticked.
    7. Then go back ,Select message>Further data>Dispatch time>Select 'Send immediately (when saving application)'
    Back and save PO.
    8. Check SCOT. PO will be in the waiting list. If u want to see the detailed list of waiting items then go to transaction SOST. Specify the Send date, select the check box Waiting & execute.
    If you want further details Please check the SAP note 191470.
    Or
    If you want a particular document in PDF , Goto SE38 enter program as RSTXPDFT4 , Enter Spool number of the document generated while print output that you want to convert in to PDF. Give location where you want to save. open the file in PDF format. Then attach this file to the email.
    Regards,
    hareesha

  • I know that how to convert any documents to pdf file, but don't know how to get barcode on it. I am using windows 8.1. and want to see barcode on my documents before the print. Please help.

    I know that how to convert any documents to pdf file, but don't know how to get barcode on it. I am using windows 8.1. and want to see barcode on my documents before the print. Please help.

    Hi Frank ,
    Please refer to the following link and see if this helps.
    https://helpx.adobe.com/acrobat/kb/error-organizer-database-damaged-reset-1.html
    Regards
    Sukrit Dhingra

  • Exporting a Report to a pdf file with drill down!

    Hi,
    I would like to export a Report to a pdf file.
    My Report includes drill down options. I require the exported pdf with drill down options.
    (Similar to Navigation options in a PDF file).
    I hope this makes sense.
    Please provide a better solution for me.
    If am not wrong, this facility is not available with Crystal Reports!!!
    Thanks,
    Ramesh.

    Hi Ramesh
    You can download the trial versions of the Crystal Report from the following link:
    https://websmp202.sap-ag.de/support (Please copy the link and paste it to your web browser).
    You can get the license by putting a request in the follwoing link:
    https://websmp202.sap-ag.de/support(Click on Request License key under Service Corner).
    Hope it helps.
    Regards
    Sourashree Ghosh

  • Is it possible to export the page activity report to a pdf file?

    Is it possible to export the page activity report to a pdf file?and is there any api or samples to be reference

    Do you mean audit history?   One method would be similar to the following sample that you could extend to create a PDF from the data returned:
    http://www.eyelock.net/blog/archives/533
    BUT the method used above via JCR Query is an implementation detail.  For future proofing, you should use the ReplicationStatus status = page.adaptTo(ReplicationStatus.class in your code to get the audit logs for a particular page, rather than a straight JCR query. (recommended by Jörg Hoh @ http://forums.adobe.com/message/5253760).

  • How to convert a password protected pdf file?

    How do I convert a password protected pdf file to Word?

    Yup. You all are right. I ordered Adobe Acrobat today and the order is still processing. I can get to Adobe Acrobat.com but that too does not work. I guess I will have to wait until my order is processed before I get the keys to the kingdom. Thanks for your help and please forgive my ignorance.Regards,Bob

  • Convert portfolio to single pdf file

    Hi, I have a portfolio of my email archive which I want to convert to a single pdf file. The way I'm doing it is by combining files and adding the portfolio file and then clicking combine, merge files into a single pdf, adding the portfolio and selecting single pdf file. This 'breaks up' the portfolio into its individual constituents which you can then combing into a single normal pdf file.
    But there is a problem. In the portfolio the original date of the email is retained so you can sort the emails chronologically. However, when the portfolio is broken up the individual files are dated on the date the portfolio is created and so the new file is not sorted in the chronological send/receive order of the emails.
    So my question is: how do I combine emails to a single pdf file in the chronological order of the emails?
    Many thanks
    Ps Since typing this message I've noticed that when printing all files in the portfolio it also doesn't print it in chronological order even though that's how they're sorted in the portfolio.

    Something to try —
    View the open Portfolio in the List or Basic Grid view.
    Select all the files.
    Select File > Sae Files from Portfolio > Use the Browse For Folder dialog to select a destination.
    Click OK.
    A copy of the Portfolio's files will be in the designated location.
    Perform the Combine > Merge Files into a Single PDF action.
    Be well..
    Message was edited by: CtDave

  • Each page of Oracle Report Generates separate pdf file.

    I have a problem that i want that oracle report runs for one time and generates sepatate pdf files for each oracle report page.eg. if there are 8 page of report then 8 pdf files should generate (one pdf file for each page) but the condition is that the print job is set to NO and page range should not be given each time.

    What version of Reports are you using?
    If it's 10g then have a look at Report Bursting as this should enable you to send the report to multiple files based on a repeating group.
    Mark

  • Will adobe pdf converter recognize an Hebrew pdf file?

    Will Adobe pdf converter recognize an Hebrew pdf file and convert it into an editable Word or OpenOffice file?

    Our ExportPDF service doesn't support Hebrew text at this time.  Feel free to vote for this feature here: http://forums.adobe.com/ideas/1554
    -David

  • I downloaded a magazine as a web archive and want to know can I convert it to a PDF file and if so, how do I do that please

    I downloaded an magazine as a web archive and want to convert ii to a PDF file. Can I do this and if so, how ? Thank You

    Thank you Frederic, however when I click on "open with", 3 sidebars (?) open in this order ..Safari (default); Textedit; Other. If I click on "other", another window opens with "recommended applications" highlighted. Preview is not one of the chosen applications. However if I click on "all applications", Preview is then highlighted, but it only has an "open" window and I don't get an opportunity to File>Save as PDF.
    I hope this makes sense...ellietess

  • How to write adapter module to convert the xml to pdf file

    Hi all,
      how to write adapter module to convert the xml to pdf file.
    Please any body assist step by step procedure.

    PI 7.1 XML to PDF transformation
    have you seen below links:
    http://forums.sdn.sap.com/thread.jspa?threadID=1212478
    http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/14363

  • Converting report output to pdf by submit spooland email to multiple vendor

    Hi all,
               my current program converting the report output to pdf and then downaloding andsending  to vendor email.If user enter single vendor is o.k. but if suppose user enter multiple vendors,report is dipalying with multiple vendor information and all this information converting to one pdf file only.but i need particular vendor pdf have particular vendor info only excluding remaining vendor info.I am pasting my code.can anyone suggest?
    TYPES: BEGIN OF type_data,
           lifnr TYPE ekko-lifnr,
           matnr TYPE lips-matnr,
           vgbel TYPE lips-vgbel,
           vgpos TYPE lips-vgpos,
           mfrgr TYPE lips-mfrgr,
           vbeln TYPE ekes-vbeln,
           erdat TYPE ekes-erdat,
           lfdat TYPE ekes-eindt,
           lgort TYPE lips-lgort,
           verur TYPE ekes-xblnr,
           lfuhr TYPE ekes-uzeit,
           lfimg TYPE lips-lfimg,
           meins TYPE lips-meins,
           posnr TYPE lips-posnr,
           kdmat TYPE lips-kdmat,
           dabmg TYPE ekes-dabmg,
           eindt TYPE eket-eindt,
    * Add by liza DEVK989704
           park TYPE ZPO_PARK-menge,
    * End by liza DEVK989704
           END OF type_data.
    DATA: gt_data TYPE STANDARD TABLE OF type_data.
    DATA: gw_data LIKE LINE OF gt_data.
    form display_list.
    DATA: lv_maktx   TYPE makt-maktx,
            lv_adv(01) TYPE c.
      DATA: lv_menge TYPE zomm_t0104m-menge.
    *-- Set titles
      title1 = 'Shipping notifications'.
      title2 = '(Formerly Known As Matsushita Industrial )'.
      title3 = sy-title.
      IF NOT pa_fax IS INITIAL.
        NEW-PAGE LINE-SIZE 120 LINE-COUNT 44.
        title3 = 'Outstanding shipping notifications by supplier'.
      ENDIF.
      SORT gt_data BY lifnr lfdat matnr vgbel vgpos eindt.
      LOOP AT gt_data INTO gw_data.
        AT NEW lifnr.
          NEW-PAGE.
          sy-pagno = 1.
    *-- Get the vendor name
          CLEAR: gv_name1,
                 gv_telf1,
                 gv_telfx.
          SELECT SINGLE name1 telf1 telfx
                 INTO (gv_name1, gv_telf1, gv_telfx)
                 FROM lfa1
                 WHERE lifnr = gw_data-lifnr.
        ENDAT.
    AT NEW matnr.
    *-- Get the material description
          CLEAR lv_maktx.
          SELECT SINGLE maktx INTO lv_maktx
                 FROM makt
                 WHERE matnr = gw_data-matnr
                   AND spras = sy-langu.
        ENDAT.
    *-- If "only pending shipping notifications" is selected, remove all
    *   entries with no pending quantity
        IF gw_data-lfimg LE gw_data-dabmg AND
           pa_pend = 'X'.
          CONTINUE.
        ENDIF.
    *-- Highlight entries where the SN delivery date is before the PO
    *   delivery date
        IF gw_data-lfdat < gw_data-eindt.
          FORMAT INTENSIFIED ON.
          lv_adv = 'X'.
        ELSE.
          FORMAT INTENSIFIED OFF.
          CLEAR lv_adv.
        ENDIF.
        lv_menge = gw_data-lfimg - gw_data-dabmg.
    * Add by liza DEVK989704
        clear: PARKING, T_PARK.
        refresh: T_PARK.
        Select * from ZPO_PARK into T_PARK
        where vbeln = gw_data-vbeln
        and lifnr = gw_data-lifnr
        and matnr =  gw_data-matnr.
        Append T_PARK.
        Endselect.
        Loop at T_PARK.
          PARKING = PARKING + T_PARK-menge.
        Endloop.
        gw_data-park = PARKING.
    * End by liza DEVK989704
        IF pa_fax IS INITIAL.
          WRITE:/2(18) gw_data-matnr,
                  (40) lv_maktx,
                       gw_data-vgbel,
                       gw_data-eindt,
                  (04) gw_data-mfrgr,
                  (18) gw_data-verur,
                       gw_data-vbeln,
                       gw_data-lfdat,
                  (07) gw_data-lfimg UNIT gw_data-meins,
                  (07) gw_data-dabmg UNIT gw_data-meins,
                  (07) lv_menge UNIT gw_data-meins,
                       gw_data-lgort,
                       gw_data-erdat,
                  (01) lv_adv,
    * Add by liza DEVK989704
                  (08) gw_data-park.
    * End by liza DEVK989704
        ELSE.
          WRITE:/2(12) gw_data-matnr,
                  (26) lv_maktx,
                       gw_data-vgbel,
                  (16) gw_data-verur,
                       gw_data-vbeln,
                       gw_data-lfdat,
                  (07) gw_data-lfimg UNIT gw_data-meins,
                  (07) gw_data-dabmg UNIT gw_data-meins,
                  (07) lv_menge UNIT gw_data-meins,
                       gw_data-lgort.
        ENDIF.
        PERFORM write_vline.

    AT END OF lifnr.
         If pa_dtim NE '000000'.
          ULINE.
          SKIP.
          WRITE:/12 TS_VEND.
          WRITE:/12 TS_ATT.
          WRITE:/12 TS_FROM.
          SKIP.                                     "D01K934099
          WRITE:/12'DELIVERY TIME:',pa_dtim.        "D01K934099
          SKIP.                                     "D01K934099
          WRITE:/12 TS_TEXT1.
          WRITE:/12 TS_TEXT2.
          WRITE:/12 TS_TEXT3.
          WRITE:/12 TS_TEXT4.
        Else.
          ULINE.
          SKIP.
          WRITE:/12 TS_VEND.
          WRITE:/12 TS_ATT.
          WRITE:/12 TS_FROM.
          WRITE:/12 TS_TEXT1.
          WRITE:/12 TS_TEXT2.
          WRITE:/12 TS_TEXT3.
          WRITE:/12 TS_TEXT4.
    Endif.
    ENDAT.
         move-corresponding gw_data to t_data.
         move : lv_maktx  to t_data-maktx,
                lv_menge  to t_data-menge,
                lv_adv    to t_data-adv,
                parking   to t_data-park.
           append t_data.
    L_X = 'X'.
      CALL FUNCTION 'GET_PRINT_PARAMETERS'
       EXPORTING
         NO_DIALOG                      = L_X
       IMPORTING
         OUT_PARAMETERS                 = GS_PRINT_PARAMS
         VALID                          = G_VALID
      IF SY-SUBRC  0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
          GS_PRINT_PARAMS-PAART = 'X_65_80'.
          GS_PRINT_PARAMS-LINSZ = '185'.
    *   /*----------store the current selection screen details---------/
      CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
        EXPORTING
          CURR_REPORT           = SY-REPID
        TABLES
          SELECTION_TABLE       = T_RSPARAMS
       EXCEPTIONS
         NOT_FOUND             = 1
         NO_REPORT             = 2
         OTHERS                = 3
      IF SY-SUBRC  0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    *   /*--- importing variable value set at first time to restrict the infinite loop --------/.
    IMPORT VAR FROM MEMORY ID 'abc' .
      VAR = VAR + 1 .
      P_UNAME = SY-UNAME .
      P_REPID = SY-REPID .
    * /*------checking variable to restricted scecond time exction of this block of code---------/
      IF VAR = 1 .
        V_MEMID = 1 .
        EXPORT VAR TO MEMORY ID 'abc' .
    * /*-----------submitting the spool request--------------/
        SUBMIT (P_REPID) WITH SELECTION-TABLE T_RSPARAMS
                           TO SAP-SPOOL
                         SPOOL PARAMETERS GS_PRINT_PARAMS
                         WITHOUT SPOOL DYNPRO
                         AND RETURN.
    endif.
    FREE MEMORY ID 'abc'.
    *  /*-------Calculating the lenth of report name--------/
      v_len = STRLEN( P_REPID ) .
    *  /*-------consutrucing the database variable  rq2name to search the spool request---------/
      IF v_len >= 9 .
        CONCATENATE P_REPID+0(9)
                    P_UNAME+0(3) INTO LC_RQ2NAME .
      ELSE.
        V_LEN1 = 9 - V_LEN .
        DO V_LEN1 TIMES .
          CONCATENATE V_TEMP '_' INTO V_TEMP .
        ENDDO.
        CONCATENATE P_REPID V_TEMP
                    P_UNAME INTO LC_RQ2NAME .
      ENDIF.
    *  /*--------selecting the spool request using the above constructed variable----------/
      SELECT  * FROM TSP01 INTO TABLe IT_TSP01
              WHERE RQ2NAME = LC_RQ2NAME .
    * /*--------sorting the internal table-----------/
      SORT  it_tsp01 BY RQCRETIME DESCENDING .
    * /*--------reading the first spool request-------/
      READ TABLE IT_TSP01 INDEX 1.
    * /*--------Convert Spool to PDF-----------/
      IF GS_PRINT_PARAMS-PDEST IS INITIAL.
        GS_PRINT_PARAMS-PDEST = 'LOCL'.
      ENDIF.
      CONCATENATE P_DEST T_DATA-LIFNR '.PDF' INTO G_FILENAME.
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
        EXPORTING
          SRC_SPOOLID                    = IT_TSP01-RQIDENT
         NO_DIALOG                      = SPACE
       IMPORTING
         PDF_BYTECOUNT                  = G_BYTECOUNT
       TABLES
         PDF                            = T_PDF
       EXCEPTIONS
         ERR_NO_ABAP_SPOOLJOB           = 1
         ERR_NO_SPOOLJOB                = 2
         ERR_NO_PERMISSION              = 3
         ERR_CONV_NOT_POSSIBLE          = 4
         ERR_BAD_DESTDEVICE             = 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
         OTHERS                         = 12
      IF SY-SUBRC  0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

Maybe you are looking for