Skip to Content
author's profile photo Former Member
Former Member

Sending PDF output attachment in e-mail to external users from BSP

Hi All,

Please gothrough the below requirement details :

Requirement Details:

Need to achieve the functionality of sending a PDF attachment of invoice to an external

e-mail address from the BSP Application.

Implementation Details:

The Print out Output determination is already done in the system. We are using SAP R/3 4.7 (620)

In the Transaction VF03 in the initial screen there is a menubar "Billing document" and underneath that menu there is a menu item called "Issue". If we click the "Issue" menu item all the output that are already proposed will be visible and we can select the printout Output determination and can issue a printout.

I had created a FM to call from BSP and that function module will take the Invoice number as input and will call the "VF03" transaction using BDC and will trigger the Sapscript Printout . I see the the sapscript in the spool after I call the Function module .

But I don't know how I can get the Spool request number for that Function module call from BSP page ????

I got struck in this approach...

If I know the Spool number after calling the function module the it's very easy to call the following FM's for sending a e-mail with the Invoice PDF attachment.

CONVERT_OTFSPOOLJOB_2_PDF

QCE1_CONVERT

SO_NEW_DOCUMENT_ATT_SEND_API1

Please let me know if anyone can help me in this ...

Please reply ASAP.

Thanks,

Greetson

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Feb 15, 2005 at 08:48 PM

    I have done something similar to this in the past. However I had to submit the output processing to the background as a job. I create a Job via code. In the first step I insert my program that will create the output (in this case you BDC to VF03).

    Then in the second step of the job I have a program to convert the spool to PDF. I use the following code to get the spool of a pervious step.

     clear jselect.
    *jselect-jobname = '*'.
      jselect-username = '*'.
    
    ****Have this program get its own Job Name
      call function 'GET_JOB_RUNTIME_INFO'
           importing
    *         EVENTID                 =
    *         EVENTPARM               =
    *         EXTERNAL_PROGRAM_ACTIVE =
              jobcount                = jselect-jobcount
              jobname                 = jselect-jobname
    *         STEPCOUNT               =
           exceptions
                no_runtime_info         = 1
                others                  = 2.
    
    ****Read the spool number for this job step.
      clear tbtcp.
      select single listident from tbtcp
             into tbtcp-listident
             where jobname   = jselect-jobname
               and jobcount  = jselect-jobcount
               and stepcount = step.
      if tbtcp-listident = 0.
        message i009 with step.
      endif.
    

    This might not be exactly what you are looking for, but perhaps it can put you on the correct path.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Thomas Jung

      I used JOB_OPEN, JOB_SUBMIT & JOB_CLOSE and was aable to retrive the Spool number from the table TBTCP.

      Thanks for your help...

      Here below is my code :

      REPORT ZTEST1.

      *data LISTOBJECT like ABAPLIST occurs 1000 with header line.

      *start-of-selection.

      *

      *sy-batch = ' '.

      *

      • SUBMIT WS_MONITOR_OUTB_DEL_FREE

      • VIA SELECTION-SCREEN

    • USING SELECTION-SET 'TEST'

    • EXPORTING LIST TO MEMORY

    • AND RETURN.

    • *CALL FUNCTION 'LIST_FROM_MEMORY'

      • TABLES

      • LISTOBJECT = listobject.

      • EXCEPTIONS

      • NOT_FOUND = 1

      • OTHERS = 2

      **break-point. .

      *IF SY-SUBRC <> 0.

      • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

      • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

      *ENDIF.

      *

      *CALL FUNCTION 'WRITE_LIST'

      • EXPORTING

      • WRITE_ONLY = 'X'

      • TABLES

      • LISTOBJECT = listobject

      • EXCEPTIONS

      • EMPTY_LIST = 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.

      *

      data : I_PDF like TLINE occurs 1000 with header line,

      V_PDF_BYTECOUNT type i,

      V_PDF_SPOOLID type TSP01-RQIDENT,

      V_OTF_PAGECOUNT type i,

      V_BTC_JOBNAME type TBTCJOB-JOBNAME,

      V_BTC_JOBCOUNT type TBTCJOB-JOBCOUNT.

      DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE.

      DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

      DATA: OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.

      DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

      DATA: RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE.

      DATA: DOC_CHNG LIKE SODOCCHGI1.

      DATA: TAB_LINES LIKE SY-TABIX.

      DATA: VAFILENAME(100) value 'greetson.pdf'.

      DATA: JOBDATA type SXJOBDATA.

      data arc_params type arc_params.

      data print_params type pri_params.

      data g_send_prog type syrepid value 'ZVF03_TEST_PROG'.

      data immediate type btcchar1.

      data: i_jobname type tbtcp-jobname,

      i_jobcount type tbtcp-jobcount,

      i_jobstepcount type tbtcp-stepcount.

      DATA RECIPIENT_OBJ LIKE SWOTOBJID.

      CONSTANTS: sx_true TYPE sx_boolean VALUE 'X'.

      Tables: tbtcp.

      clear jobdata.

      jobdata-jobname = 'zgre'.

      • --- start job immediately ---

      call function 'JOB_OPEN'

      exporting

      jobname = jobdata-jobname

      jobclass = 'A'

      importing

      jobcount = jobdata-jobcount

      exceptions

      cant_create_job = 1

      invalid_job_data = 2

      jobname_missing = 3

      others = 4.

      if sy-subrc <> 0.

      if not sy-msgid is initial.

      message id sy-msgid type 'I' number sy-msgno

      with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4

      raising no_job_created.

      else.

      raise no_job_created.

      endif.

      endif.

      • call function 'GET_PRINT_PARAMETERS'

      • exporting

      • mode = 'BATCH'

      • report = g_send_prog

      • no_dialog = 'X'

      • new_list_id = 'X' " neue Spoolliste pro Step

      • importing

      • out_parameters = print_params

      • out_archive_parameters = arc_params

      • exceptions

      • others = 0.

      call function 'JOB_SUBMIT'

      exporting

      • arcparams = arc_params

      authcknam = sy-uname

      jobcount = jobdata-jobcount

      jobname = jobdata-jobname

      • priparams = print_params

      report = g_send_prog

      • variant =

      exceptions

      bad_priparams = 1

      bad_xpgflags = 2

      invalid_jobdata = 3

      jobname_missing = 4

      job_notex = 5

      job_submit_failed = 6

      lock_failed = 7

      program_missing = 8

      prog_abap_and_extpg_set = 9

      others = 10.

      if sy-subrc <> 0.

      if not sy-msgid is initial.

      message id sy-msgid type 'I' number sy-msgno

      with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4

      raising no_job_created.

      else.

      raise no_job_created.

      endif.

      endif.

      immediate = sx_true.

      call function 'JOB_CLOSE'

      exporting

      jobcount = jobdata-jobcount

      jobname = jobdata-jobname

      strtimmed = immediate

      • calendar_id = startspecs-calendarid

      • event_id = startspecs-eventid

      • event_param = startspecs-eventparm

      • event_periodic = startspecs-periodic

      • laststrtdt = startspecs-laststrtdt

      • laststrttm = startspecs-laststrttm

      • prddays = startspecs-prddays

      • prdhours = startspecs-prdhours

      • prdmins = startspecs-prdmins

      • prdmonths = startspecs-prdmonths

      • prdweeks = startspecs-prdweeks

      • predjob_checkstat = startspecs-checkstat

      • pred_jobcount = startspecs-predjobcnt

      • pred_jobname = startspecs-predjob

      • sdlstrtdt = startspecs-sdlstrtdt

      • sdlstrttm = startspecs-sdlstrttm

      • startdate_restriction = startspecs-prdbehav

      • targetsystem = startspecs-instname

      • start_on_workday_not_before = startspecs-notbefore

      • start_on_workday_nr = startspecs-wdayno

      • workday_count_direction = startspecs-wdaycdir

      RECIPIENT_OBJ = RECIPIENT_OBJ

      exceptions

      cant_start_immediate = 1

      invalid_startdate = 2

      jobname_missing = 3

      job_close_failed = 4

      job_nosteps = 5

      job_notex = 6

      lock_failed = 7

      invalid_target = 8

      others = 9.

      if sy-subrc <> 0.

      if not sy-msgid is initial.

      message id sy-msgid type 'I' number sy-msgno

      with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4

      raising no_job_created.

      else.

      raise no_job_created.

      endif.

      endif.

      ****Read the spool number for this job step. clear tbtcp.

      select single listident

      from tbtcp

      into tbtcp-listident

      where jobname = jobdata-jobname

      and jobcount = jobdata-jobcount . "and

      " stepcount = i_jobstepcount.

      data : v_spoolno type TSP01-RQIDENT.

      v_spoolno = tbtcp-listident.

      CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

      EXPORTING

      SRC_SPOOLID = v_spoolno

      • NO_DIALOG =

      • DST_DEVICE =

      • PDF_DESTINATION =

      IMPORTING

      PDF_BYTECOUNT = V_PDF_BYTECOUNT

      PDF_SPOOLID = V_PDF_SPOOLID

      OTF_PAGECOUNT = V_OTF_PAGECOUNT

      BTC_JOBNAME = V_BTC_JOBNAME

      BTC_JOBCOUNT = V_BTC_JOBCOUNT

      TABLES

      PDF = I_PDF

      EXCEPTIONS

      ERR_NO_OTF_SPOOLJOB = 1

      ERR_NO_SPOOLJOB = 2

      ERR_NO_PERMISSION = 3

      ERR_CONV_NOT_POSSIBLE = 4

      ERR_BAD_DSTDEVICE = 5

      USER_CANCELLED = 6

      ERR_SPOOLERROR = 7

      ERR_TEMSEERROR = 8

      ERR_BTCJOB_OPEN_FAILED = 9

      ERR_BTCJOB_SUBMIT_FAILED = 10

      ERR_BTCJOB_CLOSE_FAILED = 11

      OTHERS = 12.

      IF SY-SUBRC <> 0.

      • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

      • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

      ENDIF.

      DOC_CHNG-OBJ_NAME = 'SAPSACRIPTMAIL'.

      DOC_CHNG-OBJ_DESCR = 'SAP_SACRIPT_MAIL.'.

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

      *CREATING THE MAIL TEXT.

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

      CONCATENATE 'This is a TestMail for Greetson on ' SY-DATUM

      SY-UZEIT INTO OBJTXT-LINE .

      APPEND OBJTXT.

      DESCRIBE TABLE OBJTXT LINES TAB_LINES.

      READ TABLE OBJTXT INDEX TAB_LINES.

      DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

      CLEAR OBJPACK-TRANSF_BIN.

      OBJPACK-HEAD_START = 1.

      OBJPACK-HEAD_NUM = 0.

      OBJPACK-BODY_START = 1.

      OBJPACK-BODY_NUM = TAB_LINES.

      OBJPACK-DOC_TYPE = 'RAW'.

      APPEND OBJPACK.

      CALL FUNCTION 'QCE1_CONVERT'

      TABLES

      T_SOURCE_TAB = I_PDF

      T_TARGET_TAB = OBJBIN

      EXCEPTIONS

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

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

      *CREATING THE PDF ATTACHMENT.

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

      DESCRIBE TABLE OBJBIN LINES TAB_LINES.

      OBJPACK-TRANSF_BIN = 'X'.

      OBJPACK-HEAD_START = 1.

      OBJPACK-HEAD_NUM = 1.

      OBJPACK-BODY_START = 1.

      OBJPACK-BODY_NUM = TAB_LINES.

      OBJPACK-DOC_TYPE = 'PDF'.

      OBJPACK-OBJ_NAME = 'Greetson'.

      OBJPACK-OBJ_DESCR = VAFILENAME.

      OBJPACK-DOC_SIZE = TAB_LINES * 255.

      APPEND OBJPACK.

      OBJHEAD = 'Greetson.PDF'.

      APPEND OBJHEAD.

      CLEAR OBJHEAD.

      VAFILENAME = 'Greetson'.

      • Creating the recipient list(ERS).

      RECLIST-RECEIVER = 'greetson@yahoo.com'.

      RECLIST-REC_TYPE = 'U'.

      APPEND RECLIST.

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

      *SEND MAIL FUNCTION MODULE.

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

      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

      EXPORTING

      DOCUMENT_DATA = DOC_CHNG

      PUT_IN_OUTBOX = 'X'

      TABLES

      PACKING_LIST = OBJPACK

      OBJECT_HEADER = OBJHEAD

      CONTENTS_BIN = OBJBIN

      CONTENTS_TXT = OBJTXT

      RECEIVERS = RECLIST

      EXCEPTIONS

      TOO_MANY_RECEIVERS = 1

      DOCUMENT_NOT_SENT = 2

      OPERATION_NO_AUTHORIZATION = 4

      OTHERS = 99.

      IF SY-SUBRC <> 0.

      • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

      • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

      ENDIF.

      REFRESH RECLIST.

      Thanks,

      Greetson

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.