cancel
Showing results for 
Search instead for 
Did you mean: 

automatic form generation on creation transfer order for delivery note?

Former Member
0 Kudos

Hi,

I have to create a form that should automatically be generated on the creation of a transfer order for delivery note. How do I trigger this automatic creation of the form? And how can the transfer order number be passed to my print program?

Thx!

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

hi christophe,

To issue the delivery output, go to transaction VL02N.

Then go to EXTRAS-> OUTPUT->HEADER->EDIT

In the Message output screen enter the relevant output type created for the delivery.

Choose the relevant medium of output.

Choose Simple Mail, in this case the field NAST-NACHA will be having a value of 7.

Specify the Partner Function; in this case it is MA -> Mail partner address

Select the Communication Method for the output type maintained.

This will take you to the SAPOFFICE screen.

Enter there the E-Mail Address to which you want to send the delivery document as PDF.

A mail will be sent to the e-mail address of the E-Mail Address specified, with the delivery output form as a PDF attachment.

hope it will help u ..

&----


*& Report ZZ_TEST *

*& *

&----


*& *

*& *

&----


REPORT zz_test .

INCLUDE zz_test_top.

INCLUDE zz_test01.

----


  • FORM entry *

----


  • ........ *

----


  • --> RETURN_CODE *

  • --> US_SCREEN *

----


FORM entry USING return_code us_screen.

CLEAR retcode.

xscreen = us_screen.

PERFORM processing USING us_screen.

CASE retcode.

WHEN 0.

return_code = 0.

WHEN 3.

return_code = 3.

WHEN OTHERS.

return_code = 1.

ENDCASE.

ENDFORM. "entry

&----


*& Include ZZ_TEST_TOP *

&----


TABLES : nast,

tnapr.

TYPES : BEGIN OF t_SOUDNAMEI1.

INCLUDE STRUCTURE SOUDNAMEI1.

TYPES : END OF t_SOUDNAMEI1.

  • 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,

i_lips LIKE lips OCCURS 0 WITH HEADER LINE,

i_SOUDNAMEI1 TYPE STANDARD TABLE OF t_SOUDNAMEI1.

  • Work Area declarations

DATA:w_objhead TYPE soli_tab,

wa_control_parameters TYPE ssfctrlop,

wa_output_options TYPE ssfcompop,

w_return TYPE ssfcrescl,

w_doc_chng TYPE sodocchgi1,

w_data TYPE sodocchgi1,

w_buffer TYPE string,"To convert from 132 to 255

wa_SOUDNAMEI1 TYPE t_SOUDNAMEI1,

  • Variables declarations

w_form_name TYPE rs38l_fnam,

w_len_in LIKE sood-objlen,

w_len_out LIKE sood-objlen,

w_len_outn TYPE i,

w_lines_txt TYPE i,

w_lines_bin TYPE i,

retcode TYPE sy-subrc,

xscreen TYPE c,

w_spld TYPE usr01-spld,

w_receiver TYPE SOXNA-FULLNAME,

w_OBJ_RECORD TYPE OBJ_RECORD,

w_user type sy-uname,

w_email TYPE ad_smtpadr.

  • Constants Declaration

CONSTANTS : c_x TYPE c VALUE 'X',

c_atrate(1) TYPE c VALUE '@'.

&----


*& Include ZZ_TEST01 *

&----


----


  • FORM PROCESSING *

----


FORM processing USING proc_screen.

SELECT * FROM lips

INTO TABLE i_lips

WHERE vbeln = nast-objky.

  • Call Function module to Getfunction Module name Generated by Smartform

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = tnapr-sform

IMPORTING

fm_name = w_form_name

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3.

IF sy-subrc <> 0.

retcode = sy-subrc.

ENDIF.

CLEAR : wa_control_parameters,

wa_output_options.

CASE nast-nacha.

WHEN '1'.

wa_control_parameters-device = 'PRINTER'.

WHEN '7'.

DATA: l_email TYPE ad_smtpadr.

wa_output_options-tdnoprev = c_x.

wa_control_parameters-getotf = c_x.

  • To get the default output device maintained in the

  • User profile

SELECT SINGLE spld FROM usr01

INTO w_spld

WHERE bname EQ nast-usnam.

IF sy-subrc EQ 0.

MOVE w_spld TO wa_output_options-tddest .

ENDIF.

wa_output_options-tdnoprev = c_x.

wa_control_parameters-getotf = c_x.

  • To get the email address maintained for the particular output

CALL FUNCTION 'NAST_GET_MESSAGE_OBJECT_RECV'

EXPORTING

pi_objkey = nast-tdname

IMPORTING

pe_addr = w_receiver

CHANGING

pc_objhandle = w_obj_record

EXCEPTIONS

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

IF w_receiver NA c_atrate.

  • To retrieve the E-Mail Id in case we get the User name from NAST

CLEAR wa_soudnamei1.

REFRESH i_soudnamei1.

MOVE w_receiver TO wa_soudnamei1-fullname.

  • To get the user name

