Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

hwo to get the spool number from report output

Former Member
0 Kudos

Hi,

I am displaying some output in the report using write statements and within my program I need to collect the output written by write statements and send it as an email.So for that I need to generate the spool number and I am using the below code to do that



CONSTANTS:
    l_linsz TYPE sy-linsz VALUE 201, " Line size
    l_paart TYPE sy-paart VALUE 'X_65_132'.  " Paper Format


  l_uname = sy-uname .
  l_repid = sy-repid .
*-- 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
      new_list_id            = k_x
      no_dialog              = k_x
      user                   = l_uname
    IMPORTING
      out_parameters         = l_mstr_print_parms
      valid                  = l_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 l_mstr_print_parms-pdest = space.
    l_mstr_print_parms-pdest = k_lp01.
  ENDIF.
*-- Explicitly set line width, and output format so that
*-- the PDF conversion comes out OK
  l_mstr_print_parms-linsz = l_linsz.
  l_mstr_print_parms-paart = l_paart.
  l_variante = sy-slset.
* submitting the spool request
  *SUBMIT (l_repid) TO SAP-SPOOL*
                   *SPOOL PARAMETERS l_mstr_print_parms*
                   *WITHOUT SPOOL DYNPRO*
                   *AND RETURN.*



*
*Calculating the lenth of report name
  lv_len = STRLEN( l_repid ) .
*consutrucing the database variable  rq2name to search the spool
*request
  IF lv_len >= 9 .
    CONCATENATE l_repid+0(9)
                l_uname+0(3) INTO lc_rq2name .
  ELSE.
    lv_len = 9 - lv_len .
    DO lv_len TIMES .
      CONCATENATE lv_temp '_' INTO lv_temp .
    ENDDO.
    CONCATENATE l_repid lv_temp
                l_uname INTO lc_rq2name .
  ENDIF.

*selecting the spool request using the above consructed varibale
  SELECT   * FROM tsp01 INTO TABLE lt_tsp01
          WHERE rq2name = lc_rq2name .
*sorting the interbla table
  SORT  lt_tsp01 BY rqcretime DESCENDING .
*reading the first spool request
  READ TABLE lt_tsp01 INTO ls_tsp01 INDEX 1.

but the problem with the above code is I am using variants to execute the report but when the above piece of code is getting executed it is clearing all the variant values on the selection screen and it is defaulting the values on the selection screen.

Is there any way i can execute the above code without any problem in the selection screen.

Thanks

Bala Duvvuri

1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor
0 Kudos

Hello Bala,

I wouldn't SUBMIT the same program to get the Spool number. You can achieve the same by [NEW-PAGE PRINT ON|http://help.sap.com/abapdocu_702/en/abapnew-page_print.htm#!ABAP_ADDITION_1@1@] command.

Check the code snippet i've provided below:

DATA: spfli_wa         TYPE spfli,
      print_parameters TYPE pri_params,
      valid_flag       TYPE c LENGTH 1.

START-OF-SELECTION.

  CALL FUNCTION 'GET_PRINT_PARAMETERS'
    EXPORTING
      no_dialog            = 'X'
    IMPORTING
      out_parameters       = print_parameters
      valid                = valid_flag
    EXCEPTIONS
      invalid_print_params = 2
      OTHERS               = 4.

  IF valid_flag = 'X' AND sy-subrc = 0.

*   1. Write the output to the output list(no spool is generated)
    SELECT carrid connid
           FROM spfli
           INTO CORRESPONDING FIELDS OF spfli_wa.
      WRITE: / spfli_wa-carrid, spfli_wa-connid.
    ENDSELECT.

*   2. Write the output to SAP spool(no list is displayed)
    NEW-PAGE PRINT ON PARAMETERS print_parameters NO DIALOG.

    SELECT carrid connid
           FROM spfli
           INTO CORRESPONDING FIELDS OF spfli_wa.
      WRITE: / spfli_wa-carrid, spfli_wa-connid.
    ENDSELECT.

    NEW-PAGE PRINT OFF.

    MESSAGE i000(zibi027) WITH 'Spool' sy-spono 'is generated!!!'.

    "You can use the spool number (SY-SPONO) to email the list output

  ENDIF.

Hope this helps.

BR,

Suhas

3 REPLIES 3

Former Member
0 Kudos

Hi,

Can you include the statement "... USING SELECTION-SET variant " in the SUBMIT statement used to call the report.

Thanks & Regards,

Harish

SuhaSaha
Advisor
Advisor
0 Kudos

Hello Bala,

I wouldn't SUBMIT the same program to get the Spool number. You can achieve the same by [NEW-PAGE PRINT ON|http://help.sap.com/abapdocu_702/en/abapnew-page_print.htm#!ABAP_ADDITION_1@1@] command.

Check the code snippet i've provided below:

DATA: spfli_wa         TYPE spfli,
      print_parameters TYPE pri_params,
      valid_flag       TYPE c LENGTH 1.

START-OF-SELECTION.

  CALL FUNCTION 'GET_PRINT_PARAMETERS'
    EXPORTING
      no_dialog            = 'X'
    IMPORTING
      out_parameters       = print_parameters
      valid                = valid_flag
    EXCEPTIONS
      invalid_print_params = 2
      OTHERS               = 4.

  IF valid_flag = 'X' AND sy-subrc = 0.

*   1. Write the output to the output list(no spool is generated)
    SELECT carrid connid
           FROM spfli
           INTO CORRESPONDING FIELDS OF spfli_wa.
      WRITE: / spfli_wa-carrid, spfli_wa-connid.
    ENDSELECT.

*   2. Write the output to SAP spool(no list is displayed)
    NEW-PAGE PRINT ON PARAMETERS print_parameters NO DIALOG.

    SELECT carrid connid
           FROM spfli
           INTO CORRESPONDING FIELDS OF spfli_wa.
      WRITE: / spfli_wa-carrid, spfli_wa-connid.
    ENDSELECT.

    NEW-PAGE PRINT OFF.

    MESSAGE i000(zibi027) WITH 'Spool' sy-spono 'is generated!!!'.

    "You can use the spool number (SY-SPONO) to email the list output

  ENDIF.

Hope this helps.

BR,

Suhas

Former Member
0 Kudos

Thanks Suhas that did the trick