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: 

Convert Smarform to PDF with Spool

Former Member

Hello Guys,

i need to convert a smartform to a PDF and send it via mail from a Spool-Request. I managed to do the conversion with the FM 'SSF_FUNCTION_MODULE_NAME' and then call the smartform with 'CALL FUNCTION v_form_name' and it works.

The smartform has import parameters that need to be filled with data so the smartform won't be empty.

DATA:

      gv_addr     TYPE addr_key,

      gv_nast     TYPE nast,

      gv_vbdka    TYPE vbdka,

      gv_vbdpa    LIKE TABLE OF vbdpa,

      gv_vbdpau   LIKE TABLE OF vbdpau.

CALL FUNCTION v_form_name

  EXPORTING

    control_parameters = w_ctrlop

    output_options     = w_compop

    is_addres          = gv_addr

    is_nast            = gv_nast

    is_vbdka           = gv_vbdka

    user_settings      = 'X'

  IMPORTING

    job_output_info    = w_return

  TABLES

    it_vbdpa           = gv_vbdpa

    it_vbdpau          = gv_vbdpau

  EXCEPTIONS

    formatting_error   = 1

    internal_error     = 2

    send_error         = 3

    user_canceled      = 4

    OTHERS             = 5.

is_addres, is_nast and is_vbdka are required.

The interface of the smartform IMPORT PARAMETERS are as followed:

*"     VALUE(ARCHIVE_INDEX) TYPE  TOA_DARA OPTIONAL

*"     VALUE(ARCHIVE_INDEX_TAB) TYPE  TSFDARA OPTIONAL

*"     VALUE(ARCHIVE_PARAMETERS) TYPE  ARC_PARAMS OPTIONAL

*"     VALUE(CONTROL_PARAMETERS) TYPE  SSFCTRLOP OPTIONAL

*"     VALUE(MAIL_APPL_OBJ) TYPE  SWOTOBJID OPTIONAL

*"     VALUE(MAIL_RECIPIENT) TYPE  SWOTOBJID OPTIONAL

*"     VALUE(MAIL_SENDER) TYPE  SWOTOBJID OPTIONAL

*"     VALUE(OUTPUT_OPTIONS) TYPE  SSFCOMPOP OPTIONAL

*"     VALUE(USER_SETTINGS) TYPE  TDBOOL DEFAULT 'X'

*"     VALUE(IS_VBDKA) TYPE  VBDKA

*"     VALUE(IS_NAST) TYPE  NAST

*"     VALUE(IS_ADDRES) TYPE  ADDR_KEY

I can't find any relation between those. The ADRNR in the NAST table is empty, it is the only possible relation i found to get the data i need. Even the spool request in the SP01 transaction doesn't give me any information on how to fill those.

If i run my Program the mail gets sent (but not immediatly immediately). The PDF File has the structure of the smartform in it, but not the data that is required. See here :

If there is any way to fill those parameters and you could tell me or any other way to do that, i would be thankful.

6 REPLIES 6

SimoneMilesi
Active Contributor
0 Kudos

Hello!

First of all, there are a lot of threads and a wonderful Wiki on how to transform a smartform into a a PDF https://wiki.scn.sap.com/wiki/display/Snippets/Convert+Smartform+to+PDF+format

Why the output is empty: your code passes empty tables and structures so how can you have some data on output?

Former Member
0 Kudos

As i mentioned, the conversion works just fine. Also i know that those tables and structures are empty, thats what i said in my Question! My Question wasn't on how to convert a smartform to PDF, i questioned on how to fill those tables/structures to get the correct data that i need. Thats why i gave the import parameters from the smartform as an information for you, to help me out with that.

SimoneMilesi
Active Contributor
0 Kudos

Well, which data to pass... it's up to your logic and needs!
NAST stores the printout messages and their status.

What do you want to print?

What's that smartform?

Jelena
Active Contributor
0 Kudos

The question title literally says "Convert Smarform to PDF with Spool", I thought the same thing a Simone - this must be 1001st question on this. 🙂 Why would you make this a title of the question if this is not the question? It's confusing to others and ineffective. Most regulars will just see the title and won't even open it.

