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: 

Smartform is converted to PDF,how to Mail

kiran_k8
Active Contributor
0 Kudos

Hi Folks,

I had customised the Invoice smartform and converted it into pdf.Now I want SDN experts help so that I can add a feature where the user can send it through mail too.

Can anyone here please let me know how to do that?

Note:-PDF conversion is done.

K.Kiran.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Kiran,

When you call the smart form FM, you can get the OTF data in a tables parameter.

You can convert the OTF data into PDF data using the function module.

CONVERT_OTF_2_PDF or SX_OBJECT_CONVERT_OTF_PDF

.

then you can build the attachment and send a mail using the FM:

SO_NEW_DOCUMENT_ATT_SEND_API1

REPORT zptpfrm202p_pogr_pr_instr MESSAGE-ID zmm.

----


  • TABLES *

----


  • Database table made for getting information about PRINTPREVIEW and

  • PRINT command more than one times

TABLES: zgr_table.

TYPE-POOLS:syscr.

----


  • GLOBAL TYPE DECLARATION *

----


DATA: zdoc_output_info TYPE ssfcrespd, "SF:Return Document Inf.

zjob_output_info TYPE ssfcrescl, "SF:Return value at end of

  • form printing

i_control TYPE ssfctrlop ,

i_output_options TYPE ssfcompop,

zjob_output_opts TYPE ssfcresop. "SF:Return value at start

  • of form printing

*This internal table is used for storing Document Segment: Material

DATA: BEGIN OF i_mseg.

INCLUDE STRUCTURE mseg.

DATA: END OF i_mseg.

  • This internal table is used for storing Header: Material Document

DATA: BEGIN OF i_mkpf.

INCLUDE STRUCTURE mkpf.

DATA: END OF i_mkpf.

*Variables

DATA flag(1) TYPE c.

DATA: vfile TYPE string.

----


  • SELECTION-SCREEN *

----


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.

PARAMETERS:p_mblnr TYPE mkpf-mblnr OBLIGATORY MATCHCODE OBJECT zganesh,

p_mjahr TYPE mkpf-mjahr OBLIGATORY MATCHCODE OBJECT zganesh1,

p_zeile TYPE mseg-zeile OBLIGATORY MATCHCODE OBJECT zganesh2.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-001.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN POSITION 10.

PARAMETER:r_disp RADIOBUTTON GROUP g1 USER-COMMAND u1 DEFAULT 'X'.

SELECTION-SCREEN:COMMENT 15(10) text-002 .

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN POSITION 10.

PARAMETERS: r_down RADIOBUTTON GROUP g1.

SELECTION-SCREEN:COMMENT 15(10) text-003.

*PARAMETERS: v_file LIKE rlgrap-filename .

*SELECTION-SCREEN:COMMENT 70(50) text-005.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN POSITION 10.

PARAMETERS: r_print RADIOBUTTON GROUP g1 .

SELECTION-SCREEN:COMMENT 15(10) text-004.

SELECTION-SCREEN END OF LINE.

PARAMETERS: v_file LIKE rlgrap-filename MODIF ID g12.

SELECTION-SCREEN END OF BLOCK b2.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR v_file.

DATA : wlv_field_name LIKE dynpread-fieldname,

wlv_file_name LIKE ibipparms-path.

wlv_field_name = v_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

field_name = wlv_field_name

IMPORTING

file_name = wlv_file_name.

IF sy-subrc EQ 0.

vfile = wlv_file_name.

v_file = wlv_file_name.

ENDIF.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

IF screen-name = 'V_FILE'.

IF r_disp EQ 'X' OR r_print EQ 'X'.

screen-input = 0.

ELSE.

screen-input = '1'.

ENDIF.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

----


  • START-OF-SELECTION EVENT *

----


START-OF-SELECTION.

----


  • CALLING CONVERSION FUNCTION MODULE 'CONVERSION_EXIT_ALPHA_INPUT' *

----


*Conversion function module for appending 00 befor MBLNR FIELD

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = p_mblnr

IMPORTING

output = p_mblnr.

  • Call subroutine for fetching data from database

PERFORM get_data.

----


  • END-OF-SELECTION EVENT *

----


END-OF-SELECTION.

  • Call subroutine for calling and processing smartform

PERFORM call_smartform.

&----


*& Form get_data

&----


  • Subroutine for fetching data from database

----


FORM get_data .

  • Fetching data from MKPF table with using parameters MBLNR and MJAHR

SELECT SINGLE * FROM mkpf

INTO i_mkpf

WHERE mblnr = p_mblnr

AND mjahr = p_mjahr.

IF sy-subrc EQ 0.

  • Fetching data from MSEG with using parameters MBLNR,ZEILE and MJAHR

SELECT SINGLE * FROM mseg

INTO i_mseg

WHERE mblnr = i_mkpf-mblnr

AND mjahr = i_mkpf-mjahr

AND zeile = p_zeile.

IF sy-subrc NE 0.

CLEAR i_mseg.

ENDIF.

ELSE.

MESSAGE i000.

EXIT.

ENDIF.

ENDFORM. " get_data

&----


*& Form call_smartform

&----


  • Subroutine for calling smartform

----


FORM call_smartform .

  • Local template used in the processing output of smartform

TYPES: BEGIN OF lt_ztable,

mandt TYPE sy-mandt,

mblnr TYPE mseg-mblnr,

flag(1) TYPE c,

END OF lt_ztable.

CONSTANTS: c_x(1) TYPE c VALUE 'X'.

  • Workarea

DATA: lw_ztable TYPE lt_ztable.

*Variable used in the smartform

DATA: lv_form(30) TYPE c,

lv_fm_name(30) TYPE c.

lv_form = 'ZPTPFRM202L_POGR'.

*Calling function module SSF_FUNCTION_MODULE_NAME which gives new name

*to the function module that will generated by smartform.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = lv_form

