cancel
Showing results for 
Search instead for 
Did you mean: 

how can i save my smart form progam into pdf file

Former Member
0 Kudos

hi i knew that i need ot use convert_otf fm to make the smartform into pdf format could any one help me how to implement this my program

Accepted Solutions (1)

Accepted Solutions (1)

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Check this sample code from sdn.Get back in case of clarifications.

REPORT zswar.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME.

PARAMETER: p_date LIKE sy-datum.

PARAMETER: p_rea TYPE char255.

SELECTION-SCREEN: END OF BLOCK b1.

DATA: ws_ucomm LIKE sy-ucomm.

INITIALIZATION.

SET PF-STATUS 'STANDARD' OF PROGRAM 'ZSWAR'.

AT SELECTION-SCREEN.

ws_ucomm = sy-ucomm.

CASE ws_ucomm.

WHEN '&PDF'.

PERFORM f1000_download_form.

EXIT.

WHEN '&BACK'.

SET SCREEN 0.

EXIT.

WHEN '&EXIT'.

SET SCREEN 0.

EXIT.

WHEN '&canc'.

SET SCREEN 0.

LEAVE TO SCREEN 0.

ENDCASE.

&----


*& Form F1000_DOWNLOAD_FORM

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f1000_download_form.

DATA: form_name TYPE rs38l_fnam.

DATA: wa_ctrlop TYPE ssfctrlop,

wa_outopt TYPE ssfcompop.

DATA: t_otfdata TYPE ssfcrescl,

t_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.

DATA: t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE.

DATA: w_filesize TYPE i.

DATA: w_bin_filesize TYPE i.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'ZSMARTFORM_SWAR'

  • VARIANT = ' '

  • DIRECT_CALL = ' '

IMPORTING

fm_name = form_name

EXCEPTIONS

no_form = 1

no_function_module = 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.

wa_ctrlop-getotf = 'X'.

wa_ctrlop-no_dialog = 'X'.

wa_outopt-tdnoprev = 'X'.

CALL FUNCTION form_name

EXPORTING

  • ARCHIVE_INDEX =

  • ARCHIVE_INDEX_TAB =

  • ARCHIVE_PARAMETERS =

control_parameters = wa_ctrlop

  • MAIL_APPL_OBJ =

  • MAIL_RECIPIENT =

  • MAIL_SENDER =

output_options = wa_outopt

user_settings = 'X'

mydate = p_date

reason = p_rea

IMPORTING

  • DOCUMENT_OUTPUT_INFO =

job_output_info = t_otfdata

  • JOB_OUTPUT_OPTIONS =

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