Jelena
Active Contributor
0 Kudos

It looks like you're trying to use a form that is meant to be used in the sales document output (configured in NACE transaction).

Try FM RV_DOCUMENT_PRINT_VIEW, at least that's what is used in our system. Not sure if there is a newer/better FM for this. If there is you'll likely find it in the output program assigned to the V1 output in NACE.

This is a sample call of FM. If you don't have NAST, all you need is the document number (VBELN).

 vbco3-mandt = sy-mandt.
 vbco3-spras = nast-spras.  <- language
vbco3-vbeln = nast-objky. <- VBAK-VBELN with leading zeroes vbco3-kunde = nast-parnr. <- partner (usually Sold-to VBAK-KUNNR) vbco3-parvw = nast-parvw. <- partner type (AG = Sold-to) CALL FUNCTION 'RV_DOCUMENT_PRINT_VIEW' EXPORTING comwa = vbco3 IMPORTING kopf = vbdka TABLES pos = tvbdpa mess = da_mess EXCEPTIONS fehler_bei_datenbeschaffung = 1.

Former Member
0 Kudos

Please check if it helps: This is to convert spool into PDF -

FORM f_prepare_pdf_attach TABLES pt_table.

 DATA: lw_print_params TYPE pri_params,
 lt_data_otf TYPE TABLE OF tline,
 lw_pdf_otf TYPE tline,
 lv_xstring TYPE xstring,
 lc_mode TYPE sycallr.

* Get the print parameters
 IF gv_spoolid_ut IS NOT INITIAL.
 lc_mode = 'CURRENT'.
 ENDIF.

 CALL FUNCTION 'GET_PRINT_PARAMETERS'
 EXPORTING
 authority = space
 copies = gc_copy_u
 cover_page = space
 data_set = space
 department = space
 destination = space
 expiration = gc_exp_u
 immediately = space
 new_list_id = abap_true
 no_dialog = abap_true
 user = sy-uname
 mode = lc_mode
 IMPORTING
 out_parameters = lw_print_params
 EXCEPTIONS
 archive_info_not_found = 1
 invalid_print_params = 2
 invalid_archive_params = 3
 OTHERS = 4.
 IF sy-subrc <> 0.
 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
 ENDIF.

* Set the printer destination
 IF lw_print_params-pdest = space.
 lw_print_params-pdest = gc_dest_u. "LOCL
 ENDIF.

* set the line size and paper format
 lw_print_params-linsz = '132'.
 lw_print_params-paart = 'X_65_132'.

* set the print parameters for spool
 NEW-PAGE PRINT ON PARAMETERS lw_print_params
 NO DIALOG NO-TITLE NO-HEADING.

* check if output data
 IF NOT pt_table[] IS INITIAL.
* print the output data in ALV in the spool
 PERFORM f_print_alv_data TABLES pt_table.
 ENDIF.

 NEW-PAGE PRINT OFF.
* get the spool number
 IF gv_spoolid_ut IS INITIAL.
 gv_spoolid_ut = sy-spono.
 ENDIF.

 IF gv_spoolid_ut IS NOT INITIAL.

 lw_print_params-linsz = '-185'.
 lw_print_params-paart = 'X_65_255'.
* convert Spool into OTF format data
 CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
 EXPORTING
 src_spoolid = gv_spoolid_ut
 dst_device = lw_print_params-pdest
 TABLES
 pdf = lt_data_otf
 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.

* convert OTF data into xtring format
 LOOP AT lt_data_otf INTO lw_pdf_otf.
 ASSIGN lw_pdf_otf TO <fs_xline_u> CASTING.
 CONCATENATE lv_xstring <fs_xline_u> INTO lv_xstring IN BYTE MODE.
 ENDLOOP.

* get PDF xstring and convert it to BCS format
 gv_size_x_u = XSTRLEN( lv_xstring ).
 gt_objbin_x_u = cl_document_bcs=>xstring_to_solix(
 ip_xstring = lv_xstring ).
 ENDIF.

ENDFORM. " F_PREPARE_PDF_ATTACH