IMPORTING

fm_name = lv_fm_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.

*Calling function module that will be generated by smartform

IF r_disp = c_x.

i_output_options-tdimmed = space.

i_output_options-tdnewid = c_x.

i_output_options-tddest = 'LOCL'.

i_control-no_dialog = 'X'.

i_control-preview = 'X'.

ELSEIF r_print = c_x.

i_output_options-tdimmed = c_x.

i_output_options-tddest = 'LOCL'.

i_control-no_dialog = c_x.

ELSE.

i_output_options-tdimmed = space.

i_output_options-tdnewid = c_x.

i_output_options-tddest = 'LOCL'.

i_control-getotf = 'X'.

i_control-preview = space.

i_control-no_dialog = c_x.

flag = c_x.

ENDIF.

CALL FUNCTION lv_fm_name

EXPORTING

control_parameters = i_control

output_options = i_output_options

user_settings = space

zmkpf = i_mkpf

zmseg = i_mseg

IMPORTING

document_output_info = zdoc_output_info

job_output_info = zjob_output_info

job_output_options = zjob_output_opts

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.

  • Modify the database table if it found the print command

IF zjob_output_opts-tdpreview NE c_x.

lw_ztable-mandt = sy-mandt.

lw_ztable-mblnr = p_mblnr.

lw_ztable-flag = c_x.

MODIFY zgr_table FROM lw_ztable.

CLEAR lw_ztable.

ENDIF.

IF flag EQ c_x.

DATA: li_lines LIKE tline OCCURS 100 WITH HEADER LINE.

DATA: lv_file TYPE string,

lbin_fsiz TYPE i.

lv_file = v_file.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

IMPORTING

bin_filesize = lbin_fsiz

TABLES

otf = zjob_output_info-otfdata

lines = li_lines

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

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

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = lbin_fsiz

filename = lv_file

filetype = 'BIN'

TABLES

data_tab = li_lines

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22.

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. " call_smartform

Hope this resolves your query.

<b>Reward all the helpful answers.</b>

Regards

10 REPLIES 10

Former Member
0 Kudos

Hi Kiran,

When you call the smart form FM, you can get the OTF data in a tables parameter.

You can convert the OTF data into PDF data using the function module.

CONVERT_OTF_2_PDF or SX_OBJECT_CONVERT_OTF_PDF

.

then you can build the attachment and send a mail using the FM:

SO_NEW_DOCUMENT_ATT_SEND_API1

REPORT zptpfrm202p_pogr_pr_instr MESSAGE-ID zmm.

----


  • TABLES *

----


  • Database table made for getting information about PRINTPREVIEW and

  • PRINT command more than one times

TABLES: zgr_table.

TYPE-POOLS:syscr.

----


  • GLOBAL TYPE DECLARATION *

----


DATA: zdoc_output_info TYPE ssfcrespd, "SF:Return Document Inf.

zjob_output_info TYPE ssfcrescl, "SF:Return value at end of

  • form printing

i_control TYPE ssfctrlop ,

i_output_options TYPE ssfcompop,

zjob_output_opts TYPE ssfcresop. "SF:Return value at start

  • of form printing

*This internal table is used for storing Document Segment: Material

DATA: BEGIN OF i_mseg.

INCLUDE STRUCTURE mseg.

DATA: END OF i_mseg.

  • This internal table is used for storing Header: Material Document

DATA: BEGIN OF i_mkpf.

INCLUDE STRUCTURE mkpf.

DATA: END OF i_mkpf.

*Variables

DATA flag(1) TYPE c.

DATA: vfile TYPE string.

----


  • SELECTION-SCREEN *

----


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.

PARAMETERS:p_mblnr TYPE mkpf-mblnr OBLIGATORY MATCHCODE OBJECT zganesh,

p_mjahr TYPE mkpf-mjahr OBLIGATORY MATCHCODE OBJECT zganesh1,

p_zeile TYPE mseg-zeile OBLIGATORY MATCHCODE OBJECT zganesh2.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-001.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN POSITION 10.

PARAMETER:r_disp RADIOBUTTON GROUP g1 USER-COMMAND u1 DEFAULT 'X'.

SELECTION-SCREEN:COMMENT 15(10) text-002 .

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN POSITION 10.

PARAMETERS: r_down RADIOBUTTON GROUP g1.

SELECTION-SCREEN:COMMENT 15(10) text-003.

*PARAMETERS: v_file LIKE rlgrap-filename .

*SELECTION-SCREEN:COMMENT 70(50) text-005.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN POSITION 10.

PARAMETERS: r_print RADIOBUTTON GROUP g1 .

SELECTION-SCREEN:COMMENT 15(10) text-004.

SELECTION-SCREEN END OF LINE.

PARAMETERS: v_file LIKE rlgrap-filename MODIF ID g12.

SELECTION-SCREEN END OF BLOCK b2.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR v_file.

DATA : wlv_field_name LIKE dynpread-fieldname,

wlv_file_name LIKE ibipparms-path.

wlv_field_name = v_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

field_name = wlv_field_name

IMPORTING

file_name = wlv_file_name.

IF sy-subrc EQ 0.

vfile = wlv_file_name.

v_file = wlv_file_name.

ENDIF.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

IF screen-name = 'V_FILE'.

IF r_disp EQ 'X' OR r_print EQ 'X'.

screen-input = 0.

ELSE.

screen-input = '1'.

ENDIF.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

----


  • START-OF-SELECTION EVENT *

----


START-OF-SELECTION.

----


  • CALLING CONVERSION FUNCTION MODULE 'CONVERSION_EXIT_ALPHA_INPUT' *

----


*Conversion function module for appending 00 befor MBLNR FIELD

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = p_mblnr

IMPORTING

output = p_mblnr.

  • Call subroutine for fetching data from database

PERFORM get_data.

