Application Development and Automation 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: 
Read only

How to trigger script form to auto generate spool?

JasClemencio
Explorer
0 Likes
2,948

Requirement is to create interface that will be triggered by outside app, They will pass invoice number then SAP will call the invoice form and download to PDF in a local file. 

So far i am calling program RFKORD50 but this only let me preview the file and will only generate spool once i manually select PRINT. I need this program to auto generate the spool once called then i will convert the spool to PDF

 

 

 

REPORT z_trigger_script_to_pdf.

PARAMETERS: p_docnum TYPE bkorm-belnr OBLIGATORY DEFAULT '7035000025', " Document Number
            p_path   TYPE rlgrap-filename  OBLIGATORY DEFAULT 'C:\Users\jasmine.clemencio\Desktop\UAT.pdf', " File path for PDF output
            p_comp   TYPE bkorm-bukrs OBLIGATORY DEFAULT 'MY10',
            p_year   TYPE bkorm-gjahr OBLIGATORY DEFAULT '2023',
            p_cor    TYPE bkorm-event OBLIGATORY DEFAULT 'Z0017'.

DATA: lv_spool_no   TYPE tsp01-rqident,
      lv_file_path  TYPE rlgrap-filename,
      lv_parameters TYPE string.

" Step 1: Call RFKORD50 to generate spool
SUBMIT zrfkord50
  WITH rbelnr  = p_docnum
  WITH rgjahr  = p_comp
  WITH rgjahr   = p_year
  WITH revent  =  p_cor
  WITH spool = 'X' " Indicate spool creation
  AND RETURN.


" Step 2: Retrieve the spool number
SELECT SINGLE rqident
  INTO lv_spool_no
  FROM tsp01
  WHERE rq2name = sy-uname
    AND rqclient = sy-mandt.
lv_spool_no = 13300.
*IF sy-subrc NE 0.
*  WRITE: / 'Failed to retrieve spool number.'.
*  EXIT.
*ENDIF.

WRITE: / 'Spool Number:', lv_spool_no.

" Step 3: Call RSTXPDFT4 to convert spool to PDF

SUBMIT zrstxpdft4
  WITH spoolno = 13300
  WITH p_file  =  p_path
  EXPORTING LIST TO MEMORY
  AND RETURN.

 

 

 

 

Requirement is to create interface that will be triggered by outside app, They will pass invoice number then SAP will call the invoice form and download to PDF in a local file. 

So far i am calling program RFKORD50 but this only let me preview the file and will only generate spool once i manually select PRINT. I need this program to auto generate the spool once called then i will convert the spool to PDF

 

 

 

REPORT z_trigger_script_to_pdf.

PARAMETERS: p_docnum TYPE bkorm-belnr OBLIGATORY DEFAULT '7035000025', " Document Number
            p_path   TYPE rlgrap-filename  OBLIGATORY DEFAULT 'C:\Users\jasmine.clemencio\Desktop\UAT.pdf', " File path for PDF output
            p_comp   TYPE bkorm-bukrs OBLIGATORY DEFAULT 'MY10',
            p_year   TYPE bkorm-gjahr OBLIGATORY DEFAULT '2023',
            p_cor    TYPE bkorm-event OBLIGATORY DEFAULT 'Z0017'.

DATA: lv_spool_no   TYPE tsp01-rqident,
      lv_file_path  TYPE rlgrap-filename,
      lv_parameters TYPE string.

" Step 1: Call RFKORD50 to generate spool
SUBMIT zrfkord50
  WITH rbelnr  = p_docnum
  WITH rgjahr  = p_comp
  WITH rgjahr   = p_year
  WITH revent  =  p_cor
  WITH spool = 'X' " Indicate spool creation
  AND RETURN.


" Step 2: Retrieve the spool number
SELECT SINGLE rqident
  INTO lv_spool_no
  FROM tsp01
  WHERE rq2name = sy-uname
    AND rqclient = sy-mandt.
lv_spool_no = 13300.
*IF sy-subrc NE 0.
*  WRITE: / 'Failed to retrieve spool number.'.
*  EXIT.
*ENDIF.

WRITE: / 'Spool Number:', lv_spool_no.

" Step 3: Call RSTXPDFT4 to convert spool to PDF

SUBMIT zrstxpdft4
  WITH spoolno = 13300
  WITH p_file  =  p_path
  EXPORTING LIST TO MEMORY
  AND RETURN.

 

 

 

 

7 REPLIES 7
Read only

FredericGirod
Active Contributor
0 Likes
2,854

Did you try to call function like SET_PRINT_PARAMETERS ?  

to set create new spool 

print immedialty ... 

Read only

0 Likes
2,631

the code above works fine. Except i cannot run the program in background because of program 

rfkord50

@FredericGirod wrote:

Did you try to call function like SET_PRINT_PARAMETERS ?  

to set create new spool 

print immedialty ... 


 
Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,846

You could also

  • Execute the first SUBMIT with additions WITHOUT SPOOL DYNPRO and TO SAP-SPOOL spool_options (build this structure spool_options with FM GET_PRINT_PARAMETERS to prevent some immediate print and delete)
  • Get the spool number of the created spool request which is contained in a SPA/GPA parameter named SPI, using GET PARAMETER ID 'SPI' FIELD spoolno.
Read only

0 Likes
2,631

the code above works fine. Except i cannot run the program in background because of program 

Read only

WO1
Associate
Associate
0 Likes
2,689

And use CL_RSPO_SPOOLID_TO_PDF=>GET_SPOOL_PDF to get the PDF as an xstring.

Read only

0 Likes
2,631

this works when i run background? external app will trigger the FM

Read only

WO1
Associate
Associate
0 Likes
2,604

Yes, CL_RSPO_SPOOLID_TO_PDF=>GET_SPOOL_PDF can be called in the background.