Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

reg sending mail attachment

Hi,

im working on sending report output as mail attachment in pdf format..

but im not getting the required output,,,i.e., even after entering email addresses in the selection screen....im not getting any mail to the respective mail-ids..

im pasting the code..pls fix the problem..

pls let me know wat we have to do in SCOT transaction after executing the program....pls respond ..pls ..

-


TABLES : t001, "COMPANY CODE

knb1, "CUSTOMER MASTER(COMPANY CODE)

cdhdr, "CHANGE DOCUMENT HEADER

knkk, "CUSTOMER MASTER CREDIT MANAGEMENT: CONTROL AREA DATA

kna1, "GENERAL DATA IN CUSTOMER MASTER

adrc, "ADDRESSES (BUSINESS ADDRESS SERVICES)

t001s, "ACCOUNTING CLERKS

adrt, "COMMUNICATION DATA TEXT (BUSINESS ADDRESS SERVICES)

adr6. "E-MAIL ADDRESSES (BUSINESS ADDRESS SERVICES)

TABLES: itcpo, "SAPscript output interface

itcpp. "SAPscript output parameters

TYPES: BEGIN OF y_t001,

bukrs TYPE bukrs,

kkber TYPE kkber,

adrnr TYPE adrnr,

END OF y_t001.

TYPES: BEGIN OF y_cust,

p_objectid TYPE cdobjectv,

END OF y_cust.

TYPES: BEGIN OF y_knkk,

kunnr TYPE kunnr,

kkber TYPE kkber,

dtrev TYPE dtrev_cm,

nxtrv TYPE nxtrv_cm,

klimk TYPE klimk,

dbwae TYPE dbwae_cm,

END OF y_knkk.

TYPES: BEGIN OF y_customer,

kunnr TYPE kunnr,

adrnr TYPE adrnr,

END OF y_customer.

TYPES: BEGIN OF y_custo ,

kunnr TYPE kunnr,

name TYPE name1_gp,

kkber TYPE kkber,

END OF y_custo.

TYPES: BEGIN OF y_knkk1,

kunnr LIKE knkk-kunnr,

dtrev LIKE knkk-dtrev,

nxtrv LIKE knkk-nxtrv,

klimk LIKE knkk-klimk,

END OF y_knkk1.

TYPES: BEGIN OF y_report_display,

kunnr TYPE kunnr,

name TYPE name1_gp,

dtrev TYPE dtrev_cm,

nxtrv TYPE nxtrv_cm,

klimk TYPE klimk,

dbwae TYPE dbwae_cm,

END OF y_report_display.

TYPES: BEGIN OF y_adrt,

addrnumber TYPE adrnr,

comm_type TYPE ad_comm,

remark TYPE ad_remark2,

persnumber TYPE ad_persnum,

date_from TYPE ad_date_fr,

consnumber TYPE ad_consnum,

smtp_addr TYPE ad_smtpadr,

END OF y_adrt.

*TYPES : BEGIN OF y_adr6,

  • addrnumber TYPE ad_addrnum,

  • persnumber TYPE ad_persnum,

  • date_from TYPE ad_date_fr,

  • consnumber TYPE ad_consnum,

  • smtp_addr TYPE ad_smtpadr,

  • END OF y_adr6.

*TYPES: BEGIN OF y_addr,

  • addrnumber TYPE adrnr,

  • name1 TYPE ad_name1,

  • postcode TYPE ad_pstcd1,

  • city1 TYPE ad_city1,

  • street TYPE ad_street,

  • housenum TYPE ad_hsnm1,

  • telnum TYPE ad_tlnmbr1,

  • faxnum TYPE ad_fxnmbr1,

*

  • END OF y_addr.

TYPES: BEGIN OF y_custnam,

adrnr TYPE adrnr,

name2 TYPE ad_name1,

END OF y_custnam.

TYPES: BEGIN OF y_kna1,

kunnr TYPE kunnr,

adrnr TYPE adrnr,

name1 TYPE name1,

END OF y_kna1.

TYPES: BEGIN OF y_knb1,

kunnr TYPE kunnr,

bukrs TYPE bukrs,

busab TYPE busab,

END OF y_knb1.

TYPES: BEGIN OF y_clv,

dtrev TYPE dtrev_cm,

nxtrv TYPE nxtrv_cm,

klimk TYPE klimk,

END OF y_clv.

TYPES: BEGIN OF y_ccname,

sname TYPE t001s-sname,

END OF y_ccname.

*TYPES DECLARATION FOR DESIGING SCRIPT

TYPES : BEGIN OF y_adrc,

addrnumber LIKE adrc-addrnumber,

name1 LIKE adrc-name1,

post_code1 LIKE adrc-post_code1,

city1 LIKE adrc-city1,

street LIKE adrc-street,

house_num1 LIKE adrc-house_num1,

tel_number LIKE adrc-tel_number,

nation LIKE adrc-nation ,

fax_number LIKE adrc-fax_number,

country LIKE adrc-country,

END OF y_adrc.

