Skip to Content
0
Nov 27, 2013 at 04:44 AM

the file is damaged and could not be repaired when smartforms convert to pdf

55 Views

i m using your code but error is occur

please help me


when i goto sost and open my pdf file at that time give error message

my whole program is below

report ypayment_advice2.

tables : bsak,skat.


types : begin of t_bsak,
belnr type bsak-belnr,
gjahr type bsak-gjahr,
augbl type bsak-augbl,
augdt type bsak-augdt,
xblnr type bsak-xblnr,
bldat type bsak-bldat,
* DMBTR TYPE BSAK-DMBTR,
* WAERS TYPE BSAK-WAERS,
lifnr type bsak-lifnr,
saknr type bsak-saknr,
budat type bsak-budat,
* EBELN TYPE BSAK-EBELN,
* EBELP TYPE BSAK-EBELP,
bukrs type bsak-bukrs,
buzei type bsak-buzei,
*
ebeln type bseg-ebeln,
ebelp type bseg-ebelp,
hkont type bseg-hkont,
shkzg type bseg-shkzg,
werks type bseg-werks,
dmbtr type bseg-dmbtr,
bldat1 type bsak-bldat,
xblnr1 type bsak-xblnr,

end of t_bsak.
types : begin of t_bseg,
belnr type bseg-belnr,
gjahr type bseg-gjahr,
ebeln type bseg-ebeln,
ebelp type bseg-ebelp,
hkont type bseg-hkont,
shkzg type bseg-shkzg,
werks type bseg-werks,
dmbtr type bseg-dmbtr,

end of t_bseg.

types : begin of t_bseg2,
belnr type bseg-belnr,
gjahr type bseg-gjahr,
ebeln type bseg-ebeln,
ebelp type bseg-ebelp,
werks type bseg-werks,
end of t_bseg2.

types : begin of t_bseg1,
augbl type bseg-augbl,
gjahr type bseg-gjahr,
hkont type bseg-hkont,
end of t_bseg1.


types : begin of t_bkpf,
bukrs type bkpf-bukrs,
cpudt type bkpf-cpudt,
blart type bkpf-blart,
usnam type bkpf-usnam,
budat type bkpf-budat,
end of t_bkpf.
types : begin of t_bsak1,
lifnr type bsak-lifnr,
end of t_bsak1.
*DATA : IT_FINAL TYPE STANDARD TABLE OF T_FINAL WITH HEADER LINE.
*DATA : WA_FINAL TYPE T_FINAL.

data : wrk_answer type c.
data : it_bsak type standard table of t_bsak.
data : wa_bsak type t_bsak.

data : it_bsak_temp type standard table of t_bsak1 with header line,
wa_bsak_temp type t_bsak1.

data : it_bsak_temp1 type standard table of t_bsak1 with header line,
wa_bsak_temp1 type t_bsak1.

data : it_bsak1 type standard table of t_bsak.
data : wa_bsak1 type t_bsak.

data : it_bseg type standard table of t_bseg.
data : wa_bseg type t_bseg.

data : it_bseg1 type standard table of t_bseg1.
data : wa_bseg1 type t_bseg1.

data : it_bseg2 type standard table of t_bseg2.
data : wa_bseg2 type t_bseg2.


data : it_bkpf type standard table of t_bkpf.
data : wa_bkpf type t_bkpf.

data : l_cntr type i value 1.
data : op type ssfcompop.
data : control type ssfctrlop.

data: formname1 type tdsfname," value 'YPAYMENT_ADVICE',
fm_name type rs38l_fnam.

data : i_smtp_addr type adr6-smtp_addr,
i_adrnr type lfa1-adrnr.

data: gd_recsize type i.
*
data : it_tsp01 type standard table of tsp01 with header line .
data : it_pdf like tline occurs 0 with header line .

data : gd_buffer type string.
data: gd_spool_nr like tsp01-rqident,
gd_destination like rlgrap-filename,
gd_bytecount like tst01-dsize.

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.

data : w_emailid type adr6-smtp_addr.