----


  • END-OF-SELECTION EVENT *

----


END-OF-SELECTION.

  • Call subroutine for calling and processing smartform

PERFORM call_smartform.

&----


*& Form get_data

&----


  • Subroutine for fetching data from database

----


FORM get_data .

  • Fetching data from MKPF table with using parameters MBLNR and MJAHR

SELECT SINGLE * FROM mkpf

INTO i_mkpf

WHERE mblnr = p_mblnr

AND mjahr = p_mjahr.

IF sy-subrc EQ 0.

  • Fetching data from MSEG with using parameters MBLNR,ZEILE and MJAHR

SELECT SINGLE * FROM mseg

INTO i_mseg

WHERE mblnr = i_mkpf-mblnr

AND mjahr = i_mkpf-mjahr

AND zeile = p_zeile.

IF sy-subrc NE 0.

CLEAR i_mseg.

ENDIF.

ELSE.

MESSAGE i000.

EXIT.

ENDIF.

ENDFORM. " get_data

&----


*& Form call_smartform

&----


  • Subroutine for calling smartform

----


FORM call_smartform .

  • Local template used in the processing output of smartform

TYPES: BEGIN OF lt_ztable,

mandt TYPE sy-mandt,

mblnr TYPE mseg-mblnr,

flag(1) TYPE c,

END OF lt_ztable.

CONSTANTS: c_x(1) TYPE c VALUE 'X'.

  • Workarea

DATA: lw_ztable TYPE lt_ztable.

*Variable used in the smartform

DATA: lv_form(30) TYPE c,

lv_fm_name(30) TYPE c.

lv_form = 'ZPTPFRM202L_POGR'.

*Calling function module SSF_FUNCTION_MODULE_NAME which gives new name

*to the function module that will generated by smartform.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = lv_form

IMPORTING

fm_name = lv_fm_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.

*Calling function module that will be generated by smartform

IF r_disp = c_x.

i_output_options-tdimmed = space.

i_output_options-tdnewid = c_x.

i_output_options-tddest = 'LOCL'.

i_control-no_dialog = 'X'.

i_control-preview = 'X'.

ELSEIF r_print = c_x.

i_output_options-tdimmed = c_x.

i_output_options-tddest = 'LOCL'.

i_control-no_dialog = c_x.

ELSE.

i_output_options-tdimmed = space.

i_output_options-tdnewid = c_x.

i_output_options-tddest = 'LOCL'.

i_control-getotf = 'X'.

i_control-preview = space.

i_control-no_dialog = c_x.

flag = c_x.

ENDIF.

CALL FUNCTION lv_fm_name

EXPORTING

control_parameters = i_control

output_options = i_output_options

user_settings = space

zmkpf = i_mkpf

zmseg = i_mseg

IMPORTING

document_output_info = zdoc_output_info

job_output_info = zjob_output_info

job_output_options = zjob_output_opts

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.

  • Modify the database table if it found the print command

IF zjob_output_opts-tdpreview NE c_x.

lw_ztable-mandt = sy-mandt.

lw_ztable-mblnr = p_mblnr.

lw_ztable-flag = c_x.

MODIFY zgr_table FROM lw_ztable.

CLEAR lw_ztable.

ENDIF.

IF flag EQ c_x.

DATA: li_lines LIKE tline OCCURS 100 WITH HEADER LINE.

DATA: lv_file TYPE string,

lbin_fsiz TYPE i.

lv_file = v_file.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

IMPORTING

bin_filesize = lbin_fsiz

TABLES

otf = zjob_output_info-otfdata

lines = li_lines

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

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

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = lbin_fsiz

filename = lv_file

filetype = 'BIN'

TABLES

data_tab = li_lines

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22.

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. " call_smartform

Hope this resolves your query.

<b>Reward all the helpful answers.</b>

Regards

Former Member
0 Kudos

Hi,

Check this blog.

/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

Regards,

Dhana

Former Member
0 Kudos

Hi Kiran,

check this sample program which will convert spool to pdf and will send mail .


PARAMETER: p_email1 LIKE somlreci1-receiver
                    DEFAULT 'aaaa@aaaa.com',
           p_sender LIKE somlreci1-receiver
                    DEFAULT 'aaa@aaaa.com',
           p_delspl AS CHECKBOX.

*DATA DECLARATION
DATA: gd_recsize TYPE i.

* Spool IDs
TYPES: BEGIN OF t_tbtcp.
        INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.
DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
      wa_tbtcp TYPE t_tbtcp.

* Job Runtime Parameters
DATA: gd_eventid LIKE tbtcm-eventid,
      gd_eventparm LIKE tbtcm-eventparm,
      gd_external_program_active LIKE tbtcm-xpgactive,
      gd_jobcount LIKE tbtcm-jobcount,
      gd_jobname LIKE tbtcm-jobname,
      gd_stepcount LIKE tbtcm-stepcount,
      gd_error    TYPE sy-subrc,
      gd_reciever TYPE sy-subrc.


DATA:  w_recsize TYPE i.

DATA: gd_subject   LIKE sodocchgi1-obj_descr,
      it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      gd_sender_type     LIKE soextreci1-adr_typ,
      gd_attachment_desc TYPE so_obj_nam,
      gd_attachment_name TYPE so_obj_des.

* Spool to PDF conversions
DATA: gd_spool_nr LIKE tsp01-rqident,
      gd_destination LIKE rlgrap-filename,
      gd_bytecount LIKE tst01-dsize,
      gd_buffer TYPE string.

* Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0.
        INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.

CONSTANTS: c_dev LIKE  sy-sysid VALUE 'DEV',
           c_no(1)     TYPE c   VALUE ' ',
           c_device(4) TYPE c   VALUE 'LOCL'.

************************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.

