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

smartforms

Former Member
0 Likes
812

Hi,

How to convert a smart form to PDF file. Please can any body explain me with example code.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
718

Just check these links ..

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

pls try this code.

*&----


*

*& Report : ZPDF_FORMAT

*& Description : Conversion of Purchase Order into PDF format

*& used in the workflow (Do Not Change or Delete).

*&----


*

REPORT zpdf .

*&----


*

*& Tables used

*&----


*

TABLES: nast, tsp01, t024, spop, lfa1, tnapr.

*&----


*

*& Data declaration

*&----


*

DATA: spoolno LIKE tsp01-rqident.

DATA: rcode LIKE sy-subrc.

*data: doc_auth like zoutput-ztag.

DATA: cancel.

DATA: pdf LIKE tline OCCURS 0 WITH HEADER LINE.

DATA: numbytes TYPE i,

pdfspoolid LIKE tsp01-rqident,

jobname LIKE tbtcjob-jobname,

jobcount LIKE tbtcjob-jobcount,

is_otf.

DATA: client LIKE tst01-dclient,

name LIKE tst01-dname,

objtype LIKE rststype-type,

type LIKE rststype-type.

DATA: dir_loc(3).

DATA: t_docno LIKE vbak-vbeln..

DATA: spoolreq1 LIKE tsp01sys.

DATA: spoolreq LIKE rsporq OCCURS 0 WITH HEADER LINE.

DATA: t_frgke LIKE ekko-frgke.

DATA: okcode(10),

flag,

t_ekgrp LIKE ekko-ekgrp,

t_lifnr LIKE ekko-lifnr,

s_mail.

  • Data Declartion for mailing system - Start.

DATA: objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.

DATA: objhead LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: reclist1 LIKE somlreci1 OCCURS 500 WITH HEADER LINE.

DATA: reclist LIKE somlreci1 OCCURS 500 WITH HEADER LINE.

DATA: itab LIKE somlreci1 OCCURS 50 WITH HEADER LINE."RKU 220802

DATA: doc_chng LIKE sodocchgi1.

DATA: BEGIN OF bdcdata OCCURS 0.

INCLUDE STRUCTURE bdcdata.

DATA: END OF bdcdata.

DATA: tab_lines LIKE sy-tabix.

DATA: verkf LIKE ekko-verkf.

DATA: bemail(250), vemail(250).

*&----


*

  • Data acceptance

*&----


*

SELECTION-SCREEN BEGIN OF BLOCK blk0_input WITH FRAME .

PARAMETERS: docno LIKE ekko-ebeln OBLIGATORY LOWER CASE.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN END OF BLOCK blk0_input.

*&----


*

  • Initialisation

*&----


*

*initialization.

*&----


*

  • Screen Parameters Validation

*&----


*

*at selection-screen.

AT SELECTION-SCREEN.

SELECT SINGLE frgke INTO t_frgke FROM ekko

WHERE ebeln = docno

AND frgke = 'R'.

IF sy-subrc <> 0.

MESSAGE 'DOCUMENT NOT RELEASED' TYPE 'E'.

ENDIF.

*&----


*

  • Execution Part

*&----


*

START-OF-SELECTION.

  • For PO related operation

  • Dislay Buyer Group, Name and Email id

SELECT SINGLE

ekgrp

lifnr

verkf

INTO (t_ekgrp, t_lifnr, verkf)

FROM ekko

WHERE ekko~mandt = sy-mandt

AND ebeln = docno.

IF sy-subrc = 0.

SELECT SINGLE * FROM lfa1

WHERE lfa1~mandt = sy-mandt

AND lifnr = t_lifnr.

ENDIF.

  • Get message status from NAST or assign msg status NAST stru

  • Pass the message status and get spool data

PERFORM check_output_create_spool.

IF rcode NE 0.

IF rcode = 9.

  • message s185 with text-e04.

ELSE.

  • message s185 with text-e01.

ENDIF.

EXIT.

ENDIF.

  • find the spool

PERFORM find_spool_request_id.

IF sy-subrc <> 0.

  • message s185 with text-003.

EXIT.

ENDIF.

  • READ TABLE spoolreq

  • WITH KEY rq0name = nast-dsnam

    • rq1name = 'LP01'

  • rqclient = '800'

    • rq2name = sy-uname

  • rqowner = sy-uname.

  • IF sy-subrc <> 0.

  • CASE sy-subrc.

  • WHEN 1.

    • message s185 with text-e03.

  • WHEN OTHERS.

    • message s185 with text-e02.

  • ENDCASE.

  • EXIT.

  • ENDIF.

spoolno = spoolreq-rqident.

  • Convert SPOOL job to PDF

PERFORM convert_spool_to_pdf.

  • Send through mail

PERFORM assign_data_4_mail.

PERFORM send_mail_with_attachment.

  • Delete created spool request

spoolreq1-rqident = spoolno.

  • PERFORM delete_spool_job.

*&----


*

*& Form check_output_create_spool

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM check_output_create_spool.

SELECT SINGLE * FROM nast WHERE objky = docno

AND kappl = 'EF'

AND kschl = 'NEU'

AND aktiv = space

AND nacha = '1'.

IF sy-subrc EQ 0.

  • COUNT = COUNT + 1.

PERFORM mssage_status_field_value.

nast-vsztp = '4'.

PERFORM einzelnachricht_dialog(rsnast00) USING rcode.

ELSE.

CLEAR nast-uhrvr.

CLEAR nast-cmfpnr.

CLEAR nast-datvr.

PERFORM mssage_status_field_value.

nast-vsztp = '4'.

PERFORM einzelnachricht_dialog(rsnast00) USING rcode.

  • else.

  • rcode = 9.

ENDIF.

ENDFORM. " check_output_create_spool

*&----


*

*& Form mssage_status_field_value

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM mssage_status_field_value .

nast-mandt = '800'.

nast-kappl = 'EF'.

nast-kschl = 'NEU'.

nast-objky = docno.

nast-ldest = 'LP01'.

nast-anzal = 1.

nast-dimme = 'X'.

nast-delet = 'X'.

nast-nacha = '1'.

nast-vsztp = '2'.

nast-spras = 'E'.

nast-vstat = '0'.

nast-manue = 'X'.

nast-erdat = sy-datum.

nast-eruhr = sy-uzeit.

nast-usnam = sy-uname.

nast-tdreceiver = sy-uname.

concatenate sy-uzeit+2(4) 'PDF' into nast-dsnam.

ENDFORM. " mssage_status_field_value

*&----


*

*& Form find_spool_request_id

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM find_spool_request_id.

CALL FUNCTION 'RSPO_FIND_SPOOL_REQUESTS'

EXPORTING

allclients = '800'

  • authority = ' '

datatype = '*'

has_output_requests = '*'

rq0name = nast-dsnam "'*'

rq1name = '*'

rq2name = '*'

rqdest = 'LP01'

  • rqident = 0

rqowner = sy-uname

TABLES

spoolrequests = spoolreq

EXCEPTIONS

no_permission = 1

OTHERS = 2.

ENDFORM. " find_spool_request_id

*&----


*

