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: 

File Attaching While Printing

Former Member
0 Kudos

Hi all

I have this issue: I need when user print some kind of document to catch document printed and in some way attach it.

The scope is general ( I should catch for example invoice document or purchase order). I have searched forum with no luck.

I don't know which tool it's more appropriate for this kind of working (GOS or DMS) but before starting I would like to know if there is a way to catch the form printed (as pdf for example) for storing it. And in this way, any hints about HOW to store it is welcome ...

in general ... any hints is welcome!

thanks

Gabriele

1 ACCEPTED SOLUTION

mgbernardo
Participant
0 Kudos

Hi Gabriele!

If you are using sapscript, you can use a pair of functions to achieve your requierements.

In close form on your print program you must get the OTF of the spool and then attach it to your document.

The code would be something like this:

 

data: otf type standard table of itcoo.

    REFRESH otf.



    CALL FUNCTION 'CLOSE_FORM'
      IMPORTING
        RESULT  = itcpp
      TABLES
        otfdata = otf.

      CALL FUNCTION 'CONVERT_OTF_AND_ARCHIVE'
        EXPORTING
         arc_p                          = arc_params
         arc_i                          = toa_dara
         format                         = 'PDF'
*           ARC_TAB                        =
*           ARCHIVE_COPIES                 = ' '
*           MAX_COPIES                     = '001'
        TABLES
          otf                            = otf
       EXCEPTIONS
         error_archiv                   = 1
         error_communicationtable       = 2
         error_connectiontable          = 3
         error_kernel                   = 4
         error_parameter                = 5
         error_format                   = 6
         OTHERS                         = 7
                .

Hope it helps

Regards

3 REPLIES 3

mgbernardo
Participant
0 Kudos

Hi Gabriele!

If you are using sapscript, you can use a pair of functions to achieve your requierements.

In close form on your print program you must get the OTF of the spool and then attach it to your document.

The code would be something like this:

 

data: otf type standard table of itcoo.

    REFRESH otf.



    CALL FUNCTION 'CLOSE_FORM'
      IMPORTING
        RESULT  = itcpp
      TABLES
        otfdata = otf.

      CALL FUNCTION 'CONVERT_OTF_AND_ARCHIVE'
        EXPORTING
         arc_p                          = arc_params
         arc_i                          = toa_dara
         format                         = 'PDF'
*           ARC_TAB                        =
*           ARCHIVE_COPIES                 = ' '
*           MAX_COPIES                     = '001'
        TABLES
          otf                            = otf
       EXCEPTIONS
         error_archiv                   = 1
         error_communicationtable       = 2
         error_connectiontable          = 3
         error_kernel                   = 4
         error_parameter                = 5
         error_format                   = 6
         OTHERS                         = 7
                .

Hope it helps

Regards

0 Kudos

Thank you

I think also this solution should work. I am working with Smartforms and followed solution found here

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

mixed with CONVERT_OTF_2_PDF after calling smartforms.

The really important thing with this strategy (for anyone will fight with same problem) is to convert output table of CONVERT_OTF_2_PDF (132 char) to a 255 char table ... something like:

LOOP AT it_lines INTO wa_lines.

     wa_file = wa_lines.                   " convert to string ...

     CONCATENATE file wa_file INTO file .   " ... and concatenate in 'file' string

   ENDLOOP.

   " build table from string 'file'

   DATA len TYPE i.                " lenght of portion analized

   DATA wa_doc_content LIKE LINE OF lt_doc_content.

   DO.

     len = STRLEN( file ).

     IF len GT 255.

       wa_doc_content = file(255).   " get component

       file = file+255.              " update left

     ELSE.

       wa_doc_content = file" get component

       CLEAR file.

     ENDIF.

     INSERT wa_doc_content INTO TABLE lt_doc_content.

     IF file IS INITIAL. "exit condition

       EXIT.

     ENDIF.

   ENDDO.

Former Member
0 Kudos

I think the best way for you would be to use Archive link. This is just customizing in SAP and you don't need any ABAP code. You define that SAP should print, store or print/store the output. The document's are then stored in the SAP system or in a content server.