* Write statement to represent report output. Spool request is created
* if write statement is executed in background. This could also be an
* ALV grid which would be converted to PDF without any extra effort
  WRITE 'Hello World'.
  new-page.
  commit work.
  new-page print off.

  IF sy-batch EQ 'X'.
    PERFORM get_job_details.
    PERFORM obtain_spool_id.

************************************
*** Alternative way could be to submit another program and store spool
*** id into memory.
*submit ZSPOOLTOPDF2
*        to sap-spool
*        spool parameters   %_print
*        archive parameters %_print
*        without spool dynpro
*        and return.
************************************

* Get spool id from program called above
*  IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.

    PERFORM convert_spool_to_pdf.
    PERFORM process_email.

    if p_delspl EQ 'X'.
      PERFORM delete_spool.
    endif.

    IF sy-sysid = c_dev.
      wait up to 5 seconds.
      SUBMIT rsconn01 WITH mode   = 'INT'
                      WITH output = 'X'
                      AND RETURN.
    ENDIF.
  ELSE.
    SKIP.
    WRITE:/ 'Program must be executed in background in-order for spool',
            'request to be created.'.
  ENDIF.


*---------------------------------------------------------------------*
*       FORM obtain_spool_id                                          *
*---------------------------------------------------------------------*
FORM obtain_spool_id.
  CHECK NOT ( gd_jobname IS INITIAL ).
  CHECK NOT ( gd_jobcount IS INITIAL ).

  SELECT * FROM  tbtcp
                 INTO TABLE it_tbtcp
                 WHERE      jobname     = gd_jobname
                 AND        jobcount    = gd_jobcount
                 AND        stepcount   = gd_stepcount
                 AND        listident   <> '0000000000'
                 ORDER BY   jobname
                            jobcount
                            stepcount.

  READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
  IF sy-subrc = 0.
    message s004(zdd) with gd_spool_nr.
    gd_spool_nr = wa_tbtcp-listident.
    MESSAGE s004(zdd) WITH gd_spool_nr.
  ELSE.
    MESSAGE s005(zdd).
  ENDIF.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM get_job_details                                          *
*---------------------------------------------------------------------*
FORM get_job_details.
* Get current job details
  CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
       IMPORTING
            eventid                 = gd_eventid
            eventparm               = gd_eventparm
            external_program_active = gd_external_program_active
            jobcount                = gd_jobcount
            jobname                 = gd_jobname
            stepcount               = gd_stepcount
       EXCEPTIONS
            no_runtime_info         = 1
            OTHERS                  = 2.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM convert_spool_to_pdf                                     *
*---------------------------------------------------------------------*
FORM convert_spool_to_pdf.

  CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
       EXPORTING
            src_spoolid              = gd_spool_nr
            no_dialog                = c_no
            dst_device               = c_device
       IMPORTING
            pdf_bytecount            = gd_bytecount
       TABLES
            pdf                      = it_pdf_output
       EXCEPTIONS
            err_no_abap_spooljob     = 1
            err_no_spooljob          = 2
            err_no_permission        = 3
            err_conv_not_possible    = 4
            err_bad_destdevice       = 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.

  CHECK sy-subrc = 0.

* Transfer the 132-long strings to 255-long strings
  LOOP AT it_pdf_output.
    TRANSLATE it_pdf_output USING ' ~'.
    CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
  ENDLOOP.

  TRANSLATE gd_buffer USING '~ '.

  DO.
    it_mess_att = gd_buffer.
    APPEND it_mess_att.
    SHIFT gd_buffer LEFT BY 255 PLACES.
    IF gd_buffer IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM process_email                                            *
*---------------------------------------------------------------------*
FORM process_email.
  DESCRIBE TABLE it_mess_att LINES gd_recsize.
  CHECK gd_recsize > 0.
  PERFORM send_email USING p_email1.
*  perform send_email using p_email2.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM send_email                                               *
*---------------------------------------------------------------------*
*  -->  p_email                                                       *
*---------------------------------------------------------------------*
FORM send_email USING p_email.
  CHECK NOT ( p_email IS INITIAL ).

  REFRESH it_mess_bod.

* Default subject matter
  gd_subject         = 'Subject'.
  gd_attachment_desc = 'Attachname'.
*  CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
  it_mess_bod        = 'Message Body text, line 1'.
  APPEND it_mess_bod.
  it_mess_bod        = 'Message Body text, line 2...'.
  APPEND it_mess_bod.

* If no sender specified - default blank
  IF p_sender EQ space.
    gd_sender_type  = space.
  ELSE.
    gd_sender_type  = 'INT'.
  ENDIF.


* Send file by email as .xls speadsheet
  PERFORM send_file_as_email_attachment
                               tables it_mess_bod
                                      it_mess_att
                                using p_email
                                      'Example .xls documnet attachment'
                                      'PDF'
                                      gd_attachment_name
                                      gd_attachment_desc
                                      p_sender
                                      gd_sender_type
                             changing gd_error
                                      gd_reciever.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM delete_spool                                             *
*---------------------------------------------------------------------*
FORM delete_spool.
  DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.

  ld_spool_nr = gd_spool_nr.

  CHECK p_delspl <> c_no.
  CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
       EXPORTING
            spoolid = ld_spool_nr.
ENDFORM.


*&---------------------------------------------------------------------*
*&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
*&---------------------------------------------------------------------*
*       Send email
*----------------------------------------------------------------------*
FORM send_file_as_email_attachment tables it_message
                                          it_attach
                                    using p_email
                                          p_mtitle
                                          p_format
                                          p_filename
                                          p_attdescription
                                          p_sender_address
                                          p_sender_addres_type
                                 changing p_error
                                          p_reciever.


  DATA: ld_error    TYPE sy-subrc,
        ld_reciever TYPE sy-subrc,
        ld_mtitle LIKE sodocchgi1-obj_descr,
        ld_email LIKE  somlreci1-receiver,
        ld_format TYPE  so_obj_tp ,
        ld_attdescription TYPE  so_obj_nam ,
        ld_attfilename TYPE  so_obj_des ,
        ld_sender_address LIKE  soextreci1-receiver,
        ld_sender_address_type LIKE  soextreci1-adr_typ,
        ld_receiver LIKE  sy-subrc.

