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: 

Print preview of Billing Invoice(VF01/02/03) is not coming ?

Former Member
0 Kudos
593

I have done necessary changes to make Billing Invoice script to PDF conversion and send that as an attachment to mail id of customer. Now mail is triggering but print preview is not working.

Steps followed:

1.  Get e-mail id

2.  CONVERT_OTF ( Script - PDF )

3.  SCMS_XSTRING_TO_BINARY

4.  Send mail through - SO_NEW_DOCUMENT_ATT_SEND_API1

8 REPLIES 8

former_member188724
Contributor
0 Kudos
84

Hi,

You are talking about pdf preview?

If yes then are you passing the PDF_PREVIEW as X in the convert_otf?

Hope this helps.

Regards,

K.S


0 Kudos
84

Thanks for your early reply.

I did as suggested by you, still no preview . May be some other thing i am missing.

0 Kudos
84

Hi,

Can you pls paste the Piece of code where you write the preview.

Regards,

K.S

0 Kudos
84

Code line (Open Form , Close Form, Send Mail);

FORM FORM_OPEN USING US_SCREEN US_COUNTRY.

INCLUDE ZRVADOPFO.

ENDFORM.      

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

FORM FORM_CLOSE.

CALL FUNCTION 'CLOSE_FORM'
*    IMPORTING
*      RESULT = W_RES
TABLES
OTFDATA = I_RECORD[]
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC NE 0.
RETCODE = SY-SUBRC.
PERFORM PROTOCOL_UPDATE.

ELSE.

  PERFORM GET_EMAILID.

IF MAIL_FLG = 'Y'.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT                = 'PDF'
MAX_LINEWIDTH         =
132
PDF_PREVIEW           =
'X'
IMPORTING
BIN_FILESIZE          = V_LEN_IN
BIN_FILE              = V_LEN_PD
TABLES
OTF                   = I_RECORD[]
LINES                 = I_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 'OTF conversion error' TYPE 'E'.
ELSE.
* BINARY CONVERSION
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER     = V_LEN_PD
TABLES
BINARY_TAB = I_RECORD.

* Mail Header, body & Mail Sending
PERFORM SEND_MAIL.

ENDIF.
ENDIF.
SET COUNTRY SPACE.
*  ENDIF.
ENDIF.
ENDFORM.                   
"FORM_CLOSE

FORM SEND_MAIL .

REFRESH: I_RECLIST,
I_OBJTXT,
I_OBJBIN,
I_OBJPACK.
CLEAR WA_OBJHEAD.
I_OBJBIN[] = I_RECORD[].

DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.
* Create Message Body Title and Description
I_OBJTXT =
'Dear Sir / Madam, PFA of Invoice'.
APPEND I_OBJTXT.

DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.

READ TABLE I_OBJTXT INDEX V_LINES_TXT.

CONCATENATE 'Invoice No:' NAST-OBJKY INTO WA_DOC_DAT-OBJ_DESCR.

WA_DOC_DAT-OBJ_NAME =
'SAPRPT'.
WA_DOC_DAT-EXPIRY_DAT = SY-DATUM +
10.
WA_DOC_DAT-OBJ_DESCR = WA_DOC_DAT-OBJ_DESCR.
"'Purchase Order'.
WA_DOC_DAT-SENSITIVTY =
'F'.
WA_DOC_DAT-DOC_SIZE = V_LINES_TXT *
255.
WA_DOC_DAT-DOC_SIZE =  ( V_LINES_BIN -
1 ) * 510 + STRLEN( I_OBJBIN ).
* 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'.
I_OBJPACK-OBJ_LANGU =
'E'.
APPEND I_OBJPACK.
* Attachment (pdf-Attachment)
I_OBJPACK-TRANSF_BIN =
'X'.
I_OBJPACK-HEAD_START =
1.
I_OBJPACK-HEAD_NUM =
1.
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-DOC_SIZE = ( V_LINES_BIN -
1 ) * 255 + STRLEN( I_TLINE ).
I_OBJPACK-BODY_NUM = V_LINES_TXT.
I_OBJPACK-DOC_TYPE =
'PDF'.
I_OBJPACK-OBJ_NAME =
'SMART'.
I_OBJPACK-OBJ_DESCR =
'Invoice'.
I_OBJPACK-DOC_SIZE = V_LINES_BIN *
255.
I_OBJPACK-BODY_NUM = V_LINES_BIN.
I_OBJPACK-DOC_TYPE =
'PDF'.
*    i_objpack-obj_name = 'SmartForm'.
I_OBJPACK-OBJ_DESCR =
'Invoice'.
APPEND I_OBJPACK.