* 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: t_otfdata type soli_tab,
t_otfdata_item type soli_tab,
t_objhex type solix_tab,
t_objhead type soli_tab,
w_transfer type sx_boolean,
w_length type sood-objlen,
w_length_item type sood-objlen,
w_lines_txt type i,
w_lines_bin type i,
wa_soli type soli,
wa_solix type solix,
w_doc_chng type sodocchgi1,
t_objcont type standard table of soli with header line,
t_objcont_item type standard table of soli with header line,
t_objpack like sopcklsti1 occurs 0 with header line,
t_reclist like somlreci1 occurs 0 with header line,
t_objtxt like solisti1 occurs 0 with header line.

data : ls_control type ssfctrlop,
ls_output type ssfcrescl,
ls_output_opt type ssfcompop,
lt_lines type table of tline,
lt_linesx type table of tdline.


data : lv_pdf type xstring,
lv_filelen type i,
lv_file type string.

*
selection-screen begin of block b1 with frame title text-001.
select-options : p_lifnr for bsak-lifnr.
select-options : p_augbl for bsak-augbl obligatory,
p_year for bsak-gjahr obligatory.
* P_BUDAT FOR BSAK-BUDAT.

selection-screen end of block b1.


start-of-selection.

perform get_data.
perform process_data .
perform call_smartforms.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .

select augbl gjahr budat xblnr
from bsak
into corresponding fields of table it_bsak1
where augbl in p_augbl
and gjahr in p_year
and blart = 'KZ'
and lifnr in p_lifnr.

if sy-subrc <> 0.
message 'No Record Found ' type 'E'.
endif.


select augbl augdt belnr gjahr xblnr
dmbtr lifnr saknr budat bukrs buzei
from bsak
into corresponding fields of table it_bsak
for all entries in it_bsak1
where augbl = it_bsak1-augbl
and augdt = it_bsak1-budat
and blart = 'RE'.
* FOR ALL ENTRIES IN IT_BSAK
* WHERE AUGBL = '1500000011' "IT_BSAK-AUGBL
* AND GJAHR = '2013' "IT_BSAK-GJAHR
* AND BLART = 'RE'.

select belnr gjahr shkzg dmbtr koart
from bseg
into corresponding fields of table it_bseg
for all entries in it_bsak
where belnr = it_bsak-belnr
and gjahr = it_bsak-gjahr
and koart = 'K'.
* AND BUKRS = IT_BSAK-BUKRS.
* AND BUZEI = IT_BSAK-BUZEI.

select belnr gjahr hkont
from bseg
into corresponding fields of table it_bseg1
for all entries in it_bsak1
where belnr = it_bsak1-augbl
and gjahr = it_bsak1-gjahr
and koart = 'S'.

select belnr gjahr ebeln ebelp werks
from bseg
into corresponding fields of table it_bseg2
for all entries in it_bseg
where belnr = it_bseg-belnr
and gjahr = it_bseg-gjahr
and buzid = 'W'.

* BREAK ABAP.

select bukrs cpudt blart usnam budat
from bkpf
into corresponding fields of table it_bkpf
for all entries in it_bsak
where belnr = it_bsak-belnr
and gjahr = it_bsak-gjahr.
* AND BUKRS = IT_BSAK-BUKRS
* .
loop at it_bsak into wa_bsak.
read table it_bseg into wa_bseg with key belnr = wa_bsak-belnr
gjahr = wa_bsak-gjahr.
if sy-subrc = 0.
move wa_bseg-shkzg to wa_bsak-shkzg.
move wa_bseg-dmbtr to wa_bsak-dmbtr.
modify it_bsak from wa_bsak transporting shkzg dmbtr.
endif.
read table it_bseg2 into wa_bseg2 with key belnr = wa_bsak-belnr
gjahr = wa_bsak-gjahr.
if sy-subrc = 0.
move wa_bseg2-ebeln to wa_bsak-ebeln.
move wa_bseg2-ebelp to wa_bsak-ebelp.
move wa_bseg2-werks to wa_bsak-werks.
modify it_bsak from wa_bsak transporting ebeln ebelp werks .
endif.