data:   t_packing_list like sopcklsti1 occurs 0 with header line,
        t_contents like solisti1 occurs 0 with header line,
        t_receivers like somlreci1 occurs 0 with header line,
        t_attachment like solisti1 occurs 0 with header line,
        t_object_header like solisti1 occurs 0 with header line,
        w_cnt type i,
        w_sent_all(1) type c,
        w_doc_data like sodocchgi1.


  ld_email   = p_email.
  ld_mtitle = p_mtitle.
  ld_format              = p_format.
  ld_attdescription      = p_attdescription.
  ld_attfilename         = p_filename.
  ld_sender_address      = p_sender_address.
  ld_sender_address_type = p_sender_addres_type.


* Fill the document data.
  w_doc_data-doc_size = 1.

* Populate the subject/generic message attributes
  w_doc_data-obj_langu = sy-langu.
  w_doc_data-obj_name  = 'SAPRPT'.
  w_doc_data-obj_descr = ld_mtitle .
  w_doc_data-sensitivty = 'F'.

* Fill the document data and get size of attachment
  CLEAR w_doc_data.
  READ TABLE it_attach INDEX w_cnt.
  w_doc_data-doc_size =
     ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
  w_doc_data-obj_langu  = sy-langu.
  w_doc_data-obj_name   = 'SAPRPT'.
  w_doc_data-obj_descr  = ld_mtitle.
  w_doc_data-sensitivty = 'F'.
  CLEAR t_attachment.
  REFRESH t_attachment.
  t_attachment[] = it_attach[].

* Describe the body of the message
  CLEAR t_packing_list.
  REFRESH t_packing_list.
  t_packing_list-transf_bin = space.
  t_packing_list-head_start = 1.
  t_packing_list-head_num = 0.
  t_packing_list-body_start = 1.
  DESCRIBE TABLE it_message LINES t_packing_list-body_num.
  t_packing_list-doc_type = 'RAW'.
  APPEND t_packing_list.

* Create attachment notification
  t_packing_list-transf_bin = 'X'.
  t_packing_list-head_start = 1.
  t_packing_list-head_num   = 1.
  t_packing_list-body_start = 1.

  DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
  t_packing_list-doc_type   =  ld_format.
  t_packing_list-obj_descr  =  ld_attdescription.
  t_packing_list-obj_name   =  ld_attfilename.
  t_packing_list-doc_size   =  t_packing_list-body_num * 255.
  APPEND t_packing_list.

* Add the recipients email address
  CLEAR t_receivers.
  REFRESH t_receivers.
  t_receivers-receiver = ld_email.
  t_receivers-rec_type = 'U'.
  t_receivers-com_type = 'INT'.
  t_receivers-notif_del = 'X'.
  t_receivers-notif_ndel = 'X'.
  APPEND t_receivers.

  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
       EXPORTING
            document_data              = w_doc_data
            put_in_outbox              = 'X'
            sender_address             = ld_sender_address
            sender_address_type        = ld_sender_address_type
            commit_work                = 'X'
       IMPORTING
            sent_to_all                = w_sent_all
       TABLES
            packing_list               = t_packing_list
            contents_bin               = t_attachment
            contents_txt               = it_message
            receivers                  = t_receivers
       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.

* Populate zerror return code
  ld_error = sy-subrc.

* Populate zreceiver return code
  LOOP AT t_receivers.
    ld_receiver = t_receivers-retrn_code.
  ENDLOOP.
ENDFORM.

Regards,

Raghav

kiran_k8
Active Contributor
0 Kudos

Hi Folks,

Just help me with the code that needs to be added so that I can send the smartform through mail.

K.Kiran.

Former Member
0 Kudos

Use the following code .

FORM CONVERT_OTF_PDF.

DATA WA_OBJBIN LIKE SOLISTI1.

DESCRIBE TABLE OBJTXT LINES PDFLINES.

*-- A funtion module to convert otf to pdf format

CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'

EXPORTING

FORMAT_SRC = 'OTF'

FORMAT_DST = 'PDF'

DEVTYPE = 'PRINTER'

  • FUNCPARA =

LEN_IN = PDFLINES

IMPORTING

LEN_OUT = PDFLINES

TABLES

CONTENT_IN = OBJTXT

CONTENT_OUT = OBJBIN

EXCEPTIONS

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

CLEAR TAB_LINES.

APPEND 'Oil Statement' TO OBJTXT.

APPEND INITIAL LINE TO OBJTXT.

APPEND INITIAL LINE TO OBJTXT.

DESCRIBE TABLE OBJBIN LINES PDFLINES.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

REFRESH OBJTXT. "added by GMREDDY

*-- a perform to do the email

IF V_COPIES_NO = 'TELEFAX'.

PERFORM DO_THE_EMAIL_FAX.

ELSE.

PERFORM DO_THE_EMAIL.

ENDIF.

ENDFORM.

for the DO_THE_EMAIL.....

&----


*& Form do_the_email

&----


  • Mailing with the function module so_new_document_att_send_api1

----


FORM DO_THE_EMAIL.

CLEAR V_MESS2.

*-- creation of the entry for the compressed document

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

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK.

*-- creation of the entry for the attachment

CLEAR OBJPACK.

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = PDFLINES.

  • objpack-objname =

OBJPACK-OBJ_DESCR = 'Oil Statement.PDF'.

OBJPACK-DOC_TYPE = 'PDF'.

OBJPACK-DOC_SIZE = PDFLINES * 255.

APPEND OBJPACK.

*-- populating the t_receivers with mail address

  • READ TABLE t_adr6 INDEX 1.

