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: 

SAP invoice as PDF - No problem - Attaching an additional PDF - Big problem

0 Kudos

Hi' everybody

I have spent a few hours looking into all kind of stuff, but none of it seems to answer my question.

My company sends invoices via mail where the mail i attached as an pdf, and it works just fine when the communication strategy was correctly set up.

I have a new requirement, that I am trying to solve. The business attaches different PDF-documents to the invoice as GOS-objects, and these PDF's they would like to be attached to the e-mail when we run RSNAST00

I have been making a SAT-trace today to see where I could retrieve the GOS-PDF-objects and attach these to the e-mail that is created with the pdf-invoice.

And here I am stuck - do any of you experts know how to solve this puzzle ? I have absolutely no idea where to do attatch these documents.

Am I supposed to make the changes (and which changes) in RSNAST00, our copy of RVADIN01 (old sap-script-invoice-program) or are they supposed to be created in the lower layers of the application ?

I really hopy you can help me out here 🙂

Kind Regards

Peter C

1 ACCEPTED SOLUTION

CreyJ
Participant
0 Kudos

Hello Peter,

David is correct.

In addition, you have

1) to prevent emailing by the system from processing:

set the field LVS_ITCPO-TDGETOTF = 'X'. before open form and retrieve otf data in close form.


CALL FUNCTION 'CLOSE_FORM'
       IMPORTING
         RESULT  = I_ITCPP
       TABLES
         OTFDATA = OTF_DATA
       EXCEPTIONS
         OTHERS  = 1.

2) Then you have to convert the otf to pdf an create a send request for the spool.


FORM CONVERT_OTF_TO_PDF 

TABLES  LT_OTFDATA STRUCTURE ITCOO.

              LT_LINES STRUCTURE TLINE,

   DATA: LV_OTF_MEMORY_SWITCH TYPE BOOLEAN,
           LT_OTF TYPE TABLE OF ITCOO,
           LV_BINFILESIZE TYPE I,
           LV_BIN_FILE TYPE XSTRING,
           LV_PDF TYPE FPCONTENT.

* convert to otf
   CALL FUNCTION 'CONVERT_OTF'
     EXPORTING
       FORMAT                = 'PDF'
     IMPORTING
       BIN_FILESIZE          = LV_BINFILESIZE
       BIN_FILE              = LV_BIN_FILE
     TABLES
       OTF                   = LT_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.
     RETCODE = SY-SUBRC.
     SYST-MSGTY = 'E'.
     PERFORM PROTOCOL_UPDATE.
     EXIT.
   ENDIF.

.ENDFORM.

3) Then you have to create an own send document. (i would also use CL_BCS). (If you create the spool as PDF attachment, you can also use an individual body text for the email.)

4) Then you can attach the document from the GOS.

But you have to do this in the printing program itself, so you have to modify or copy RFACIN01

Regards

-Jürgen-

some snippets for sending with BCS

TRY.
           LO_SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).
...

With a text as mail body text

                   LO_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
                                     I_TYPE    = 'RAW' "
                                     I_TEXT     = LI_MAILBODY
                                     I_SUBJECT = LW_SUBJECT ).

With an HTML as mail body

   LO_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
                           I_TYPE    = 'HTM'"'RAW' " cf. RAW, DOC
                           I_TEXT     = LI_MAILBODY
                           I_SUBJECT = LW_SUBJECT ).

add pdf attachment

CALL METHOD LO_DOCUMENT->ADD_ATTACHMENT
                 EXPORTING
                   I_ATTACHMENT_TYPE    = 'PDF'
                   I_ATTACHMENT_SUBJECT = LW_FILENAME
                   I_ATT_CONTENT_HEX    = LI_PDF_CONTENT.

*   add document to send request
           LO_SEND_REQUEST->SET_DOCUMENT( LO_DOCUMENT ).

*           add recipient (e-mail address)
             LO_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS(
                                I_ADDRESS_STRING = LW_EMAILADDR ).

