2010 Dec 29 9:33 AM
Hello there everybody,
right now I'm facing an very awful problem. My task is to create a report that should be run by RSNAST00 for a certain message type. The report should create a invoice document with the help of SAP-script, but it should create this invoice document under certain conditions. If the invoice should send by mail, I have to receive the OTF-data. After that the data should be converted to binary data and attached as a PDF-File to the mail.
The previous results a very satisfying, everything works. The mail is send to the receiver. The attachments are part of the mail.
BUT during my test I recognized that the invoice document is not archived to our digital file archive. The normal case is that an printed invoice document is stored in the archive as a PDF-file.
I searched for a solution and found the reason why I these document is not stored in the archive. If you extract the OTF-Data while creating the invoice document by SAP-script, the function "OPEN_FORM" will not archiving the following document.
I found an evidence for this assumption, as i debugged through the "OPEN_FORM"-function.
Here is my question!
How do I archiving the invoice document although I extract the OTF-Data? (ATTENTION! Any spools should be created)
Greetings GollmerBZ
UPDATE:
I use the FM "CONVERT_OTF" to create bin data for the PDF-attachment. This FM owns a parameter called archive_index. Am I able to archive the invoice with the help of the FM CONVERT_OTF???
Edited by: GollmerBZ on Dec 29, 2010 11:28 AM
"threat GETOTF like preview: no archiving, no data is sent to spool
if itcpp-tdgetotf = 'X'.
itcpp-tdpreview = 'X'.
endif.
2010 Dec 29 10:35 AM
Hi,
You should create a Spool for the generated PDF.
After the data is converted from OTF to PDF .. write this data to spool ..
DATA: BEGIN OF datatab OCCURS 100,
line(80) TYPE x,
END OF datatab.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
archive_index = ' '
copynumber = 0
ascii_bidi_vis2log = ' '
pdf_delete_otftab = ' '
IMPORTING
bin_filesize = ls_bin_file
bin_file = bin_file
TABLES
otf = gt_otfdata
lines = lt_pdfdata
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
l_strlen = STRLEN( bin_file ).
l_strlen1 = STRLEN( bin_file ).
DO.
IF l_strlen GT 80.
MOVE bin_file+0(80) TO datatab-line.
APPEND datatab.
l_strlen = l_strlen - 80.
bin_file1 = bin_file+80.
ELSE.
MOVE bin_file+0(l_strlen) TO datatab-line.
APPEND datatab.
EXIT.
ENDIF.
ENDDO.
CALL FUNCTION 'ADS_SR_OPEN'
EXPORTING
dest = printer
append = append
doctype = doctype
IMPORTING
handle = handle
spoolid = spoolid
partname = partname
EXCEPTIONS
device_missing = 1
no_such_device = 2
operation_failed = 3.
Get printer attributes
CALL FUNCTION 'ADS_GET_PRINTER_ATTRIBUTES'
EXPORTING
dest = printer
IMPORTING
adstype = adstype.
extension = '.pdf'.
CONCATENATE partname extension INTO filename.
Get path of global directory
CALL 'C_SAPGPARAM'
ID 'NAME' FIELD 'DIR_GLOBAL'
ID 'VALUE' FIELD globaldir.
CONCATENATE globaldir '/' filename INTO pathname.
OPEN DATASET pathname FOR OUTPUT IN BINARY MODE.
LOOP AT datatab.
TRANSFER datatab TO pathname.
ENDLOOP.
CLOSE DATASET pathname.
pages = 2.
CLEAR : no_pdf.
CALL FUNCTION 'ADS_SR_CONFIRM'
EXPORTING
handle = handle
partname = partname
size = l_strlen1
pages = pages
no_pdf = no_pdf
EXCEPTIONS
handle_not_valid = 1
operation_failed = 2
OTHERS = 3.
CALL FUNCTION 'ADS_SR_CLOSE'
EXPORTING
handle = handle
EXCEPTIONS
handle_not_valid = 1
operation_failed = 2
OTHERS = 3.
The above writes the file to spool in the form of an Adobe form.
Regards,
Srini.
2010 Dec 29 10:35 AM
Hi,
You should create a Spool for the generated PDF.
After the data is converted from OTF to PDF .. write this data to spool ..
DATA: BEGIN OF datatab OCCURS 100,
line(80) TYPE x,
END OF datatab.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
archive_index = ' '
copynumber = 0
ascii_bidi_vis2log = ' '
pdf_delete_otftab = ' '
IMPORTING
bin_filesize = ls_bin_file
bin_file = bin_file
TABLES
otf = gt_otfdata
lines = lt_pdfdata
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
l_strlen = STRLEN( bin_file ).
l_strlen1 = STRLEN( bin_file ).
DO.
IF l_strlen GT 80.
MOVE bin_file+0(80) TO datatab-line.
APPEND datatab.
l_strlen = l_strlen - 80.
bin_file1 = bin_file+80.
ELSE.
MOVE bin_file+0(l_strlen) TO datatab-line.
APPEND datatab.
EXIT.
ENDIF.
ENDDO.
CALL FUNCTION 'ADS_SR_OPEN'
EXPORTING
dest = printer
append = append
doctype = doctype
IMPORTING
handle = handle
spoolid = spoolid
partname = partname
EXCEPTIONS
device_missing = 1
no_such_device = 2
operation_failed = 3.
Get printer attributes
CALL FUNCTION 'ADS_GET_PRINTER_ATTRIBUTES'
EXPORTING
dest = printer
IMPORTING
adstype = adstype.
extension = '.pdf'.
CONCATENATE partname extension INTO filename.
Get path of global directory
CALL 'C_SAPGPARAM'
ID 'NAME' FIELD 'DIR_GLOBAL'
ID 'VALUE' FIELD globaldir.
CONCATENATE globaldir '/' filename INTO pathname.
OPEN DATASET pathname FOR OUTPUT IN BINARY MODE.
LOOP AT datatab.
TRANSFER datatab TO pathname.
ENDLOOP.
CLOSE DATASET pathname.
pages = 2.
CLEAR : no_pdf.
CALL FUNCTION 'ADS_SR_CONFIRM'
EXPORTING
handle = handle
partname = partname
size = l_strlen1
pages = pages
no_pdf = no_pdf
EXCEPTIONS
handle_not_valid = 1
operation_failed = 2
OTHERS = 3.
CALL FUNCTION 'ADS_SR_CLOSE'
EXPORTING
handle = handle
EXCEPTIONS
handle_not_valid = 1
operation_failed = 2
OTHERS = 3.
The above writes the file to spool in the form of an Adobe form.
Regards,
Srini.
2010 Dec 29 10:51 AM
Hello Sinri,
thanks for your Answer, but there should be no spool created in this process.
I'll post my coding to understand how I'm doing it right now.
FORM sende_mail USING otfdata LIKE g_otfdata .
DATA: l_bindat TYPE xstring "PDF-Daten fuer Mail
,lt_tline LIKE STANDARD TABLE OF tline
,lt_bindata LIKE STANDARD TABLE OF solisti1
,lwa_bindata LIKE LINE OF lt_bindata
,lt_txtdata LIKE STANDARD TABLE OF solisti1
,lwa_txtdata LIKE LINE OF lt_txtdata
,lt_headdata LIKE STANDARD TABLE OF solisti1
,lwa_headdata LIKE LINE OF lt_headdata
,lt_packdata LIKE STANDARD TABLE OF sopcklsti1
,lwa_packdata LIKE LINE OF lt_packdata
,lt_reciever LIKE STANDARD TABLE OF somlreci1
,lwa_reciever LIKE LINE OF lt_reciever
,l_doc_chng LIKE sodocchgi1
,l_bin_filesize TYPE n
,l_tabix LIKE sy-tabix.
CLEAR: l_bindat, lt_tline, lt_bindata,
lt_txtdata, lt_packdata, lt_reciever, lt_headdata.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
archive_index = toa_dara
IMPORTING
bin_filesize = l_bin_filesize
bin_file = l_bindat
TABLES
otf = otfdata
lines = lt_tline
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.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = l_bindat
TABLES
binary_tab = lt_bindata.
CLEAR: lwa_packdata, lwa_txtdata.
lwa_txtdata = 'Dies ist eine Testmail'.
APPEND lwa_txtdata TO lt_txtdata.
lwa_txtdata = 'Dies ist eine Testmail'.
APPEND lwa_txtdata TO lt_txtdata.
lwa_txtdata = 'Dies ist eine Testmail'.
APPEND lwa_txtdata TO lt_txtdata.
lwa_txtdata = 'Dies ist eine Testmail'.
APPEND lwa_txtdata TO lt_txtdata.
lwa_txtdata = 'Dies ist eine Testmail'.
APPEND lwa_txtdata TO lt_txtdata.
"Bestimmen der Dokumentenlaenge.
DESCRIBE TABLE lt_txtdata LINES l_tabix.
READ TABLE lt_txtdata INDEX l_tabix INTO lwa_txtdata.
"Dokumenteneigenschaften
l_doc_chng-obj_name = 'HEADER'.
l_doc_chng-obj_descr = 'Supertestmail'.
l_doc_chng-doc_size = ( l_tabix - 1 ) * 255 + STRLEN( lwa_txtdata ).
"Eintrag in der PACKLIST fuer Mailtext
lwa_packdata-transf_bin = ''.
lwa_packdata-head_start = 0.
lwa_packdata-head_num = 0.
lwa_packdata-body_start = 1.
lwa_packdata-body_num = l_tabix.
lwa_packdata-doc_type = 'RAW'.
APPEND lwa_packdata TO lt_packdata.
CLEAR: lwa_packdata, lwa_txtdata, lwa_headdata.
DESCRIBE TABLE lt_bindata LINES l_tabix.
READ TABLE lt_bindata INDEX l_tabix INTO lwa_bindata.
lwa_headdata-line = 'testpdf.pdf'.
APPEND lwa_headdata TO lt_headdata.
lwa_packdata-transf_bin = 'X'.
lwa_packdata-head_start = 1.
lwa_packdata-head_num = 1.
lwa_packdata-body_start = 1.
lwa_packdata-body_num = l_tabix.
lwa_packdata-doc_type = 'PDF'.
lwa_packdata-obj_name = 'anlage.pdf'.
lwa_packdata-obj_descr ='Tolle Anlage'.
lwa_packdata-doc_size = ( l_tabix - 1 ) * 255 + STRLEN( lwa_bindata ).
APPEND lwa_packdata TO lt_packdata.
CLEAR: lwa_packdata, lwa_txtdata.
lwa_reciever-receiver = 'someadress'.
lwa_reciever-rec_type = 'U'.
APPEND lwa_reciever TO lt_reciever.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = l_doc_chng
commit_work = 'X'
TABLES
packing_list = lt_packdata
object_header = lt_headdata
contents_bin = lt_bindata
contents_txt = lt_txtdata
receivers = lt_reciever
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.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. "sende_mail
Edited by: GollmerBZ on Dec 29, 2010 11:52 AM
2010 Dec 30 7:01 AM
Data declaration for mail
DATA: i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_objhead LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_tline TYPE TABLE OF tline WITH HEADER LINE,
i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
wa_doc_chng LIKE sodocchgi1,
l_adrnr TYPE adrc-addrnumber,
l_adsmtp TYPE TABLE OF adsmtp WITH HEADER LINE,
llines TYPE sy-tabix.
CLEAR : i_objbin, i_reclist, i_objtxt.
REFRESH : i_objbin, i_reclist, i_objtxt.
*Populate values for mail text.
i_objtxt = ' Details'.
APPEND i_objtxt.
DESCRIBE TABLE i_objtxt LINES llines.
READ TABLE i_objtxt INDEX llines.
wa_doc_chng-doc_size = llines * 255.
wa_doc_chng-obj_name = 'EMAIL'.
wa_doc_chng-obj_descr = 'Details'.
* Main Text
CLEAR : i_objpack.
i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
i_objpack-doc_type = 'RAW'.
i_objpack-body_num = llines.
APPEND i_objpack.
CLEAR i_objpack.
*Convert output of script to OTF data
CLEAR: i_tline, llines.
REFRESH i_tline.
* Convert OTF to PDF
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = llines
TABLES
otf = i_otfdata
lines = i_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
IF sy-subrc <> 0 OR
llines IS INITIAL.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
REFRESH : i_record.
*Format OTF data
CALL FUNCTION 'QCE1_CONVERT'
TABLES
t_source_tab = i_tline
t_target_tab = i_record
EXCEPTIONS
convert_not_possible = 1
OTHERS = 2.
IF sy-subrc <> 0.
WRITE : / 'Error in conversion of pdf lines'(015).
ENDIF.
APPEND LINES OF i_record TO i_objbin.
Edited by: Krupaji on Dec 30, 2010 8:05 AM
2010 Dec 30 7:02 AM
DESCRIBE TABLE i_objbin LINES l_lines.
CLEAR i_objpack.
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 1.
i_objpack-body_start = 1.
i_objpack-body_num = llines.
i_objpack-obj_name = 'Settlement'.
i_objpack-obj_descr = 'Settlement Details'.
i_objpack-doc_size = llines * 255 .
i_objpack-doc_type = 'PDF'.
APPEND i_objpack.
IF kona-knuma IS NOT INITIAL.
CLEAR i_objpack.
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 1.
i_objpack-body_start = llines + 1.
i_objpack-doc_type = 'XLS'.
i_objpack-obj_name = 'Rebate Details'.
i_objpack-obj_descr = 'Chargebacks Business Volume Details' .
PERFORM get_rebate_details TABLES it_outtab
i_objbin.
DESCRIBE TABLE i_objbin LINES llines.
i_objpack-body_num = llines - i_objpack-body_start.
i_objpack-doc_size = i_objpack-body_num * 255.
APPEND i_objpack.
CLEAR i_objpack.
ENDIF.
*Selecting address number to get mail id.
SELECT SINGLE adrnr INTO l_adrnr FROM kna1
WHERE kunnr = kona-bonem.
CALL FUNCTION 'ADDR_COMM_GET'
EXPORTING
address_number = l_adrnr
table_type = 'ADSMTP'
TABLES
comm_table = l_adsmtp
EXCEPTIONS
parameter_error = 1
address_not_exist = 2
internal_error = 3
OTHERS = 4.
LOOP AT l_adsmtp.
i_reclist-receiver = l_adsmtp-smtp_addr.
i_reclist-rec_type = 'U'.
i_reclist-com_type = 'INT'.
APPEND i_reclist.
ENDLOOP.
*sending report output and script output as mail
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 = i_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.
2010 Dec 30 8:37 AM
Hello Krupaji,
thanks to your code I found a way to extract the e-mail-adress of a bp. But unfortunately it doesn't help finding a solution for my archiving problem. Maybe I missed an important part in your code. The part of the code where you're archiving the invoice document.
Greet GollmerBZ
2010 Dec 30 9:44 AM
exactly what u want tell ?
see i have report which all data convert into OTF and then OTF to
PDF then download into server and do password protect and again
fetch form server after that i convert into ZIP and send individual invoice
in this code small part of code which i given to u now tell what u want exactly?
2011 Jan 01 9:08 AM
Hi Krupaji,
I've already finished the report. My conversion works fine. The Reports runs through the rsnast00. Normally every printed object is automatically archived through "Archivelink", if the parameter NAST-TDARMOD is above 1. The archived object is connected to the invoice order. After the Archivlink done it's job you're able to see the invoice documents as an attachment of the invoice object in SAP.
I want to reach that I can archive the OTF-data (not the PPDF as I said before) as an attachment of the invoice object, just like I would print the invoice document with the parameter NAST-TDARMOD above 1.
Greetz GollmerBZ
2011 Jan 04 8:31 AM
Hello People,
I solved the archiving problem by myself. The solution is written down in ...
Greetz GollmerBZ
2010 Dec 30 8:55 AM
i hope this link might be helpful
http://help.sap.com/saphelp_40b/helpdata/en/2a/fa05cd493111d182b70000e829fbfe/content.htm
it is having list of FM to be used in archiving process
regards,
Mullai
2010 Dec 30 9:14 AM
Hi mullai,
I've found this link too, thank you very much. Unfortunately I didn't find an example code where I can see the relation between this bunch of FMs. Furthermore I don't understand how to connect the invoice document to the object in JHF3 (insert in table JHAGA).
The result should be an entry in the enclosures list of the invoice in transaction JHF2 or JHF3.
Greetz GollmerBZ
2023 Feb 20 12:23 PM
Did not find an answer here, so I figured it myself, use in this scenario FM CONVERT_OTF_AND_ARCHIVE