t_otf[] = t_otfdata-otfdata[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

  • ARCHIVE_INDEX = ' '

IMPORTING

bin_filesize = w_bin_filesize

TABLES

otf = t_otf

lines = t_pdf_tab

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 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.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

bin_filesize = w_bin_filesize

  • CODEPAGE = ' '

filename = 'd:\test.PDF'

filetype = 'BIN'

  • MODE = ' '

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • COL_SELECT = ' '

  • COL_SELECTMASK = ' '

  • NO_AUTH_CHECK = ' '

IMPORTING

filelength = w_filesize

TABLES

data_tab = t_pdf_tab

  • FIELDNAMES =

EXCEPTIONS

file_open_error = 1

file_write_error = 2

invalid_filesize = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

OTHERS = 10

.

IF sy-subrc <> 0.

MESSAGE i003(z00) WITH 'File not downloaded succesfully'.

ELSE.

MESSAGE i003(z00) WITH 'File Test.pdf downloaded succesfully '

'under D drive'.

ENDIF.

ENDFORM. " F1000_DOWNLOAD_FORM

Former Member
0 Kudos

HI Jayanthi im getting the message as

status standard of hte user interface zswar missing

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

That's because of

SET PF-STATUS 'STANDARD' OF PROGRAM 'ZSWAR'.

Remove the statement.

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

DATA: ws_ucomm LIKE sy-ucomm.

DATA: form_name TYPE rs38l_fnam.

DATA: wa_ctrlop TYPE ssfctrlop,

wa_outopt TYPE ssfcompop.

DATA: t_otfdata TYPE ssfcrescl,

t_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.

DATA: t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE.

DATA: w_filesize TYPE i.

DATA: w_bin_filesize TYPE i.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'ZSMARTFORM_SWAR'<b>"your smartform name</b>IMPORTING

fm_name = form_name

EXCEPTIONS

no_form = 1

no_function_module = 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.

wa_ctrlop-getotf = 'X'.

wa_ctrlop-no_dialog = 'X'.

wa_outopt-tdnoprev = 'X'.

<b>*Copy the generated fm from se37 and use patterns for displaying in ABAP editor.Then change the '/..../' fm to form_name and use the parameters as mentioned in addition to your smartform parameters.</b>

CALL FUNCTION form_name

EXPORTING

control_parameters = wa_ctrlop

output_options = wa_outopt

user_settings = 'X'

IMPORTING

job_output_info = t_otfdata

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

t_otf[] = t_otfdata-otfdata[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = w_bin_filesize

TABLES

otf = t_otf

lines = t_pdf_tab

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 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.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

bin_filesize = w_bin_filesize

  • CODEPAGE = ' '

filename = 'd:\test.PDF'

filetype = 'BIN'

IMPORTING

filelength = w_filesize

TABLES

data_tab = t_pdf_tab

EXCEPTIONS

file_open_error = 1

file_write_error = 2

invalid_filesize = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

OTHERS = 10

.

IF sy-subrc <> 0.

<b>*You should include message-id in the report heading</b>

MESSAGE i000 with 'File not downloaded succesfully'.

ELSE.

MESSAGE i000 WITH 'File Test.pdf downloaded succesfully'.

ENDIF.

Message was edited by:

Jayanthi Jayaraman

Former Member
0 Kudos

i m unable to exucete the progrm do i need to do any thing esi other than changing the form name to my form name and where do we need to give the print program. plz help me out of this

Former Member
0 Kudos

just config the form name and print program name in NACE for perticular output type.

Former Member
0 Kudos

REPORT ZSF_EXPORT_INVOICE.

&----


*& Report ZINV1

*&

&----


*&

*&

&----


TABLES : KNA1, " General Data In Customer Master

KNB1, " Customer Master(Company Code)

BSID, " Accounting: Secondary Index for Customers

ZSMARTFORM, " Custom table for Storing Bank Details

zsf_exp_inv, " Structure that stores required fields from all tables used

KNVK. " Customer Master Contact Partner

data : Begin of it_struct occurs 0.

include structure zsf_exp_inv01.

data : End of it_struct.

types : begin of ty_bsid,

kunnr like bsid-kunnr,

WAERS like bsid-WAERS,

XBLNR LIKE BSID-XBLNR,

BUDAT LIKE BSID-BUDAT,

WRBTR LIKE BSID-WRBTR,

BUKRS LIKE BSID-BUKRS,

end of ty_bsid.

types : begin of ty_kna1,

kunnr like kna1-kunnr,

NAME1 LIKE KNA1-NAME1,

STRAS LIKE KNA1-STRAS,

MCOD3 LIKE KNA1-MCOD3,

LAND1 LIKE KNA1-LAND1,

SORTL LIKE KNA1-SORTL,

end of ty_kna1.

types : begin of ty_knb1,

kunnr like knb1-kunnr,

ZTERM LIKE KNB1-ZTERM,

end of ty_knb1.

types : begin of ty_knVK,

kunnr like kNVK-kunnr,

NAME1 LIKE KNVK-NAME1,

end of ty_knVK.

types : begin of ty_ZSMARTFORM,

SNO LIKE ZSMARTFORM-SNO,

CURRENCY LIKE zsmartform-currency,

BANKNAME LIKE zsmartform-bankname,

ADDRESS1 LIKE ZSMARTFORM-ADDRESS1,

ADDRESS2 LIKE ZSMARTFORM-ADDRESS2,

ADDRESS3 LIKE ZSMARTFORM-ADDRESS3,

ADDRESS4 LIKE ZSMARTFORM-ADDRESS4,

ADDRESS5 LIKE ZSMARTFORM-ADDRESS5,

ADDRESS6 LIKE ZSMARTFORM-ADDRESS6,

VALIDFROM LIKE ZSMARTFORM-VALIDFROM,

VALIDTO LIKE ZSMARTFORM-VALIDTO,

end of ty_ZSMARTFORM.

data : it_bsid type table of ty_bsid,

it_kna1 type table of ty_kna1,

it_knb1 type table of ty_knb1,

it_zsmartform type table of ty_zsmartform,

it_knVK type table of ty_kNVK.

data : wa_bsid like line of it_bsid,

wa_kna1 like line of it_kna1,

wa_knb1 like line of it_knb1,

wa_zsmartform like line of it_zsmartform,

wa_knVK like line of it_knVK.

*****************Selection Screen**********************************

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-000.

SELECT-OPTIONS : S_KUNNR FOR KNA1-KUNNR,

S_belnr FOR BSID-belnr,

S_BUKRS FOR BSID-BUKRS,

S_CURR FOR ZSMARTFORM-CURRENCY.

SELECTION-SCREEN END OF BLOCK B1.

DATA : BEGIN OF IT_PARAM OCCURS 0.

INCLUDE STRUCTURE ZPARAMETERS.

DATA : END OF IT_PARAM.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-001.

SKIP 1.

Parameters : OPTION1 AS CHECKBOX,

P_POINF(300) type c,

OPTION2 AS CHECKBOX,

P_DESC(300) TYPE C,

OPTION3 AS CHECKBOX,

P_MONTH(200) TYPE C,

OPTION4 AS CHECKBOX,

P_RATE(100) TYPE C.

SELECTION-SCREEN END OF BLOCK B2.

*********************************************************************

**********************PARAMETERS***********************************

data : l type i,

Y(300) type c,

j type i,

k type i value 1,

s type i,

m(300) type c,

p type i,

z type i.

data : l1 type i,

Y1(300) type c,

j1 type i,

k1 type i value 1,

s1 type i,

m1(300) type c,

p1 type i,

z1 type i.

data : l2 type i,

Y2(300) type c,

j2 type i,

k2 type i value 1,

s2 type i,

m2(300) type c,

p2 type i,

z2 type i.

data : l3 type i,

Y3(300) type c,

j3 type i,

k3 type i value 1,

s3 type i,

m3(300) type c,

p3 type i,

z3 type i.

IF OPTION1 = 'X'.

concatenate P_POINF ',' into P_POINF.

l = strlen( P_POINF ).

do l times.

Y = P_POINF+j(k).

case Y.

when ','.

m = P_POINF+s(z).

s = j + 1.

z = -1.

p = p + 1.

if p = 1.

IT_PARAM-LINE1 = m.

endif.

if p = 2.

IT_PARAM-LINE2 = m.

endif.

if p = 3.

IT_PARAM-LINE3 = m.

endif.

  • when '.'.

if p = 4.

IT_PARAM-LINE4 = m.

endif.

endcase.

j = j + 1.

z = z + 1.

enddo.

ENDIF.

IF OPTION2 = 'X'.

concatenate P_DESC ',' into P_DESC.

l1 = strlen( P_DESC ).

do l1 times.

Y1 = P_DESC+j1(k1).

case Y1.

when ','.

m1 = P_DESC+s1(z1).

s1 = j1 + 1.

z1 = -1.

p1 = p1 + 1.

if p1 = 1.

IT_PARAM-LINE5 = m1.

endif.

if p1 = 2.

IT_PARAM-LINE6 = m1.

endif.

if p1 = 3.

IT_PARAM-LINE7 = m1.

endif.

  • when '.'.

if p1 = 4.

IT_PARAM-LINE8 = m1.

endif.

endcase.

j1 = j1 + 1.

z1 = z1 + 1.

enddo.

ENDIF.

IF OPTION3 = 'X'.

concatenate P_MONTH ',' into P_MONTH.

l2 = strlen( P_MONTH ).

do l2 times.

Y2 = P_MONTH+j2(k2).

case Y2.

when ','.

m2 = P_MONTH+s2(z2).

s2 = j2 + 1.

z2 = -1.

p2 = p2 + 1.

if p2 = 1.

IT_PARAM-LINE9 = m2.

endif.

if p2 = 2.

IT_PARAM-LINE10 = m2.

endif.

if p2 = 3.

IT_PARAM-LINE11 = m2.

endif.

  • when '.'.

if p2 = 4.

IT_PARAM-LINe12 = m2.

endif.

endcase.

j2 = j2 + 1.

z2 = z2 + 1.

enddo.

ENDIF.

IF OPTION4 = 'X'.

concatenate P_RATE ',' into P_RATE.

l3 = strlen( P_RATE ).

do l3 times.

Y3 = P_RATE+j3(k3).

case Y3.

when ','.

m3 = P_RATE+s3(z3).

s3 = j3 + 1.

z3 = -1.

p3 = p3 + 1.

if p3 = 1.

IT_PARAM-LINE13 = m3.

endif.

if p3 = 2.

IT_PARAM-LINE14 = m3.

endif.

if p3 = 3.

IT_PARAM-LINE15 = m3.

endif.

if p3 = 4.

IT_PARAM-LINe16 = m3.

endif.

endcase.

j3 = j3 + 1.

z3 = z3 + 1.

enddo.

ENDIF.

APPEND IT_PARAM.

*********************************************************

select * from kna1 into corresponding fields of table it_kna1 where kunnr in s_kunnr.

select * from knb1 into corresponding fields of table it_knb1 for all entries in it_kna1 where kunnr = it_kna1-kunnr.

select * from bsid into corresponding fields of table it_bsid for all entries in it_kna1 where kunnr = it_kna1-kunnr and belnr in s_belnr and bukrs in s_bukrs..

SELECT * FROM KNVK INTO CORRESPONDING FIELDS OF TABLE IT_KNVK FOR ALL ENTRIES IN IT_KNA1 WHERE KUNNR = IT_KNA1-KUNNR.

select * from zsmartform into corresponding fields of table it_zsmartform .

DATA : AMT LIKE SPELL.

loop at it_bsid into wa_bsid.

read table it_kna1 into wa_kna1 with key kunnr = wa_bsid-kunnr.

read table it_knb1 into wa_knb1 with key kunnr = wa_bsid-kunnr.

read table it_zsmartform into wa_zsmartform with key CURRENCY = wa_bsid-WAERS.

READ TABLE IT_KNVK INTO WA_KNVK WITH KEY KUNNR = WA_BSID-KUNNR.

it_struct-name1 = wa_kna1-name1.

it_struct-stras = wa_kna1-stras.

it_struct-mcod3 = wa_kna1-mcod3.

it_struct-land1 = wa_kna1-land1.

it_struct-sortl = wa_kna1-sortl.

it_struct-zterm = wa_knb1-zterm.

it_struct-xblnr = wa_bsid-xblnr.

  • it_struct-currency = wa_zsmartform-currency.

it_struct-currency = wa_bsid-waers.

it_struct-budat = wa_bsid-budat.

it_struct-BANKNAME = wa_zsmartform-BANKNAME.

it_struct-ADDRESS1 = wa_zsmartform-ADDRESS1.

it_struct-ADDRESS2 = wa_zsmartform-ADDRESS2.

it_struct-ADDRESS3 = wa_zsmartform-ADDRESS3.

it_struct-ADDRESS4 = wa_zsmartform-ADDRESS4.

it_struct-ADDRESS5 = wa_zsmartform-ADDRESS5.

it_struct-ADDRESS6 = wa_zsmartform-ADDRESS6.

it_struct-CURR = WA_BSID-WRBTR.

IT_STRUCT-NAME = WA_KNVK-NAME1.

  • IT_STRUCT-AMOUNT = IT_SPELL-AMT.

append it_struct.

endloop.

data : x type i,

x1 type i,

a type string.

loop at it_struct.

x = strlen( it_struct-curr ).

x1 = x - 3.

a = it_struct-curr+0(x1).

CALL FUNCTION 'SPELL_AMOUNT'

EXPORTING

AMOUNT = a

    • CURRENCY = ' '

    • FILLER = ' '

    • LANGUAGE = SY-LANGU

IMPORTING

IN_WORDS = AMT.

    • EXCEPTIONS

    • NOT_FOUND = 1

    • TOO_LARGE = 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.

endloop.

CALL FUNCTION '/1BCDWB/SF00000001'

EXPORTING

  • ARCHIVE_INDEX =

  • ARCHIVE_INDEX_TAB =

  • ARCHIVE_PARAMETERS =

  • CONTROL_PARAMETERS =

  • MAIL_APPL_OBJ =

  • MAIL_RECIPIENT =

  • MAIL_SENDER =

  • OUTPUT_OPTIONS =

  • USER_SETTINGS = 'X'

IN_WORDS = amt

  • IMPORTING

  • DOCUMENT_OUTPUT_INFO =

  • JOB_OUTPUT_INFO =

  • JOB_OUTPUT_OPTIONS =

TABLES

I_ZSF_EXP_INV = it_struct

I_ZPARAMETERS = it_param

  • EXCEPTIONS

  • FORMATTING_ERROR = 1

  • INTERNAL_ERROR = 2

  • SEND_ERROR = 3

  • USER_CANCELED = 4

  • OTHERS = 5

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Former Member
0 Kudos

hi kishan could u plz tell me the steps how i need to configure in nace to save the program into pdf format

jayanthi_jayaraman
Active Contributor
0 Kudos

DATA: ws_ucomm LIKE sy-ucomm.

DATA: form_name TYPE rs38l_fnam.

DATA: wa_ctrlop TYPE ssfctrlop,

wa_outopt TYPE ssfcompop.

DATA: t_otfdata TYPE ssfcrescl,

t_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.

DATA: t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE.

DATA: w_filesize TYPE i.

DATA: w_bin_filesize TYPE i.

wa_ctrlop-getotf = 'X'.

wa_ctrlop-no_dialog = 'X'.

wa_outopt-tdnoprev = 'X'.

CALL FUNCTION '/1BCDWB/SF00000001'

EXPORTING

control_parameters = wa_ctrlop

output_options = wa_outopt

user_settings = 'X'

IN_WORDS = amt

importing

job_output_info = t_otfdata

TABLES

I_ZSF_EXP_INV = it_struct

I_ZPARAMETERS = it_param.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

t_otf[] = t_otfdata-otfdata[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = w_bin_filesize

TABLES

otf = t_otf

lines = t_pdf_tab

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 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.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

bin_filesize = w_bin_filesize

  • CODEPAGE = ' '

filename = 'd:\test.PDF'

filetype = 'BIN'

IMPORTING

filelength = w_filesize

TABLES

data_tab = t_pdf_tab

EXCEPTIONS

file_open_error = 1

file_write_error = 2

invalid_filesize = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

OTHERS = 10

.

IF sy-subrc <> 0.

*You should include message-id in the report heading

MESSAGE i000 with 'File not downloaded succesfully'.

ELSE.

MESSAGE i000 WITH 'File Test.pdf downloaded succesfully'.

ENDIF.

Former Member
0 Kudos

HI JAYANTHI THANKU VERY MUCH FOR changing the program but the paramaters and tables that i have used like amt it_struct,it_param that r used in fm

are declared in the print program so i have aproblem of how i can merge that print prog that i sent eaarlier into the program that u provided

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

It's easy.

In your code replace this part with my code.

CALL FUNCTION '/1BCDWB/SF00000001'

EXPORTING

  • ARCHIVE_INDEX =

  • ARCHIVE_INDEX_TAB =

  • ARCHIVE_PARAMETERS =

  • CONTROL_PARAMETERS =

  • MAIL_APPL_OBJ =

  • MAIL_RECIPIENT =

  • MAIL_SENDER =

  • OUTPUT_OPTIONS =

  • USER_SETTINGS = 'X'

IN_WORDS = amt

  • IMPORTING

  • DOCUMENT_OUTPUT_INFO =

  • JOB_OUTPUT_INFO =

  • JOB_OUTPUT_OPTIONS =

TABLES

I_ZSF_EXP_INV = it_struct

I_ZPARAMETERS = it_param

  • EXCEPTIONS

  • FORMATTING_ERROR = 1

  • INTERNAL_ERROR = 2

  • SEND_ERROR = 3

  • USER_CANCELED = 4

  • OTHERS = 5

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Former Member
0 Kudos

I HAVE DONE IT I M GETTING THE OUTPUT AS FILE NOT DOWN LOADED

MORE OVER I M NOT GETTING THE PRINT PREVIEW OPTION I M DIRECTLY GETTING ONLY PRINT OPTION AFTER I PRESS PRINT THE OUTPUT I M GETTING IS FILE NOT DOWNLODED. PLZ HELP ME OUT OF THIS

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Remove these lines in the code.

wa_ctrlop-no_dialog = 'X'.

wa_outopt-tdnoprev = 'X'.

You will get print preview.

Check the sy-subrc value after convert_otf fm and gui_download fm.

Former Member
0 Kudos

HI JAYANTHI thank you for ur answer, now i m able to view the print preiview but still i m getting the message as file not downloaded sucessfully below is the code plz chk .r there any default settings that are to be done for this.

&----


*& Report ZSF

*&

&----


*&

*&

&----


REPORT ZSF.

&----


*& Report ZINV1

*&

&----


*&

*&

&----


TABLES : KNA1, " General Data In Customer Master

KNB1, " Customer Master(Company Code)

BSID, " Accounting: Secondary Index for Customers

ZSMARTFORM, " Custom table for Storing Bank Details

zsf_exp_inv, " Structure that stores required fields from all tables used

KNVK. " Customer Master Contact Partner

data : Begin of it_struct occurs 0.

include structure zsf_exp_inv01.

data : End of it_struct.

types : begin of ty_bsid,

kunnr like bsid-kunnr,

WAERS like bsid-WAERS,

XBLNR LIKE BSID-XBLNR,

BUDAT LIKE BSID-BUDAT,

WRBTR LIKE BSID-WRBTR,

BUKRS LIKE BSID-BUKRS,

end of ty_bsid.

types : begin of ty_kna1,

kunnr like kna1-kunnr,

NAME1 LIKE KNA1-NAME1,

STRAS LIKE KNA1-STRAS,

MCOD3 LIKE KNA1-MCOD3,

LAND1 LIKE KNA1-LAND1,

SORTL LIKE KNA1-SORTL,

end of ty_kna1.

types : begin of ty_knb1,

kunnr like knb1-kunnr,

ZTERM LIKE KNB1-ZTERM,

end of ty_knb1.

types : begin of ty_knVK,

kunnr like kNVK-kunnr,

NAME1 LIKE KNVK-NAME1,

end of ty_knVK.

types : begin of ty_ZSMARTFORM,

SNO LIKE ZSMARTFORM-SNO,

CURRENCY LIKE zsmartform-currency,

BANKNAME LIKE zsmartform-bankname,

ADDRESS1 LIKE ZSMARTFORM-ADDRESS1,

ADDRESS2 LIKE ZSMARTFORM-ADDRESS2,

ADDRESS3 LIKE ZSMARTFORM-ADDRESS3,

ADDRESS4 LIKE ZSMARTFORM-ADDRESS4,

ADDRESS5 LIKE ZSMARTFORM-ADDRESS5,

ADDRESS6 LIKE ZSMARTFORM-ADDRESS6,

VALIDFROM LIKE ZSMARTFORM-VALIDFROM,

VALIDTO LIKE ZSMARTFORM-VALIDTO,

end of ty_ZSMARTFORM.

data : it_bsid type table of ty_bsid,

it_kna1 type table of ty_kna1,

it_knb1 type table of ty_knb1,

it_zsmartform type table of ty_zsmartform,

it_knVK type table of ty_kNVK.

data : wa_bsid like line of it_bsid,

wa_kna1 like line of it_kna1,

wa_knb1 like line of it_knb1,

wa_zsmartform like line of it_zsmartform,

wa_knVK like line of it_knVK.

*****************Selection Screen**********************************

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-000.

SELECT-OPTIONS : S_KUNNR FOR KNA1-KUNNR,

S_belnr FOR BSID-belnr,

S_BUKRS FOR BSID-BUKRS,

S_CURR FOR ZSMARTFORM-CURRENCY.

SELECTION-SCREEN END OF BLOCK B1.

DATA : BEGIN OF IT_PARAM OCCURS 0.

INCLUDE STRUCTURE ZPARAMETERS.

DATA : END OF IT_PARAM.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-001.

SKIP 1.

Parameters : OPTION1 AS CHECKBOX,

P_POINF(300) type c,

OPTION2 AS CHECKBOX,

P_DESC(300) TYPE C,

OPTION3 AS CHECKBOX,

P_MONTH(200) TYPE C,

OPTION4 AS CHECKBOX,

P_RATE(100) TYPE C.

SELECTION-SCREEN END OF BLOCK B2.

*********************************************************************

**********************PARAMETERS***********************************

data : l type i,

Y(300) type c,

j type i,

k type i value 1,

s type i,

m(300) type c,

p type i,

z type i.

data : l1 type i,

Y1(300) type c,

j1 type i,

k1 type i value 1,

s1 type i,

m1(300) type c,

p1 type i,

z1 type i.

data : l2 type i,

Y2(300) type c,

j2 type i,

k2 type i value 1,

s2 type i,

m2(300) type c,

p2 type i,

z2 type i.

data : l3 type i,

Y3(300) type c,

j3 type i,

k3 type i value 1,

s3 type i,

m3(300) type c,

p3 type i,

z3 type i.

IF OPTION1 = 'X'.

concatenate P_POINF ',' into P_POINF.

l = strlen( P_POINF ).

do l times.

Y = P_POINF+j(k).

case Y.

when ','.

m = P_POINF+s(z).

s = j + 1.

z = -1.

p = p + 1.

if p = 1.

IT_PARAM-LINE1 = m.

endif.

if p = 2.

IT_PARAM-LINE2 = m.

endif.

if p = 3.

IT_PARAM-LINE3 = m.

endif.

  • when '.'.

if p = 4.

IT_PARAM-LINE4 = m.

endif.

endcase.

j = j + 1.

z = z + 1.

enddo.

ENDIF.

IF OPTION2 = 'X'.

concatenate P_DESC ',' into P_DESC.

l1 = strlen( P_DESC ).

do l1 times.

Y1 = P_DESC+j1(k1).

case Y1.

when ','.

m1 = P_DESC+s1(z1).

s1 = j1 + 1.

z1 = -1.

p1 = p1 + 1.

if p1 = 1.

IT_PARAM-LINE5 = m1.

endif.

if p1 = 2.

IT_PARAM-LINE6 = m1.

endif.

if p1 = 3.

IT_PARAM-LINE7 = m1.

endif.

  • when '.'.

if p1 = 4.

IT_PARAM-LINE8 = m1.

endif.

endcase.

j1 = j1 + 1.

z1 = z1 + 1.

enddo.

ENDIF.

IF OPTION3 = 'X'.

concatenate P_MONTH ',' into P_MONTH.

l2 = strlen( P_MONTH ).

do l2 times.

Y2 = P_MONTH+j2(k2).

case Y2.

when ','.

m2 = P_MONTH+s2(z2).

s2 = j2 + 1.

z2 = -1.

p2 = p2 + 1.

if p2 = 1.

IT_PARAM-LINE9 = m2.

endif.

if p2 = 2.

IT_PARAM-LINE10 = m2.

endif.

if p2 = 3.

IT_PARAM-LINE11 = m2.

endif.

  • when '.'.

if p2 = 4.

IT_PARAM-LINe12 = m2.

endif.

endcase.

j2 = j2 + 1.

z2 = z2 + 1.

enddo.

ENDIF.

IF OPTION4 = 'X'.

concatenate P_RATE ',' into P_RATE.

l3 = strlen( P_RATE ).

do l3 times.

Y3 = P_RATE+j3(k3).

case Y3.

when ','.

m3 = P_RATE+s3(z3).

s3 = j3 + 1.

z3 = -1.

p3 = p3 + 1.

if p3 = 1.

IT_PARAM-LINE13 = m3.

endif.

if p3 = 2.

IT_PARAM-LINE14 = m3.

endif.

if p3 = 3.

IT_PARAM-LINE15 = m3.

endif.

if p3 = 4.

IT_PARAM-LINe16 = m3.

endif.

endcase.

j3 = j3 + 1.

z3 = z3 + 1.

enddo.

ENDIF.

APPEND IT_PARAM.

*********************************************************

select * from kna1 into corresponding fields of table it_kna1 where kunnr in s_kunnr.

select * from knb1 into corresponding fields of table it_knb1 for all entries in it_kna1 where kunnr = it_kna1-kunnr.

select * from bsid into corresponding fields of table it_bsid for all entries in it_kna1 where kunnr = it_kna1-kunnr and belnr in s_belnr and bukrs in s_bukrs..

SELECT * FROM KNVK INTO CORRESPONDING FIELDS OF TABLE IT_KNVK FOR ALL ENTRIES IN IT_KNA1 WHERE KUNNR = IT_KNA1-KUNNR.

select * from zsmartform into corresponding fields of table it_zsmartform .

DATA : AMT LIKE SPELL.

loop at it_bsid into wa_bsid.

read table it_kna1 into wa_kna1 with key kunnr = wa_bsid-kunnr.

read table it_knb1 into wa_knb1 with key kunnr = wa_bsid-kunnr.

read table it_zsmartform into wa_zsmartform with key CURRENCY = wa_bsid-WAERS.

READ TABLE IT_KNVK INTO WA_KNVK WITH KEY KUNNR = WA_BSID-KUNNR.

it_struct-name1 = wa_kna1-name1.

it_struct-stras = wa_kna1-stras.

it_struct-mcod3 = wa_kna1-mcod3.

it_struct-land1 = wa_kna1-land1.

it_struct-sortl = wa_kna1-sortl.

it_struct-zterm = wa_knb1-zterm.

it_struct-xblnr = wa_bsid-xblnr.

  • it_struct-currency = wa_zsmartform-currency.

it_struct-currency = wa_bsid-waers.

it_struct-budat = wa_bsid-budat.

it_struct-BANKNAME = wa_zsmartform-BANKNAME.

it_struct-ADDRESS1 = wa_zsmartform-ADDRESS1.

it_struct-ADDRESS2 = wa_zsmartform-ADDRESS2.

it_struct-ADDRESS3 = wa_zsmartform-ADDRESS3.

it_struct-ADDRESS4 = wa_zsmartform-ADDRESS4.

it_struct-ADDRESS5 = wa_zsmartform-ADDRESS5.

it_struct-ADDRESS6 = wa_zsmartform-ADDRESS6.

it_struct-CURR = WA_BSID-WRBTR.

IT_STRUCT-NAME = WA_KNVK-NAME1.

  • IT_STRUCT-AMOUNT = IT_SPELL-AMT.

append it_struct.

endloop.

data : x type i,

x1 type i,

a type string.

loop at it_struct.

x = strlen( it_struct-curr ).

x1 = x - 3.

a = it_struct-curr+0(x1).

CALL FUNCTION 'SPELL_AMOUNT'

EXPORTING

AMOUNT = a

    • CURRENCY = ' '

    • FILLER = ' '

    • LANGUAGE = SY-LANGU

IMPORTING

IN_WORDS = AMT.

    • EXCEPTIONS

    • NOT_FOUND = 1

    • TOO_LARGE = 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.

endloop.

DATA: ws_ucomm LIKE sy-ucomm.

DATA: form_name TYPE rs38l_fnam.

DATA: wa_ctrlop TYPE ssfctrlop,

wa_outopt TYPE ssfcompop.

DATA: t_otfdata TYPE ssfcrescl,

t_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.

DATA: t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE.

DATA: w_filesize TYPE i.

DATA: w_bin_filesize TYPE i.

wa_ctrlop-getotf = 'X'.

CALL FUNCTION '/1BCDWB/SF00000001'

EXPORTING

control_parameters = wa_ctrlop

output_options = wa_outopt

user_settings = 'X'

IN_WORDS = amt

importing

job_output_info = t_otfdata

TABLES

I_ZSF_EXP_INV = it_struct

I_ZPARAMETERS = it_param.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

t_otf[] = t_otfdata-otfdata[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = w_bin_filesize

TABLES

otf = t_otf

lines = t_pdf_tab

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 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.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

bin_filesize = w_bin_filesize

  • CODEPAGE = ' '

filename = 'd:\test.PDF'

filetype = 'BIN'

IMPORTING

filelength = w_filesize

TABLES

data_tab = t_pdf_tab

EXCEPTIONS

file_open_error = 1

file_write_error = 2

invalid_filesize = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

OTHERS = 10

.

IF sy-subrc <> 0.

*You should include message-id in the report heading

WRITE : 'File not downloaded succesfully'.

ELSE.

WRITE : 'File Test.pdf downloaded succesfully'.

ENDIF.

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

What is the sy-subrc you are getting after 'CONVERT_OTF' fm and ws_download fm?

Message was edited by:

Jayanthi Jayaraman

Former Member
0 Kudos

i m getting sy-subrc <> 0.

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

change the path in the below code and make change in the write statement also and let me know what is the output you are getting.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

bin_filesize = w_bin_filesize

  • CODEPAGE = ' '

filename = <b>'c:\test.PDF'</b>

filetype = 'BIN'

IMPORTING

filelength = w_filesize

TABLES

data_tab = t_pdf_tab

EXCEPTIONS

file_open_error = 1

file_write_error = 2

invalid_filesize = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

OTHERS = 10

.

IF sy-subrc <> 0.

*You should include message-id in the report heading

WRITE : <b>sy-subrc</b>.

ELSE.

WRITE : 'File Test.pdf downloaded succesfully'.

ENDIF.

Jayanthi Jayaraman

Former Member
0 Kudos

thanku very very very very very much the problem is solved

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Kindly assign points for useful answers.

Former Member
0 Kudos

i have assigned full 10 points

Answers (4)

Answers (4)

Former Member
0 Kudos

I tried doing the same using the program given in response to the question above with the sample code below with the required changes.The error that was displayed on the output screen is as:

status standard of the user interface zprogname missing

though the required status exists and the interface to zprogname is generated in menu painter.

REPORT zswar.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME.

PARAMETER: p_date LIKE sy-datum.

PARAMETER: p_rea TYPE char255.

SELECTION-SCREEN: END OF BLOCK b1.

DATA: ws_ucomm LIKE sy-ucomm.

INITIALIZATION.

SET PF-STATUS 'STANDARD' OF PROGRAM 'ZSWAR'.

AT SELECTION-SCREEN.

ws_ucomm = sy-ucomm.

CASE ws_ucomm.

WHEN '&PDF'.

PERFORM f1000_download_form.

EXIT.

WHEN '&BACK'.

SET SCREEN 0.

EXIT.

WHEN '&EXIT'.

SET SCREEN 0.

EXIT.

WHEN '&canc'.

SET SCREEN 0.

LEAVE TO SCREEN 0.

ENDCASE.

&----


*& Form F1000_DOWNLOAD_FORM

&----


text

-


--> p1 text

<-- p2 text

-


FORM f1000_download_form.

DATA: form_name TYPE rs38l_fnam.

DATA: wa_ctrlop TYPE ssfctrlop,

wa_outopt TYPE ssfcompop.

DATA: t_otfdata TYPE ssfcrescl,

t_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.

DATA: t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE.

DATA: w_filesize TYPE i.

DATA: w_bin_filesize TYPE i.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'ZSMARTFORM_SWAR'

VARIANT = ' '

DIRECT_CALL = ' '

IMPORTING

fm_name = form_name

EXCEPTIONS

no_form = 1

no_function_module = 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.

wa_ctrlop-getotf = 'X'.

wa_ctrlop-no_dialog = 'X'.

wa_outopt-tdnoprev = 'X'.

CALL FUNCTION form_name

EXPORTING

ARCHIVE_INDEX =

ARCHIVE_INDEX_TAB =

ARCHIVE_PARAMETERS =

control_parameters = wa_ctrlop

MAIL_APPL_OBJ =

MAIL_RECIPIENT =

MAIL_SENDER =

output_options = wa_outopt

user_settings = 'X'

mydate = p_date

reason = p_rea

IMPORTING

DOCUMENT_OUTPUT_INFO =

job_output_info = t_otfdata

JOB_OUTPUT_OPTIONS =

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5

.

IF sy-subrc 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

t_otf] = t_otfdata-otfdata[.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

ARCHIVE_INDEX = ' '

IMPORTING

bin_filesize = w_bin_filesize

TABLES

otf = t_otf

lines = t_pdf_tab

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 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.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

bin_filesize = w_bin_filesize

CODEPAGE = ' '

filename = 'd:\test.PDF'

filetype = 'BIN'

MODE = ' '

WK1_N_FORMAT = ' '

WK1_N_SIZE = ' '

WK1_T_FORMAT = ' '

WK1_T_SIZE = ' '

COL_SELECT = ' '

COL_SELECTMASK = ' '

NO_AUTH_CHECK = ' '

IMPORTING

filelength = w_filesize

TABLES

data_tab = t_pdf_tab

FIELDNAMES =

EXCEPTIONS

file_open_error = 1

file_write_error = 2

invalid_filesize = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

OTHERS = 10

.

IF sy-subrc 0.

MESSAGE i003(z00) WITH 'File not downloaded succesfully'.

ELSE.

MESSAGE i003(z00) WITH 'File Test.pdf downloaded succesfully '

'under D drive'.

ENDIF.

ENDFORM. " F1000_DOWNLOAD_FORM

Former Member
0 Kudos

yeah i have assigned thankx

Former Member
0 Kudos

hi,

Here is the sample program to convert the spool request to pdf and send it as an attachment.

*&---------------------------------------------------------------------*
*& Report  ZRICHA_SPOOL2PDF
*&
*&---------------------------------------------------------------------*
*& Converts spool request into PDF document and emails it to           *
*& recipicant.                                                         *
*&                                                                     *
*& Execution                                                           *
*& ---------                                                           *
*& This program must be run as a background job in-order for the write *
*& commands to create a Spool request rather than be displayed on      *
*& screen                                                              *
*&---------------------------------------------------------------------*

REPORT  ZRICHA_SPOOL2PDF.

PARAMETER: p_email1 LIKE somlreci1-receiver
                                    DEFAULT 'richa@abc.com',
           p_sender LIKE somlreci1-receiver
                                    DEFAULT 'richa@abc.com',
           p_delspl  AS CHECKBOX.

*DATA DECLARATION
DATA: gd_recsize TYPE i.

* Spool IDs
TYPES: BEGIN OF t_tbtcp.
        INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.
DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
      wa_tbtcp TYPE t_tbtcp.

* Job Runtime Parameters
DATA: gd_eventid LIKE tbtcm-eventid,
      gd_eventparm LIKE tbtcm-eventparm,
      gd_external_program_active LIKE tbtcm-xpgactive,
      gd_jobcount LIKE tbtcm-jobcount,
      gd_jobname LIKE tbtcm-jobname,
      gd_stepcount LIKE tbtcm-stepcount,
      gd_error    TYPE sy-subrc,
      gd_reciever TYPE sy-subrc.


DATA:  w_recsize TYPE i.

DATA: gd_subject   LIKE sodocchgi1-obj_descr,
      it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      gd_sender_type     LIKE soextreci1-adr_typ,
      gd_attachment_desc TYPE so_obj_nam,
      gd_attachment_name TYPE so_obj_des.

* Spool to PDF conversions
DATA: gd_spool_nr LIKE tsp01-rqident,
      gd_destination LIKE rlgrap-filename,
      gd_bytecount LIKE tst01-dsize,
      gd_buffer TYPE string.

* Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0.
        INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.

CONSTANTS: c_dev LIKE  sy-sysid VALUE 'DEV',
           c_no(1)     TYPE c   VALUE ' ',
           c_device(4) TYPE c   VALUE 'LOCL'.

************************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.

* Write statement to represent report output. Spool request is created
* if write statement is executed in background. This could also be an
* ALV grid which would be converted to PDF without any extra effort
  WRITE 'Hello World'.
  new-page.
  commit work.
  new-page print off.

  IF sy-batch EQ 'X'.
    PERFORM get_job_details.
    PERFORM obtain_spool_id.

************************************
*** Alternative way could be to submit another program and store spool
*** id into memory, will be stored in sy-spono.
*submit ZSPOOLTOPDF2
*        to sap-spool
*        spool parameters   %_print
*        archive parameters %_print
*        without spool dynpro
*        and return.
************************************

* Get spool id from program called above
*  IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.

    PERFORM convert_spool_to_pdf.
    PERFORM process_email.

    if p_delspl EQ 'X'.
      PERFORM delete_spool.
    endif.

    IF sy-sysid = c_dev.
      wait up to 5 seconds.
      SUBMIT rsconn01 WITH mode   = 'INT'
                      WITH output = 'X'
                      AND RETURN.
    ENDIF.
  ELSE.
    SKIP.
    WRITE:/ 'Program must be executed in background in-order for spool',
            'request to be created.'.
  ENDIF.


*---------------------------------------------------------------------*
*       FORM obtain_spool_id                                          *
*---------------------------------------------------------------------*
FORM obtain_spool_id.
  CHECK NOT ( gd_jobname IS INITIAL ).
  CHECK NOT ( gd_jobcount IS INITIAL ).

  SELECT * FROM  tbtcp
                 INTO TABLE it_tbtcp
                 WHERE      jobname     = gd_jobname
                 AND        jobcount    = gd_jobcount
                 AND        stepcount   = gd_stepcount
                 AND        listident   <> '0000000000'
                 ORDER BY   jobname
                            jobcount
                            stepcount.

  READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
  IF sy-subrc = 0.
    message s004(zdd) with gd_spool_nr.
    gd_spool_nr = wa_tbtcp-listident.
    MESSAGE s004(zdd) WITH gd_spool_nr.
  ELSE.
    MESSAGE s005(zdd).
  ENDIF.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM get_job_details                                          *
*---------------------------------------------------------------------*
FORM get_job_details.
* Get current job details
  CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
       IMPORTING
            eventid                 = gd_eventid
            eventparm               = gd_eventparm
            external_program_active = gd_external_program_active
            jobcount                = gd_jobcount
            jobname                 = gd_jobname
            stepcount               = gd_stepcount
       EXCEPTIONS
            no_runtime_info         = 1
            OTHERS                  = 2.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM convert_spool_to_pdf                                     *
*---------------------------------------------------------------------*
FORM convert_spool_to_pdf.

  CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
       EXPORTING
            src_spoolid              = gd_spool_nr
            no_dialog                = c_no
            dst_device               = c_device
       IMPORTING
            pdf_bytecount            = gd_bytecount
       TABLES
            pdf                      = it_pdf_output
       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.

  CHECK sy-subrc = 0.

* Transfer the 132-long strings to 255-long strings
  LOOP AT it_pdf_output.
    TRANSLATE it_pdf_output USING ' ~'.
    CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
  ENDLOOP.

  TRANSLATE gd_buffer USING '~ '.

  DO.
    it_mess_att = gd_buffer.
    APPEND it_mess_att.
    SHIFT gd_buffer LEFT BY 255 PLACES.
    IF gd_buffer IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM process_email                                            *
*---------------------------------------------------------------------*
FORM process_email.
  DESCRIBE TABLE it_mess_att LINES gd_recsize.
  CHECK gd_recsize > 0.
  PERFORM send_email USING p_email1.
*  perform send_email using p_email2.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM send_email                                               *
*---------------------------------------------------------------------*
*  -->  p_email                                                       *
*---------------------------------------------------------------------*
FORM send_email USING p_email.
  CHECK NOT ( p_email IS INITIAL ).

  REFRESH it_mess_bod.

* Default subject matter
  gd_subject         = 'Subject'.
  gd_attachment_desc = 'Attachname'.
*  CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
  it_mess_bod        = 'Message Body text, line 1'.
  APPEND it_mess_bod.
  it_mess_bod        = 'Message Body text, line 2...'.
  APPEND it_mess_bod.

* If no sender specified - default blank
  IF p_sender EQ space.
    gd_sender_type  = space.
  ELSE.
    gd_sender_type  = 'INT'.
  ENDIF.


* Send file by email as .xls speadsheet
  PERFORM send_file_as_email_attachment
                               tables it_mess_bod
                                      it_mess_att
                                using p_email
                                      'Example .xls documnet attachment'
                                      'PDF'
                                      gd_attachment_name
                                      gd_attachment_desc
                                      p_sender
                                      gd_sender_type
                             changing gd_error
                                      gd_reciever.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM delete_spool                                             *
*---------------------------------------------------------------------*
FORM delete_spool.
  DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.

  ld_spool_nr = gd_spool_nr.

  CHECK p_delspl <> c_no.
  CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
       EXPORTING
            spoolid = ld_spool_nr.
ENDFORM.


*&---------------------------------------------------------------------*
*&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
*&---------------------------------------------------------------------*
*       Send email
*----------------------------------------------------------------------*
FORM send_file_as_email_attachment tables it_message
                                          it_attach
                                    using p_email
                                          p_mtitle
                                          p_format
                                          p_filename
                                          p_attdescription
                                          p_sender_address
                                          p_sender_addres_type
                                 changing p_error
                                          p_reciever.


  DATA: ld_error    TYPE sy-subrc,
        ld_reciever TYPE sy-subrc,
        ld_mtitle LIKE sodocchgi1-obj_descr,
        ld_email LIKE  somlreci1-receiver,
        ld_format TYPE  so_obj_tp ,
        ld_attdescription TYPE  so_obj_nam ,
        ld_attfilename TYPE  so_obj_des ,
        ld_sender_address LIKE  soextreci1-receiver,
        ld_sender_address_type LIKE  soextreci1-adr_typ,
        ld_receiver LIKE  sy-subrc.

data:   t_packing_list like sopcklsti1 occurs 0 with header line,
        t_contents like solisti1 occurs 0 with header line,
        t_receivers like somlreci1 occurs 0 with header line,
        t_attachment like solisti1 occurs 0 with header line,
        t_object_header like solisti1 occurs 0 with header line,
        w_cnt type i,
        w_sent_all(1) type c,
        w_doc_data like sodocchgi1.


  ld_email   = p_email.
  ld_mtitle = p_mtitle.
  ld_format              = p_format.
  ld_attdescription      = p_attdescription.
  ld_attfilename         = p_filename.
  ld_sender_address      = p_sender_address.
  ld_sender_address_type = p_sender_addres_type.


* Fill the document data.
  w_doc_data-doc_size = 1.

* Populate the subject/generic message attributes
  w_doc_data-obj_langu = sy-langu.
  w_doc_data-obj_name  = 'SAPRPT'.
  w_doc_data-obj_descr = ld_mtitle .
  w_doc_data-sensitivty = 'F'.

* Fill the document data and get size of attachment
  CLEAR w_doc_data.
  READ TABLE it_attach INDEX w_cnt.
  w_doc_data-doc_size =
     ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
  w_doc_data-obj_langu  = sy-langu.
  w_doc_data-obj_name   = 'SAPRPT'.
  w_doc_data-obj_descr  = ld_mtitle.
  w_doc_data-sensitivty = 'F'.
  CLEAR t_attachment.
  REFRESH t_attachment.
  t_attachment[] = it_attach[].

* Describe the body of the message
  CLEAR t_packing_list.
  REFRESH t_packing_list.
  t_packing_list-transf_bin = space.
  t_packing_list-head_start = 1.
  t_packing_list-head_num = 0.
  t_packing_list-body_start = 1.
  DESCRIBE TABLE it_message LINES t_packing_list-body_num.
  t_packing_list-doc_type = 'RAW'.
  APPEND t_packing_list.

* Create attachment notification
  t_packing_list-transf_bin = 'X'.
  t_packing_list-head_start = 1.
  t_packing_list-head_num   = 1.
  t_packing_list-body_start = 1.

  DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
  t_packing_list-doc_type   =  ld_format.
  t_packing_list-obj_descr  =  ld_attdescription.
  t_packing_list-obj_name   =  ld_attfilename.
  t_packing_list-doc_size   =  t_packing_list-body_num * 255.
  APPEND t_packing_list.

* Add the recipients email address
  CLEAR t_receivers.
  REFRESH t_receivers.
  t_receivers-receiver = ld_email.
  t_receivers-rec_type = 'U'.
  t_receivers-com_type = 'INT'.
  t_receivers-notif_del = 'X'.
  t_receivers-notif_ndel = 'X'.
  APPEND t_receivers.

  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
       EXPORTING
            document_data              = w_doc_data
            put_in_outbox              = 'X'
            sender_address             = ld_sender_address
            sender_address_type        = ld_sender_address_type
            commit_work                = 'X'
       IMPORTING
            sent_to_all                = w_sent_all
       TABLES
            packing_list               = t_packing_list
            contents_bin               = t_attachment
            contents_txt               = it_message
            receivers                  = t_receivers
       EXCEPTIONS
            too_many_receivers         = 1
            document_not_sent          = 2
            document_type_not_exist    = 3
            operation_no_authorization = 4
            parameter_error            = 5
            x_error                    = 6
            enqueue_error              = 7
            OTHERS                     = 8.

* Populate zerror return code
  ld_error = sy-subrc.

* Populate zreceiver return code
  LOOP AT t_receivers.
    ld_receiver = t_receivers-retrn_code.
  ENDLOOP.
ENDFORM.

Regars,

Richa

Former Member
0 Kudos

REPORT yKTREE_smartform1_new .

***************************DECLARATIONS*******************************

TABLES: zKTREE_t1,sflight.

DATA: cparam TYPE ssfctrlop,

outop TYPE ssfcompop,

fm_name TYPE rs38l_fnam,

my_tabix TYPE sy-tabix,

file_size TYPE i,

bin_filesize TYPE i.

DATA: tab_otf_data TYPE ssfcrescl,

pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE,

itab LIKE TABLE OF zshail_t1 WITH HEADER LINE,

otab TYPE TABLE OF sflight WITH HEADER LINE,

tab_otf_final TYPE itcoo OCCURS 0 WITH HEADER LINE.

start-of-selection.

                                  • suppressing the dialog box****************************

outop-tddest = 'LP01'.

cparam-no_dialog = 'X'.

cparam-preview = space.

cparam-getotf = 'X'.

****************for the first smartform*******************************

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'ZSHAIL_SMFORM2'

  • VARIANT = ' '

  • DIRECT_CALL = ' '

IMPORTING

fm_name = fm_name

EXCEPTIONS

no_form = 1

no_function_module = 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.

SELECT my_id my_income my_name FROM zshail_t1 INTO TABLE itab.

CALL FUNCTION fm_name

EXPORTING

  • ARCHIVE_INDEX =

  • ARCHIVE_INDEX_TAB =

  • ARCHIVE_PARAMETERS =

control_parameters = cparam

  • MAIL_APPL_OBJ =

  • MAIL_RECIPIENT =

  • MAIL_SENDER =

output_options = outop

user_settings = space

IMPORTING

  • DOCUMENT_OUTPUT_INFO =

job_output_info = tab_otf_data

  • JOB_OUTPUT_OPTIONS =

TABLES

it_tab = itab[]

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*********appending the otf data into the final table*********************

tab_otf_final[] = tab_otf_data-otfdata[].

*************for the second smartform************************************

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'ZSHAIL_SMTAB'

  • VARIANT = ' '

  • DIRECT_CALL = ' '

IMPORTING

fm_name = fm_name

EXCEPTIONS

no_form = 1

no_function_module = 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.

SELECT carrid connid fldate price FROM sflight INTO CORRESPONDING FIELDS

OF TABLE otab.

CALL FUNCTION fm_name

EXPORTING

  • ARCHIVE_INDEX =

  • ARCHIVE_INDEX_TAB =

  • ARCHIVE_PARAMETERS =

control_parameters = cparam

  • MAIL_APPL_OBJ =

  • MAIL_RECIPIENT =

  • MAIL_SENDER =

output_options = outop

user_settings = space

IMPORTING

  • DOCUMENT_OUTPUT_INFO =

job_output_info = tab_otf_data

  • JOB_OUTPUT_OPTIONS =

TABLES

itab = otab[]

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

**removing the initial and final markers from the OTF data*********

DELETE tab_otf_data-otfdata WHERE tdprintcom = '//'.

                                  • searching for the end-of-page in OTF table************

READ TABLE tab_otf_final WITH KEY tdprintcom = 'EP'.

my_tabix = sy-tabix + 1.

                        • appending the modified OTF table to the final OTF table****

INSERT LINES OF tab_otf_data-otfdata INTO tab_otf_final INDEX my_tabix.

                        • converting OTF data into pdf data**************************

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

  • ARCHIVE_INDEX = ' '

  • COPYNUMBER = 0

  • ASCII_BIDI_VIS2LOG = ' '

IMPORTING

bin_filesize = bin_filesize

  • BIN_FILE =

TABLES

otf = tab_otf_final

lines = pdf_tab

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

err_bad_otf = 4

OTHERS = 5

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

************downloading the converted PDF data to your local PC*******

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = bin_filesize

filename = 'D:\TEST.PDF'

filetype = 'BIN'

  • APPEND = ' '

  • WRITE_FIELD_SEPARATOR = ' '

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

IMPORTING

filelength = file_size

TABLES

data_tab = pdf_tab

  • FIELDNAMES =

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22

.