IF NOT T_ADR6[] IS INITIAL.

LOOP AT T_ADR6.

T_RECEIVERS-RECEIVER = T_ADR6-SMTP_ADDR.

T_RECEIVERS-REC_TYPE = 'U'.

APPEND T_RECEIVERS.

CLEAR T_RECEIVERS.

ENDLOOP.

ENDIF.

IF SY-SYSID NE 'S8P' AND NOT P_EMAIL IS INITIAL.

CLEAR T_RECEIVERS.

REFRESH T_RECEIVERS.

MOVE P_EMAIL TO T_RECEIVERS-RECEIVER.

T_RECEIVERS-REC_TYPE = 'U'.

APPEND T_RECEIVERS.

CLEAR T_RECEIVERS.

ENDIF.

*added by GMREDDY

  • Creation of the document to be sent

DOC_DATA-OBJ_NAME = 'Oil Statement'.

DOC_DATA-OBJ_DESCR = 'Oil Statement'.

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

*-- Calling a function module to send an E-mail

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_DATA

PUT_IN_OUTBOX = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

PACKING_LIST = OBJPACK

OBJECT_HEADER = OBJHEAD

CONTENTS_BIN = OBJBIN

CONTENTS_TXT = OBJTXT

  • contents_hex = objbin

  • OBJECT_PARA =

  • OBJECT_PARB =

RECEIVERS = T_RECEIVERS

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.

V_MESS2 = ' Email ID Unavailable'(I01).

ENDIF.

  • CONCATENATE v_mess1 v_mess2 INTO t_exception_report-output

  • SEPARATED BY space.

CLEAR : V_MESS2,

T_RECEIVERS[].

REFRESH: OBJPACK,OBJHEAD ,OBJBIN ,OBJTXT.

CLEAR:DOC_DATA.

ENDFORM. " do_the_email

0 Kudos

Hi Kiran,

It is showing that OBJXTEXT IS UNKNOWN.

K.Kiran.

Former Member
0 Kudos

hi,

I suppose u already have the PDF data in an internal table .

Make use of the function module SO_NEW_DOCUMENT_ATT_SEND_API1 to send the mails.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = l_t_doc_data ---> SUBJECT OF THE MAIL

put_in_outbox = 'X'

TABLES

packing_list = l_t_pack

object_header = l_t_objhead --> NAME OF ATTACHED DOCUMENT

contents_bin = g_t_con_bin --> ATTACHMENT (PDF INT TAB)

contents_txt = l_t_con_text --> BODY

receivers = l_t_receivers --> RECEIVERS OF THE MAIL

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.

for packing list (l_t_pack )-->

  • Creation of the entry for the compressed document

CLEAR l_t_pack-transf_bin.

l_t_pack-head_start = 1.

l_t_pack-head_num = 0.

l_t_pack-body_start = 1.

l_t_pack-body_num = l_tablines1.

l_t_pack-doc_size = l_tablines1 * 255.

l_t_pack-doc_type = 'RAW'.

APPEND l_t_pack.

  • Creation of the entry for the attachment document

l_t_pack-transf_bin = 'X'.

l_t_pack-head_start = 1.

l_t_pack-head_num = 1.

l_t_pack-body_start = 1.

l_t_pack-body_num = l_tablines2.

l_t_pack-doc_type = 'PDF'.

l_t_pack-doc_size = l_tablines2 * 255.

l_t_pack-obj_descr = text-011.

APPEND l_t_pack.

i HOPE THIS WILL HEPL YOU....

REVERT BACK IF YOU HAVE NAY CONFUSIONS.

REWARD POINTS IF YOU GET THE SOLUTION....

Rashmi

0 Kudos

Hi Rashmi,

This is the code which we are using to convert the smartform to pdf and everything is fine.Kindly do the needed so that it can be sent as a mail,if you find time.

REPORT rlb_invoice.

----


  • Print of a invoice by SAPscript SMART FORMS *

----


  • declaration of data

*INCLUDE YRLB_INVOICE_DATA_DECLARE.

INCLUDE rlb_invoice_data_declare.

  • definition of forms

*INCLUDE YRLB_INVOICE_FORM01.

INCLUDE rlb_invoice_form01.

*INCLUDE YRLB_PRINT_FORMS.

INCLUDE rlb_print_forms.

data: ans type c,

ans_hold type c,

pdf_file_size TYPE i,

gs_output_info TYPE SSFCRESCL,

t_pdf_data TYPE TABLE OF tline,

Filename type string,

OUTPUTOPTIONS TYPE SSFCOMPOP,

*gs_output_info TYPE ssfcrescl,

gs_control_pars TYPE ssfctrlop,

gt_docs LIKE TABLE OF docs. "#EC *

data : JOB_OUTPUT_INFO type SSFCRESCL. "#EC *

constants : file LIKE rlgrap-filename value SPACE, "'C:\temp\', "#EC NOTEXT

c_extn(4) value '.pdf'.

----


  • FORM ENTRY

----


FORM entry USING return_code us_screen. "#EC *

DATA: lf_retcode TYPE sy-subrc.

CLEAR retcode.

xscreen = us_screen.

PERFORM processing USING us_screen

CHANGING lf_retcode.

IF lf_retcode NE 0.

return_code = 1.

ELSE.

return_code = 0.

ENDIF.

ENDFORM. "ENTRY

----


  • FORM PROCESSING *

----


FORM processing USING proc_screen

CHANGING cf_retcode. "#EC *

TABLES : ZWIRETEXT, "#EC *

VBRK. "#EC *

DATA: ls_print_data_to_read TYPE lbbil_print_data_to_read.

DATA: ls_bil_invoice TYPE lbbil_invoice.

DATA: lf_fm_name TYPE rs38l_fnam.

DATA: ls_control_param TYPE ssfctrlop.

DATA: ls_composer_param TYPE ssfcompop.

