Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to default "Srandard Preview" in SOST using 'SO_NEW_DOCUMENT_ATT_SEND_API1'

dubbaka
Participant
0 Kudos

Hello All,

I am using FM 'SO_NEW_DOCUMENT_ATT_SEND_API1' to send Smart form attachments through an email, however when I display the form in SOST it opens new PDF file as shown below.

I have to display document in "Standard Print preview" format as below.

Is there any way to default "Standard Print preview" setting in code? please let me know if anyone knows.

Code:

IF cf_retcode = 0.
PERFORM set_print_param USING ls_addr_key
CHANGING ls_control_param
ls_composer_param
ls_recipient
ls_sender
cf_retcode.
ENDIF.

IF cf_retcode = 0.
* determine smartform function module for delivery note
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = lf_formname
* variant = ' '
* direct_call = ' '
IMPORTING
fm_name = lf_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
ENDIF.

IF cf_retcode = 0.
* call smartform delivery note
ls_control_param-getotf = 'X'.

CALL FUNCTION lf_fm_name
EXPORTING
archive_index = toa_dara
archive_parameters = arc_params
control_parameters = ls_control_param
* mail_appl_obj =
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
user_settings = ' '
is_dlv_delnote = ls_dlv_delnote
is_nast = nast
IMPORTING
* document_output_info =
job_output_info = fs_ssfcrescl
* job_output_options =
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
ENDIF.

READ TABLE ls_dlv_delnote-hd_adr INTO ls_ledlv_hd_adr INDEX 1 .

IF sy-subrc = 0 .
REFRESH lt_emails .
SELECT
addrnumber
smtp_addr
FROM adr6
INTO TABLE lt_emails
WHERE addrnumber = ls_ledlv_hd_adr-addr_no.
* AND flgdefault NE abap_true .

IF lt_emails IS NOT INITIAL .

IF fs_ssfcrescl-otfdata[] IS NOT INITIAL.
it_otf_data[] = fs_ssfcrescl-otfdata[].

CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = w_binfilesize
TABLES
otf = it_otf_data
lines = it_pdf_data
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.

wa_doc_data-obj_name = 'SF'.
wa_doc_data-obj_descr = nast-tdcovtitle.
* Passing the Smartform text lines to SAPoffice: Single List with Column Length 255 table
CLEAR : i_objbin.
LOOP AT it_pdf_data.
gv_pos = 255 - gv_len.
IF gv_pos > 134. "length of pdf_table
gv_pos = 134.
ENDIF.
i_objbin+gv_len = it_pdf_data(gv_pos).
gv_len = gv_len + gv_pos.
IF gv_len = 255. "length of out (contents_bin)
APPEND i_objbin.
CLEAR: i_objbin, gv_len.
IF gv_pos < 134.
i_objbin = it_pdf_data+gv_pos.
gv_len = 134 - gv_pos.
ENDIF.
ENDIF.
ENDLOOP.
IF gv_len > 0.
APPEND i_objbin.
ENDIF.

* Filling the details in SAPoffice: Description of Imported Object Components table
DESCRIBE TABLE i_objbin[] LINES gv_tab_lines.
CLEAR i_objbin.
READ TABLE i_objbin INDEX gv_tab_lines.
IF sy-subrc = 0.
it_pcklist-doc_size = ( gv_tab_lines - 1 ) * 255 + strlen( i_objbin ).
it_pcklist-transf_bin = 'X'.
it_pcklist-head_start = 1.
it_pcklist-head_num = 0.
it_pcklist-body_start = 1.
it_pcklist-body_num = gv_tab_lines.
it_pcklist-doc_type = 'PDF'.
it_pcklist-obj_name = 'ATTACHMENT'.
it_pcklist-obj_descr = 'test'.
APPEND it_pcklist.
CLEAR it_pcklist.
ENDIF.
LOOP AT lt_emails INTO ls_emails .
CLEAR it_receivers.
it_receivers-receiver = ls_emails-smtp_addr.
it_receivers-rec_type = 'U'.
APPEND it_receivers.
CLEAR ls_emails .
IF it_receivers[] IS NOT INITIAL.
*-----Calling the function module to sending email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_doc_data
put_in_outbox = 'X'
* commit_work = 'X'
TABLES
packing_list = it_pcklist
contents_bin = i_objbin[]
receivers = it_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.
IF sy-subrc = 0.

ENDIF.
ENDIF .

ENDLOOP.
REFRESH: it_receivers,
it_pcklist.
ENDIF .
ENDIF.
ENDIF.

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