CALL FUNCTION 'SO_NAME_CONVERT_API1'

EXPORTING

name = wa_soudnamei1

TABLES

names = i_soudnamei1

EXCEPTIONS

user_not_exist = 1

parameter_error = 2

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

CLEAR wa_soudnamei1.

READ TABLE i_soudnamei1 INTO wa_soudnamei1 INDEX 1.

MOVE wa_soudnamei1-sapname TO w_user.

  • To get the e-mail Id maintained in the user profile

CALL FUNCTION 'FTR_CORR_CHECK_EMAIL_SAP_USER'

EXPORTING

i_user = w_user

IMPORTING

e_email_address = l_email

EXCEPTIONS

mail_address = 1

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

MOVE l_email TO w_receiver.

ENDIF.

MOVE w_receiver TO w_email.

ENDCASE.

wa_control_parameters-no_dialog = c_x.

wa_control_parameters-langu = nast-spras .

wa_output_options-tdteleland = nast-tland.

wa_output_options-tdtelenum = nast-telfx .

wa_output_options-tdsenddate = nast-erdat .

wa_output_options-tdsendtime = nast-eruhr .

wa_output_options-tddataset = nast-dsnam .

wa_output_options-tdsuffix1 = nast-dsuf1 .

wa_output_options-tdsuffix2 = nast-dsuf2 .

wa_output_options-tdimmed = nast-dimme .

wa_output_options-tddelete = nast-delet .

wa_output_options-tdautority = nast-tdautority.

wa_output_options-tdcovtitle = nast-tdcovtitle .

wa_output_options-tdcover = nast-tdocover .

wa_output_options-tdreceiver = nast-tdreceiver.

wa_output_options-tddivision = nast-tddivision.

wa_output_options-tdcopies = nast-anzal .

wa_output_options-tdnewid = c_x.

wa_output_options-tdarmod = nast-tdarmod.

wa_output_options-tdnoarmch = c_x.

CALL FUNCTION w_form_name

EXPORTING

  • archive_index = toa_dara

  • archive_parameters = arc_params

control_parameters = wa_control_parameters

output_options = wa_output_options

user_settings = ' '

IMPORTING

job_output_info = w_return

TABLES

it_lips = i_lips

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5.

IF nast-nacha EQ 7 AND sy-subrc EQ 0.

i_otf[] = w_return-otfdata[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = w_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.

  • Convert PDF from 132 to 255.

LOOP AT i_tline.

  • Replacing space by ~

TRANSLATE i_tline USING ' ~'.

CONCATENATE w_buffer i_tline INTO w_buffer.

ENDLOOP.

  • Replacing ~ by space

TRANSLATE w_buffer USING '~ '.

DO.

i_record = w_buffer.

  • Appending 255 characters as a record

APPEND i_record.

SHIFT w_buffer LEFT BY 255 PLACES.

IF w_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

REFRESH: i_reclist,

i_objtxt,

i_objbin,

i_objpack.

CLEAR w_objhead.

  • Object with PDF.

i_objbin[] = i_record[].

DESCRIBE TABLE i_objbin LINES w_lines_bin.

  • Document information.

w_doc_chng-obj_name = 'Smartform'.

w_doc_chng-expiry_dat = sy-datum + 10.

CONCATENATE 'Delivery' 'Note'

INTO w_doc_chng-obj_descr.

*w_doc_chng-obj_descr = 'Smart form output'.

w_doc_chng-sensitivty = 'F'. "Functional object

w_doc_chng-doc_size = w_lines_txt * 255.

  • Pack to main body as RAW.

  • Obj. to be transported not in binary form

CLEAR i_objpack-transf_bin.

  • Start line of object header in transport packet

i_objpack-head_start = 1.

  • Number of lines of an object header in object packet

i_objpack-head_num = 0.

  • Start line of object contents in an object packet

i_objpack-body_start = 1.

  • Number of lines of the object contents in an object packet

i_objpack-body_num = w_lines_txt.

  • Code for document class

i_objpack-doc_type = 'RAW'.

APPEND i_objpack.

  • Packing as PDF.

i_objpack-transf_bin = 'X'.

i_objpack-head_start = 1.

i_objpack-head_num = 1.

i_objpack-body_start = 1.

i_objpack-body_num = w_lines_bin.

i_objpack-doc_type = 'PDF'.

i_objpack-obj_name = 'Smartform'.

CONCATENATE 'Delivery' 'Note' '.pdf'

INTO i_objpack-obj_descr.

i_objpack-doc_size = w_lines_bin * 255.

APPEND i_objpack.

  • Document information.

CLEAR i_reclist.

  • e-mail receivers.

i_reclist-receiver = w_email.

i_reclist-express = 'X'.

i_reclist-rec_type = 'U'. "Internet address

APPEND i_reclist.

  • sending mail.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = w_doc_chng

put_in_outbox = 'X'

TABLES

packing_list = i_objpack

object_header = w_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.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDIF.

ENDFORM. "processing