DATA: ls_recipient TYPE swotobjid.

DATA: ls_sender TYPE swotobjid.

DATA: lf_formname TYPE tdsfname.

DATA: ls_addr_key LIKE addr_key.

DATA: ls_dlv-land LIKE vbrk-land1. "#EC *

DATA: ls_job_info TYPE ssfcrescl.

*****

DATA: GS_ITAB3 TYPE STANDARD TABLE OF zwiretext WITH HEADER LINE.

DATA : GS_ITAB TYPE STANDARD TABLE OF STXH WITH HEADER LINE,

GS_ITAB1 TYPE STANDARD TABLE OF TLINE WITH HEADER LINE,

GS_ITAB2 TYPE STANDARD TABLE OF TTXIT WITH HEADER LINE.

*****

  • SmartForm from customizing table TNAPR

lf_formname = tnapr-sform.

  • determine print data

PERFORM set_print_data_to_read USING lf_formname

CHANGING ls_print_data_to_read

cf_retcode.

IF cf_retcode = 0.

  • select print data

PERFORM get_data USING ls_print_data_to_read

CHANGING ls_addr_key

ls_dlv-land

ls_bil_invoice

cf_retcode.

ENDIF.

IF cf_retcode = 0.

PERFORM set_print_param USING ls_addr_key

ls_dlv-land

CHANGING ls_control_param

ls_composer_param

ls_recipient

ls_sender

cf_retcode.

ENDIF.

IF cf_retcode = 0.

  • determine smartform function module for invoice

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING formname = lf_formname

  • variant = ' '

  • direct_call = ' '

IMPORTING fm_name = lf_fm_name

EXCEPTIONS no_form = 1

no_function_module = 2

OTHERS = 3.

IF sy-subrc <> 0.

  • error handling

cf_retcode = sy-subrc.

PERFORM protocol_update.

ENDIF.

ENDIF.

IF cf_retcode = 0.

PERFORM check_repeat.

IF ls_composer_param-tdcopies EQ 0.

nast_anzal = 1.

ELSE.

nast_anzal = ls_composer_param-tdcopies.

ENDIF.

ls_composer_param-tdcopies = 1.

DO nast_anzal TIMES.

  • In case of repetition only one time archiving

IF sy-index > 1 AND nast-tdarmod = 3.

nast_tdarmod = nast-tdarmod.

nast-tdarmod = 1.

ls_composer_param-tdarmod = 1.

ENDIF.

IF sy-index NE 1 AND repeat IS INITIAL.

repeat = 'X'.

ENDIF.

ENDDO.

      • added for PDF format.

CALL FUNCTION 'POPUP_TO_CONFIRM'

EXPORTING

TITLEBAR = 'INVOICE PRINTING'

TEXT_QUESTION = 'Do you want to Print the Invoice or Convert to PDF format ???' "#EC NOTEXT

TEXT_BUTTON_1 = 'Print Invoice' "#EC NOTEXT

TEXT_BUTTON_2 = 'PDF Format' "#EC NOTEXT

DEFAULT_BUTTON = '1'

DISPLAY_CANCEL_BUTTON = 'X'

START_COLUMN = 25

START_ROW = 6

IMPORTING

ANSWER = ans

EXCEPTIONS

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

MOVE ans TO ans_hold.

                • SURESH

DATA : GF_VBELN LIKE VBRK-VBELN,

GF_KUNRG LIKE VBRK-KUNRG,

GF_VKORG LIKE VBRK-VKORG,

GF_VTWEG LIKE VBRK-VTWEG,

GF_SPART LIKE VBRK-SPART,

GF_TDNM(90) TYPE C.

SELECT SINGLE VBAP~VBELN INTO GF_VBELN "#EC *

FROM VBRP INNER JOIN VBAP ON VBRP~VGBEL EQ VBAP~VBELN

WHERE VBRP~VBELN EQ ls_bil_invoice-HD_GEN-BIL_NUMBER.

SELECT * FROM STXH

INTO CORRESPONDING FIELDS OF TABLE GS_ITAB

WHERE TDNAME EQ GF_VBELN AND

TDOBJECT ='VBBK' AND TDID NE 'ZTEL'.

IF SY-SUBRC NE 0.

SELECT SINGLE VBRK~KUNRG

VBRK~VKORG

VBRK~VTWEG

VBRK~SPART

INTO (GF_KUNRG, GF_VKORG, GF_VTWEG, GF_SPART)

FROM VBRK INNER JOIN KNVV ON KNVV~KUNNR EQ VBRK~KUNRG

WHERE VBRK~VBELN EQ ls_bil_invoice-HD_GEN-BIL_NUMBER.

CONCATENATE GF_KUNRG GF_VKORG GF_VTWEG GF_SPART INTO GF_TDNM.

SELECT * FROM STXH

INTO CORRESPONDING FIELDS OF TABLE GS_ITAB

WHERE TDNAME EQ GF_TDNM

  • WHERE TDNAME EQ 'TESTCRM 30000100'

AND TDOBJECT ='KNVV'.

ENDIF.

SELECT * FROM STXH

INTO CORRESPONDING FIELDS OF GS_ITAB

WHERE TDNAME EQ GF_VBELN AND

TDOBJECT = 'VBBK' AND TDID EQ 'ZTEL'.

APPEND GS_ITAB.

ENDSELECT.

CONCATENATE '%' GF_VBELN '%' INTO GF_TDNM.

SELECT * FROM STXH

INTO CORRESPONDING FIELDS OF GS_ITAB

WHERE TDNAME LIKE GF_TDNM AND

TDOBJECT ='VBBP'.

APPEND GS_ITAB.

ENDSELECT.

LOOP AT GS_ITAB.

CLEAR : GS_ITAB1,GS_ITAB2.

REFRESH : GS_ITAB1,GS_ITAB2.