*   add recipient to send request
           LO_SEND_REQUEST->ADD_RECIPIENT( I_RECIPIENT = LO_RECIPIENT ).

....

*   ---------- send document ---------------------------------------
           LW_SENT_TO_ALL = LO_SEND_REQUEST->SEND(
               I_WITH_ERROR_SCREEN = 'X' ).

           IF LW_SENT_TO_ALL = 'X'.

* add here a success message

          ENDIF.


... catch errors

CATCH CX_BCS INTO LO_BCS_EXCEPTION.
           MESSAGE E019(MS) "with LO_BCS_EXCEPTION->ERROR_TYPE
           RAISING SEND_ERROR.
*     Sending fax/mail failed
           EXIT.
       ENDTRY.



see also

http://scn.sap.com/thread/1888422

https://scn.sap.com/thread/768673

5 REPLIES 5

former_member235395
Contributor
0 Kudos

Hi Peter,

All files saved using GOS are located on SRGBTBREL Table(You can found there).

Now, your can use:

CALL METHOD cl_binary_relation=>read_links

          EXPORTING

            is_object           = gs_lpor

            it_relation_options = lt_relat

          IMPORTING

            et_links            = t_links.

LOOP AT t_links INTO s_links.

        REFRESH: lt_object_content_l, lt_hex, lt_content.

        CLEAR: lwa_document_data.

        MOVE s_links-instid_b TO lv_document_id.

* Read the data

        CALL FUNCTION 'SO_DOCUMENT_READ_API1'

          EXPORTING

            document_id                = lv_document_id

          IMPORTING

            document_data              = lwa_document_data

          TABLES

            contents_hex               = lt_hex

            object_content             = lt_content

          EXCEPTIONS

            document_id_not_exist      = 1

            operation_no_authorization = 2

            x_error                    = 3

            OTHERS                     = 4.

for read the attach files on GOS. So, you will have find  a program neccesary for add those files and send with your invoice.

You are using standard or custom program? If you using Custom program will be use CL_BCS by send email, else, find any proper object(Exit, Badi, Enhancemet) for achieve your process.


Regards

0 Kudos

Adding to David's suggestion:

There are two Classes for the GOS objects that I think will be helpful.

They are cl_gos_srv_attachment_list and cl_gos_toolbox_model.

Something similar to the code below - I think its worth having a look at these two Classes as you are working with GOS attachments.

DATA:

     lo_gos_attach   TYPE REF TO cl_gos_srv_attachment_list,

     lo_gos_model   TYPE REF TO cl_gos_toolbox_model,

     ls_borident        TYPE borident,

     lv_instid_b         TYPE sibfboriid,

     lv_sibflporb        TYPE sibflporb,

     lv_def_attrb        TYPE swc_value.

   READ TABLE pt_alv ASSIGNING <ls_alv> INDEX pv_row.

   CHECK sy-subrc EQ 0.

   IF <ls_alv>-note IS INITIAL.

     MESSAGE s010 WITH text-020.

   ELSE.

     PERFORM check_authority USING 'FB03'.

     CONCATENATE <ls_alv>-bukrs <ls_alv>-belnr

                 <ls_alv>-gjahr <ls_alv>-buzei

           INTO  ls_borident-objkey.

     lv_sibflporb-instid = ls_borident-objkey.

     lv_sibflporb-typeid = 'BSEG'.

     lv_sibflporb-catid  = 'BO'.

     lv_def_attrb        = ls_borident-objkey.

     CREATE OBJECT lo_gos_attach.

     CREATE OBJECT lo_gos_model

       EXPORTING

         is_object   = lv_sibflporb

         ip_mode   = lo_gos_attach->mp_mode_read.

     lo_gos_attach->set_object(

       EXPORTING

         is_lporb                     = lv_sibflporb

         ip_default_attribute = lv_def_attrb

         ip_mode                    = lo_gos_attach->mp_mode_read

         io_model                   = lo_gos_model ).

     lo_gos_attach->execute(

       EXCEPTIONS

         execution_failed  = 1

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

   ENDIF.

Cheers,

Sougata.

CreyJ
Participant
0 Kudos

Hello Peter,

David is correct.

In addition, you have

1) to prevent emailing by the system from processing:

set the field LVS_ITCPO-TDGETOTF = 'X'. before open form and retrieve otf data in close form.


CALL FUNCTION 'CLOSE_FORM'
       IMPORTING
         RESULT  = I_ITCPP
       TABLES
         OTFDATA = OTF_DATA
       EXCEPTIONS
         OTHERS  = 1.

2) Then you have to convert the otf to pdf an create a send request for the spool.


FORM CONVERT_OTF_TO_PDF 

TABLES  LT_OTFDATA STRUCTURE ITCOO.

              LT_LINES STRUCTURE TLINE,

   DATA: LV_OTF_MEMORY_SWITCH TYPE BOOLEAN,
           LT_OTF TYPE TABLE OF ITCOO,
           LV_BINFILESIZE TYPE I,
           LV_BIN_FILE TYPE XSTRING,
           LV_PDF TYPE FPCONTENT.

* convert to otf
   CALL FUNCTION 'CONVERT_OTF'
     EXPORTING
       FORMAT                = 'PDF'
     IMPORTING
       BIN_FILESIZE          = LV_BINFILESIZE
       BIN_FILE              = LV_BIN_FILE
     TABLES
       OTF                   = LT_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.
     RETCODE = SY-SUBRC.
     SYST-MSGTY = 'E'.
     PERFORM PROTOCOL_UPDATE.
     EXIT.
   ENDIF.

.ENDFORM.

3) Then you have to create an own send document. (i would also use CL_BCS). (If you create the spool as PDF attachment, you can also use an individual body text for the email.)

4) Then you can attach the document from the GOS.

But you have to do this in the printing program itself, so you have to modify or copy RFACIN01

Regards

-Jürgen-

some snippets for sending with BCS

TRY.
           LO_SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).
...

With a text as mail body text

                   LO_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
                                     I_TYPE    = 'RAW' "
                                     I_TEXT     = LI_MAILBODY
                                     I_SUBJECT = LW_SUBJECT ).

With an HTML as mail body

   LO_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
                           I_TYPE    = 'HTM'"'RAW' " cf. RAW, DOC
                           I_TEXT     = LI_MAILBODY
                           I_SUBJECT = LW_SUBJECT ).

add pdf attachment

CALL METHOD LO_DOCUMENT->ADD_ATTACHMENT
                 EXPORTING
                   I_ATTACHMENT_TYPE    = 'PDF'
                   I_ATTACHMENT_SUBJECT = LW_FILENAME
                   I_ATT_CONTENT_HEX    = LI_PDF_CONTENT.

*   add document to send request
           LO_SEND_REQUEST->SET_DOCUMENT( LO_DOCUMENT ).

*           add recipient (e-mail address)
             LO_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS(
                                I_ADDRESS_STRING = LW_EMAILADDR ).

*   add recipient to send request
           LO_SEND_REQUEST->ADD_RECIPIENT( I_RECIPIENT = LO_RECIPIENT ).

....

*   ---------- send document ---------------------------------------
           LW_SENT_TO_ALL = LO_SEND_REQUEST->SEND(
               I_WITH_ERROR_SCREEN = 'X' ).

           IF LW_SENT_TO_ALL = 'X'.

* add here a success message

          ENDIF.


... catch errors

CATCH CX_BCS INTO LO_BCS_EXCEPTION.
           MESSAGE E019(MS) "with LO_BCS_EXCEPTION->ERROR_TYPE
           RAISING SEND_ERROR.
*     Sending fax/mail failed
           EXIT.
       ENDTRY.



see also

http://scn.sap.com/thread/1888422

https://scn.sap.com/thread/768673

0 Kudos

Ups typing mistake I meain RVADIN01 instead RFACIN01, but i also saw now, that you already copied it...

0 Kudos

Hi Jürgen

Thanks a lot - just the answer I was looking for.

You made my day !

Kind regards

Peter