*& Form convert_spool_to_pdf

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM convert_spool_to_pdf.

SELECT SINGLE * FROM tsp01 WHERE rqident = spoolno.

IF sy-subrc <> 0.

WRITE: / 'Spool order does not exist'

COLOR COL_NEGATIVE.

EXIT.

ENDIF.

client = tsp01-rqclient.

name = tsp01-rqo1name.

CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

EXPORTING

authority = 'SP01'

client = client

name = name

part = 1

IMPORTING

type = type

objtype = objtype

EXCEPTIONS

fb_error = 1

fb_rsts_other = 2

no_object = 3

no_permission = 4.

IF objtype(3) = 'OTF'.

is_otf = 'X'.

ELSE.

is_otf = space.

ENDIF.

IF is_otf = 'X'.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = spoolno

no_dialog = ' '

IMPORTING

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

btc_jobname = jobname

btc_jobcount = jobcount

TABLES

pdf = pdf

EXCEPTIONS

err_no_otf_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

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

  • if sy-subrc <> 0.

  • case sy-subrc.

  • when 1.

  • write: / text-001 color col_positive.

  • when 2.

  • write: / text-002 color col_negative.

  • exit.

  • when 3.

  • write: / text-003 color col_negative.

  • exit.

  • when 4.

  • write: / text-004 color col_negative.

  • exit.

  • when others.

  • write: / text-005 color col_negative.

  • exit.

  • endcase.

  • endif.

ELSE.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = spoolno

no_dialog = ' '

  • DST_DEVICE =

  • PDF_DESTINATION =

IMPORTING

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

  • LIST_PAGECOUNT =

btc_jobname = jobname

btc_jobcount = jobcount

TABLES

pdf = pdf

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.

  • case sy-subrc.

  • when 0.

*write: / 'Funktion CONVERT_ABAPSPOOLJOB_2_PDF erfolgreich

*(successful)'.

    • color col_positive.

  • when 1.

  • write: / text-001 color col_positive.

  • when 2.

  • write: / text-002 color col_negative.

  • exit.

  • when 3.

  • write: / text-003 color col_negative.

  • exit.

  • when 4.

  • write: / text-004 color col_negative.

  • exit.

  • when others.

  • write: / text-005 color col_negative.

  • exit.

  • endcase.

ENDIF.

ENDFORM. " convert_spool_to_pdf

*&----


*

*& Form delete_spool_job

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM delete_spool_job .

CALL FUNCTION 'RSPO_IDELETE_SPOOLREQ'

EXPORTING

spoolreq = spoolreq1

  • IMPORTING

  • RC =

  • STATUS =

EXCEPTIONS

error = 1

OTHERS = 2

.

IF sy-subrc <> 0.

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

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

ENDIF.

ENDFORM. " delete_spool_job

*

*&----


*

*& Form ASSIGN_DATA_4_MAIL

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM assign_data_4_mail .

  • Text content of the mail

  • move 'Purchase order: ' to objtxt.

  • append objtxt.

  • move verkf to objtxt.

  • append objtxt.

  • move lfa1-name1 to objtxt.

  • append objtxt.

  • concatenate lfa1-ort01 lfa1-pstlz

  • into objtxt separated by space.

  • append objtxt.

  • clear: objtxt.

  • append objtxt.

  • append objtxt.

*

CLEAR objtxt.

CONCATENATE 'Purchase Order - ' docno

' has been released.'

INTO objtxt SEPARATED BY space.

APPEND objtxt.

  • clear: objtxt.

  • append objtxt.

  • append objtxt.

*

MOVE ' ' TO objtxt.

APPEND objtxt.

  • clear: objtxt.

  • append objtxt.

  • append objtxt.

  • concatenate 'Note:- This is an automatic mail sender.'

  • ' Please do not reply to this mail ID.'

  • into objtxt.

  • append objtxt.

  • concatenate

  • ' Any query, please send the mail to the respective buyer'''

  • 's mail id.' into objtxt.

  • append objtxt.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

input = docno

IMPORTING

output = docno.

  • TLINE format will be coverted as 255 char foramt

CALL FUNCTION 'QCE1_CONVERT'

TABLES

t_source_tab = pdf

t_target_tab = objbin

EXCEPTIONS

convert_not_possible = 1

OTHERS = 2.

DESCRIBE TABLE objtxt LINES tab_lines.

  • creation of the entry for the compressed document

CLEAR objpack.

objpack-transf_bin = ''.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'RAW'.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

APPEND objpack.

  • creation of the entry for the Attachemnt

DESCRIBE TABLE objbin LINES tab_lines.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'PDF'.

CONCATENATE docno '.PDF' INTO objpack-obj_name.

objpack-obj_descr = objpack-obj_name.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

APPEND objpack.

  • For Object Header

CONCATENATE docno '.PDF' INTO objhead.

APPEND objhead.

doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

CONCATENATE 'Purchase Order - ' docno ' has been released'

INTO doc_chng-obj_descr.

doc_chng-obj_prio = 1.

  • recipient Details

CLEAR reclist1.

CLEAR reclist.

REFRESH reclist1.

REFRESH reclist.

  • SELECT SINGLE * FROM t024

  • WHERE t024~mandt = sy-mandt

  • AND ekgrp = t_ekgrp.

  • reclist1-receiver = t024-smtp_addr.

reclist1-rec_type = 'U'.

reclist1-com_type = 'INT'.

reclist1-receiver = 'mukundhan.kn@lntinfotech.com'.

  • modify table reclist transporting rec_type receiver COM_TYPE .

  • where rec_type is initial.

APPEND reclist1 TO reclist.

ENDFORM. " ASSIGN_DATA_4_MAIL

*&----


*

*& Form send_mail_with_attachment

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM send_mail_with_attachment.

  • sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

CASE sy-subrc.

WHEN 0.

PERFORM flush_mail.

  • message 'Mail sent successfully' type 'I'.

  • when 1.

  • message 'No authorization for sending to the specified number'

*type 'E'.

  • when 2.

  • message 'Document could not be sent to any recipient' type 'E'.

  • when 4.

  • message 'No send authorization' type 'E'.

  • when others.

  • message 'Error occurred while sending' type 'E'.

ENDCASE.

ENDFORM. " send_mail_with_attachment

*----


*

  • Start new screen *

*----


*

FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM. "bdc_dynpro

*----


*

  • Insert field *

*----


*

FORM bdc_field USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM. "bdc_field

*&----


*

*& Form AUTOMATE

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM flush_mail .

PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=PDIA'.

PERFORM bdc_dynpro USING 'SAPLSPO4' '0300'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=FURT'.

PERFORM bdc_field USING 'BDC_CURSOR'

'SVALD-VALUE(01)'.

PERFORM bdc_field USING 'SVALD-VALUE(01)'

'int'.

PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BACK'.

PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BACK'.

CALL TRANSACTION 'SCOT' USING bdcdata

MODE 'N'

UPDATE 'S'.

ENDFORM. " AUTOMATE

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

Check this sample code and use gui_download to download the pdf.

REPORT zzz_test3 .

  • Internal Table declarations

DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,

i_tline TYPE TABLE OF tline WITH HEADER LINE,