read table it_bseg1 into wa_bseg1 with key gjahr = wa_bsak-gjahr.
if sy-subrc = 0.
move wa_bseg1-hkont to wa_bsak-hkont.
modify it_bsak from wa_bsak transporting hkont where gjahr = wa_bsak-gjahr.
endif.

read table it_bsak1 into wa_bsak1 with key augbl = wa_bsak-augbl
gjahr = wa_bsak-gjahr.
if sy-subrc = 0.
move wa_bsak1-bldat to wa_bsak-bldat1.
move wa_bsak1-xblnr to wa_bsak-xblnr1.
modify it_bsak from wa_bsak transporting bldat1 xblnr1 where augbl = wa_bsak-augbl
and gjahr = wa_bsak-gjahr.
endif.
endloop.

loop at it_bsak into wa_bsak.
move wa_bsak-lifnr to wa_bsak_temp-lifnr.
append wa_bsak_temp to it_bsak_temp .
endloop.

loop at it_bsak_temp into wa_bsak_temp.
collect wa_bsak_temp into it_bsak_temp1.
endloop.


endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form process_data .

export it_bsak to memory id 'IT_BSAK'.
export it_bseg to memory id 'IT_BSEG'.
export it_bkpf to memory id 'IT_BKPF'.
* BREAK ABAP.
endform. " PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form CALL_SMARTFORMS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form call_smartforms .
* LOOP AT IT_BSAK_TEMP.
call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = 'YPAYMENT_ADVICE1'
importing
fm_name = fm_name.



* CALL FUNCTION FM_NAME"'/1BCDWB/SF00000442'
* EXPORTING
* P_LIFNR = IT_BSAK_TEMP-LIFNR.


call function fm_name"'/1BCDWB/SF00000442'
exporting
it_bsak = it_bsak
it_bseg = it_bseg
it_bkpf = it_bkpf.

clear wrk_answer.
* BREAK ABAP.
call function 'POPUP_TO_CONFIRM'
exporting
titlebar = 'LOGOFF'
* DIAGNOSE_OBJECT = ' '
text_question = 'Do You Want Send Mail?'
text_button_1 = 'YES'
* ICON_BUTTON_1 = ' '
text_button_2 = 'NO'
display_cancel_button = space
start_column = 25
start_row = 6
importing
answer = wrk_answer
* TABLES
* PARAMETER =
exceptions
text_not_found = 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.
*Mail send coding


check wrk_answer = '1'.


loop at it_bsak_temp1 into wa_bsak_temp1.
break abap.

select single adrnr from lfa1
into i_adrnr where lifnr = wa_bsak_temp1-lifnr.

select single smtp_addr from adr6
into w_emailid
where addrnumber = i_adrnr.
if w_emailid is not initial.
perform mail.
else.
message 'E-Mail Address is not maintained for Vendor' type 'S'.
endif.

endloop.



endform. " CALL_SMARTFORMS
*&---------------------------------------------------------------------*
*& Form SEND_EMAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_EMAIL1 text
*----------------------------------------------------------------------*
form send_email using p_email.
check not ( p_email is initial ).

refresh it_mess_bod.
*BREAK-POINT.
* DEFAULT SUBJECT MATTER
gd_subject = 'SUBJECT'.
gd_attachment_desc = 'Invoice '.
* CONCATENATE 'ATTACH_NAME' ' ' INTO GD_ATTACHMENT_NAME.
it_mess_bod = 'Hi,'.
append it_mess_bod.
it_mess_bod = 'Kindly Find an attached copy of Sale Invoice : '.
concatenate it_mess_bod p_lifnr into it_mess_bod separated by space.
append it_mess_bod.
it_mess_bod = 'This is system generated Mail,So do not reply.'
.
append it_mess_bod.
it_mess_bod = 'Thank you,'.
append it_mess_bod.
it_mess_bod = 'Gokul Refoils & Solvent Ltd.'.
append it_mess_bod.
data : p_sender type somlreci1-receiver.

