Code Bgfor Mail Trigger
Code Bgfor Mail Trigger
Code Bgfor Mail Trigger
*---------------------------------------------------------------------*
* Selection Screen
*---------------------------------------------------------------------*
*SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
*SELECTION-SCREEN SKIP.
**PARAMETERS : p_ebeln LIKE ekko-ebeln OBLIGATORY.
**SELECT-OPTIONS : s_ebeln FOR ekko-ebeln no INTERVALS .
**PARAMETERS : p_mailto TYPE ad_smtpadr.
*SELECTION-SCREEN SKIP.
*SELECTION-SCREEN END OF BLOCK b1.
*---------------------------------------------------------------------*
* START-OF-SELECTION.
*---------------------------------------------------------------------*
START-OF-SELECTION.
BREAK-POINT.
*CLEAR : gv_formname , p_ebeln.
PERFORM get_hourly_data.
*&---------------------------------------------------------------------*
*& Form GET_HOURly_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
*FORM GET_HOURly_DATA .
*
**select * from cdhdr INTO TABLE it_cdhdr WHERE udate = SY-DATUM ."AND utime in
W_TIME1.
*
*ENDFORM.
*PERFORM entry USING retcode xscreen.
*
*FORM ENTRY USING return_code TYPE sy-subrc
* us_screen TYPE c.
*
*
*
* REFRESH: gt_ekko, gt_ekpo, gt_item.
* CLEAR: gs_ekko, gs_ekpo, gs_head, gs_item.
* CLEAR: p_ebeln.
*
* PERFORM processing." USING us_screen
*ENDFORM.
*&---------------------------------------------------------------------*
*& Form PROCESSING
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
*FORM PROCESSING .
* DATA: lf_formname TYPE tdsfname,
* ls_delivery_key TYPE leshp_delivery_key.
*
* lf_formname = tnapr-sform.
* gv_formname = tnapr-sform.
*IF p_ebeln IS INITIAL.
* p_ebeln = nast-objky.
* ENDIF.
*ENDFORM.
*&---------------------------------------------------------------------*
*& Form sub_read_ekko
*&---------------------------------------------------------------------*
FORM sub_read_ekko.
*PO Header
SELECT SINGLE *
FROM ekko
INTO gs_ekko
WHERE ebeln = WA_EKKO-EBELN.
ENDIF.
* IF gs_ekko-bukrs = '1000'.
* IF gs_ekko-bsart = 'ZSRO' OR gs_ekko-bsart = 'ZSRX'.
* gv_formname = 'ZMM_PO_PRINT2'.
* ELSEIF gs_ekko-bsart = 'ZSUB'.
* gv_formname = 'ZMM_PO_PRINT3'.
* ELSE.
* gv_formname = 'ZMM_PO_PRINT_GST'.
* ENDIF.
* ELSEIF gs_ekko-bukrs = '2000'.
* IF gs_ekko-bsart = 'ZSRO' OR gs_ekko-bsart = 'ZSRX'.
* gv_formname = 'ZMM_PO_PRINT22'.
* ELSEIF gs_ekko-bsart = 'ZSUB'.
* gv_formname = 'ZMM_PO_PRINT33'.
* ELSE.
* gv_formname = 'ZMM_PO_PRINT11'.
* ENDIF.
* ENDIF.
gs_head-waers = gs_ekko-waers.
*&---------------------------------------------------------------------*
*& Form sub_read_ekpo
*&---------------------------------------------------------------------*
FORM sub_read_ekpo.
*PO Item
SELECT *
FROM ekpo
INTO TABLE gt_ekpo
WHERE ebeln = WA_EKKO-EBELN
AND loekz = ''.
SORT gt_ekpo BY ebelp.
READ TABLE gt_ekpo INTO gs_ekpo INDEX 1.
*&---------------------------------------------------------------------*
*& Form sub_read_cadrc
*&---------------------------------------------------------------------*
FORM sub_read_cadrc.
*Company Address
SELECT SINGLE *
FROM t001
INTO gs_t001
WHERE bukrs = gs_ekko-bukrs.
SELECT SINGLE *
FROM adrc
INTO gs_cadrc
WHERE addrnumber = gs_t001-adrnr.
*&---------------------------------------------------------------------*
*& Form sub_read_lfa1
*&---------------------------------------------------------------------*
FORM sub_read_lfa1.
*Vendor
SELECT SINGLE *
FROM lfa1
INTO gs_lfa1
WHERE lifnr = gs_ekko-lifnr.
*&---------------------------------------------------------------------*
*& Form sub_read_adrc
*&---------------------------------------------------------------------*
FORM sub_read_ladrc.
*LIFNR ADRC
SELECT SINGLE *
FROM adrc
INTO gs_ladrc
WHERE addrnumber = gs_lfa1-adrnr.
*&---------------------------------------------------------------------*
*& Form sub_read_ladr6
*&---------------------------------------------------------------------*
FORM sub_read_ladr6.
IF sy-subrc = 0.
lv_mail = gs_ladr6-SMTP_ADDR.
ENDIF.
*&---------------------------------------------------------------------*
*& Form sub_read_t024
*&---------------------------------------------------------------------*
FORM sub_read_t024.
SELECT SINGLE *
FROM t024
INTO gs_t024
WHERE ekgrp = gs_ekko-ekgrp.
*&---------------------------------------------------------------------*
*& Form sub_read_t001w
*&---------------------------------------------------------------------*
FORM sub_read_t001w.
DATA : lv_werks TYPE werks_d.
SELECT SINGLE *
FROM t001w
INTO gs_t001w
WHERE werks = gs_ekpo-werks.
SELECT SINGLE *
FROM t001w
INTO gs_t001w2
WHERE werks = gs_ekpo-werks.
SELECT SINGLE *
FROM adrc
INTO gs_padrc2
WHERE addrnumber = gs_t001w2-adrnr.
*&---------------------------------------------------------------------*
*& Form sub_read_J_1IMOCOMP
*&---------------------------------------------------------------------*
FORM sub_read_j_1imocomp.
SELECT SINGLE *
FROM j_1imocomp
INTO gs_j_1imocomp
WHERE bukrs = gs_ekko-bukrs
AND werks = gs_ekpo-werks.
*Plant's Address
SELECT SINGLE *
FROM adrc
INTO gs_padrc
WHERE addrnumber = gs_t001w-adrnr.
*&---------------------------------------------------------------------*
*& Form sub_read_makt
*&---------------------------------------------------------------------*
FORM sub_read_makt.
*Material Description
IF gt_ekpo IS NOT INITIAL.
SELECT *
FROM makt
INTO TABLE gt_makt
FOR ALL ENTRIES IN gt_ekpo
WHERE matnr = gt_ekpo-matnr.
ENDIF.
*&---------------------------------------------------------------------*
*& Form sub_read_J_1IMTCHID
*&---------------------------------------------------------------------*
FORM sub_read_j_1imtchid.
*Chapter ID
IF gt_ekpo IS NOT INITIAL.
SELECT *
FROM j_1imtchid
INTO TABLE gt_j_1imtchid
FOR ALL ENTRIES IN gt_ekpo
WHERE matnr = gt_ekpo-matnr
AND werks = gt_ekpo-werks.
ENDIF.
*Delivery Date
IF gt_ekpo IS NOT INITIAL.
SELECT *
FROM eket
INTO TABLE gt_eket
FOR ALL ENTRIES IN gt_ekpo
WHERE ebeln = gt_ekpo-ebeln
AND ebelp = gt_ekpo-ebelp.
ENDIF.
*&---------------------------------------------------------------------*
*& Form sub_read_T006A
*&---------------------------------------------------------------------*
FORM sub_read_t006a.
*UOM
IF gt_ekpo IS NOT INITIAL.
SELECT *
FROM t006a
INTO TABLE gt_t006a
FOR ALL ENTRIES IN gt_ekpo
WHERE spras = 'E'
AND msehi = gt_ekpo-meins.
ENDIF.
*&---------------------------------------------------------------------*
*& Form sub_read_Price
*&---------------------------------------------------------------------*
FORM sub_read_price.
REFRESH: gt_amt.
*Pricing Conditions
SELECT *
FROM prcd_elements
INTO TABLE gt_price
WHERE knumv = gs_ekko-knumv
AND kinak = ''.
DELETE gt_price WHERE kposn IS INITIAL.
LOOP AT gt_price INTO gs_price WHERE kschl = 'PB00' OR kschl = 'PBXX' OR kschl =
'P001'.
lv_total = lv_total + gs_price-kwert.
CLEAR: gs_price, gs_amt.
ENDLOOP.
IF gs_ekko-waers = 'JPY'.
lv_total = lv_total * 100.
ENDIF.
*Condition Records
gs_amt-col1 = 'Gross Value'.
gs_amt-col3 = lv_total.
COLLECT gs_amt INTO gt_amt.
CLEAR: gs_price, gs_amt.
*Taxes - Excise
LOOP AT gt_ekpo INTO gs_ekpo1.
CALL FUNCTION 'ZCALCULATE_TAX_ITEM'
EXPORTING
ebeln = gs_ekpo1-ebeln
ebelp = gs_ekpo1-ebelp
TABLES
t_xkomv = lt_komv.
*Taxes - VAT/CST
LOOP AT gt_ekpo INTO gs_ekpo1.
CALL FUNCTION 'ZCALCULATE_TAX_ITEM'
EXPORTING
ebeln = gs_ekpo1-ebeln
ebelp = gs_ekpo1-ebelp
TABLES
t_xkomv = lt_komv.
REFRESH: lt_komv.
CLEAR: gs_ekpo1, gs_amt.
ENDLOOP.
LOOP AT lt_komv INTO ls_komv WHERE kschl = 'STE1' OR kschl = 'STI1' OR kschl =
'SBC4' OR kschl = 'SRL1' OR kschl = 'KKC4'.
gs_amt-col1 = 'Service Tax'.
gs_amt-col3 = ls_komv-kwert.
COLLECT: gs_amt INTO gt_amt.
CLEAR: ls_komv, gs_amt.
ENDLOOP.
REFRESH: lt_komv.
CLEAR: gs_ekpo1, gs_amt.
ENDLOOP.
*Taxes - Singapore (GST)
LOOP AT gt_ekpo INTO gs_ekpo1.
CALL FUNCTION 'ZCALCULATE_TAX_ITEM'
EXPORTING
ebeln = gs_ekpo1-ebeln
ebelp = gs_ekpo1-ebelp
TABLES
t_xkomv = lt_komv.
REFRESH: lt_komv.
CLEAR: gs_ekpo1, gs_amt.
ENDLOOP.
gs_amt-col1 = 'CGST'.
gs_amt-col3 = lv_cgst.
APPEND gs_amt TO gt_amt.
* IF lv_cgst_rc NE '0.00'.
* gs_amt-col1 = 'CGST-RC'.
* gs_amt-col3 = ( -1 ) * lv_cgst_rc.
* APPEND gs_amt TO gt_amt.
* ENDIF.
gs_amt-col1 = 'SGST'.
gs_amt-col3 = lv_sgst.
APPEND gs_amt TO gt_amt.
* IF lv_sgst_rc NE '0.00'.
* gs_amt-col1 = 'SGST-RC'.
* gs_amt-col3 = ( -1 ) * lv_sgst_rc.
* APPEND gs_amt TO gt_amt.
* ENDIF.
gs_amt-col1 = 'IGST'.
gs_amt-col3 = lv_igst.
APPEND gs_amt TO gt_amt.
* IF lv_igst_rc NE '0.00'.
* gs_amt-col1 = 'IGST-RC'.
* gs_amt-col3 = ( -1 ) * lv_igst_rc.
* APPEND gs_amt TO gt_amt.
* ENDIF.
*****************************
LOOP AT gt_price INTO gs_price WHERE ( kschl = 'FRA1' OR kschl = 'FRA2' OR kschl
= 'FRA3'
OR kschl = 'FRB1' OR kschl = 'FRB2' OR kschl = 'FRB3' ) AND ( lifnr = gs_ekko-
lifnr ).
gs_amt-col1 = 'Total Freight Charges'.
gs_amt-col3 = gs_price-kwert.
COLLECT gs_amt INTO gt_amt.
CLEAR: gs_price, gs_amt.
ENDLOOP.
LOOP AT gt_price INTO gs_price WHERE kschl = 'ZINR' OR kschl = 'ZINA' OR kschl =
'ZINM'.
gs_amt-col1 = 'Total Insurance Charges'.
gs_amt-col3 = gs_price-kwert.
COLLECT gs_amt INTO gt_amt.
CLEAR: gs_price, gs_amt.
ENDLOOP.
LOOP AT gt_price INTO gs_price WHERE kschl = 'ZLUC' AND ( lifnr = gs_ekko-
lifnr ).
gs_amt-col1 = 'Loading Charges'.
gs_amt-col3 = gs_price-kwert.
COLLECT gs_amt INTO gt_amt.
CLEAR: gs_price, gs_amt.
ENDLOOP.
LOOP AT gt_price INTO gs_price WHERE kschl = 'ZCFC' AND ( lifnr = gs_ekko-
lifnr ).
gs_amt-col1 = 'Clearing Charges'.
gs_amt-col3 = gs_price-kwert.
COLLECT gs_amt INTO gt_amt.
CLEAR: gs_price, gs_amt.
ENDLOOP.
LOOP AT gt_price INTO gs_price WHERE kschl = 'ZBNC' AND ( lifnr = gs_ekko-
lifnr ).
gs_amt-col1 = 'Bank Charges'.
gs_amt-col3 = gs_price-kwert.
COLLECT gs_amt INTO gt_amt.
CLEAR: gs_price, gs_amt.
ENDLOOP.
LOOP AT gt_price INTO gs_price WHERE kschl = 'ZINC' AND ( lifnr = gs_ekko-
lifnr ).
gs_amt-col1 = 'Inspection Charges'.
gs_amt-col3 = gs_price-kwert.
COLLECT gs_amt INTO gt_amt.
CLEAR: gs_price, gs_amt.
ENDLOOP.
CLEAR: lv_total.
LOOP AT gt_amt INTO gs_amt WHERE col1 <> 'Net Value'.
lv_total = lv_total + gs_amt-col3.
ENDLOOP.
*Amount in words
CREATE OBJECT lo_spell.
ls_amt = lv_total.
"m1
if gs_ekko-waers = 'JPY'.
ls_amt = ls_amt / 100 .
endif.
CALL METHOD lo_spell->spell_amount_in
EXPORTING
iv_amount = ls_amt
iv_currency = gs_ekko-waers "'INR'
iv_language = sy-langu
RECEIVING
rs_words = ls_words_spell.
gs_head-amount_words = ls_words_spell.
*&---------------------------------------------------------------------*
*& Form sub_read_terms
*&---------------------------------------------------------------------*
FORM sub_read_terms.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form sub_read_addressess
*&---------------------------------------------------------------------*
FORM sub_read_addressess.
DATA: lv_title(10) TYPE c.
gs_head-heading2 = gs_t001-butxt.
gs_head-heading = gs_t001-butxt."m1
IF gs_ekko-zzinvoice_to = 'P'.
gs_head-i_add1 = gs_padrc-street.
gs_head-i_add2 = gs_padrc-str_suppl1.
CONCATENATE gs_padrc-city1 '-' gs_padrc-post_code1 INTO
gs_head-i_add3 SEPARATED BY space.
ELSE.
gs_head-i_add1 = gs_padrc2-street.
gs_head-i_add2 = gs_padrc2-str_suppl1.
CONCATENATE gs_padrc-city1 '-' gs_padrc-post_code1 INTO
gs_head-i_add3 SEPARATED BY space.
ENDIF.
DO 3 TIMES.
IF gs_head-i_add1 IS INITIAL.
gs_head-i_add1 = gs_head-i_add2.
CLEAR: gs_head-i_add2.
ENDIF.
IF gs_head-i_add2 IS INITIAL.
gs_head-i_add2 = gs_head-i_add3.
CLEAR: gs_head-i_add3.
ENDIF.
IF gs_head-i_add3 IS INITIAL.
gs_head-i_add3 = gs_head-i_add4.
CLEAR: gs_head-i_add4.
ENDIF.
ENDDO.
if gs_ekko-ihrez IS NOT INITIAL."m1
lv_kunnr = gs_ekko-ihrez(10).
SELECT SINGLE * from kna1 INTO gs_kna1 WHERE kunnr = lv_kunnr.
IF sy-subrc eq 0.
select single * from adrc INTO gs_kadrc WHERE ADDRNUMBER = gs_kna1-adrnr.
IF sy-subrc eq 0.
gs_head-heading = gs_kadrc-name1.
* gs_head-d_add1 = gs_kadrc-name1.
gs_head-d_add1 = gs_kadrc-street.
CONCATENATE gs_kadrc-city1 '-' gs_kadrc-post_code1 INTO
gs_head-d_add3 SEPARATED BY space.
gs_head-d_add2 = gs_kadrc-STR_SUPPL1.
gs_head-d_gstin = gs_kna1-stcd3.
ENDIF.
ELSE.
lv_ref_ind = 'X'.
ENDIF.
else.
lv_ref_ind = 'X'.
endif."m1
if gs_head-d_add1 is INITIAL.
READ TABLE gt_ekpo INTO gs_ekpo WITH KEY ebelp = '00010'.
IF gs_ekpo-adrnr IS INITIAL.
gs_head-d_add1 = gs_padrc-street.
gs_head-d_add2 = gs_padrc-str_suppl1.
CONCATENATE gs_padrc-city1 '-' gs_padrc-post_code1 INTO
gs_head-d_add3 SEPARATED BY space.
ELSE.
SELECT SINGLE * FROM adrc INTO gs_padrc WHERE addrnumber = gs_ekpo-adrnr.
SELECT SINGLE * FROM tsad3t INTO gs_tsad3t WHERE langu = 'E' AND title =
gs_padrc-title.
CONCATENATE gs_tsad3t-title_medi gs_padrc-name1 gs_padrc-name2 INTO gs_head-
d_add1 SEPARATED BY space.
gs_head-d_add2 = gs_padrc-street.
CONCATENATE gs_padrc-city1 '-' gs_padrc-post_code1 INTO
gs_head-d_add3 SEPARATED BY space.
ENDIF.
endif.
DO 3 TIMES.
IF gs_head-d_add1 IS INITIAL.
gs_head-d_add1 = gs_head-d_add2.
CLEAR: gs_head-d_add2.
ENDIF.
IF gs_head-d_add2 IS INITIAL.
gs_head-d_add2 = gs_head-d_add3.
CLEAR: gs_head-d_add3.
ENDIF.
IF gs_head-d_add3 IS INITIAL.
gs_head-d_add3 = gs_head-d_add4.
CLEAR: gs_head-d_add4.
ENDIF.
ENDDO.
***********VENDOR***************
SELECT SINGLE GST_BLAND FROM ZT005U INTO gs_head-v_state_cd WHERE BLAND =
gs_lfa1-regio.
gs_head-v_gstin = gs_lfa1-stcd3.
gs_head-v_add1 = gs_ladrc-name1.
SHIFT gs_lfa1-lifnr LEFT DELETING LEADING '0'.
CONCATENATE gs_head-v_add1 '(' gs_lfa1-lifnr ')' INTO gs_head-v_add1 SEPARATED BY
space.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gs_lfa1-lifnr
IMPORTING
output = gs_lfa1-lifnr.
gs_head-v_add2 = gs_ladrc-street.
gs_head-v_add3 = gs_ladrc-str_suppl1.
CONCATENATE gs_ladrc-city1 gs_ladrc-post_code1 INTO gs_head-v_add4 SEPARATED BY
space.
DO 3 TIMES.
IF gs_head-v_add1 IS INITIAL.
gs_head-v_add1 = gs_head-v_add2.
CLEAR: gs_head-v_add2.
ENDIF.
IF gs_head-v_add2 IS INITIAL.
gs_head-v_add2 = gs_head-v_add3.
CLEAR: gs_head-v_add3.
ENDIF.
IF gs_head-v_add3 IS INITIAL.
gs_head-v_add3 = gs_head-v_add4.
CLEAR: gs_head-v_add4.
ENDIF.
ENDDO.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form sub_read_ESLL
*&---------------------------------------------------------------------*
FORM sub_read_esll.
gt_ekpo1[] = gt_ekpo[].
LOOP AT gt_ekpo1 ASSIGNING <lf_ekpo>.
<lf_ekpo>-packno = <lf_ekpo>-packno + 1.
ENDLOOP.
UNASSIGN: <lf_ekpo>.
*UOM
IF gt_esll2 IS NOT INITIAL.
SELECT * FROM ASMD INTO TABLE GT_ASMD FOR ALL ENTRIES IN gt_esll2 WHERE
ASNUM = gt_esll2-SRVPOS .
SELECT *
FROM t006a
INTO TABLE gt_t006a2
FOR ALL ENTRIES IN gt_esll2
WHERE spras = 'E'
AND msehi = gt_esll2-meins.
ENDIF.
*&---------------------------------------------------------------------*
*& Form sub_read_resb
*&---------------------------------------------------------------------*
FORM sub_read_resb.
*Chapter ID
IF gt_resb3 IS NOT INITIAL.
SELECT *
FROM j_1imtchid
INTO TABLE gt_j_1imtchid3
FOR ALL ENTRIES IN gt_resb3
WHERE matnr = gt_resb3-matnr
AND werks = gt_resb3-werks.
ENDIF.
*&---------------------------------------------------------------------*
*& Form sub_read_final
*&---------------------------------------------------------------------*
FORM sub_read_final.
REFRESH: gt_text.
gs_head-po_no = gs_ekko-ebeln.
CONCATENATE gs_ekko-bedat+6(2) '/' gs_ekko-bedat+4(2) '/' gs_ekko-bedat+0(4) INTO
gs_head-po_date.
gs_head-provider_add = gs_lfa1-adrnr.
gs_head-salesperson = gs_ekko-verkf.
gs_head-smob_no = gs_lfa1-telf2.
gs_head-stel_no = gs_lfa1-telf1.
gs_head-semail = gs_ladr6-smtp_addr.
* gs_head-bcontact_person = gs_adrp-NAME_FIRST. "gs_t024-eknam.
CONCATENATE gs_adrp-name_first gs_adrp-name_last INTO gs_head-bcontact_person
SEPARATED BY space.
gs_head-bcontact_no = gs_adr2-tel_number. "gs_t024-ektel.
gs_head-bemail = gs_adr6-smtp_addr. "gs_t024-smtp_addr.
*Header Text
DATA: newline1(2) TYPE x VALUE '0D0A'.
DATA: lv_tdname TYPE thead-tdname.
CLEAR: lv_tdname, gs_text.
REFRESH : t_lines.
lv_tdname = gs_ekpo-ebeln .
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = 'F01'
language = sy-langu
name = lv_tdname
object = 'EKKO'
TABLES
lines = t_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
LOOP AT t_lines.
IF t_lines-tdline IS NOT INITIAL.
IF gs_head-head_txt IS INITIAL.
CONCATENATE gs_head-head_txt t_lines-tdline INTO gs_head-head_txt.
ELSE.
IF t_lines-tdformat IS INITIAL.
CONCATENATE gs_head-head_txt t_lines-tdline INTO gs_head-head_txt.
ELSE.
CONCATENATE gs_head-head_txt t_lines-tdline INTO gs_head-head_txt
SEPARATED BY cl_abap_char_utilities=>cr_lf.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
* IF gs_text-item_text1 IS NOT INITIAL.
* CONCATENATE 'Item' gs_ekpo-ebelp ':' gs_text-item_text1 INTO gs_text-
item_text1 SEPARATED BY space.
* APPEND: gs_text TO gt_text.
* ENDIF.
*Purchase Order
REFRESH : gt_item.
DATA: lv_item TYPE char30.
LOOP AT gt_ekpo INTO gs_ekpo.
gs_item-ebelp = gs_ekpo-ebelp.
SHIFT gs_item-ebelp LEFT DELETING LEADING '0'.
gs_item-mat_code = gs_ekpo-matnr.
READ TABLE gt_makt INTO gs_makt WITH KEY matnr = gs_ekpo-matnr.
IF sy-subrc = 0.
gs_item-maktx = gs_makt-maktx.
ELSE.
gs_item-maktx = gs_ekpo-txz01.
ENDIF.
READ TABLE gt_eket INTO gs_eket WITH KEY ebeln = gs_ekpo-ebeln ebelp = gs_ekpo-
ebelp.
IF sy-subrc = 0.
CONCATENATE gs_eket-eindt+6(2) '/' gs_eket-eindt+4(2) '/' gs_eket-eindt+0(4)
INTO gs_item-del_date.
ENDIF.
READ TABLE gt_price INTO gs_price WITH KEY kposn = gs_ekpo-ebelp kschl =
'RA00'.
IF sy-subrc = 0.
gs_price-kbetr = gs_price-kbetr * -1.
gs_item-discount = gs_price-kbetr.
ENDIF.
IF gs_item-hsn_code IS INITIAL.
gs_item-hsn_code = gs_ekpo-j_1bnbm.
ENDIF.
*Include Text
CLEAR: lv_tdname, gs_text.
REFRESH : t_lines.
CONCATENATE gs_ekpo-ebeln gs_ekpo-ebelp INTO lv_tdname.
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = 'F01'
language = sy-langu
name = lv_tdname
object = 'EKPO'
TABLES
lines = t_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
LOOP AT t_lines.
* IF t_lines-tdline IS NOT INITIAL.
* CONCATENATE gs_text-item_text1 t_lines-tdline INTO gs_text-item_text1.
* ENDIF.
IF t_lines-tdline IS NOT INITIAL.
IF gs_text-item_text1 IS INITIAL.
CONCATENATE gs_text-item_text1 t_lines-tdline INTO gs_text-item_text1.
ELSE.
IF t_lines-tdformat IS INITIAL.
CONCATENATE gs_text-item_text1 t_lines-tdline INTO gs_text-item_text1.
ELSE.
CONCATENATE gs_text-item_text1 t_lines-tdline INTO gs_text-item_text1
SEPARATED BY cl_abap_char_utilities=>cr_lf.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
IF gs_text-item_text1 IS NOT INITIAL.
CONCATENATE 'Item' gs_ekpo-ebelp ':' INTO lv_item SEPARATED BY space.
CONCATENATE lv_item gs_text-item_text1 INTO gs_text-item_text1 SEPARATED BY
cl_abap_char_utilities=>cr_lf.
APPEND: gs_text TO gt_text.
ENDIF.
CLEAR: gs_ekpo.
ENDLOOP.
*Delivery Schedule
IF gs_ekko-zzdel_tick IS INITIAL AND gs_ekko-zzcomp_tick IS INITIAL.
gs_head-ann2 = 'X'.
ENDIF.
IF gs_ekko-zzdel_tick IS NOT INITIAL.
SORT gt_eket BY ebeln ebelp.
LOOP AT gt_eket INTO gs_eket.
lv_count = lv_count + 1.
gs_del-sno = lv_count.
READ TABLE gt_ekpo INTO gs_ekpo WITH KEY ebeln = gs_eket-ebeln ebelp =
gs_eket-ebelp.
IF sy-subrc = 0.
gs_del-mat_code = gs_ekpo-matnr.
REFRESH : gt_item2.
LOOP AT gt_ekpo INTO gs_ekpo.
gs_item2-sno = gs_ekpo-ebelp.
gs_item2-maktx = gs_ekpo-txz01.
READ TABLE gt_eket INTO gs_eket WITH KEY ebeln = gs_ekpo-ebeln ebelp = gs_ekpo-
ebelp.
IF sy-subrc = 0.
CONCATENATE gs_eket-eindt+6(2) '/' gs_eket-eindt+4(2) '/' gs_eket-eindt+0(4)
INTO gs_item2-del_date.
ENDIF.
gs_item2-netpr = gs_ekpo-netpr.
gs_item2-menge = gs_ekpo-menge.
gs_item2-tot_value = gs_ekpo-netpr * gs_ekpo-menge.
READ TABLE gt_price INTO gs_price WITH KEY kposn = gs_ekpo-ebelp kschl =
'RA00'.
IF sy-subrc = 0.
gs_price-kbetr = gs_price-kbetr * -1.
gs_item2-discount = gs_price-kbetr.
ENDIF.
APPEND: gs_item2 TO gt_item2.
READ TABLE gt_ekpo1 INTO gs_ekpo1 WITH KEY ebeln = gs_ekpo-ebeln ebelp =
gs_ekpo-ebelp.
IF sy-subrc = 0.
READ TABLE gt_esll1 INTO gs_esll1 WITH KEY packno = gs_ekpo1-packno extrow
= gs_esll2-extrow.
IF sy-subrc = 0.
gs_item2-mat_code = gs_esll1-srvpos.
SHIFT gs_item2-mat_code LEFT DELETING LEADING '0'.
ENDIF.
ENDIF.
FORM pdf_form.
gv_formname = 'ZMM_PO_PRINT_GST'.
***************Fetch Function Module Name of the FORM****************
TRY.
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = gv_formname
IMPORTING
e_funcname = gv_function_name.
CATCH cx_fp_api_usage.
CATCH cx_fp_api_repository INTO gv_rcx_rep.
CATCH cx_fp_api_internal .
ENDTRY.
* gs_fp_docparams-dynamic = 'X'.
if gs_ekko-bsart eq 'ZSRO'.
CALL FUNCTION gv_function_name
EXPORTING
/1bcdwb/docparams = gs_fp_docparams
ls_head = gs_head
lt_final = gt_item_srv[]
lt_amt = gt_amt
lt_del = gt_del
lt_text = gt_text
lt_item2 = gt_item2
lt_amt2 = gt_amt2
lt_comp = gt_comp3
ann2 = gs_head-ann2
IMPORTING
/1bcdwb/formoutput = gs_formoutput
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
else.
CALL FUNCTION gv_function_name
EXPORTING
/1bcdwb/docparams = gs_fp_docparams
ls_head = gs_head
lt_final = gt_item
lt_amt = gt_amt
lt_del = gt_del
lt_text = gt_text
lt_item2 = gt_item2
lt_amt2 = gt_amt2
lt_comp = gt_comp3
ann2 = gs_head-ann2
IMPORTING
/1bcdwb/formoutput = gs_formoutput
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
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.
*************************Close spool job*******************************
CALL FUNCTION 'FP_JOB_CLOSE'
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CONVERT_PDF_BINARY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM CONVERT_PDF_BINARY .
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = gs_formoutput-pdf
* APPEND_TO_TABLE = ' '
* IMPORTING
* OUTPUT_LENGTH =
TABLES
BINARY_TAB = it_att_content_hex .
.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form MAIL_ATTACHMENT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM MAIL_ATTACHMENT .
IF lv_mail is NOT INITIAL .
CLASS cl_bcs DEFINITION LOAD.
DATA:
lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
lo_send_request = cl_bcs=>create_persistent( ).
* Message body and subject
DATA:
lt_message_body TYPE bcsy_text VALUE IS INITIAL,
lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.
APPEND 'Dear,' TO lt_message_body.
append ' ' to lt_message_body.
APPEND 'Please find the attached Po. .' TO lt_message_body.
append ' ' to lt_message_body.
append 'Note: It is an auto-generated mail do not reply.' to lt_message_body.
APPEND 'Thank You,' TO lt_message_body.
APPEND ' ' TO lt_message_body.
APPEND 'Regards' TO lt_message_body.
APPEND 'GreyOrange Team' TO lt_message_body.
lo_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_message_body
i_subject = 'Purchase order from GreyOrange india Pvt. Ltd').
DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL.
TRY.
lo_document->add_attachment(
EXPORTING
i_attachment_type = 'PDF'
i_attachment_subject = 'Purchase order Form'
i_att_content_hex = it_att_content_hex ).
CATCH cx_document_bcs INTO lx_document_bcs.
ENDTRY.
* Add attachment
* Pass the document to send request
lo_send_request->set_document( lo_document ).
* Create sender
DATA:
lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL.
lo_sender = cl_sapuser_bcs=>create( sy-uname ).
* Set sender
lo_send_request->set_sender(
EXPORTING
i_sender = lo_sender ).
* Create recipient
DATA:
lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.
* lo_recipient = cl_sapuser_bcs=>create( sy-uname ).
lo_recipient = cl_cam_address_bcs=>create_internet_address( lv_mail ).
** Set recipient
lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = 'X' ).
* Send email
DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL.
lo_send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = lv_sent_to_all ).
COMMIT WORK.
IF lv_sent_to_all IS INITIAL.
MESSAGE i500(sbcoms) WITH lv_mail.
ELSE.
MESSAGE s022(so).
ENDIF.
else.
lv_mail1 = gs_head-bemail.
ENDIF.
endif.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_HOURLY_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM GET_HOURLY_DATA .
w_time2 = sy-uzeit.
* w_time1 = w_time2 - 3590.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = w_time2
IMPORTING
OUTPUT = w_time2.
w_time1 = w_time2 - 3590.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = w_time1
IMPORTING
OUTPUT = w_time1.
* SELECT * FROM cdhdr INTO TABLE it_cdhdr WHERE OBJECTCLAS = 'EINKBELEG' AND
UDATE = sy-datum AND ( utime > w_time1 OR utime < w_time2 )
* AND ( tcode = 'ME29N' OR
TCODE = 'ME28' ).
SELECT * FROM cdhdr INTO TABLE it_cdhdr WHERE OBJECTCLAS = 'EINKBELEG' AND UDATE
= sy-datum AND utime > w_time1 AND utime < w_time2
AND ( tcode = 'ME29N' OR
TCODE = 'ME28' ).
IF IT_CDHDR IS NOT INITIAL.
LOOP AT IT_CDHDR INTO WA_CDHDR.
WA_PO-EBELN = WA_CDHDR-OBJECTID.
* WA_PO-OBJECTCLAS = WA_CDHDR-OBJECTCLAS.
APPEND WA_PO TO IT_PO.
ENDLOOP.
ENDIF.
IF IT_PO IS NOT INITIAL .
SELECT * FROM ekko INTO TABLE it_ekko FOR ALL ENTRIES IN it_PO WHERE ebeln =
IT_PO-EBELN AND frgke = '1'.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form MAIL_TOUSER
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM MAIL_TOUSER .
SELECT single * FROM adr6 INTO wa_adr6 WHERE ADDRNUMBER = wa_ekko-adrnr and
FLG_NOUSE = 'X'.
IF sy-subrc = 0 .
CLEAR:mailto,main_text.
REFRESH:main_text[].
* TRY.
mailto = wa_adr6-SMTP_ADDR.
* -------- CREATE PERSISTENT SEND REQUEST ------------------------
send_request = cl_bcs=>create_persistent( ).
* APPEND space TO main_text.
* CONCATENATE 'Dear ' INTO str SEPARATED BY space.
* CONCATENATE 'Dear ,' into str .
str = 'Dear,'.
* CONCATENATE 'Please find attached your overdue status as on'
lv_dates '.' INTO lv_body SEPARATED BY space.
APPEND str TO main_text.
clear str.
APPEND space TO main_text.
* CLEAR lv_body.
CONCATENATE 'Your Purchase order' wa_ekko-ebeln ' has been released
in SAP.' INTO str SEPARATED BY space.
* CONCATENATE 'Please find attached your overdue status as on'
lv_dates '.' INTO lv_body SEPARATED BY space.
APPEND str TO main_text.
clear str.
COMMIT WORK.
IF sent_to_all IS INITIAL.
MESSAGE i500(sbcoms) WITH mailto.
ELSE.
MESSAGE s022(so).
ENDIF.
SKIP.
ENDIF.
ENDFORM.