*TO GET C1 (CUSTOMER NAME IN RUSSIAN

TYPES : BEGIN OF y_adrc1,

addrnumber LIKE adrc-addrnumber,

name1 LIKE adrc-name1,

nation LIKE adrc-nation,

END OF y_adrc1.

*TO GET C7

TYPES :BEGIN OF y_t001s,

bukrs LIKE t001s-bukrs, "Company Code

busab LIKE t001s-busab,

sname LIKE t001s-sname,

END OF y_t001s.

CONSTANTS:

c_printer LIKE itcpp-tddevice VALUE 'PRINTER',

c_true(1) TYPE c VALUE 'X',

c_1(1) TYPE n VALUE '1',

c_pdf_format(3) TYPE c VALUE 'PDF',

c_u LIKE soos1-recesc VALUE 'U',

c_recipient_name LIKE soos1-recnam VALUE 'U-',

c_english LIKE sy-langu VALUE 'E',

c_f LIKE sood1-objsns VALUE 'F',

c_int(3) TYPE c VALUE 'INT',

c_main(4) TYPE c VALUE 'ITEM',

c_main_window(4) TYPE c VALUE 'MAIN',

c_header(6) TYPE c VALUE 'HEADER',

c_minus_sign(1) TYPE c VALUE '-',

c_document_type LIKE sood-objtp VALUE 'EXT',

c_space(1) TYPE c VALUE ' '.

DATA t_result LIKE itcpp.

DATA :w_t001 TYPE t001,

w_custo TYPE y_custo,

w_knkk TYPE y_knkk,

w_cust TYPE y_cust,

w_customer TYPE y_customer,

w_report_display TYPE y_report_display,

  • w_addr TYPE y_addr,

w_custnam TYPE y_custnam,

w_adrt TYPE y_adrt,

  • w_adr6 TYPE y_adr6,

w_kna1 TYPE y_kna1,

w_knb1 TYPE y_knb1,

w_clv TYPE y_clv,

w_ccname TYPE y_ccname.

DATA: w_error_found(1) TYPE c,

w_key_date_text(30) TYPE c,

w_total(10) TYPE p DECIMALS 2,

w_htddevice LIKE itcpp-tddevice.

DATA: E_PROFILE LIKE SOPRD.

DATA: t_t001 TYPE STANDARD TABLE OF y_t001,

t_custo TYPE STANDARD TABLE OF y_custo,

t_knkk TYPE STANDARD TABLE OF y_knkk,

t_cust TYPE STANDARD TABLE OF y_cust,

t_customer TYPE STANDARD TABLE OF y_customer,

t_report_display TYPE STANDARD TABLE OF y_report_display,

  • t_addr TYPE STANDARD TABLE OF y_addr,

t_custnam TYPE STANDARD TABLE OF y_custnam,

t_adrt TYPE STANDARD TABLE OF y_adrt,

  • t_adr6 TYPE STANDARD TABLE OF y_adr6,

t_kna1 TYPE STANDARD TABLE OF y_kna1,

t_knb1 TYPE STANDARD TABLE OF y_knb1,

t_clv TYPE STANDARD TABLE OF y_clv,

t_ccname TYPE STANDARD TABLE OF y_ccname.

DATA : number LIKE spell,

amount(1000) TYPE c.

  • For storing error log

DATA: BEGIN OF t_error OCCURS 0,

kunnr LIKE kna1-kunnr,

comm(30) TYPE c,

END OF t_error.

  • For storing customer's email address

DATA: BEGIN OF t_email OCCURS 0,

smtp_addr LIKE adr6-smtp_addr,

END OF t_email.

  • To be used in the function to send a layout via email

DATA: t_otfdata LIKE itcoo OCCURS 0 WITH HEADER LINE,

t_htline LIKE tline OCCURS 0 WITH HEADER LINE.

  • DATA DECLARATIONS FOR DESIGING SCRIPT

DATA : it_t001 TYPE STANDARD TABLE OF y_t001,

wa_t001 TYPE y_t001.

*

DATA : it_adrc TYPE STANDARD TABLE OF y_adrc,

wa_adrc type y_adrc.

DATA : it_adrc1 TYPE STANDARD TABLE OF y_adrc1,

wa_adrc1 TYPE y_adrc1.

DATA : it_knb1 TYPE STANDARD TABLE OF y_knb1,

wa_knb1 TYPE y_knb1.

DATA : it_kna1 TYPE STANDARD TABLE OF y_kna1,

wa_kna1 TYPE y_kna1.

DATA : it_knkk TYPE STANDARD TABLE OF y_knkk,

wa_knkk TYPE y_knkk.

DATA : it_knkk1 TYPE STANDARD TABLE OF y_knkk1,

wa_knkk1 TYPE y_knkk1.

DATA : it_t001s TYPE STANDARD TABLE OF y_t001s,

wa_t001s TYPE y_t001s.

*DATA STATEMENTS FOR EMAIL ADDRESSES

DATA : it_adrt TYPE TABLE OF y_adrt,

wa_adrt TYPE y_adrt,

wa_email LIKE t_email.

*DATA : it_adr6 TYPE TABLE OF y_adr6,

  • wa_adr6 TYPE y_adr6,

DATA : counter TYPE i,

counter1 TYPE i,

c5 LIKE spell.

SELECTION-SCREEN BEGIN OF BLOCK clcn WITH FRAME TITLE text-200.

SELECTION-SCREEN SKIP.

PARAMETERS: p_bukrs LIKE t001-bukrs OBLIGATORY, "COMPANY CODE

p_kkber LIKE t001-kkber OBLIGATORY. "CREDIT CONTROL AREA

SELECT-OPTIONS: s_kunnr FOR knb1-kunnr OBLIGATORY, "CUSTOMER NUMBER

s_datum FOR sy-datum OBLIGATORY DEFAULT sy-datum. "DATE OF CREDIT LIMIT UPDATE

SELECTION-SCREEN SKIP.

PARAMETERS : p_simul AS CHECKBOX DEFAULT 'X'. "RUN IN SIMULATION MODE

SELECTION-SCREEN SKIP.

PARAMETERS : p_lemail LIKE adr6-smtp_addr. " EMAIL

SELECTION-SCREEN END OF BLOCK clcn.

AT SELECTION-SCREEN.

PERFORM f0100_validate_bukrs. "* For Company Code.

PERFORM f0200_validate_kkber. "* For Credit Control Area.

PERFORM f0300_validate_kunnr. "* For Customer Number

PERFORM f0400_validate_datum. "* For Date of Credit Limit Update

PERFORM f0500_validate_simul. "* For simulation mode and e-mail address

*======================================================================

START-OF-SELECTION.

PERFORM f1000_get_customer. "** COLLECT INFO FOR REPORT DISPLAY

IF p_simul is initial AND NOT P_lemail IS INITIAL.

PERFORM F1000_CHECK_GATEWAY_CONNECTION.

ENDIF.

IF p_simul IS INITIAL AND NOT p_lemail IS INITIAL.

PERFORM f3000_process_data_script USING t_report_display.

ENDIF.

END-OF-SELECTION.

IF NOT p_simul IS INITIAL.

PERFORM f2000_display_customer USING t_report_display.

ENDIF.

FORM f0100_validate_bukrs.

DATA : w_bukrs TYPE bukrs.

    • VALIDATION OF P_BUKRS

SELECT SINGLE bukrs

FROM t001

INTO w_bukrs

WHERE bukrs EQ p_bukrs.

IF sy-subrc NE 0.

MESSAGE e999(zf) WITH 'Invalid Company Code' p_bukrs. "(E01).

*AUTHORIZATION CHECK

AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'

ID 'BUKRS' FIELD p_bukrs

ID 'ACTVT' FIELD '03'.

IF sy-subrc NE 0.

MESSAGE e999(zf) WITH 'No Authorization for company code' p_bukrs."(e06).

ENDIF.

ENDIF.

ENDFORM. " F0100_VALIDATE_BUKRS

*Eject

&----


*& Form F0200_VALIDATE_KKBER

&----


  • *-> CREDIT CONTROL AREA AUTHORITY CHECK

----


  • FOR CREDIT CONTROL AREA.

FORM f0200_validate_kkber.

DATA : w_kkber LIKE t001-kkber.

SELECT SINGLE kkber

FROM t001

INTO w_kkber

WHERE bukrs EQ p_bukrs

AND kkber EQ p_kkber.

IF sy-subrc NE 0.

MESSAGE e999(zf) WITH

'Credit Control Area' p_kkber 'not defined for Company Code' p_bukrs."(e02).

  • MESSAGE e999 WITH text-e02 p_kkber .

ENDIF.

ENDFORM. "F0200_VALIDATE_KKBER

&----


*& Form F0300_VALIDATE_KUNNR

&----


  • *-> CUSTOMER NUMBER AUTHORITY CHECK

----


FORM f0300_validate_kunnr.

    • VALIDATION OF S_KUNNR

DATA : w_kunnr TYPE kunnr,

w_bukrs TYPE bukrs.

IF s_kunnr IS INITIAL .

MESSAGE e999 WITH 'Enter Customer Number'(e04).

SUBMIT (sy-cprog) VIA SELECTION-SCREEN.

ENDIF.

LOOP AT s_kunnr.

CLEAR : w_kunnr,

w_bukrs.

IF NOT s_kunnr-low IS INITIAL.

SELECT SINGLE kunnr bukrs

FROM knb1 INTO (w_kunnr ,w_bukrs)

WHERE kunnr EQ s_kunnr-low

AND bukrs EQ p_bukrs.

IF sy-subrc NE 0.

MESSAGE e999(zf) WITH 'Customer S_KUNNR-LOW not defined in company code' p_bukrs."(e03).

ENDIF.

ENDIF. "if not s_kunnr-low is initial.

IF NOT s_kunnr-high IS INITIAL.

CLEAR : w_kunnr,

w_bukrs.

SELECT SINGLE kunnr bukrs

FROM knb1 INTO (w_kunnr , w_bukrs)

WHERE kunnr EQ s_kunnr-high

AND bukrs EQ p_bukrs.

IF sy-subrc NE 0.

MESSAGE e999(zf) WITH 'Customer S_KUNNR-HIGH not defined in company code' p_bukrs."(e03).

ENDIF.

ENDIF. "if not s_kunnr-high is initial.

ENDLOOP. " loop at s_kunnr

ENDFORM. " F0200_VALIDATE_KUNNR

&----


*& Form F0400_VALIDATE_DATUM

&----


  • *-> DATE OF CREDIT LIMIT UPDATE

FORM f0400_validate_datum.

IF s_kunnr IS INITIAL AND s_datum IS INITIAL.

MESSAGE e999 WITH 'Enter either Date of CL update or Customer number.'(e04).

ENDIF.

ENDFORM. "F0400_VALIDATE_DATUM

&----


*& Form F1000_GET_CUSTOMER

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f1000_get_customer .

DATA : w_kunnr LIKE knkk-kunnr,

w_kkber LIKE knkk-kkber.

IF s_datum IS NOT INITIAL.

SELECT objectid

FROM cdhdr

INTO TABLE t_cust

WHERE objectclas IN ('KLIM','DTREV','NXTRV')

AND change_ind IN ('U','I')

AND udate IN s_datum.

  • WHERE ( objectclas EQ 'KLIM' OR objectclas EQ 'DTREV' OR objectclas EQ 'NXTRV')

  • AND ( change_ind EQ 'U' OR change_ind EQ 'I')

  • AND udate IN s_datum .

*

ENDIF.

IF sy-subrc NE 0.

MESSAGE s999 WITH 'There is no data for selected period'(e07).

ELSE.

MOVE t_cust TO t_customer.

ENDIF.

SORT t_customer BY kunnr.

IF NOT t_customer[] IS INITIAL.

SELECT kunnr

kkber

dtrev

nxtrv

klimk

dbwae

FROM knkk

INTO TABLE t_knkk

FOR ALL ENTRIES IN t_customer

WHERE kunnr = t_customer-kunnr

AND kkber = p_kkber.

ELSE.

MESSAGE e999 WITH text-e07.

ENDIF.

IF sy-subrc NE 0.

ENDIF.

SORT t_knkk BY kunnr kkber.

IF NOT t_knkk[] IS INITIAL.

SELECT kunnr

name1

FROM kna1

INTO TABLE t_custo

FOR ALL ENTRIES IN t_knkk

WHERE kunnr = t_knkk-kunnr.

ENDIF.

IF sy-subrc = 0.

ENDIF.

SORT t_custo BY kunnr kkber.

LOOP AT t_custo INTO w_custo.

CLEAR w_knkk.

READ TABLE t_knkk INTO w_knkk WITH KEY kunnr = w_custo-kunnr

BINARY SEARCH.

IF sy-subrc = 0.

w_report_display-kunnr = w_custo-kunnr.

w_report_display-name = w_custo-name.

w_report_display-dtrev = w_knkk-dtrev.

w_report_display-nxtrv = w_knkk-nxtrv.

w_report_display-klimk = w_knkk-klimk.

w_report_display-dbwae = w_knkk-dbwae.

APPEND w_report_display TO t_report_display .

ENDIF.

ENDLOOP.

ENDFORM. " F1000_GET_CUSTOMER

&----


*& Form F2000_DISPLAY_CUSTOMER

&----


  • text

----


  • -->P_T_REPORT_DISPLAY text

----


FORM f2000_display_customer USING p_t_report_display.

DATA: no TYPE n VALUE 1.

DATA: t_data TYPE STANDARD TABLE OF y_report_display.

t_data = p_t_report_display.

DATA : w_data LIKE LINE OF t_data .

ULINE (118).

WRITE:/ sy-vline,

8 'CREDIT LIMIT CHANGE NOTIFICATION REPORT ON',

sy-datum , 118 sy-vline.

ULINE (118).

WRITE:/ sy-vline,'NO'(008) ,

10 sy-vline, 11 'CUSTOMER NUMBER',

28 sy-vline, 29 'CUSTOMER NAME', 43 sy-vline,

44 'CREDIT LIMIT VALID', 63 sy-vline ,

64 'CREDIT LIMIT AMOUNT', 85 sy-vline, 86 'CURRENCY',

95 sy-vline , 96 'Notification Status',118 sy-vline.

ULINE (118).

WRITE:/ sy-vline,43 sy-vline, 44 'FROM', 53 sy-vline,

56 'TILL', 63 sy-vline, 118 sy-vline .

ULINE (118).

LOOP AT t_data INTO w_data.

WRITE:/ sy-vline, no,

10 sy-vline, 11 w_data-kunnr ,

28 sy-vline, 29 w_data-name, 43 sy-vline, 44 w_data-dtrev,

53 sy-vline, 56 w_data-nxtrv ,63 sy-vline ,64 w_data-klimk,

85 sy-vline, 86 w_data-dbwae,

95 sy-vline , 118 sy-vline.

no = no + 1.

ULINE (118).

ENDLOOP.

ENDFORM. " F2000_DISPLAY_CUSTOMER

&----


*& Form F3000_PROCESS_DATA_SCRIPT

&----


  • text

----


  • -->P_T_REPORT_DISPLAY text

----


FORM f3000_process_data_script USING p_t_report_display.

DATA: t_data TYPE STANDARD TABLE OF y_report_display.

t_data = p_t_report_display.

DATA : w_data LIKE LINE OF t_data .

DATA: temp_is_negative(1) TYPE c,

temp_text(20) TYPE c,

temp_sname LIKE t001s-sname,

temp_email LIKE adr6-smtp_addr.

DATA : number LIKE spell,

amount(255) TYPE c.

PERFORM f3100_initialize_settings.

LOOP AT t_data INTO w_data.

AT NEW kunnr.

CLEAR w_error_found.

IF p_simul IS INITIAL AND NOT p_lemail IS INITIAL.

PERFORM f3300_open_form.

  • data: wa_t001 like line of t001

DATA : begin of wa_t001,

adrnr like t001-adrnr,

end of wa_t001.

SELECT SINGLE

adrnr FROM t001 INTO wa_t001

WHERE bukrs = p_bukrs.

DATA: BEGIN OF wa_adrc,

addrnumber LIKE adrc-addrnumber,

name1 LIKE adrc-name1,

post_code1 LIKE adrc-post_code1,

city1 LIKE adrc-city1,

street LIKE adrc-street,

house_num1 LIKE adrc-house_num1,

tel_number LIKE adrc-tel_number,

nation LIKE adrc-nation ,

fax_number LIKE adrc-fax_number,

country LIKE adrc-country,

END OF wa_adrc.

SELECT SINGLE

addrnumber

name1

post_code1

city1

street

house_num1

tel_number

nation

fax_number

country

FROM adrc

INTO corresponding fields of wa_adrc

WHERE addrnumber EQ wa_t001-adrnr AND

nation EQ ' '.

PERFORM f3700_write_form.

DATA: wa_kna1 LIKE LINE OF t_kna1,

wa_adrcc LIKE LINE OF it_adrc.

SELECT SINGLE

kunnr

adrnr FROM kna1

INTO wa_kna1

WHERE kunnr = w_data-kunnr.

IF sy-subrc EQ 0.

SELECT SINGLE

addrnumber

name1

FROM adrc

INTO wa_adrcc

WHERE addrnumber = wa_kna1-adrnr

AND nation = ' '.

ENDIF.

PERFORM f3701_write_form.

DATA : wa_knkk LIKE LINE OF t_knkk.

DATA : counter TYPE i,

counter1 TYPE i.

IF sy-subrc EQ 0.

  • SELECT SINGLE KUNNR

  • DTREV

  • NXTRV

  • KLIMK FROM KNKK INTO WA_KNKK WHERE

  • KUNNR EQ W_DATA-KUNNR.

ENDIF.

CALL FUNCTION 'SPELL_AMOUNT'

EXPORTING

amount = w_knkk-klimk

  • CURRENCY = ' '

  • FILLER = ' '

language = sy-langu

IMPORTING

in_words = number.

IF sy-subrc <> 0.

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

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

ENDIF.

amount = number-word.

PERFORM f3702_write_form.

DATA: wa_knb1 LIKE LINE OF t_knb1.

IF sy-subrc EQ 0.

SELECT SINGLE

busab

FROM knb1

INTO wa_knb1

WHERE kunnr = w_data-kunnr

AND bukrs = p_bukrs.

ENDIF.

DATA : wa_t001s LIKE LINE OF it_t001s.

IF sy-subrc EQ 0.

SELECT SINGLE bukrs

busab

sname

FROM t001s

INTO wa_t001s

WHERE bukrs = wa_knb1-bukrs

AND busab = wa_knb1-busab.

ENDIF.

PERFORM f3703_write_form.

PERFORM f3704_write_form.

IF counter1 < counter.

PERFORM f3705_write_form.

ENDIF.

PERFORM f3706_close_form.

ENDIF.

ENDAT.

IF w_error_found EQ c_true.

ENDIF.

AT END OF kunnr.

  • PERFORM F3400_WRITE_FORM USING C_TOTAL C_MAIN_WINDOW.

  • PERFORM F3500_CLOSE_FORM.

IF p_simul IS INITIAL AND NOT p_lemail IS INITIAL. "Email setting

PERFORM f3200_get_email_addr USING w_data-kunnr.

PERFORM f3600_send_data_via_email USING w_data-kunnr.

ENDIF.

ENDAT.

ENDLOOP.

WRITE:/ ' E-Mail is sent to the customer'.

ENDFORM. " F3000_PROCESS_DATA_SCRIPT

&----


*& Form F3100_INITIALIZE_SETTINGS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f3100_initialize_settings .

SELECT SINGLE spld

INTO itcpo-tddest

FROM usr01

WHERE bname EQ sy-uname.

IF sy-subrc NE 0.

itcpo-tddest = 'LOCAL'.

ENDIF.

w_htddevice = c_printer.

itcpo-tddest = ''.

itcpo-tdrdidev = ''.

itcpo-tdsenddate = sy-datum.

itcpo-tdsendtime = sy-uzeit.

itcpo-tdschedule = 'IMM'.

itcpo-tdimmed = ' '.

  • itcpo-tdnewid = c_true. "PRINT: New spool request

itcpo-tdlifetime = c_1. "PRINT: Spool retention period

itcpo-tdgetotf = c_true.

IF p_simul IS INITIAL AND NOT p_lemail IS INITIAL. "Email setting

itcpo-tdgetotf = c_true.

ENDIF.

ENDFORM. " F3100_INITIALIZE_SETTINGS

&----


*& Form f0500_validate_simul

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f0500_validate_simul .

IF p_simul IS INITIAL AND p_lemail IS INITIAL. "Email setting

  • MESSAGE e999(zf) WITH 'Enter Email address'. "(e05).

ENDIF.

ENDFORM. " f0500_validate_simul

&----


*& Form F3600_SEND_DATA_VIA_EMAIL

&----


  • text

----


  • -->P_W_DATA_KUNNR text

----


FORM f3600_send_data_via_email USING p_w_data_kunnr.

DATA: fle1(2) TYPE p,

fle2(2) TYPE p,

off1 TYPE p,

hltlines TYPE i,

temp_filesize TYPE i,

hfeld(500) TYPE c,

header(50) TYPE c,

htabix LIKE sy-tabix,

x_sent_to_all LIKE sonv-flag.

DATA: BEGIN OF x_objcont OCCURS 0.

INCLUDE STRUCTURE soli.

  • INCLUDE STRUCTURE SOLISTI1.

DATA: END OF x_objcont.

DATA: BEGIN OF x_object_hd_change.

INCLUDE STRUCTURE sood1.

DATA: END OF x_object_hd_change.

DATA: BEGIN OF x_receivers OCCURS 0.

INCLUDE STRUCTURE soos1.

  • INCLUDE STRUCTURE SOMLRECI1.

DATA: END OF x_receivers.

DATA: BEGIN OF x_objhead OCCURS 1.

INCLUDE STRUCTURE soli.

DATA: END OF x_objhead.

**Data: begin of objpack occurs 0.

    • include structure SOPCKLSTI1.

**Data: end of objpack.

**

**Data: begin of email_data occurs 0.

    • include structure SODOCCHGI1.

**Data: end of email_data.

  • Converts the layout set to PDF format

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = c_pdf_format

IMPORTING

bin_filesize = temp_filesize

TABLES

otf = t_otfdata

lines = t_htline

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

OTHERS = 4.

IF sy-subrc NE 0.

w_error_found = c_true.

t_error-kunnr = p_w_data_kunnr.

t_error-comm = 'Error in conversion to PDF format.'(e08).

APPEND t_error.

CLEAR t_error.

EXIT.

ENDIF.

  • Convert the PDF file into an internal table which to be used in the

  • function that will send a PDF file to a email address

DESCRIBE TABLE t_htline LINES hltlines.

  • DESCRIBE FIELD T_HTLINE LENGTH FLE1 IN BYTE MODE.

DESCRIBE FIELD t_htline LENGTH fle1

IN CHARACTER MODE.

  • DESCRIBE FIELD X_OBJCONT LENGTH FLE2 IN BYTE MODE.

DESCRIBE FIELD x_objcont LENGTH fle2

IN CHARACTER MODE.

CLEAR x_objcont.

REFRESH x_objcont.

LOOP AT t_htline.

htabix = sy-tabix.

MOVE t_htline TO hfeld+off1.

IF htabix = hltlines.

fle1 = STRLEN( t_htline ).

ENDIF.

off1 = off1 + fle1.

IF off1 GE fle2.

CLEAR x_objcont.

x_objcont = hfeld(fle2).

APPEND x_objcont.

SHIFT hfeld BY fle2 PLACES.

off1 = off1 - fle2.

ENDIF.

IF htabix = hltlines.

IF off1 GT 0.

CLEAR x_objcont.

x_objcont = hfeld(off1).

APPEND x_objcont.

ENDIF.

ENDIF.

ENDLOOP.

    • LOOP AT t_email.

    • x_receivers-receiver = t_email-smtp_addr.

    • x_receivers-rec_type = c_u.

    • APPEND x_receivers.

    • ENDLOOP.

**

**

    • x_receivers-receiver = p_lemail.

    • x_receivers-rec_type = c_u.

    • APPEND x_receivers.

**

    • DESCRIBE TABLE x_objcont LINES sy-tfill.

    • READ TABLE x_objcont INDEX sy-tfill.

    • email_data-doc_size = ( sy-tfill - 1 ) * 255 + STRLEN( x_objcont ).

**

    • CLEAR objpack-transf_bin.

    • objpack-head_start = 1.

    • objpack-head_num = 0.

    • objpack-body_start = 1.

    • objpack-body_num = sy-tfill.

    • objpack-doc_type = 'RAW'.

    • APPEND objpack.

**

    • email_data-obj_descr = 'Notification'.

    • APPEND email_data.

**

    • IF x_receivers[] IS NOT INITIAL.

    • CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    • EXPORTING

    • document_data = email_data

    • put_in_outbox = 'X'

    • commit_work = 'X' "used from rel. 6.10

    • TABLES

    • packing_list = objpack

      • object_header = email_fname

      • contents_bin = email_text

    • contents_txt = x_objcont

    • receivers = x_receivers.

    • endif.

CLEAR x_objhead.

REFRESH x_objhead.

CLEAR x_object_hd_change.

x_object_hd_change-objnam = 'EMAIL'(t04).

header = 'Procter & Gamble'(t05).

x_object_hd_change-objdes = header. "Title

x_object_hd_change-objla = c_english. "Language

x_object_hd_change-objsns = c_f.

x_object_hd_change-objlen = temp_filesize.

x_object_hd_change-file_ext = c_pdf_format.

  • Transfer the email address to an internal table which will be used

  • in the function that will send a PDF file to a email address

CLEAR x_receivers.

REFRESH x_receivers.

LOOP AT t_email.

x_receivers-sndex = c_true.

x_receivers-sndpri = c_1.

x_receivers-recesc = c_u.

x_receivers-recnam = c_recipient_name.

  • Populate the email address of the customer

x_receivers-recextnam = t_email-smtp_addr.

x_receivers-recesc = c_english.

x_receivers-sndart = c_int.

APPEND x_receivers.

ENDLOOP.

x_receivers-sndex = c_true.

x_receivers-sndpri = c_1.

x_receivers-recesc = c_u.

x_receivers-recnam = c_recipient_name.

  • Populate the Local mail address

x_receivers-recextnam = p_lemail.

x_receivers-recesc = c_english.

x_receivers-sndart = c_int.

APPEND x_receivers.

  • Calling a SAP function to send out email with attachment of PDF file

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

object_hd_change = x_object_hd_change

object_type = c_document_type

outbox_flag = c_true

IMPORTING

sent_to_all = x_sent_to_all

TABLES

objcont = x_objcont

objhead = x_objhead

receivers = x_receivers

EXCEPTIONS

active_user_not_exist = 1

communication_failure = 2

component_not_available = 3

folder_not_exist = 4

folder_no_authorization = 5

forwarder_not_exist = 6

note_not_exist = 7

object_not_exist = 8

object_not_sent = 9

object_no_authorization = 10

object_type_not_exist = 11

operation_no_authorization = 12

owner_not_exist = 13

parameter_error = 14

substitute_not_active = 15

substitute_not_defined = 16

system_failure = 17

too_much_receivers = 18

user_not_exist = 19

x_error = 20

OTHERS = 21.

IF sy-subrc NE 0.

w_error_found = c_true.

t_error-kunnr = p_w_data_kunnr.

t_error-comm = 'Error in sending email.'(e09).

APPEND t_error.

CLEAR t_error.

ELSEIF sy-subrc EQ 0.

COMMIT WORK.

*Transmit Mail

SUBMIT rsconn01 WITH mode = c_int

WITH output = c_space

AND RETURN.

ENDIF.

ENDFORM. " F3600_SEND_DATA_VIA_EMAIL

&----


*& Form F3200_GET_EMAIL_ADDR

&----


  • text

----


  • -->P_T_REPORT_DISPLAY text

----


FORM f3200_get_email_addr USING p_w_data_kunnr.

REFRESH t_customer.

REFRESH t_adrt.

REFRESH t_email.

DATA: t_data TYPE STANDARD TABLE OF y_report_display.

  • t_data = p_t_report_display.

DATA : w_data LIKE LINE OF t_data .

DATA : BEGIN OF i_cust OCCURS 0,

kunnr LIKE kna1-kunnr,

adrnr LIKE kna1-adrnr,

END OF i_cust.

DATA : BEGIN OF i_adrt OCCURS 0,

addrnumber LIKE adrt-addrnumber,

comm_type LIKE adrt-comm_type ,

remark LIKE adrt-remark,

persnumber LIKE adrt-persnumber,

date_from LIKE adrt-date_from,

consnumber LIKE adrt-consnumber,

END OF i_adrt.

DATA: BEGIN OF i_adr6 OCCURS 0,

smtp_addr LIKE adr6-smtp_addr,

END OF i_adr6.

  • LOOP AT t_data INTO w_data.

SELECT SINGLE kunnr adrnr FROM kna1 INTO (i_cust-kunnr,i_cust-adrnr) WHERE

kunnr = p_w_data_kunnr.

SELECT SINGLE addrnumber

persnumber

date_from

consnumber

FROM adrt INTO (i_adrt-addrnumber,i_adrt-persnumber,i_adrt-date_from,i_adrt-consnumber)

WHERE addrnumber EQ i_cust-adrnr

AND comm_type EQ 'INT'

AND remark EQ 'NOTIF'.

  • SELECT smtp_addr FROM adr6 INTO TABLE i_adr6

  • WHERE addrnumber EQ i_adrt-addrnumber

  • AND persnumber EQ i_adrt-persnumber

  • AND date_from EQ i_adrt-date_from

  • AND consnumber EQ i_adrt-consnumber.

SELECT SINGLE smtp_addr FROM adr6 INTO i_adr6-smtp_addr

WHERE addrnumber EQ i_adrt-addrnumber

AND persnumber EQ i_adrt-persnumber

AND date_from EQ i_adrt-date_from

AND consnumber EQ i_adrt-consnumber.

APPEND i_cust TO t_customer.

APPEND i_adrt TO t_adrt.

MOVE i_adr6-smtp_addr TO t_email-smtp_addr.

APPEND t_email.

CLEAR:i_cust[],

i_adrt[] ,

i_adr6[].

  • ENDLOOP.

ENDFORM. " F3200_GET_EMAIL_ADDR

&----


*& Form F3300_OPEN_FORM

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f3300_open_form .

itcpo-tdnewid = 'X'.

itcpo-tddest = 'LP01'.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

device = w_htddevice

dialog = ' '

form = 'ZSKCLN'

language = sy-langu

OPTIONS = itcpo

IMPORTING

RESULT = itcpp

EXCEPTIONS

canceled = 1

device = 2

form = 3

OPTIONS = 4

unclosed = 5

mail_options = 6

archive_error = 7

invalid_fax_number = 8

more_params_needed_in_batch = 9

spool_error = 10

codepage = 11

OTHERS = 12.

IF sy-subrc NE 0.

IF sy-batch EQ c_true.

MESSAGE e999 WITH 'Error in open_form'(e05).

ELSE.

MESSAGE i999 WITH 'Error in open_form'(e05).

STOP.

ENDIF.

ENDIF.

ENDFORM. "f3300_open_form

*EJECT " F3300_WRITE_FORM

&----


*& Form F3700_WRITE_FORM

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f3700_write_form .

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = 'EL'

window = 'ADDRESS'

EXCEPTIONS

element = 1

function = 2

type = 3

unopened = 4

unstarted = 5

window = 6

bad_pageformat_for_print = 7

OTHERS = 8.

IF sy-subrc NE 0.

IF sy-batch EQ c_true.

  • MESSAGE e999 WITH 'Error in Write_Form'(e06).

  • ELSE.

  • MESSAGE i999 WITH 'Error in Write_Form'(e06).

STOP.

ENDIF.

ENDIF.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = 'TITLE'

window = 'TITLE'

EXCEPTIONS

element = 1

function = 2

type = 3

unopened = 4

unstarted = 5

window = 6

bad_pageformat_for_print = 7

OTHERS = 8.

IF sy-subrc NE 0.

IF sy-batch EQ c_true.

  • MESSAGE e999 WITH 'Error in Write_Form'(e06).

  • ELSE.

  • MESSAGE i999 WITH 'Error in Write_Form'(e06).

STOP.

ENDIF.

ENDIF.

ENDFORM. "f3700_write_form

*EJECT "FORM F3700_WRITE_FORM

&----


*& Form F3701_WRITE_FORM

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f3701_write_form .

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = 'ELE'

window = 'MAIN'

EXCEPTIONS

element = 1

function = 2

type = 3

unopened = 4

unstarted = 5

window = 6

bad_pageformat_for_print = 7

OTHERS = 8.

IF sy-subrc NE 0.

IF sy-batch EQ c_true.

  • MESSAGE e999 WITH 'Error in Write_Form'(e06).

  • ELSE.

  • MESSAGE i999 WITH 'Error in Write_Form'(e06).

STOP.

ENDIF.

ENDIF.

ENDFORM. "f3701_write_form

*EJECT " Form f3701_write_form.

&----


*& Form F3702_WRITE_FORM

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f3702_write_form.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = 'ELE1'

window = 'MAIN'

type = 'BODY'

EXCEPTIONS

element = 1

function = 2

type = 3

unopened = 4

unstarted = 5

window = 6

bad_pageformat_for_print = 7

OTHERS = 8.

IF sy-subrc NE 0.

IF sy-batch EQ c_true.

  • MESSAGE e999 WITH 'Error in Write_Form'(e06).

  • ELSE.

  • MESSAGE i999 WITH 'Error in Write_Form'(e06).

STOP.

ENDIF.

ENDIF.

ENDFORM. "f3702_write_form

*EJECT " F3702_WRITE_FORM

&----


*& Form F3703_WRITE_FORM

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f3703_write_form.

CALL FUNCTION 'CONTROL_FORM'

EXPORTING

command = 'BOTTOM'.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = 'ELE2'

window = 'MAIN'

type = 'BOTTOM'

EXCEPTIONS

element = 1

function = 2

type = 3

unopened = 4

unstarted = 5

window = 6

bad_pageformat_for_print = 7

OTHERS = 8.

IF sy-subrc NE 0.

IF sy-batch EQ c_true.

  • MESSAGE e999 WITH 'Error in Write_Form'(e06).

  • ELSE.

  • MESSAGE i999 WITH 'Error in Write_Form'(e06).

STOP.

ENDIF.

ENDIF.

CALL FUNCTION 'CONTROL_FORM'

EXPORTING

command = 'ENDBOTTOM'.

ENDFORM. "f3703_write_form

*EJECT " F3703_WRITE_FORM

&----


*& Form F3703_WRITE_FORM

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f3704_write_form.

CALL FUNCTION 'CONTROL_FORM'

EXPORTING

command = 'BOTTOM'.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = 'ELE2'

window = 'MAIN'

type = 'BOTTOM'

EXCEPTIONS

element = 1

function = 2

type = 3

unopened = 4

unstarted = 5

window = 6

bad_pageformat_for_print = 7

OTHERS = 8.

IF sy-subrc NE 0.

IF sy-batch EQ c_true.

  • MESSAGE e999 WITH 'Error in Write_Form'(e06).

  • ELSE.

  • MESSAGE i999 WITH 'Error in Write_Form'(e06).

STOP.

ENDIF.

ENDIF.

CALL FUNCTION 'CONTROL_FORM'

EXPORTING

command = 'ENDBOTTOM'.

ENDFORM. "F3704_WRITE_FORM

*EJECT " F3704_WRITE_FORM

&----


*& Form F3705_WRITE_FORM

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f3705_write_form.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = 'ELE3'

window = 'MAIN'

type = 'BODY'

EXCEPTIONS

element = 1

function = 2

type = 3

unopened = 4

unstarted = 5

window = 6

bad_pageformat_for_print = 7

OTHERS = 8.

IF sy-subrc NE 0.

IF sy-batch EQ c_true.

  • MESSAGE e999 WITH 'Error in Write_Form'(e06).

  • ELSE.

  • MESSAGE i999 WITH 'Error in Write_Form'(e06).

STOP.

ENDIF.

ENDIF.

ENDFORM. "F3705_WRITE_FORM

*EJECT " F3705_WRITE_FORM

&----


*& Form F3706_WRITE_FORM

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f3706_close_form.

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

RESULT = t_result

TABLES

otfdata = t_otfdata

EXCEPTIONS

unopened = 1

bad_pageformat_for_print = 2

send_error = 3

OTHERS = 4.

IF sy-subrc NE 0.

IF sy-batch EQ c_true.

  • MESSAGE e999 WITH 'Error in Close_Form'(e07).

  • ELSE.

  • MESSAGE i999 WITH 'Error in Close_Form'(e07).

STOP.

ENDIF.

ENDIF.

ENDFORM. "f3706_close_form

  • EJECT " F3706_WRITE_FORM

&----


*& Form F1000_CHECK_GATEWAY_CONNECTION

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM F1000_CHECK_GATEWAY_CONNECTION .

  • Check gateway connection

CLEAR E_PROFILE.

CALL FUNCTION 'SO_PROFILE_READ'

IMPORTING

PROFILE = E_PROFILE

EXCEPTIONS

COMMUNICATION_FAILURE = 1

PROFILE_NOT_EXIST = 2

SYSTEM_FAILURE = 3

OTHERS = 4.

IF SY-SUBRC NE 0

OR E_PROFILE-SMTP_EXIST NE C_TRUE.

IF SY-BATCH EQ C_TRUE.

MESSAGE E999

WITH 'No connection to internet gateway present.'(E01).

ELSE.

MESSAGE I999

WITH 'No connection to internet gateway present.'(E01).

STOP.

ENDIF.

ENDIF.

ENDFORM. " F1000_CHECK_GATEWAY_CONNECTION

-


regards,

jay

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question