CLEAR I_RECLIST.
I_RECLIST-RECEIVER = G_MAILID .
I_RECLIST-REC_TYPE =
'U'.
I_RECLIST-EXPRESS =
'X'.
I_RECLIST-NOTIF_DEL =
'X'.
I_RECLIST-NOTIF_NDEL =
'X'.
I_RECLIST-COM_TYPE =
'INT'.
APPEND I_RECLIST.


IF SY-TCODE = 'VF01' OR SY-TCODE = 'VF02' OR SY-TCODE = 'VF03'.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA              = WA_DOC_DAT
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.

WAIT UP TO 2 SECONDS.
SUBMIT RSCONN01 WITH MODE  = 'INT' WITH OUTPUT = 'X' AND RETURN.
COMMIT WORK.
ENDIF.
ENDFORM.                   
" SEND_MAIL  

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

INCLUDE ZRVADOPFO.

DATA: lvs_itcpo         TYPE   itcpo,
       lvf_device(30)    TYPE   c,
       lvf_dialog(1)     TYPE   c   VALUE ' ',
       lvs_recipient     LIKE   swotobjid,
       lvs_sender        LIKE   swotobjid,
       lvs_snast         TYPE   snast,
       lvf_program       LIKE   sy-repid,
       lvs_comm_type     TYPE   ad_comm,
       lvs_comm_values   TYPE   szadr_comm_values,
       lv_otf_memory_switch TYPE c.

**********************************************************************
*DATA: W_RES TYPE ITCPP.
**********************************************************************
FIELD-SYMBOLS:
   <lv_xscreen> TYPE c.

* reset return code
retcode = 0.

* if there is a communication strategy used ...
IF NOT nast-tcode IS INITIAL AND nast-nacha EQ '5'.

*   ... use stratagy to get communication type
   CALL FUNCTION 'ADDR_GET_NEXT_COMM_TYPE'
        EXPORTING
             strategy           = nast-tcode
*             ADDRESS_TYPE       =
*             ADDRESS_NUMBER     = VBDKA-ADRNR
*             PERSON_NUMBER      = VBDKA-ADRNP
             address_number     = addr_key-addrnumber
             person_number      = addr_key-persnumber
        IMPORTING
             comm_type          = lvs_comm_type
             comm_values        = lvs_comm_values
*        TABLES
*             STRATEGY_TABLE     =
        EXCEPTIONS
             address_not_exist  = 1
             person_not_exist   = 2
             no_comm_type_found = 3
             internal_error     = 4
             parameter_error    = 5
             OTHERS             = 6.
   IF sy-subrc <> 0.
     retcode = sy-subrc.
     syst-msgty = 'E'.
     PERFORM protocol_update.
   ENDIF.

ENDIF.


* convert communication data
MOVE-CORRESPONDING nast TO lvs_snast.
MOVE sy-repid           TO lvf_program.
CALL FUNCTION 'CONVERT_COMM_TYPE_DATA'
   EXPORTING
     pi_comm_type              = lvs_comm_type
     pi_comm_values            = lvs_comm_values
     pi_screen                 = us_screen
*   PI_NEWID                  =
     pi_country                = us_country
     pi_repid                  = lvf_program
     pi_snast                  = lvs_snast
   IMPORTING
     pe_itcpo                  = lvs_itcpo
     pe_device                 = lvf_device
     pe_mail_recipient         = lvs_recipient
     pe_mail_sender            = lvs_sender
   EXCEPTIONS
     comm_type_not_supported   = 1
     recipient_creation_failed = 2
     sender_creation_failed    = 3
     OTHERS                    = 4.
IF sy-subrc <> 0.
   retcode = sy-subrc.
   syst-msgty = 'E'.
   PERFORM protocol_update.
ENDIF.

CHECK retcode EQ 0.

