How to trigger script form to auto generate spool?

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:Usersjasmine.clemencioDesktopUAT.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.

 

 

 

 

Scroll to Top