I don't understand the business need here, i.e. why is it the problem of the business to display the PDF in one way or another in SOST which is NOT business stuff. The business displays emails via email clients, not SOST. Do they have time or money to lose to ask so meaningless things... You'd better challenge them.

Back to your question now.

I initially commented: I guess it must be a document type OTF (it_pcklist-doc_type) instead of PDF (which is not valid as far as I know, it should be EXT) and don't convert to PDF of course, it's converted implicitly by the SAPconnect conversion feature (OTF to PDF).

You are saying it doesn't work, so this may help you to debug by yourself.

The button "display document" of SOST triggers the method cl_sndrec_bcs=>display, which runs the function module SO_DOCUMENT_DISPATCH_MANAGER, which runs the function module SO_DOCUMENTS_MANAGER with parameter DSPO, which calls SO_DOCUMENT_VIEW_MANAGER.

In the latter function module, I can see that probably the document type (it_pcklist-doc_type) you are looking for is SCR (SAPscript, but it uses the OTF format which is also used by Smart Form), instead of PDF (which is not valid as far as I know, it should be EXT) and don't convert to PDF of course, it's converted implicitly by the SAPconnect conversion feature in SCOT node options:

NB: SO_NEW_DOCUMENT_ATT_SEND_API1 has been obsolete for 20 years (use CL_BCS instead).

10 REPLIES 10

Sandra_Rossi
Active Contributor

I don't understand the business need here, but well, I guess it must be a document type OTF (it_pcklist-doc_type) instead of PDF (which is not valid as far as I know, it should be EXT) and don't convert to PDF of course, it's converted implicitly by the SAPconnect conversion feature (OTF to PDF).

NB: SO_NEW_DOCUMENT_ATT_SEND_API1 has been obsolete for 20 years (use CL_BCS instead).

dubbaka
Participant
0 Kudos

Hello sandra.rossi,

I have tried with it_pcklist-doc_type = 'OTF' is also not working.

The business requirement is: In Delivery after repeating output types and saved, mail would be triggered to only one email id which is selected in partners.

But business wants to send mail to all email ids which are available in Delivery.

So we are extracting email ids from ADR6 based on address No and sending mails. Till here logic works fine, But print form we’re unable to display in "Standard Preview" mode, it gets displayed in PDF file which is not required.

I am trying to make changes so that "Standard Preview" can be displayed.

matt
Active Contributor
0 Kudos

Don't use the FM. Use CL_BCS classes. They're much easier.

Sandra_Rossi
Active Contributor
0 Kudos

I said "I don't understand the business need here", i.e. why it's the problem of the business to display the PDF in one way or another in SOST which is NOT business stuff. The business displays emails via email clients, not SOST. Do they have time or money to lose to ask so meaningless things...

dubbaka
Participant
0 Kudos

Hello sandra.rossi and matthew.billingham,

Thanks for your response,

Since it is existing functionality, our project doesn’t want to change the look and feel after adding email logic, that is why they want to display the document same as older one.

Coming to “CL_BCS” Class I have added this class in my logic and able to display as below. Not as Standard Preview.

Standard Preview would be like below, am I doing mistake by converting OTF to PDF?, If yes how to send form without converting OTF to PDF.

Do we get above display without converting PDF, I need above display in SOST please let me know if find any solution for this.

IF cf_retcode = 0.
* determine smartform function module for delivery note
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = lf_formname
* variant = ' '
* direct_call = ' '
IMPORTING
fm_name = lf_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
* error handling
cf_retcode = sy-subrc.
PERFORM protocol_update.
ENDIF.
ENDIF.

IF cf_retcode = 0.
* call smartform delivery note
ls_control_param-getotf = 'X'.

ls_control_param-no_dialog = 'X'.
ls_control_param-preview = space .
ls_composer_param-tdnoprev = 'X' .
ls_composer_param-tddest = 'LOCL' .
ls_composer_param-tdnoprint = 'X' .

CALL FUNCTION lf_fm_name
EXPORTING
archive_index = toa_dara
archive_parameters = arc_params
control_parameters = ls_control_param
* mail_appl_obj =
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
user_settings = ' '
is_dlv_delnote = ls_dlv_delnote
is_nast = nast
IMPORTING
* document_output_info =
job_output_info = fs_ssfcrescl
* job_output_options =
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
* error handling
cf_retcode = sy-subrc.
PERFORM protocol_update.
* get SmartForm protocoll and store it in the NAST protocoll
PERFORM add_smfrm_prot. "INS_HP_335958
ENDIF.
ENDIF.