p_sender = 'abc@abc.com'
* 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
'Narendra CHECK Invoice-Gokul Refoils & Solvent Ltd.'
*'Sale Invoice .pdf document attached'
'PDF'
gd_attachment_name
gd_attachment_desc
p_sender
gd_sender_type
changing gd_error
gd_reciever.
endform. " SEND_EMAIL
*&---------------------------------------------------------------------*
* & FORM SEND_FILE_AS_EMAIL_ATTACHMENT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->P_IT_MESS_BOD TEXT
* -->P_IT_MESS_ATT TEXT
* -->P_P_EMAIL TEXT
* -->P_1395 TEXT
* -->P_1396 TEXT
* -->P_GD_ATTACHMENT_NAME TEXT
* -->P_GD_ATTACHMENT_DESC TEXT
* -->P_P_SENDER TEXT
* -->P_GD_SENDER_TYPE TEXT
* <--P_GD_ERROR TEXT
* <--P_GD_RECIEVER TEXT
*----------------------------------------------------------------------*
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 perror
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_receivers1 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
*BREAK-POINT.
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 = w_emailid.
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_NEW_DOCUMENT_ATT_SEND_API1'
** EXPORTING
** DOCUMENT_DATA = W_DOC_DATA
** PUT_IN_OUTBOX = 'X'
** COMMIT_WORK = 'X'
** 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.
**
** COMMIT WORK.
**
** LOOP AT T_RECEIVERS.
** LD_RECEIVER = T_RECEIVERS-RETRN_CODE.
** ENDLOOP.
**ENDFORM. "SEND_FILE_AS_EMAIL_ATTACHMENT


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. "SEND_FILE_AS_EMAIL_ATTACHMENT
*&---------------------------------------------------------------------*
*& Form MAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form mail .
ls_control-no_dialog = 'X'.
ls_control-getotf = 'X'.
break abap.

call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = 'YPAYMENT_ADVICE'
importing
fm_name = fm_name.

* CONTROL-NO_DIALOG = 'X'.
* CONTROL-PREVIEW = ''.
* OP-XSFOUTDEV = 'LOGI'.
* OP-TDDEST = 'LOGI'.
* OP-TDIMMED = 'X'.

call function fm_name
exporting
control_parameters = ls_control
p_lifnr = wa_bsak_temp1-lifnr
importing
job_output_info = ls_output
* JOB_OUTPUT_OPTIONS =
exceptions
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
others = 5.
if sy-subrc <> 0.
message 'error at call funcation module' type 'E'.
endif.
call function 'CONVERT_OTF'
exporting
format = 'PDF'
max_linewidth = 132
* PDF_PREVIEW = 'X'
importing
bin_filesize = lv_filelen
bin_file = lv_pdf
tables
otf = ls_output-otfdata
lines = lt_lines
exceptions
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
others = 5.
if sy-subrc <> 0.
message 'error at convert otf to pdf funcation module' type 'E'.
endif.

clear lt_linesx.


call function 'SCMS_XSTRING_TO_BINARY'
exporting
buffer = lv_pdf
append_to_table = 'X'
* IMPORTING
* OUTPUT_LENGTH =
tables
binary_tab = lt_linesx
.

* SELECT * FROM TSP01 INTO TABLE IT_TSP01
* WHERE RQ2NAME = SY-UNAME .
*
* SORT IT_TSP01 BY RQCRETIME DESCENDING .
* READ TABLE IT_TSP01 INDEX 1.
*
* CLEAR: IT_PDF,IT_PDF[].
*
*
* CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
* EXPORTING
* SRC_SPOOLID = IT_TSP01-RQIDENT
* NO_DIALOG = ' '
* TABLES
* PDF = IT_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.
*
* CHECK SY-SUBRC = 0.
*
* LOOP AT IT_PDF.
* TRANSLATE IT_PDF USING ' ~'.
* CONCATENATE GD_BUFFER IT_PDF 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.
break abap.
* RECIPIENT
data : p_email1 type somlreci1-receiver.
p_email1 = w_emailid.
* DESCRIBE TABLE IT_MESS_ATT LINES GD_RECSIZE.
* CHECK GD_RECSIZE > 0.

perform send_email using p_email1.



endform. " MAIL