* if there is no communication type
IF  lvs_comm_type IS INITIAL.
*   set device
   CASE nast-nacha.
     WHEN '1'.
       lvf_device = 'PRINTER'.
     WHEN '2'.
       lvf_device = 'TELEFAX'.
       lvs_itcpo-tdtelenum = nast-telfx.
       IF nast-tland IS INITIAL.
         lvs_itcpo-tdteleland = us_country.
       ELSE.
         lvs_itcpo-tdteleland = nast-tland.
       ENDIF.
       lvs_itcpo-tdsenddate = nast-vsdat.
       lvs_itcpo-tdsendtime = nast-vsura.
       lvs_itcpo-tdfaxuser  = nast-usnam.
     WHEN '3'.
       lvf_device = 'TELETEX'.
       lvs_itcpo-tdtelenum = nast-teltx.
       IF nast-tland IS INITIAL.
         lvs_itcpo-tdteleland = us_country.
       ELSE.
         lvs_itcpo-tdteleland = nast-tland.
       ENDIF.
       lvs_itcpo-tdsenddate = nast-vsdat.
       lvs_itcpo-tdsendtime = nast-vsura.
     WHEN '4'.
       lvf_device = 'TELEX'.
       lvs_itcpo-tdtelenum = nast-telx1.
       IF nast-tland IS INITIAL.
         lvs_itcpo-tdteleland = us_country.
       ELSE.
         lvs_itcpo-tdteleland = nast-tland.
       ENDIF.
       lvs_itcpo-tdsenddate = nast-vsdat.
       lvs_itcpo-tdsendtime = nast-vsura.
     WHEN OTHERS.
       lvf_device = 'PRINTER'.
   ENDCASE.
ENDIF.

* fill structure itcpo
itcpo = lvs_itcpo.

* insert note 508569 {
* OTF-Output, wenn Browser-Druck
IF nast-sort1 = 'EBPP'.
   lvs_itcpo-tdgetotf = 'X'.
ENDIF.
* } end note 508569

* Print Preview for CRM Web UI and ERP Sales UI
* OTF will be converted to PDF in case of active SD EHP4 BF
IF cl_ops_switch_check=>sd_sfws_sc3( ) EQ abap_true.
* Dynamically assign for indicator XSCREEN
   ASSIGN ('XSCREEN') TO <lv_xscreen>.
   IF <lv_xscreen> IS ASSIGNED AND
      <lv_xscreen> EQ 'W'      AND
      lvf_device   EQ 'PRINTER'.
* get otf
     lvs_itcpo-tdgetotf = 'X'.
* only print
     lvs_itcpo-tdarmod = '1'.
   ENDIF.
ENDIF.

* open form
lvs_itcpo-TDGETOTF = 'X'.
CALL FUNCTION 'OPEN_FORM'
      EXPORTING
*           APPLICATION        = 'TX'
           archive_index      = toa_dara
           archive_params     = arc_params
           device             = lvf_device
           dialog             = ' '
           form               = tnapr-fonam
           language           = nast-spras
           options            = lvs_itcpo
           mail_sender        = lvs_sender
           mail_recipient     = lvs_recipient
*           MAIL_APPL_OBJECT   = ' '
*           RAW_DATA_INTERFACE = '*'
       IMPORTING
*           LANGUAGE           =
*           NEW_ARCHIVE_PARAMS =
            RESULT             = w_res
      EXCEPTIONS
           canceled           = 1
           device             = 2
           form               = 3
           options            = 4
           unclosed           = 5
           mail_options       = 6
           archive_error      = 7
           OTHERS             = 8.

IF sy-subrc NE 0.
   CASE sy-subrc.
     WHEN 7.
       retcode = sy-subrc.
       syst-msgid = 'VN'.
       syst-msgno = '096'.
       syst-msgty = 'E'.
       syst-msgv1 = nast-kschl.
       syst-msgv2 = nast-kappl.
       PERFORM protocol_update.
     WHEN OTHERS.
       retcode = sy-subrc.
       PERFORM protocol_update.
   ENDCASE.
ENDIF.
SET COUNTRY us_country.

0 Kudos
84

Hi,

In the lvs_itcpo do you set the tdpreview = 'X'?

Also do you want to generate any spool when you have tdgetotf = 'X'?

if so then to generate spool you have to use PRINT_OTF FM.

Regards,

K.S

krishna_k19
Contributor
0 Kudos
84

Hi Omkar,

    I guess you are viewing the preview of sent mail only na , if yes please go through the below code..

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           = 'SF_EXAMPLE_01'

   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'.

W_CTRLOP-DEVICE = 'PRINTER'.

   W_CTRLOP-PREVIEW = ''.

   W_COMPOP-TDDEST = 'LOCL'.

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 = 'abc@xx.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.


Regards,

Krishna

0 Kudos
84

Thanks for your early reply.

It's not smartform, it's script - PDF.

former_member220028
Active Contributor
0 Kudos
84

Hi,

with no guarantee i think you have to disable OTF output when you want to use the preview.

So in the open Form parameters if preview = X then OTF output = SPACE. i think this should work. Dont forget to make 2 close forms - 1 for email 1 for preview - hope this helps.

maybe there are more elegant ways...

Also dont forget about the archive. as far as i know you have to call the archive routine manually when getting otf-output - at least if you need to archive the invoice.

regards

Stefan Seeburger