SELECT * FROM TTXIT

INTO CORRESPONDING FIELDS OF TABLE GS_ITAB2

WHERE TDOBJECT = GS_ITAB-TDOBJECT

AND TDID = GS_ITAB-TDID

AND TDSPRAS = 'EN'.

CALL FUNCTION 'READ_TEXT' "#EC *

EXPORTING

  • CLIENT =

ID = GS_ITAB-TDID

LANGUAGE = 'E'

NAME = GS_ITAB-TDNAME

OBJECT = GS_ITAB-TDOBJECT

  • ARCHIVE_HANDLE = 0

  • LOCAL_CAT = ' '

  • IMPORTING

  • HEADER =

TABLES

LINES = GS_ITAB1

EXCEPTIONS

ID = 1

LANGUAGE = 2

NAME = 3

NOT_FOUND = 4

OBJECT = 5

REFERENCE_CHECK = 6

WRONG_ACCESS_TO_ARCHIVE = 7

OTHERS = 8

.

LOOP AT GS_ITAB1 .

READ TABLE GS_ITAB2 WITH KEY TDID = GS_ITAB-TDID TDOBJECT = GS_ITAB-TDOBJECT.

IF SY-SUBRC EQ 0 AND GS_ITAB1-TDLINE IS NOT INITIAL.

GS_ITAB3-TDLINE = GS_ITAB1-TDLINE.

GS_ITAB3-TDTEXT = GS_ITAB2-TDTEXT.

GS_ITAB3-TDID = GS_ITAB-TDID.

APPEND GS_ITAB3.

CLEAR GS_ITAB3.

ENDIF.

ENDLOOP.

ENDLOOP.

SORT GS_ITAB3 BY TDID.

                • SURESH

IF ans_hold = '1'.

      • end of addition.

  • call smartform invoice

CALL FUNCTION lf_fm_name

EXPORTING

archive_index = toa_dara

archive_parameters = arc_params

control_parameters = ls_control_param

  • mail_appl_obj =

mail_recipient = ls_recipient

mail_sender = ls_sender

output_options = ls_composer_param

user_settings = space

is_bil_invoice = ls_bil_invoice

is_nast = nast

is_repeat = repeat

importing job_output_info = ls_job_info

TABLES

GS_WIRING = GS_ITAB3

  • document_output_info =

  • job_output_options =

EXCEPTIONS formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5

.

IF sy-subrc <> 0.

  • error handling

cf_retcode = sy-subrc.

PERFORM protocol_update.

  • get SmartForm protocoll and store it in the NAST protocoll

PERFORM add_smfrm_prot.

ENDIF.

        • added here .

      • for PDF format.

ELSEIF ans_hold = '2'.

CLEAR gs_control_pars.

outputoptions-tdimmed = 'X'.

gs_control_pars-getotf = 'X'.

gs_control_pars-no_dialog = 'X'.

outputoptions-tdprinter = 'PDF1'.

  • call smartform invoice

CALL FUNCTION lf_fm_name

EXPORTING

control_parameters = gs_control_pars

is_bil_invoice = ls_bil_invoice

is_nast = nast

is_repeat = repeat

output_options = outputoptions

  • USER_SETTINGS = 'X'

  • tmp_tot_ord_val = tmp-tot_ord_val

IMPORTING

  • DOCUMENT_OUTPUT_INFO =

job_output_info = gs_output_info

TABLES

GS_WIRING = GS_ITAB3

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.

  • Write the Invoice in PDF format.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = pdf_file_size

TABLES

otf = gs_output_info-otfdata

lines = t_pdf_data

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

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

concatenate file ls_bil_invoice-HD_KOMK-BIL_NUMBER c_extn into filename.

**added on 03/04/2007***

  • filename = name.

  • Down load the Invoice In PDF format on PC.

*if filename is initial.

*if filename eq 'UNTITLED'.

  • name = 'test.pdf'.

.

*else.

  • name = filename.

  • filename = name.

  • filename1 = filename.

*endif.

data:guiobj type ref to cl_gui_frontend_services.

data:name type string.

data:path type string.

data:fullpath type string.

data:filter type string.

data:uact type i.

data:cancel.

filter = '(.)|.|'.

create object guiobj.

call method guiobj->file_save_dialog

exporting

WINDOW_TITLE = 'DOWNLOAD FILE INTO'

  • WITH_ENCODING = 'X'

INITIAL_DIRECTORY = 'C:\'

default_extension = 'pdf'

default_file_name = filename "space

file_filter = filter

changing

filename = FILENAME

path = path

fullpath = fullpath

user_action = uact.

if uact = guiobj->action_cancel.

cancel = 'X'.

exit.

endif.

******end of 03/04/2007

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = pdf_file_size

filename = filename

filetype = 'BIN'

TABLES

data_tab = t_pdf_data

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22.

IF sy-subrc <> 0.

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

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

ELSE.

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

WITH sy-msgv1.

ENDIF.

ENDIF.

        • end of addition.

  • get SmartForm spoolid and store it in the NAST protocoll

DATA ls_spoolid LIKE LINE OF ls_job_info-spoolids.

LOOP AT ls_job_info-spoolids INTO ls_spoolid.

IF ls_spoolid NE space.

PERFORM protocol_update_spool USING '342' ls_spoolid

space space space.

ENDIF.

ENDLOOP.

ls_composer_param-tdcopies = nast_anzal.

IF NOT nast_tdarmod IS INITIAL.

nast-tdarmod = nast_tdarmod.

CLEAR nast_tdarmod.

ENDIF.

ENDIF.

  • get SmartForm protocoll and store it in the NAST protocoll

  • PERFORM ADD_SMFRM_PROT.

ENDFORM. "PROCESSING

kiran_k8
Active Contributor
0 Kudos

Problem Solved

kiran_k8
Active Contributor
0 Kudos

Problem Solved