_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,

  • Work Area declarations

w_objhead TYPE soli_tab,

w_ctrlop TYPE ssfctrlop,

w_compop TYPE ssfcompop,

w_return TYPE ssfcrescl,

w_buffer TYPE string,"To convert from 132 to 255

  • Variables declarations

v_form_name TYPE rs38l_fnam,

v_len_in LIKE sood-objlen,

v_len_out LIKE sood-objlen,

v_len_outn TYPE i,

v_lines_txt TYPE i,

v_lines_bin TYPE i.

call function 'SSF_FUNCTION_MODULE_NAME'

exporting

formname = 'ZZZ_TEST2'

importing

fm_name = v_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.

w_ctrlop-getotf = 'X'.

w_ctrlop-no_dialog = 'X'.

w_compop-tdnoprev = 'X'.

CALL FUNCTION v_form_name

EXPORTING

control_parameters = w_ctrlop

output_options = w_compop

user_settings = 'X'

IMPORTING

job_output_info = w_return

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.

i_otf[] = w_return-otfdata[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = v_len_in

TABLES

otf = i_otf

lines = i_tline

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.

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

one more program....

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.

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.

Tutorial on SMART FORMS

© 2005 SAP AG 7

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'

Tutorial on SMART FORMS

© 2005 SAP AG 8

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: est.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

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

Regards

Vasu

6 REPLIES 6
Read only

Former Member
0 Likes
719

Just check these links ..

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

pls try this code.

*&----


*

*& Report : ZPDF_FORMAT

*& Description : Conversion of Purchase Order into PDF format

*& used in the workflow (Do Not Change or Delete).

*&----


*

REPORT zpdf .

*&----


*

*& Tables used

*&----


*

TABLES: nast, tsp01, t024, spop, lfa1, tnapr.

*&----


*

*& Data declaration

*&----


*

DATA: spoolno LIKE tsp01-rqident.

DATA: rcode LIKE sy-subrc.

*data: doc_auth like zoutput-ztag.

DATA: cancel.

DATA: pdf LIKE tline OCCURS 0 WITH HEADER LINE.

DATA: numbytes TYPE i,

pdfspoolid LIKE tsp01-rqident,

jobname LIKE tbtcjob-jobname,

jobcount LIKE tbtcjob-jobcount,

is_otf.

DATA: client LIKE tst01-dclient,

name LIKE tst01-dname,

objtype LIKE rststype-type,

type LIKE rststype-type.

DATA: dir_loc(3).

DATA: t_docno LIKE vbak-vbeln..

DATA: spoolreq1 LIKE tsp01sys.

DATA: spoolreq LIKE rsporq OCCURS 0 WITH HEADER LINE.

DATA: t_frgke LIKE ekko-frgke.

DATA: okcode(10),

flag,

t_ekgrp LIKE ekko-ekgrp,

t_lifnr LIKE ekko-lifnr,

s_mail.

  • Data Declartion for mailing system - Start.

DATA: objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.

DATA: objhead LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: reclist1 LIKE somlreci1 OCCURS 500 WITH HEADER LINE.

DATA: reclist LIKE somlreci1 OCCURS 500 WITH HEADER LINE.

DATA: itab LIKE somlreci1 OCCURS 50 WITH HEADER LINE."RKU 220802

DATA: doc_chng LIKE sodocchgi1.

DATA: BEGIN OF bdcdata OCCURS 0.

INCLUDE STRUCTURE bdcdata.

DATA: END OF bdcdata.

DATA: tab_lines LIKE sy-tabix.

DATA: verkf LIKE ekko-verkf.

DATA: bemail(250), vemail(250).

*&----


*

  • Data acceptance

*&----


*

SELECTION-SCREEN BEGIN OF BLOCK blk0_input WITH FRAME .

PARAMETERS: docno LIKE ekko-ebeln OBLIGATORY LOWER CASE.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN END OF BLOCK blk0_input.

*&----


*

  • Initialisation

*&----


*

*initialization.

*&----


*

  • Screen Parameters Validation

*&----


*

*at selection-screen.

AT SELECTION-SCREEN.

SELECT SINGLE frgke INTO t_frgke FROM ekko

WHERE ebeln = docno

AND frgke = 'R'.

IF sy-subrc <> 0.

MESSAGE 'DOCUMENT NOT RELEASED' TYPE 'E'.

ENDIF.

*&----


*

  • Execution Part

*&----


*

START-OF-SELECTION.

  • For PO related operation

  • Dislay Buyer Group, Name and Email id

SELECT SINGLE

ekgrp

lifnr

verkf

INTO (t_ekgrp, t_lifnr, verkf)

FROM ekko

WHERE ekko~mandt = sy-mandt

AND ebeln = docno.

IF sy-subrc = 0.

SELECT SINGLE * FROM lfa1

WHERE lfa1~mandt = sy-mandt

AND lifnr = t_lifnr.

ENDIF.

  • Get message status from NAST or assign msg status NAST stru

  • Pass the message status and get spool data

PERFORM check_output_create_spool.

IF rcode NE 0.

IF rcode = 9.

  • message s185 with text-e04.

ELSE.

  • message s185 with text-e01.

ENDIF.

EXIT.

ENDIF.

  • find the spool

PERFORM find_spool_request_id.

IF sy-subrc <> 0.

  • message s185 with text-003.

EXIT.

ENDIF.

  • READ TABLE spoolreq

  • WITH KEY rq0name = nast-dsnam

    • rq1name = 'LP01'

  • rqclient = '800'

    • rq2name = sy-uname

  • rqowner = sy-uname.

  • IF sy-subrc <> 0.

  • CASE sy-subrc.

  • WHEN 1.

    • message s185 with text-e03.

  • WHEN OTHERS.

    • message s185 with text-e02.

  • ENDCASE.

  • EXIT.

  • ENDIF.

spoolno = spoolreq-rqident.

  • Convert SPOOL job to PDF

PERFORM convert_spool_to_pdf.

  • Send through mail

PERFORM assign_data_4_mail.

PERFORM send_mail_with_attachment.

  • Delete created spool request

spoolreq1-rqident = spoolno.

  • PERFORM delete_spool_job.

*&----


*

*& Form check_output_create_spool

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM check_output_create_spool.

SELECT SINGLE * FROM nast WHERE objky = docno

AND kappl = 'EF'

AND kschl = 'NEU'

AND aktiv = space

AND nacha = '1'.

IF sy-subrc EQ 0.

  • COUNT = COUNT + 1.

PERFORM mssage_status_field_value.

nast-vsztp = '4'.

PERFORM einzelnachricht_dialog(rsnast00) USING rcode.

ELSE.

CLEAR nast-uhrvr.

CLEAR nast-cmfpnr.

CLEAR nast-datvr.

PERFORM mssage_status_field_value.

nast-vsztp = '4'.

PERFORM einzelnachricht_dialog(rsnast00) USING rcode.

  • else.

  • rcode = 9.

ENDIF.

ENDFORM. " check_output_create_spool

*&----


*

*& Form mssage_status_field_value

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM mssage_status_field_value .

nast-mandt = '800'.

nast-kappl = 'EF'.

nast-kschl = 'NEU'.

nast-objky = docno.

nast-ldest = 'LP01'.

nast-anzal = 1.

nast-dimme = 'X'.

nast-delet = 'X'.

nast-nacha = '1'.

nast-vsztp = '2'.

nast-spras = 'E'.

nast-vstat = '0'.

nast-manue = 'X'.

nast-erdat = sy-datum.

nast-eruhr = sy-uzeit.

nast-usnam = sy-uname.

nast-tdreceiver = sy-uname.

concatenate sy-uzeit+2(4) 'PDF' into nast-dsnam.

ENDFORM. " mssage_status_field_value

*&----


*

*& Form find_spool_request_id

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM find_spool_request_id.

CALL FUNCTION 'RSPO_FIND_SPOOL_REQUESTS'

EXPORTING

allclients = '800'

  • authority = ' '

datatype = '*'

has_output_requests = '*'

rq0name = nast-dsnam "'*'

rq1name = '*'

rq2name = '*'

rqdest = 'LP01'

  • rqident = 0

rqowner = sy-uname

TABLES

spoolrequests = spoolreq

EXCEPTIONS

no_permission = 1

OTHERS = 2.

ENDFORM. " find_spool_request_id

*&----


*

*& Form convert_spool_to_pdf

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM convert_spool_to_pdf.

SELECT SINGLE * FROM tsp01 WHERE rqident = spoolno.

IF sy-subrc <> 0.

WRITE: / 'Spool order does not exist'

COLOR COL_NEGATIVE.

EXIT.

ENDIF.

client = tsp01-rqclient.

name = tsp01-rqo1name.

CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

EXPORTING

authority = 'SP01'

client = client

name = name

part = 1

IMPORTING

type = type

objtype = objtype

EXCEPTIONS

fb_error = 1

fb_rsts_other = 2

no_object = 3

no_permission = 4.

IF objtype(3) = 'OTF'.

is_otf = 'X'.

ELSE.

is_otf = space.

ENDIF.

IF is_otf = 'X'.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = spoolno

no_dialog = ' '

IMPORTING

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

btc_jobname = jobname

btc_jobcount = jobcount

TABLES

pdf = pdf

EXCEPTIONS

err_no_otf_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

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

  • if sy-subrc <> 0.

  • case sy-subrc.

  • when 1.

  • write: / text-001 color col_positive.

  • when 2.

  • write: / text-002 color col_negative.

  • exit.

  • when 3.

  • write: / text-003 color col_negative.

  • exit.

  • when 4.

  • write: / text-004 color col_negative.

  • exit.

  • when others.

  • write: / text-005 color col_negative.

  • exit.

  • endcase.

  • endif.

ELSE.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = spoolno

no_dialog = ' '

  • DST_DEVICE =

  • PDF_DESTINATION =

IMPORTING

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

  • LIST_PAGECOUNT =

btc_jobname = jobname

btc_jobcount = jobcount

TABLES

pdf = pdf

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.

  • case sy-subrc.

  • when 0.

*write: / 'Funktion CONVERT_ABAPSPOOLJOB_2_PDF erfolgreich

*(successful)'.

    • color col_positive.

  • when 1.

  • write: / text-001 color col_positive.

  • when 2.

  • write: / text-002 color col_negative.

  • exit.

  • when 3.

  • write: / text-003 color col_negative.

  • exit.

  • when 4.

  • write: / text-004 color col_negative.

  • exit.

  • when others.

  • write: / text-005 color col_negative.

  • exit.

  • endcase.

ENDIF.

ENDFORM. " convert_spool_to_pdf

*&----


*

*& Form delete_spool_job

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM delete_spool_job .

CALL FUNCTION 'RSPO_IDELETE_SPOOLREQ'

EXPORTING

spoolreq = spoolreq1

  • IMPORTING

  • RC =

  • STATUS =

EXCEPTIONS

error = 1

OTHERS = 2

.

IF sy-subrc <> 0.

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

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

ENDIF.

ENDFORM. " delete_spool_job

*

*&----


*

*& Form ASSIGN_DATA_4_MAIL

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM assign_data_4_mail .

  • Text content of the mail

  • move 'Purchase order: ' to objtxt.

  • append objtxt.

  • move verkf to objtxt.

  • append objtxt.

  • move lfa1-name1 to objtxt.

  • append objtxt.

  • concatenate lfa1-ort01 lfa1-pstlz

  • into objtxt separated by space.

  • append objtxt.

  • clear: objtxt.

  • append objtxt.

  • append objtxt.

*

CLEAR objtxt.

CONCATENATE 'Purchase Order - ' docno

' has been released.'

INTO objtxt SEPARATED BY space.

APPEND objtxt.

  • clear: objtxt.

  • append objtxt.

  • append objtxt.

*

MOVE ' ' TO objtxt.

APPEND objtxt.

  • clear: objtxt.

  • append objtxt.

  • append objtxt.

  • concatenate 'Note:- This is an automatic mail sender.'

  • ' Please do not reply to this mail ID.'

  • into objtxt.

  • append objtxt.

  • concatenate

  • ' Any query, please send the mail to the respective buyer'''

  • 's mail id.' into objtxt.

  • append objtxt.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

input = docno

IMPORTING

output = docno.

  • TLINE format will be coverted as 255 char foramt

CALL FUNCTION 'QCE1_CONVERT'

TABLES

t_source_tab = pdf

t_target_tab = objbin

EXCEPTIONS

convert_not_possible = 1

OTHERS = 2.

DESCRIBE TABLE objtxt LINES tab_lines.

  • creation of the entry for the compressed document

CLEAR objpack.

objpack-transf_bin = ''.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'RAW'.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

APPEND objpack.

  • creation of the entry for the Attachemnt

DESCRIBE TABLE objbin LINES tab_lines.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'PDF'.

CONCATENATE docno '.PDF' INTO objpack-obj_name.

objpack-obj_descr = objpack-obj_name.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

APPEND objpack.

  • For Object Header

CONCATENATE docno '.PDF' INTO objhead.

APPEND objhead.

doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

CONCATENATE 'Purchase Order - ' docno ' has been released'

INTO doc_chng-obj_descr.

doc_chng-obj_prio = 1.

  • recipient Details

CLEAR reclist1.

CLEAR reclist.

REFRESH reclist1.

REFRESH reclist.

  • SELECT SINGLE * FROM t024

  • WHERE t024~mandt = sy-mandt

  • AND ekgrp = t_ekgrp.

  • reclist1-receiver = t024-smtp_addr.

reclist1-rec_type = 'U'.

reclist1-com_type = 'INT'.

reclist1-receiver = 'mukundhan.kn@lntinfotech.com'.

  • modify table reclist transporting rec_type receiver COM_TYPE .

  • where rec_type is initial.

APPEND reclist1 TO reclist.

ENDFORM. " ASSIGN_DATA_4_MAIL

*&----


*

*& Form send_mail_with_attachment

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM send_mail_with_attachment.

  • sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

CASE sy-subrc.

WHEN 0.

PERFORM flush_mail.

  • message 'Mail sent successfully' type 'I'.

  • when 1.

  • message 'No authorization for sending to the specified number'

*type 'E'.

  • when 2.

  • message 'Document could not be sent to any recipient' type 'E'.

  • when 4.

  • message 'No send authorization' type 'E'.

  • when others.

  • message 'Error occurred while sending' type 'E'.

ENDCASE.

ENDFORM. " send_mail_with_attachment

*----


*

  • Start new screen *

*----


*

FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM. "bdc_dynpro

*----


*

  • Insert field *

*----


*

FORM bdc_field USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM. "bdc_field

*&----


*

*& Form AUTOMATE

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM flush_mail .

PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=PDIA'.

PERFORM bdc_dynpro USING 'SAPLSPO4' '0300'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=FURT'.

PERFORM bdc_field USING 'BDC_CURSOR'

'SVALD-VALUE(01)'.

PERFORM bdc_field USING 'SVALD-VALUE(01)'

'int'.

PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BACK'.

PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BACK'.

CALL TRANSACTION 'SCOT' USING bdcdata

MODE 'N'

UPDATE 'S'.

ENDFORM. " AUTOMATE

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

Check this sample code and use gui_download to download the pdf.

REPORT zzz_test3 .

  • Internal Table declarations

DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,

i_tline TYPE TABLE OF tline WITH HEADER LINE,

_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,

  • Work Area declarations

w_objhead TYPE soli_tab,

w_ctrlop TYPE ssfctrlop,

w_compop TYPE ssfcompop,

w_return TYPE ssfcrescl,

w_buffer TYPE string,"To convert from 132 to 255

  • Variables declarations

v_form_name TYPE rs38l_fnam,

v_len_in LIKE sood-objlen,

v_len_out LIKE sood-objlen,

v_len_outn TYPE i,

v_lines_txt TYPE i,

v_lines_bin TYPE i.

call function 'SSF_FUNCTION_MODULE_NAME'

exporting

formname = 'ZZZ_TEST2'

importing

fm_name = v_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.

w_ctrlop-getotf = 'X'.

w_ctrlop-no_dialog = 'X'.

w_compop-tdnoprev = 'X'.

CALL FUNCTION v_form_name

EXPORTING

control_parameters = w_ctrlop

output_options = w_compop

user_settings = 'X'

IMPORTING

job_output_info = w_return

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.

i_otf[] = w_return-otfdata[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = v_len_in

TABLES

otf = i_otf

lines = i_tline

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.

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

one more program....

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.

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.

Tutorial on SMART FORMS

© 2005 SAP AG 7

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'

Tutorial on SMART FORMS

© 2005 SAP AG 8

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: est.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

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

Regards

Vasu

Read only

paruchuri_nagesh
Active Contributor
0 Likes
718

hi

ratnam try this code

pls try this code.

&----


*& Report : ZPDF_FORMAT

*& Description : Conversion of Purchase Order into PDF format

*& used in the workflow (Do Not Change or Delete).

&----


REPORT zpdf .

&----


*& Tables used

&----


TABLES: nast, tsp01, t024, spop, lfa1, tnapr.

&----


*& Data declaration

&----


DATA: spoolno LIKE tsp01-rqident.

DATA: rcode LIKE sy-subrc.

*data: doc_auth like zoutput-ztag.

DATA: cancel.

DATA: pdf LIKE tline OCCURS 0 WITH HEADER LINE.

DATA: numbytes TYPE i,

pdfspoolid LIKE tsp01-rqident,

jobname LIKE tbtcjob-jobname,

jobcount LIKE tbtcjob-jobcount,

is_otf.

DATA: client LIKE tst01-dclient,

name LIKE tst01-dname,

objtype LIKE rststype-type,

type LIKE rststype-type.

DATA: dir_loc(3).

DATA: t_docno LIKE vbak-vbeln..

DATA: spoolreq1 LIKE tsp01sys.

DATA: spoolreq LIKE rsporq OCCURS 0 WITH HEADER LINE.

DATA: t_frgke LIKE ekko-frgke.

DATA: okcode(10),

flag,

t_ekgrp LIKE ekko-ekgrp,

t_lifnr LIKE ekko-lifnr,

s_mail.

  • Data Declartion for mailing system - Start.

DATA: objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.

DATA: objhead LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: reclist1 LIKE somlreci1 OCCURS 500 WITH HEADER LINE.

DATA: reclist LIKE somlreci1 OCCURS 500 WITH HEADER LINE.

DATA: itab LIKE somlreci1 OCCURS 50 WITH HEADER LINE."RKU 220802

DATA: doc_chng LIKE sodocchgi1.

DATA: BEGIN OF bdcdata OCCURS 0.

INCLUDE STRUCTURE bdcdata.

DATA: END OF bdcdata.

DATA: tab_lines LIKE sy-tabix.

DATA: verkf LIKE ekko-verkf.

DATA: bemail(250), vemail(250).

&----


  • Data acceptance

&----


SELECTION-SCREEN BEGIN OF BLOCK blk0_input WITH FRAME .

PARAMETERS: docno LIKE ekko-ebeln OBLIGATORY LOWER CASE.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN END OF BLOCK blk0_input.

&----


  • Initialisation

&----


*initialization.

&----


  • Screen Parameters Validation

&----


*at selection-screen.

AT SELECTION-SCREEN.

SELECT SINGLE frgke INTO t_frgke FROM ekko

WHERE ebeln = docno

AND frgke = 'R'.

IF sy-subrc <> 0.

MESSAGE 'DOCUMENT NOT RELEASED' TYPE 'E'.

ENDIF.

&----


  • Execution Part

&----


START-OF-SELECTION.

  • For PO related operation

  • Dislay Buyer Group, Name and Email id

SELECT SINGLE

ekgrp

lifnr

verkf

INTO (t_ekgrp, t_lifnr, verkf)

FROM ekko

WHERE ekko~mandt = sy-mandt

AND ebeln = docno.

IF sy-subrc = 0.

SELECT SINGLE * FROM lfa1

WHERE lfa1~mandt = sy-mandt

AND lifnr = t_lifnr.

ENDIF.

  • Get message status from NAST or assign msg status NAST stru

  • Pass the message status and get spool data

PERFORM check_output_create_spool.

IF rcode NE 0.

IF rcode = 9.

  • message s185 with text-e04.

ELSE.

  • message s185 with text-e01.

ENDIF.

EXIT.

ENDIF.

  • find the spool

PERFORM find_spool_request_id.

IF sy-subrc <> 0.

  • message s185 with text-003.

EXIT.

ENDIF.

  • READ TABLE spoolreq

  • WITH KEY rq0name = nast-dsnam

    • rq1name = 'LP01'

  • rqclient = '800'

    • rq2name = sy-uname

  • rqowner = sy-uname.

  • IF sy-subrc <> 0.

  • CASE sy-subrc.

  • WHEN 1.

    • message s185 with text-e03.

  • WHEN OTHERS.

    • message s185 with text-e02.

  • ENDCASE.

  • EXIT.

  • ENDIF.

spoolno = spoolreq-rqident.

  • Convert SPOOL job to PDF

PERFORM convert_spool_to_pdf.

  • Send through mail

PERFORM assign_data_4_mail.

PERFORM send_mail_with_attachment.

  • Delete created spool request

spoolreq1-rqident = spoolno.

  • PERFORM delete_spool_job.

&----


*& Form check_output_create_spool

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM check_output_create_spool.

SELECT SINGLE * FROM nast WHERE objky = docno

AND kappl = 'EF'

AND kschl = 'NEU'

AND aktiv = space

AND nacha = '1'.

IF sy-subrc EQ 0.

  • COUNT = COUNT + 1.

PERFORM mssage_status_field_value.

nast-vsztp = '4'.

PERFORM einzelnachricht_dialog(rsnast00) USING rcode.

ELSE.

CLEAR nast-uhrvr.

CLEAR nast-cmfpnr.

CLEAR nast-datvr.

PERFORM mssage_status_field_value.

nast-vsztp = '4'.

PERFORM einzelnachricht_dialog(rsnast00) USING rcode.

  • else.

  • rcode = 9.

ENDIF.

ENDFORM. " check_output_create_spool

&----


*& Form mssage_status_field_value

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM mssage_status_field_value .

nast-mandt = '800'.

nast-kappl = 'EF'.

nast-kschl = 'NEU'.

nast-objky = docno.

nast-ldest = 'LP01'.

nast-anzal = 1.

nast-dimme = 'X'.

nast-delet = 'X'.

nast-nacha = '1'.

nast-vsztp = '2'.

nast-spras = 'E'.

nast-vstat = '0'.

nast-manue = 'X'.

nast-erdat = sy-datum.

nast-eruhr = sy-uzeit.

nast-usnam = sy-uname.

nast-tdreceiver = sy-uname.

concatenate sy-uzeit+2(4) 'PDF' into nast-dsnam.

ENDFORM. " mssage_status_field_value

&----


*& Form find_spool_request_id

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM find_spool_request_id.

CALL FUNCTION 'RSPO_FIND_SPOOL_REQUESTS'

EXPORTING

allclients = '800'

  • authority = ' '

datatype = '*'

has_output_requests = '*'

rq0name = nast-dsnam "'*'

rq1name = '*'

rq2name = '*'

rqdest = 'LP01'

  • rqident = 0

rqowner = sy-uname

TABLES

spoolrequests = spoolreq

EXCEPTIONS

no_permission = 1

OTHERS = 2.

ENDFORM. " find_spool_request_id

&----


*& Form convert_spool_to_pdf

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM convert_spool_to_pdf.

SELECT SINGLE * FROM tsp01 WHERE rqident = spoolno.

IF sy-subrc <> 0.

WRITE: / 'Spool order does not exist'

COLOR COL_NEGATIVE.

EXIT.

ENDIF.

client = tsp01-rqclient.

name = tsp01-rqo1name.

CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

EXPORTING

authority = 'SP01'

client = client

name = name

part = 1

IMPORTING

type = type

objtype = objtype

EXCEPTIONS

fb_error = 1

fb_rsts_other = 2

no_object = 3

no_permission = 4.

IF objtype(3) = 'OTF'.

is_otf = 'X'.

ELSE.

is_otf = space.

ENDIF.

IF is_otf = 'X'.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = spoolno

no_dialog = ' '

IMPORTING

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

btc_jobname = jobname

btc_jobcount = jobcount

TABLES

pdf = pdf

EXCEPTIONS

err_no_otf_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

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

  • if sy-subrc <> 0.

  • case sy-subrc.

  • when 1.

  • write: / text-001 color col_positive.

  • when 2.

  • write: / text-002 color col_negative.

  • exit.

  • when 3.

  • write: / text-003 color col_negative.

  • exit.

  • when 4.

  • write: / text-004 color col_negative.

  • exit.

  • when others.

  • write: / text-005 color col_negative.

  • exit.

  • endcase.

  • endif.

ELSE.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = spoolno

no_dialog = ' '

  • DST_DEVICE =

  • PDF_DESTINATION =

IMPORTING

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

  • LIST_PAGECOUNT =

btc_jobname = jobname

btc_jobcount = jobcount

TABLES

pdf = pdf

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.

  • case sy-subrc.

  • when 0.

*write: / 'Funktion CONVERT_ABAPSPOOLJOB_2_PDF erfolgreich

*(successful)'.

    • color col_positive.

  • when 1.

  • write: / text-001 color col_positive.

  • when 2.

  • write: / text-002 color col_negative.

  • exit.

  • when 3.

  • write: / text-003 color col_negative.

  • exit.

  • when 4.

  • write: / text-004 color col_negative.

  • exit.

  • when others.

  • write: / text-005 color col_negative.

  • exit.

  • endcase.

ENDIF.

ENDFORM. " convert_spool_to_pdf

&----


*& Form delete_spool_job

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM delete_spool_job .

CALL FUNCTION 'RSPO_IDELETE_SPOOLREQ'

EXPORTING

spoolreq = spoolreq1

  • IMPORTING

  • RC =

  • STATUS =

EXCEPTIONS

error = 1

OTHERS = 2

.

IF sy-subrc <> 0.

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

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

ENDIF.

ENDFORM. " delete_spool_job

*

&----


*& Form ASSIGN_DATA_4_MAIL

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM assign_data_4_mail .

  • Text content of the mail

  • move 'Purchase order: ' to objtxt.

  • append objtxt.

  • move verkf to objtxt.

  • append objtxt.

  • move lfa1-name1 to objtxt.

  • append objtxt.

  • concatenate lfa1-ort01 lfa1-pstlz

  • into objtxt separated by space.

  • append objtxt.

  • clear: objtxt.

  • append objtxt.

  • append objtxt.

*

CLEAR objtxt.

CONCATENATE 'Purchase Order - ' docno

' has been released.'

INTO objtxt SEPARATED BY space.

APPEND objtxt.

  • clear: objtxt.

  • append objtxt.

  • append objtxt.

*

MOVE ' ' TO objtxt.

APPEND objtxt.

  • clear: objtxt.

  • append objtxt.

  • append objtxt.

  • concatenate 'Note:- This is an automatic mail sender.'

  • ' Please do not reply to this mail ID.'

  • into objtxt.

  • append objtxt.

  • concatenate

  • ' Any query, please send the mail to the respective buyer'''

  • 's mail id.' into objtxt.

  • append objtxt.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

input = docno

IMPORTING

output = docno.

  • TLINE format will be coverted as 255 char foramt

CALL FUNCTION 'QCE1_CONVERT'

TABLES

t_source_tab = pdf

t_target_tab = objbin

EXCEPTIONS

convert_not_possible = 1

OTHERS = 2.

DESCRIBE TABLE objtxt LINES tab_lines.

  • creation of the entry for the compressed document

CLEAR objpack.

objpack-transf_bin = ''.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'RAW'.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

APPEND objpack.

  • creation of the entry for the Attachemnt

DESCRIBE TABLE objbin LINES tab_lines.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'PDF'.

CONCATENATE docno '.PDF' INTO objpack-obj_name.

objpack-obj_descr = objpack-obj_name.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

APPEND objpack.

  • For Object Header

CONCATENATE docno '.PDF' INTO objhead.

APPEND objhead.

doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

CONCATENATE 'Purchase Order - ' docno ' has been released'

INTO doc_chng-obj_descr.

doc_chng-obj_prio = 1.

  • recipient Details

CLEAR reclist1.

CLEAR reclist.

REFRESH reclist1.

REFRESH reclist.

  • SELECT SINGLE * FROM t024

  • WHERE t024~mandt = sy-mandt

  • AND ekgrp = t_ekgrp.

  • reclist1-receiver = t024-smtp_addr.

reclist1-rec_type = 'U'.

reclist1-com_type = 'INT'.

reclist1-receiver = 'mukundhan.kn@lntinfotech.com'.

  • modify table reclist transporting rec_type receiver COM_TYPE .

  • where rec_type is initial.

APPEND reclist1 TO reclist.

ENDFORM. " ASSIGN_DATA_4_MAIL

&----


*& Form send_mail_with_attachment

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM send_mail_with_attachment.

  • sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

CASE sy-subrc.

WHEN 0.

PERFORM flush_mail.

  • message 'Mail sent successfully' type 'I'.

  • when 1.

  • message 'No authorization for sending to the specified number'

*type 'E'.

  • when 2.

  • message 'Document could not be sent to any recipient' type 'E'.

  • when 4.

  • message 'No send authorization' type 'E'.

  • when others.

  • message 'Error occurred while sending' type 'E'.

ENDCASE.

ENDFORM. " send_mail_with_attachment

----


  • Start new screen *

----


FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM. "bdc_dynpro

----


  • Insert field *

----


FORM bdc_field USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM. "bdc_field

&----


*& Form AUTOMATE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM flush_mail .

PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=PDIA'.

PERFORM bdc_dynpro USING 'SAPLSPO4' '0300'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=FURT'.

PERFORM bdc_field USING 'BDC_CURSOR'

'SVALD-VALUE(01)'.

PERFORM bdc_field USING 'SVALD-VALUE(01)'

'int'.

PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BACK'.

PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BACK'.

CALL TRANSACTION 'SCOT' USING bdcdata

MODE 'N'

UPDATE 'S'.

ENDFORM. " AUTOMATE

regards,

Nagesh.Paruchuri

reward for use ful answers

Read only

Former Member
0 Likes
718

hi,

create spool request of your output and

pass it to RSTXPDFT4 programme.

raj

Read only

Former Member
0 Likes
718

hi,

use this function module

CALL FUNCTION <b>'CONVERT_OTFSPOOLJOB_2_PDF'</b>

EXPORTING

src_spoolid = src_spoolid

  • NO_DIALOG = NO_DIALOG

  • DST_DEVICE = DST_DEVICE

  • PDF_DESTINATION = PDF_DESTINATION

  • IMPORTING

  • PDF_BYTECOUNT = PDF_BYTECOUNT

  • PDF_SPOOLID = PDF_SPOOLID

  • OTF_PAGECOUNT = OTF_PAGECOUNT

  • BTC_JOBNAME = BTC_JOBNAME

  • BTC_JOBCOUNT = BTC_JOBCOUNT

TABLES

PDF = PDF

  • EXCEPTIONS

  • ERR_NO_OTF_SPOOLJOB = 1

  • ERR_NO_SPOOLJOB = 2

  • ERR_NO_PERMISSION = 3

  • ERR_CONV_NOT_POSSIBLE = 4

  • ERR_BAD_DSTDEVICE = 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

thanks

reward points if helpful...

Read only

Former Member
0 Likes
718

CUT and paste the following code.

*to get the spool id generated

SELECT rq2name

rqident

rqcretime

FROM tsp01

INTO CORRESPONDING FIELDS OF

TABLE gt_tsp01

WHERE rq2name in RUSNAM

ORDER BY rqcretime DESCENDING.

IF sy-subrc = 0 .

READ TABLE gt_tsp01 INTO gs_tsp01 INDEX 1 .

MOVE gs_tsp01-rqident TO gv_spool.

ENDIF.

*to get the output in pdf format

SELECT SINGLE * FROM tsp01 INTO gs_tsp01 WHERE rqident = gv_spool.

IF sy-subrc <> 0.

PERFORM bd_textbox_err IN PROGRAM rstxpdft USING 80

'Spool order does not exist'(003).

EXIT.

ENDIF.

gv_client = gs_tsp01-rqclient.

gv_name = gs_tsp01-rqo1name.

CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

EXPORTING

authority = 'SP01'

client = gv_client

name = gv_name

part = 1

IMPORTING

objtype = gv_objtype.

IF gv_objtype(3) = 'OTF'.

gv_is_otf = 'X'.

ELSE.

gv_is_otf = space.

ENDIF.

IF gv_is_otf = 'X'.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = gv_spool

no_dialog = ' '

IMPORTING

pdf_bytecount = gv_numbytes

btc_jobname = gv_jobname

btc_jobcount = gv_jobcount

TABLES

pdf = gt_pdf

EXCEPTIONS

err_no_otf_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

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

CASE sy-subrc.

WHEN 0.

PERFORM bd_textbox_msg IN PROGRAM rstxpdft USING 80

'Function CONVERT_OTFSPOOLJOB_2_PDF successfully'(001).

WHEN 1.

PERFORM bd_textbox_err IN PROGRAM rstxpdft USING 80

'No OTF and no ABAP Spool order'(002).

EXIT.

WHEN 2.

PERFORM bd_textbox_err IN PROGRAM rstxpdft USING 80

'Spool order does not exist'(003).

EXIT.

WHEN 3.

PERFORM bd_textbox_err IN PROGRAM rstxpdft USING 80

'No authorization for reading Spool order'(004).

EXIT.

WHEN OTHERS.

PERFORM bd_textbox_err IN PROGRAM rstxpdft USING 80

'Error with function CONVERT_OTFSPOOLJOB_2_PDF'(005).

EXIT.

ENDCASE.

ELSE.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = gv_spool

no_dialog = ' '

IMPORTING

pdf_bytecount = gv_numbytes

btc_jobname = gv_jobname

btc_jobcount = gv_jobcount

TABLES

pdf = gt_pdf

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.

CASE sy-subrc.

WHEN 0.

PERFORM bd_textbox_msg IN PROGRAM rstxpdft USING 80

'Function CONVERT_ABAPSPOOLJOB_2_PDF successfully'(006).

WHEN 1.

PERFORM bd_textbox_err IN PROGRAM rstxpdft USING 80

'No OTF and no ABAP Spool order'(002).

EXIT.

WHEN 2.

PERFORM bd_textbox_err IN PROGRAM rstxpdft USING 80

'Spool order does not exist'(003).

EXIT.

WHEN 3.

PERFORM bd_textbox_err IN PROGRAM rstxpdft USING 80

'No authorization for reading Spool order'(004).

EXIT.

WHEN OTHERS.

PERFORM bd_textbox_err IN PROGRAM rstxpdft USING 80

'Error with function CONVERT_ABAPSPOOLJOB_2_PDF'(007).

EXIT.

ENDCASE.

ENDIF.

                              • download PDF file ***********

CHECK gv_download = 'X'.

IF NOT ( gv_jobname IS INITIAL ).

PERFORM bd_textbox_var2_msg IN PROGRAM rstxpdft USING 80

'Conversion by background job'(008)

gv_jobname

gv_jobcount.

EXIT.

ENDIF.

PERFORM download_w_ext IN PROGRAM rstxpdft TABLES gt_pdf

USING gv_file

'.pdf'

'BIN'

gv_numbytes

gv_cancel.

IF gv_cancel = space.

DATA: s(80).

s = gv_numbytes. CONDENSE s.

CONCATENATE s 'Byte downloaded in file'(009)

INTO s SEPARATED BY space.

PERFORM bd_textbox_var1_msg IN PROGRAM rstxpdft USING 80

s

gv_file.

ENDIF.

use this code once your output is generated.

see the output and say print in test of apllication tool bar.

a new spool will be genrated and then say back. it will be downloaded to the desktop prompting you to save it,

REWARD ME FULL POINTS IF HAPPY.

Read only

Former Member
0 Likes
718

SMARTFORM to PDF and then MAIL

Here is the code to send the Smartform to mail as PDF attachment.

&----


*& Report ZTEST_PDF_MAIL

*&

&----


REPORT ZTEST_PDF_MAIL.

  • Internal Table declarations

DATA: I_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE,

I_TLINE TYPE TABLE OF TLINE WITH HEADER LINE,

I_RECEIVERS TYPE TABLE OF SOMLRECI1 WITH HEADER LINE,

I_RECORD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

  • Objects to send mail.

I_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

I_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

I_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

I_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

  • Work Area declarations

WA_OBJHEAD TYPE SOLI_TAB,

W_CTRLOP TYPE SSFCTRLOP,

W_COMPOP TYPE SSFCOMPOP,

W_RETURN TYPE SSFCRESCL,

WA_DOC_CHNG TYPE SODOCCHGI1,

W_DATA TYPE SODOCCHGI1,

WA_BUFFER TYPE STRING, "To convert from 132 to 255

  • Variables declarations

V_FORM_NAME TYPE RS38L_FNAM,

V_LEN_IN LIKE SOOD-OBJLEN,

V_LEN_OUT LIKE SOOD-OBJLEN,

V_LEN_OUTN TYPE I,

V_LINES_TXT TYPE I,

V_LINES_BIN TYPE I.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

FORMNAME = 'ZTEST'

IMPORTING

FM_NAME = V_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.

W_CTRLOP-GETOTF = 'X'.

W_CTRLOP-NO_DIALOG = 'X'.

W_COMPOP-TDNOPREV = 'X'.

CALL FUNCTION V_FORM_NAME

EXPORTING

CONTROL_PARAMETERS = W_CTRLOP

OUTPUT_OPTIONS = W_COMPOP

USER_SETTINGS = 'X'

IMPORTING

JOB_OUTPUT_INFO = W_RETURN

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.

I_OTF[] = W_RETURN-OTFDATA[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

MAX_LINEWIDTH = 132

IMPORTING

BIN_FILESIZE = V_LEN_IN

TABLES

OTF = I_OTF

LINES = I_TLINE

EXCEPTIONS

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

ENDIF.

LOOP AT I_TLINE.

TRANSLATE I_TLINE USING '~'.

CONCATENATE WA_BUFFER I_TLINE INTO WA_BUFFER.

ENDLOOP.

TRANSLATE WA_BUFFER USING '~'.

DO.

I_RECORD = WA_BUFFER.

APPEND I_RECORD.

SHIFT WA_BUFFER LEFT BY 255 PLACES.

IF WA_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

  • Attachment

REFRESH: I_RECLIST,

I_OBJTXT,

I_OBJBIN,

I_OBJPACK.

CLEAR WA_OBJHEAD.

I_OBJBIN[] = I_RECORD[].

  • Create Message Body Title and Description

I_OBJTXT = 'test with pdf-Attachment!'.

APPEND I_OBJTXT.

DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.

READ TABLE I_OBJTXT INDEX V_LINES_TXT.

WA_DOC_CHNG-OBJ_NAME = 'smartform'.

WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

WA_DOC_CHNG-OBJ_DESCR = 'smartform'.

WA_DOC_CHNG-SENSITIVTY = 'F'.

WA_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 255.

  • Main Text

CLEAR I_OBJPACK-TRANSF_BIN.

I_OBJPACK-HEAD_START = 1.

I_OBJPACK-HEAD_NUM = 0.

I_OBJPACK-BODY_START = 1.

I_OBJPACK-BODY_NUM = V_LINES_TXT.

I_OBJPACK-DOC_TYPE = 'RAW'.

APPEND I_OBJPACK.

  • Attachment (pdf-Attachment)

I_OBJPACK-TRANSF_BIN = 'X'.

I_OBJPACK-HEAD_START = 1.

I_OBJPACK-HEAD_NUM = 0.

I_OBJPACK-BODY_START = 1.

DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.

READ TABLE I_OBJBIN INDEX V_LINES_BIN.

I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .

I_OBJPACK-BODY_NUM = V_LINES_BIN.

I_OBJPACK-DOC_TYPE = 'PDF'.

I_OBJPACK-OBJ_NAME = 'smart'.

I_OBJPACK-OBJ_DESCR = 'test'.

APPEND I_OBJPACK.

CLEAR I_RECLIST.

I_RECLIST-RECEIVER = 'nareshreddy.k@gmail.com'.

I_RECLIST-REC_TYPE = 'U'.

APPEND I_RECLIST.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = WA_DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = I_OBJPACK

OBJECT_HEADER = WA_OBJHEAD

CONTENTS_BIN = I_OBJBIN

CONTENTS_TXT = I_OBJTXT

RECEIVERS = I_RECLIST

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.

IF SY-SUBRC <> 0.

WRITE:/ 'Error When Sending the File', SY-SUBRC.

ELSE.

WRITE:/ 'Mail sent'.

ENDIF.

If you want to send some text as Body of the Mail then follow this once

when u r callin the FM'SO_NEW_DOCUMENT_ATT_SEND_API1'.. points to remember

1.u have to pass the body of content in table CONTENTS_TXT(ia m using I_OBJBIN) (each line a record) then. suppose i have appended 11 records to the table CONTENTS_TXT .

2.PACKING_LIST(iam usign I_OBJPACK) table u ahve to append a redord as follows

I_OBJPACK-TRANSF_BIN = ' '.

I_OBJPACK-HEAD_START = 000000000000001.

I_OBJPACK-HEAD_NUM = 000000000000001.

I_OBJPACK-BODY_START = 000000000000002

I_OBJPACK-BODY_NUM = 000000000000010.

I_OBJPACK-DOC_TYPE = 'RAW'.

append I_OBJPACK-.

by the above code system treat the first line in table I_OBJBIN as header and the 2nd line to 10 lines tread as body.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = WA_DOC_CHNG

PUT_IN_OUTBOX = 'X'

TABLES

PACKING_LIST = I_OBJPACK

OBJECT_HEADER = WA_OBJHEAD

CONTENTS_BIN = I_OBJBIN

CONTENTS_TXT = I_OBJTXT

RECEIVERS = I_RECLIST

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.

regards,

srinivas