READ TABLE ls_dlv_delnote-hd_adr INTO ls_ledlv_hd_adr INDEX 1 .

IF sy-subrc = 0 .
REFRESH lt_emails .
SELECT
addrnumber
smtp_addr
FROM adr6
INTO TABLE lt_emails
WHERE addrnumber = ls_ledlv_hd_adr-addr_no.
* AND flgdefault NE abap_true .

IF lt_emails IS NOT INITIAL .

IF fs_ssfcrescl-otfdata[] IS NOT INITIAL.
it_otf_data[] = fs_ssfcrescl-otfdata[].

CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = w_binfilesize
bin_file = lv_bin_xstr
TABLES
otf = it_otf_data
lines = it_pdf_data
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_bin_xstr
TABLES
binary_tab = lt_binary_content.

TRY.
* -------- create persistent send request ------------------------
lo_bcs = cl_bcs=>create_persistent( ).
"First line
CONCATENATE 'Dear Colleague' cl_abap_char_utilities=>newline INTO lv_string_text.
APPEND lv_string_text TO lt_text.
CLEAR lv_string_text.
"Second line
CONCATENATE 'Please find attached a test smartform.'
cl_abap_char_utilities=>newline INTO lv_string_text.
APPEND lv_string_text TO lt_text.
CLEAR lv_string_text.
"Third line
APPEND 'Best Regards,' TO lt_text.
"Fourth line
APPEND 'Systems Administrator.' TO lt_text.

*---------------------------------------------------------------------
*-----------------& Create Document *------------------------
*---------------------------------------------------------------------
lo_doc_bcs = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_text[]
i_length = '12'
i_subject = 'Test Email' ). "Subject of the Email


*Add attachment to document and Add document to send request
*The internal table “lt_binary_content” contains the content of our attachment.

*---------------------------------------------------------------------
*-----------------& Add attachment to document *----------------
*---------------------------------------------------------------------
* BCS expects document content here e.g. from document upload
* binary_content = ...
CALL METHOD lo_doc_bcs->add_attachment
EXPORTING
i_attachment_type = 'PDF'
i_attachment_size = lv_bin_filesize
i_attachment_subject = 'Test Email'
i_att_content_hex = lt_binary_content.

* add document to send request
CALL METHOD lo_bcs->set_document( lo_doc_bcs ).


lo_recep = cl_cam_address_bcs=>create_internet_address(
'Valid email id' ).

"Add recipient with its respective attributes to send request
CALL METHOD lo_bcs->add_recipient
EXPORTING
i_recipient = lo_recep
i_express = 'X'.

CALL METHOD lo_bcs->set_send_immediately
EXPORTING
i_send_immediately = 'X'.

*---------------------------------------------------------------------
*-----------------& Send the email *-----------------------------
*---------------------------------------------------------------------
CALL METHOD lo_bcs->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = lv_sent_to_all ).

IF lv_sent_to_all IS NOT INITIAL.
COMMIT WORK.
ENDIF.

*---------------------------------------------------------------------
*-----------------& Exception Handling *------------------------
*---------------------------------------------------------------------
CATCH cx_bcs INTO lo_cx_bcx.
"Appropriate Exception Handling
WRITE: 'Exception:', lo_cx_bcx->error_type.
ENDTRY.

Sandra_Rossi
Active Contributor

I don't understand the business need here, i.e. why is it the problem of the business to display the PDF in one way or another in SOST which is NOT business stuff. The business displays emails via email clients, not SOST. Do they have time or money to lose to ask so meaningless things... You'd better challenge them.

Back to your question now.

I initially commented: I guess it must be a document type OTF (it_pcklist-doc_type) instead of PDF (which is not valid as far as I know, it should be EXT) and don't convert to PDF of course, it's converted implicitly by the SAPconnect conversion feature (OTF to PDF).

You are saying it doesn't work, so this may help you to debug by yourself.

The button "display document" of SOST triggers the method cl_sndrec_bcs=>display, which runs the function module SO_DOCUMENT_DISPATCH_MANAGER, which runs the function module SO_DOCUMENTS_MANAGER with parameter DSPO, which calls SO_DOCUMENT_VIEW_MANAGER.

In the latter function module, I can see that probably the document type (it_pcklist-doc_type) you are looking for is SCR (SAPscript, but it uses the OTF format which is also used by Smart Form), instead of PDF (which is not valid as far as I know, it should be EXT) and don't convert to PDF of course, it's converted implicitly by the SAPconnect conversion feature in SCOT node options:

NB: SO_NEW_DOCUMENT_ATT_SEND_API1 has been obsolete for 20 years (use CL_BCS instead).

Hello sandra.rossi,

Thanks for your response,

The issue got fixed.

PERFORM set_print_param USING ls_addr_key
CHANGING ls_control_param
ls_composer_param
ls_recipient
ls_sender
cf_retcode.

Solution: I have debugged above subroutine and found 'ADDR_GET_NEXT_COMM_TYPE' and 'CONVERT_COMM_TYPE_DATA' these give sender details.

I have called above FM's in email Id loops so that I am getting multiple sender details and in the same loop email is getting triggered in standard format.

IF cf_retcode = 0.
PERFORM set_print_param USING ls_addr_key
CHANGING ls_control_param
ls_composer_param
ls_recipient
ls_sender
cf_retcode.
.
ENDIF.

IF cf_retcode = 0.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = lf_formname
IMPORTING
fm_name = lf_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
ENDIF.

IF cf_retcode = 0.
SELECT
addrnumber
smtp_addr
FROM adr6
INTO TABLE lt_emails
WHERE addrnumber = ls_addr_key-addrnumber.
LOOP AT lt_emails INTO ls_emails.
* Get sender details for multiple email ids
PERFORM sub_get_send USING ls_emails
ls_addr_key
nast
CHANGING ls_recipient
ls_sender .

CALL FUNCTION lf_fm_name
EXPORTING
archive_index = toa_dara
archive_parameters = arc_params
control_parameters = ls_control_param
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
user_settings = ' '
is_dlv_delnote = ls_dlv_delnote
is_nast = nast
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
ENDLOOP.
ENDIF.
ENDFORM. "PROCESSING
*&---------------------------------------------------------------------*
*& Form SUB_GET_SEND
*&---------------------------------------------------------------------*
FORM sub_get_send USING ls_emails TYPE ty_emails
ls_addr_key LIKE addr_key
nast LIKE nast
CHANGING ls_recipient TYPE swotobjid
ls_sender TYPE swotobjid.

DATA: lvs_comm_type TYPE ad_comm,
lvs_comm_values TYPE szadr_comm_values,
lvs_snast TYPE snast,
lvf_program LIKE sy-repid,
pe_itcpo TYPE itcpo ,
pe_device TYPE tddevice .

MOVE-CORRESPONDING nast TO lvs_snast .
lvf_program = sy-cprog .
CALL FUNCTION 'ADDR_GET_NEXT_COMM_TYPE'
EXPORTING
strategy = nast-tcode
address_number = ls_addr_key-addrnumber
IMPORTING
comm_type = lvs_comm_type
comm_values = lvs_comm_values
EXCEPTIONS
address_not_exist = 1
person_not_exist = 2
no_comm_type_found = 3
internal_error = 4
parameter_error = 5
OTHERS = 6.

lvs_comm_values-adsmtp-smtp_addr = ls_emails-smtp_addr.
TRANSLATE ls_emails-smtp_addr TO UPPER CASE .
lvs_comm_values-adsmtp-smtp_srch = ls_emails-smtp_addr.

CALL FUNCTION 'CONVERT_COMM_TYPE_DATA'
EXPORTING
pi_comm_type = lvs_comm_type
pi_comm_values = lvs_comm_values
pi_repid = sy-repid
pi_snast = lvs_snast
IMPORTING
pe_itcpo = pe_itcpo
pe_device = pe_device
pe_mail_recipient = ls_recipient
pe_mail_sender = ls_sender
EXCEPTIONS
comm_type_not_supported = 1
recipient_creation_failed = 2
sender_creation_failed = 3
OTHERS = 4.

ENDFORM. " SUB_GET_SEND

0 Kudos

Thanks for the feedback. Good news! Only you could find it.

I don't understand why the type of print preview depends on the recipients, but well, that's SAP internal stuff, I would ask them to fix it, rather than maintaining the custom code at each software upgrade (technical debt...)

Sandra_Rossi
Active Contributor
0 Kudos

Hmmm, read again my answer. I told you to use the document type "OTF" and to NOT convert OTF to PDF. In the end, maybe it's not the document type "OTF" but "SCR". Please check my complete answer below.

Sandra_Rossi
Active Contributor
0 Kudos

By the way, please edit your question and comments (Actions>Edit), select your code and press the button [CODE], which makes the code appear colored/indented, it'll be easier for people to look at it. Thanks!