Code Bgfor Mail Trigger

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 34

*&---------------------------------------------------------------------*

*& Report ZMM_PO_MAIL_ATTACH


*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZMM_PO_MAIL_ATTACH.
TABLES : ekko, nast, tnapr.
INCLUDE messdata.
DATA : gt_ekko TYPE STANDARD TABLE OF ekko INITIAL SIZE 0,
gs_ekko TYPE ekko,
gs_ekko1 TYPE ekko,
gt_ekpo TYPE STANDARD TABLE OF ekpo INITIAL SIZE 0,
gt_ekpo1 TYPE STANDARD TABLE OF ekpo INITIAL SIZE 0,
gs_ekpo TYPE ekpo,
gs_ekpo1 TYPE ekpo,
gs_lfa1 TYPE lfa1,
gs_ladrc TYPE adrc,
gs_padrc TYPE adrc,
gs_padrc2 TYPE adrc,
gs_cadrc TYPE adrc,
gs_tsad3t TYPE tsad3t,
gs_t001 TYPE t001,
gs_ladr6 TYPE adr6,
gs_t024 TYPE t024,
gs_t0241 TYPE t024,
gs_j_1imocomp TYPE j_1imocomp,
gs_t001w TYPE t001w,
gs_t001w2 TYPE t001w,
gs_head TYPE zmm_po_h,
gs_usr21 TYPE usr21,
gs_adr2 TYPE adr2,
gs_adr6 TYPE adr6,
gs_adrp TYPE adrp,
gt_makt TYPE STANDARD TABLE OF makt INITIAL SIZE 0,
gs_makt TYPE makt,
gt_mara TYPE STANDARD TABLE OF mara INITIAL SIZE 0,
gs_mara TYPE mara,
gt_j_1imtchid TYPE STANDARD TABLE OF j_1imtchid INITIAL SIZE 0,
gs_j_1imtchid TYPE j_1imtchid,
gt_eket TYPE STANDARD TABLE OF eket INITIAL SIZE 0,
gs_eket TYPE eket,
gt_t006a TYPE STANDARD TABLE OF t006a INITIAL SIZE 0,
gs_t006a TYPE t006a,
gt_t006a2 TYPE STANDARD TABLE OF t006a INITIAL SIZE 0,
gs_t006a2 TYPE t006a,
gt_price TYPE TABLE OF prcd_elements INITIAL SIZE 0,
gs_price TYPE prcd_elements,
gt_item TYPE STANDARD TABLE OF zmm_po_i INITIAL SIZE 0,
gs_item TYPE zmm_po_i,
gt_del TYPE STANDARD TABLE OF zmm_po_i3 INITIAL SIZE 0, "For
Annexture II (Delivery Schedule)
gs_del TYPE zmm_po_i3,
gt_esll TYPE STANDARD TABLE OF esll INITIAL SIZE 0, "For Service
Order
gs_esll TYPE esll,
gt_esll1 TYPE STANDARD TABLE OF esll INITIAL SIZE 0,
gs_esll1 TYPE esll,
gt_esll2 TYPE STANDARD TABLE OF esll INITIAL SIZE 0,
gs_esll2 TYPE esll,
gt_item2 TYPE STANDARD TABLE OF zmm_po_i4 INITIAL SIZE 0,
gs_item2 TYPE zmm_po_i4,
gt_amt2 TYPE STANDARD TABLE OF zmm_po_f INITIAL SIZE 0,
gs_amt2 TYPE zmm_po_f,
gt_comp3 TYPE STANDARD TABLE OF zmm_po_i5 INITIAL SIZE 0,
gs_comp3 TYPE zmm_po_i5,
gt_j_1imtchid3 TYPE STANDARD TABLE OF j_1imtchid INITIAL SIZE 0,
gs_j_1imtchid3 TYPE j_1imtchid,
gt_makt3 TYPE STANDARD TABLE OF makt INITIAL SIZE 0,
gs_makt3 TYPE makt,
gt_resb3 TYPE STANDARD TABLE OF resb INITIAL SIZE 0,
gs_resb3 TYPE resb,
gt_mara3 TYPE STANDARD TABLE OF mara INITIAL SIZE 0,
gs_mara3 TYPE mara,
gt_amt TYPE STANDARD TABLE OF zmm_po_f INITIAL SIZE 0, "For
Conditions & Taxes
gs_amt TYPE zmm_po_f,
gt_text TYPE STANDARD TABLE OF zmm_text INITIAL SIZE 0,
gs_text TYPE zmm_text,
GT_ASMD TYPE STANDARD TABLE OF ASMD INITIAL SIZE 0,
GS_ASMD TYPE ASMD,
gt_item_srv TYPE TABLE OF ZMM_PO_I,
gs_item_srv TYPE ZMM_PO_I,
gs_kna1 TYPE kna1,"m1
gs_kadrc TYPE adrc.

data: it_att_content_hex type SOLIX_TAB,


gs_formoutput TYPE fpformoutput,
lv_mail TYPE ad_smtpadr.

DATA: lines LIKE tline OCCURS 0 WITH HEADER LINE,


t_lines LIKE tline OCCURS 0 WITH HEADER LINE,
t_lines1 LIKE tline OCCURS 0 WITH HEADER LINE,
istxh LIKE stxh OCCURS 0 WITH HEADER LINE,
var LIKE thead-tdname,
gv_bukrs TYPE bukrs,
retcode TYPE sy-subrc,
xscreen TYPE c,
flag TYPE c,
gv_formname TYPE na_fname,
lv_char20 TYPE char20,
gv_total TYPE dmbtr,
lv_cgst TYPE dmbtr,
lv_cgst_rc TYPE dmbtr,
lv_igst TYPE dmbtr,
lv_igst_rc TYPE dmbtr,
lv_sgst TYPE dmbtr,
lv_sgst_rc TYPE dmbtr,
lv_kunnr(10) TYPE N,
lv_ref_ind TYPE C.

TYPES : BEGIN OF TY_PO,


EBELN(10) TYPE C,
* OBJECTCLAS TYPE CDHDR-OBJECTCLAS,
END OF TY_PO.

data : it_cdhdr TYPE TABLE OF cdhdr,


wa_cdhdr TYPE cdhdr,
it_cdpos TYPE TABLE OF cdpos,
wa_cdpos TYPE cdpos,
it_ekko TYPE TABLE OF ekko,
wa_ekko TYPE ekko,
IT_PO TYPE TABLE OF TY_PO,
WA_PO TYPE TY_PO.

data : w_time1 TYPE T ,


w_time2 TYPE t.

DATA : mailto TYPE ad_smtpadr,


* mailfrom TYPE ad_smtpadr,
lv_mail1 TYPE ad_smtpadr,
sender TYPE REF TO if_sender_bcs,
send_request TYPE REF TO cl_bcs,
document TYPE REF TO cl_document_bcs,
recipient TYPE REF TO if_recipient_bcs,
bcs_exception TYPE REF TO cx_bcs,
main_text TYPE bcsy_text,
sent_to_all TYPE os_boolean,
binary_content TYPE solix_tab,
size TYPE so_obj_len,
str TYPE string,
str1 TYPE SO_OBJ_DES.

*******************DATA DEclaration by subhendu************


data : wa_adr6 TYPE adr6,
lv_name2 type adrp-NAME_FIRST,
lv_name3 TYPE adrp-NAME_FIRST.

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

* IF tnapr-sform IS NOT INITIAL.


* gv_formname = tnapr-sform.
* ELSE.
* gv_formname = 'ZMM_PO_PRINT_GST'.
* ENDIF.
* CHECK retcode = 0.

LOOP AT IT_EKKO INTO WA_EKKO.


clear : lv_mail , lv_mail1 , mailto.
PERFORM sub_read_ekko.
PERFORM sub_read_ekpo.
PERFORM sub_read_cadrc.
PERFORM sub_read_lfa1.
PERFORM sub_read_ladrc.
PERFORM sub_read_ladr6.
PERFORM sub_read_t024.
PERFORM sub_read_t0241.
PERFORM sub_read_t001w.
PERFORM sub_read_j_1imocomp .
PERFORM sub_read_padrc.
PERFORM sub_read_makt.
PERFORM sub_read_j_1imtchid.
PERFORM sub_read_eket.
PERFORM sub_read_t006a.
PERFORM sub_read_price.
PERFORM sub_read_terms.
PERFORM sub_read_addressess.
PERFORM sub_read_esll. "Service Order
PERFORM sub_read_resb. "Subcontracting Order
PERFORM sub_read_final.
PERFORM pdf_form.
PERFORM convert_pdf_binary.
PERFORM mail_attachment.
PERFORM mail_touser.
CLEAR : WA_EKKO.
ENDLOOP.

*ENDFORM.
*&---------------------------------------------------------------------*
*& Form sub_read_ekko
*&---------------------------------------------------------------------*
FORM sub_read_ekko.

*PO Header
SELECT SINGLE *
FROM ekko
INTO gs_ekko
WHERE ebeln = WA_EKKO-EBELN.

SELECT COUNT( * ) FROM CDPOS INTO gs_head-count


WHERE OBJECTID EQ WA_EKKO-EBELN
AND TABNAME EQ 'EKKO'
AND FNAME EQ 'FRGKE'
AND VALUE_NEW IN ( '0' ,'H' , '8' ,
'L' ).

if ( gs_ekko-FRGGR EQ 'PS' AND gs_ekko-FRGSX EQ '28' ) OR ( gs_ekko-FRGGR EQ


'PS' AND gs_ekko-FRGSX EQ '29' ) OR ( gs_ekko-FRGGR EQ 'PS' AND gs_ekko-FRGSX EQ
'30' )
OR ( gs_ekko-FRGGR EQ 'PS' AND gs_ekko-FRGSX EQ '31' ) OR ( gs_ekko-FRGGR EQ
'PS' AND gs_ekko-FRGSX EQ '49' ) OR ( gs_ekko-FRGGR EQ 'PS' AND gs_ekko-FRGSX EQ
'50' )
OR ( gs_ekko-FRGGR EQ 'PS' AND gs_ekko-FRGSX EQ '51' ) OR ( gs_ekko-FRGGR EQ
'PS' AND gs_ekko-FRGSX EQ '52' ) OR ( gs_ekko-FRGGR EQ 'PS' AND gs_ekko-FRGSX EQ
'70' )
OR ( gs_ekko-FRGGR EQ 'PS' AND gs_ekko-FRGSX EQ '71' ) OR ( gs_ekko-FRGGR EQ 'PS'
AND gs_ekko-FRGSX EQ '72' ) OR ( gs_ekko-FRGGR EQ 'PS' AND gs_ekko-FRGSX EQ '73' ).

SELECT COUNT( * ) FROM CDPOS INTO gs_head-count


WHERE OBJECTID EQ WA_EKKO-EBELN
AND TABNAME EQ 'EKKO'
AND FNAME EQ 'FRGKE'
AND VALUE_NEW EQ 'A'.

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.

* IF gs_ekko-bsart = 'ZSRO' OR gs_ekko-bsart = 'ZSRX'.


* gv_formname = 'ZMM_PO_PRINT_GST2'.
* ENDIF.

gs_head-waers = gs_ekko-waers.

ENDFORM. " sub_read_ekko

*&---------------------------------------------------------------------*
*& 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.

ENDFORM. " sub_read_ekpo

*&---------------------------------------------------------------------*
*& 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.

ENDFORM. " sub_read_cadrc

*&---------------------------------------------------------------------*
*& Form sub_read_lfa1
*&---------------------------------------------------------------------*
FORM sub_read_lfa1.

*Vendor
SELECT SINGLE *
FROM lfa1
INTO gs_lfa1
WHERE lifnr = gs_ekko-lifnr.

ENDFORM. " sub_read_lfa1

*&---------------------------------------------------------------------*
*& Form sub_read_adrc
*&---------------------------------------------------------------------*
FORM sub_read_ladrc.

*LIFNR ADRC
SELECT SINGLE *
FROM adrc
INTO gs_ladrc
WHERE addrnumber = gs_lfa1-adrnr.

ENDFORM. " sub_read_ladrc

*&---------------------------------------------------------------------*
*& Form sub_read_ladr6
*&---------------------------------------------------------------------*
FORM sub_read_ladr6.

*LIFNR ADR6 - Email


SELECT SINGLE *
FROM adr6
INTO gs_ladr6
WHERE addrnumber = gs_lfa1-adrnr.

IF sy-subrc = 0.
lv_mail = gs_ladr6-SMTP_ADDR.
ENDIF.

ENDFORM. " sub_read_ladr6

*&---------------------------------------------------------------------*
*& Form sub_read_t024
*&---------------------------------------------------------------------*
FORM sub_read_t024.

SELECT SINGLE *
FROM t024
INTO gs_t024
WHERE ekgrp = gs_ekko-ekgrp.

SELECT SINGLE * FROM usr21 INTO gs_usr21 WHERE bname = gs_ekko-ernam.


SELECT SINGLE * FROM adr2 INTO gs_adr2 WHERE addrnumber = gs_usr21-addrnumber AND
persnumber = gs_usr21-persnumber.
SELECT SINGLE * FROM adr6 INTO gs_adr6 WHERE addrnumber = gs_usr21-addrnumber AND
persnumber = gs_usr21-persnumber.
SELECT SINGLE * FROM adrp INTO gs_adrp WHERE persnumber = gs_usr21-persnumber.

ENDFORM. " sub_read_t024


*&---------------------------------------------------------------------*
*& Form sub_read_t0241
*&---------------------------------------------------------------------*
FORM sub_read_t0241.

SELECT SINGLE * FROM ekko INTO gs_ekko1 WHERE ebeln = gs_ekpo-konnr.


IF sy-subrc = 0.
SELECT SINGLE *
FROM t024
INTO gs_t0241
WHERE ekgrp = gs_ekko1-ekgrp.
ENDIF.

ENDFORM. " sub_read_t0241

*&---------------------------------------------------------------------*
*& 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.

*Address of corporate office


IF gs_ekko-bukrs = '1000'.
lv_werks = '1001'.
ELSEIF gs_ekko-bukrs = '2000'.
lv_werks = '2001'.
ENDIF.

SELECT SINGLE *
FROM t001w
INTO gs_t001w2
WHERE werks = gs_ekpo-werks.

SELECT SINGLE *
FROM adrc
INTO gs_padrc2
WHERE addrnumber = gs_t001w2-adrnr.

CONCATENATE gs_ekpo-werks '_SIGN' INTO gs_head-sign.

ENDFORM. " sub_read_t001w

*&---------------------------------------------------------------------*
*& 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.

ENDFORM. " sub_read_J_1IMOCOMP


*&---------------------------------------------------------------------*
*& Form sub_read_padrc
*&---------------------------------------------------------------------*
FORM sub_read_padrc.

*Plant's Address
SELECT SINGLE *
FROM adrc
INTO gs_padrc
WHERE addrnumber = gs_t001w-adrnr.

ENDFORM. " sub_read_padrc

*&---------------------------------------------------------------------*
*& 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.

IF gt_ekpo IS NOT INITIAL.


SELECT *
FROM mara
INTO TABLE gt_mara
FOR ALL ENTRIES IN gt_ekpo
WHERE matnr = gt_ekpo-matnr.
endif.
* if gt_mara is NOT INITIAL.
* SELECT objkt revlv from AEOI
* into gt_AEOI FOR ALL ENTRIES IN gt_mara
* where OBJKT = gt_mara-matnr.
* ENDIF.
ENDFORM. " sub_read_makt

*&---------------------------------------------------------------------*
*& 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.

ENDFORM. " sub_read_J_1IMTCHID


*&---------------------------------------------------------------------*
*& Form sub_read_eket
*&---------------------------------------------------------------------*
FORM sub_read_eket.

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

ENDFORM. " sub_read_eket

*&---------------------------------------------------------------------*
*& 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.

ENDFORM. " sub_read_T006A

*&---------------------------------------------------------------------*
*& Form sub_read_Price
*&---------------------------------------------------------------------*
FORM sub_read_price.

DATA: ls_amt TYPE bf_rwbtr,


ls_words_spell TYPE char255,
lo_spell TYPE REF TO zcl_fiwtin_utilities,
lt_komv TYPE STANDARD TABLE OF komv,
ls_komv TYPE komv,
lv_excise TYPE dmbtr,
lv_total TYPE dmbtr,
lv_discount TYPE dmbtr,
lv_packing TYPE dmbtr.

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.

LOOP AT gt_price INTO gs_price WHERE kschl = 'RA00' OR kschl = 'RB00'.


gs_amt-col1 = 'Total Discount'.
gs_amt-col3 = gs_price-kwert.
lv_discount = lv_discount + gs_price-kwert.
COLLECT gs_amt INTO gt_amt.
CLEAR: gs_price, gs_amt.
ENDLOOP.

LOOP AT gt_price INTO gs_price WHERE kschl = 'ZPC1' OR kschl = 'ZPC2'.


gs_amt-col1 = 'Total Packing Charges'.
gs_amt-col3 = gs_price-kwert.
lv_packing = lv_packing + gs_price-kwert.
COLLECT gs_amt INTO gt_amt.
CLEAR: gs_price, gs_amt.
ENDLOOP.

* LOOP AT gt_price INTO gs_price where kschl = 'PB00' or kschl = 'PBXX'.


gs_amt-col1 = 'Net Value'.
gs_amt-col3 = lv_total + lv_discount + lv_packing. "gs_price-kwert.
COLLECT gs_amt INTO gt_amt.
CLEAR: gs_price, gs_amt.
* ENDLOOP.

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

LOOP AT lt_komv INTO ls_komv.


IF ls_komv-kschl = 'JMX1' OR ls_komv-kschl = 'JMX2' OR ls_komv-kschl = 'JAX1'
OR ls_komv-kschl = 'JAX2' OR ls_komv-kschl = 'JSX1' OR ls_komv-kschl =
'JSX2'.
lv_excise = lv_excise + ls_komv-kwert.
* gs_amt-col1 = 'Total Excise Duty'.
* gs_amt-col3 = ls_komv-kwert.
* COLLECT: gs_amt INTO gt_amt.
ENDIF.
CLEAR: ls_komv, gs_amt.
ENDLOOP.
REFRESH: lt_komv.
CLEAR: gs_ekpo1, gs_amt.
ENDLOOP.
LOOP AT gt_price INTO gs_price WHERE kschl = 'JEXC'.
lv_excise = lv_excise + gs_price-kwert.
ENDLOOP.

IF lv_excise IS NOT INITIAL.


gs_amt-col1 = 'Total Excise Duty'.
gs_amt-col3 = lv_excise.
COLLECT gs_amt INTO gt_amt.
CLEAR: gs_price, gs_amt.
ENDIF.

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

LOOP AT lt_komv INTO ls_komv.


IF ls_komv-kschl = 'VTR1' OR ls_komv-kschl = 'VSR1'.
gs_amt-col1 = 'VAT'.
gs_amt-col3 = ls_komv-kwert.
COLLECT: gs_amt INTO gt_amt.
ELSEIF ls_komv-kschl = 'CSTI'.
gs_amt-col1 = 'CST'.
gs_amt-col3 = ls_komv-kwert.
COLLECT: gs_amt INTO gt_amt.
ENDIF.
CLEAR: ls_komv, gs_amt.
ENDLOOP.

REFRESH: lt_komv.
CLEAR: gs_ekpo1, gs_amt.
ENDLOOP.

*Taxes - Service Tax


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.

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.

LOOP AT lt_komv INTO ls_komv WHERE kschl = 'GSTI'.


gs_amt-col1 = 'GST'.
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.

CLEAR: lv_cgst, lv_igst, lv_sgst.

*********TAXES FOR GST INDIA CALCULATIONS********


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.

LOOP AT lt_komv INTO ls_komv.


IF ls_komv-kschl = 'JICG' OR ls_komv-kschl = 'JICN'.
lv_cgst = lv_cgst + ls_komv-kwert.
ELSEIF ls_komv-kschl = 'JISG' OR ls_komv-kschl = 'JISN' .
lv_sgst = lv_sgst + ls_komv-kwert.
ELSEIF ls_komv-kschl = 'JIIG' OR ls_komv-kschl = 'JIIN'.
lv_igst = lv_igst + ls_komv-kwert.
* ELSEIF ls_komv-kschl = 'JICR'.
* lv_cgst_rc = lv_cgst_rc + ls_komv-kwert.
* ELSEIF ls_komv-kschl = 'JISR'.
* lv_sgst_rc = lv_sgst_rc + ls_komv-kwert.
* ELSEIF ls_komv-kschl = 'JIIR'.
* lv_igst_rc = lv_igst_rc + ls_komv-kwert.
ENDIF.
ENDLOOP.
REFRESH: lt_komv.
CLEAR: gs_ekpo1.
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.

gs_amt-col1 = 'Total Value'.


gs_amt-col3 = lv_total.
APPEND gs_amt TO gt_amt.
CLEAR: gs_amt.

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

ENDFORM. " sub_read_PRICE

*&---------------------------------------------------------------------*
*& Form sub_read_terms
*&---------------------------------------------------------------------*
FORM sub_read_terms.

SELECT SINGLE vtext FROM tvzbt


INTO gs_head-pay_terms
WHERE spras = 'E'
AND zterm = gs_ekko-zterm.
IF sy-subrc <> 0.
SELECT SINGLE text1 FROM t052u
INTO gs_head-pay_terms
WHERE spras = 'E'
AND zterm = gs_ekko-zterm.
ENDIF.

SELECT SINGLE bezei FROM tinct


INTO gs_head-inco_terms
WHERE spras = 'E'
AND inco1 = gs_ekko-inco1.

CONCATENATE gs_head-inco_terms gs_ekko-inco2 INTO gs_head-inco_terms SEPARATED BY


space.

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.

SELECT SINGLE BEZEI FROM t005u INTO gs_head-v_state


WHERE SPRAS = 'E'
AND LAND1 = gs_lfa1-land1
AND BLAND = gs_lfa1-regio.

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.

FIELD-SYMBOLS: <lf_ekpo> TYPE ekpo.


*For Service Order Line items
IF gt_ekpo IS NOT INITIAL.
SELECT *
FROM esll
INTO TABLE gt_esll
FOR ALL ENTRIES IN gt_ekpo
WHERE packno = gt_ekpo-packno.
ENDIF.

gt_ekpo1[] = gt_ekpo[].
LOOP AT gt_ekpo1 ASSIGNING <lf_ekpo>.
<lf_ekpo>-packno = <lf_ekpo>-packno + 1.
ENDLOOP.
UNASSIGN: <lf_ekpo>.

IF gt_ekpo1 IS NOT INITIAL.


SELECT *
FROM esll
INTO TABLE gt_esll1
FOR ALL ENTRIES IN gt_ekpo1
WHERE packno = gt_ekpo1-packno.
ENDIF.

IF gt_esll IS NOT INITIAL.


SELECT *
FROM esll
INTO TABLE gt_esll2
FOR ALL ENTRIES IN gt_esll
WHERE packno = gt_esll-sub_packno.
ENDIF.

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

ENDFORM. " sub_read_esll

*&---------------------------------------------------------------------*
*& Form sub_read_resb
*&---------------------------------------------------------------------*
FORM sub_read_resb.

*For Subcontracting Order - Components


IF gt_ekpo IS NOT INITIAL.
SELECT *
FROM resb
INTO TABLE gt_resb3
FOR ALL ENTRIES IN gt_ekpo
WHERE ebeln = gt_ekpo-ebeln
AND ebelp = gt_ekpo-ebelp.
ENDIF.

IF gt_resb3 IS NOT INITIAL.


SELECT *
FROM makt
INTO TABLE gt_makt3
FOR ALL ENTRIES IN gt_resb3
WHERE matnr = gt_resb3-matnr.
ENDIF.

IF gt_resb3 IS NOT INITIAL.


SELECT *
FROM mara
INTO TABLE gt_mara3
FOR ALL ENTRIES IN gt_resb3
WHERE matnr = gt_resb3-matnr.
ENDIF.

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

DATA: lv_count TYPE i.


IF gs_ekko-zzcomp_tick IS NOT INITIAL.
SORT gt_resb3 BY ebeln ebelp.
LOOP AT gt_resb3 INTO gs_resb3.
lv_count = lv_count + 1.
gs_comp3-sno = lv_count.
gs_comp3-mat_code = gs_resb3-baugr.
gs_comp3-comp_code = gs_resb3-matnr.
gs_comp3-uom = gs_resb3-meins.
gs_comp3-menge = gs_resb3-bdmng.

READ TABLE gt_makt INTO gs_makt WITH KEY matnr = gs_ekpo-matnr.


IF sy-subrc = 0.
gs_comp3-maktx = gs_makt-maktx.
ENDIF.

READ TABLE gt_makt3 INTO gs_makt3 WITH KEY matnr = gs_resb3-matnr.


IF sy-subrc = 0.
gs_comp3-comp_desc = gs_makt3-maktx.
ENDIF.

READ TABLE gt_mara3 INTO gs_mara3 WITH KEY matnr = gs_resb3-matnr.


IF sy-subrc = 0.
gs_comp3-drawing_no = gs_mara3-zeinr.
gs_comp3-version = gs_mara3-zeivr.
ENDIF.

READ TABLE gt_j_1imtchid3 INTO gs_j_1imtchid3 WITH KEY matnr = gs_ekpo-matnr


werks = gs_ekpo-werks.
IF sy-subrc = 0.
gs_comp3-chapterid = gs_j_1imtchid3-j_1ichid.
ENDIF.

APPEND : gs_comp3 TO gt_comp3.


CLEAR: gs_resb3.
ENDLOOP.
ENDIF.

ENDFORM. " sub_read_resb

*&---------------------------------------------------------------------*
*& 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.

IF gs_t0241-ektel IS NOT INITIAL.


gs_head-ccontact_ref = gs_ekpo-konnr.
gs_head-ccontact_person = gs_t0241-eknam.
gs_head-ccontact_no = gs_t0241-ektel.
gs_head-cemail = gs_t0241-smtp_addr.
ELSE.
gs_head-ccontact_ref = 'NA'.
gs_head-ccontact_person = 'NA'.
gs_head-ccontact_no = 'NA'.
gs_head-cemail = 'NA'.
ENDIF.
gs_head-vat_cst = gs_j_1imocomp-j_1icstno.
gs_head-service_tax = gs_j_1imocomp-j_1isern.
gs_head-range = gs_j_1imocomp-j_1iexrg.
gs_head-division = gs_j_1imocomp-j_1iexdi.
gs_head-commiss = gs_j_1imocomp-j_1iexco.
gs_head-register = gs_j_1imocomp-j_1iexrn.
gs_head-ecc = gs_j_1imocomp-j_1iexcd.
gs_head-pan = gs_j_1imocomp-j_1ipanno.
gs_head-tin = gs_j_1imocomp-j_1ilstno.
IF gs_ekko-bukrs = '1000'.
gs_head-iec = '0514033215'.
ELSEIF gs_ekko-bukrs = '2000'.
gs_head-iec = 'UEN 201402119R'.
ENDIF.
gs_head-invoiceto_add = gs_t001w-adrnr.
gs_head-delivery_add = gs_t001w-adrnr.
IF gs_ekko-FRGKE NE '1'.
gs_head-status = 'PO Status - Yet to be Released'.
CLEAR: gs_head-sign.
ELSE.
gs_head-status = 'PO Status - Released'.
ENDIF.

SELECT SINGLE GSTIN FROM J_1BBRANCH


INTO gs_head-b_gstin WHERE bukrs = gs_ekko-bukrs
AND branch = gs_t001w-j_1bbranch.
IF gs_head-d_gstin eq ' ' and lv_ref_ind EQ 'X'."m1
* if gs_head-v_gstin is NOT INITIAL.
* gs_head-d_gstin = gs_head-v_gstin.
* ELSEIF gs_head-b_gstin is NOT INITIAL.
gs_head-d_gstin = gs_head-b_gstin.
* endif.
ENDIF."m1

*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_mara INTO gs_mara WITH KEY matnr = gs_ekpo-matnr.


IF sy-subrc = 0.
gs_item-drawing_no = gs_mara-zeinr.
* gs_item-version = gs_mara-zeivr.
SELECT SINGLE revlv from AEOI into gs_item-version
where OBJKT = gs_ekpo-matnr.
ENDIF.

READ TABLE gt_j_1imtchid INTO gs_j_1imtchid WITH KEY matnr = gs_ekpo-matnr


werks = gs_ekpo-werks.
IF sy-subrc = 0.
gs_item-chapterid = gs_j_1imtchid-j_1ichid.
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_t006a INTO gs_t006a WITH KEY msehi = gs_ekpo-meins.


IF sy-subrc = 0.
gs_item-uom = gs_t006a-mseht.
ENDIF.

gs_item-netpr = gs_ekpo-netpr / gs_ekpo-peinh.


gs_item-netpr1 = gs_ekpo-brtwr / gs_ekpo-menge. " / gs_ekpo-peinh.
"M1
if gs_ekko-waers = 'JPY'.
gs_item-netpr = gs_item-netpr * 100.
gs_item-netpr1 = gs_item-netpr1 * 100.
ENDIF.
"M1
* gs_item-netpr1 = gs_ekpo-netpr / gs_ekpo-peinh.
gs_item-peinh = gs_ekpo-peinh.
gs_item-menge = gs_ekpo-menge.
gs_item-tot_value = gs_ekpo-brtwr.
if gs_ekko-waers = 'JPY'.
gs_item-tot_value = gs_item-tot_value * 100.
ENDIF.
* gs_item-tot_value = gs_ekpo-netpr / gs_ekpo-peinh * 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_item-discount = gs_price-kbetr.
ENDIF.

CALL FUNCTION 'J_1IG_GET_HSN_SAC'


EXPORTING
IM_MATNR = gs_item-mat_code
IM_WERKS = gs_ekpo-werks
* IM_ASNUM =
IM_COUNTRY = 'IN'
IMPORTING
EX_HSN_SAC = gs_item-hsn_code
.

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.

APPEND: gs_item TO gt_item.


CLEAR: gs_item, gs_t006a, gs_j_1imtchid, gs_eket, gs_makt, gs_price, gs_mara,
lv_item.

CLEAR: gs_ekpo.
ENDLOOP.

DATA: lv_count TYPE i.

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

READ TABLE gt_makt INTO gs_makt WITH KEY matnr = gs_ekpo-matnr.


IF sy-subrc = 0.
gs_del-maktx = gs_makt-maktx.
ENDIF.
READ TABLE gt_t006a INTO gs_t006a WITH KEY msehi = gs_ekpo-meins.
IF sy-subrc = 0.
gs_del-uom = gs_t006a-mseht.
ENDIF.
ENDIF.
gs_del-menge = gs_eket-menge.
CONCATENATE gs_eket-eindt+6(2) '/' gs_eket-eindt+4(2) '/' gs_eket-eindt+0(4)
INTO gs_del-del_date.

APPEND : gs_del TO gt_del.


CLEAR: gs_eket, gs_ekpo, gs_del, gs_makt, gs_t006a.
ENDLOOP.
ENDIF.
*Service Order

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.

READ TABLE gt_t006a INTO gs_t006a WITH KEY msehi = gs_ekpo-meins.


IF sy-subrc = 0.
gs_item2-uom = gs_t006a-mseht.
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.

if gs_item2 is NOT INITIAL.


gs_item_srv-ebelp = gs_item2-sno.
gs_item_srv-MAT_CODE = gs_item2-mat_code.
gs_item_srv-MAKTX = gs_item2-maktx.
* gs_item_srv-DRAWING_NO = gs_item2-.
* gs_item_srv-VERSION = gs_item2-version.
* gs_item_srv-CHAPTERID = gs_item2-chapterid.
gs_item_srv-DEL_DATE = gs_item2-del_date.
gs_item_srv-MENGE = gs_item2-menge.
gs_item_srv-UOM = gs_item2-uom.
gs_item_srv-NETPR = gs_item2-netpr.
* gs_item_srv-PEINH = gs_item2-peinh.
gs_item_srv-TOT_VALUE = gs_item2-tot_value.
gs_item_srv-DISCOUNT = gs_item2-discount.
gs_item_srv-NETPR1 = gs_ekpo-brtwr / gs_ekpo-menge.
gs_item_srv-HSN_CODE = gs_ekpo-J_1BNBM .
shift gs_item_srv-HSN_CODE LEFT DELETING LEADING '0'.
append gs_item_srv to gt_item_srv.
CLEAR:gs_item_srv.
endif.
*Sub Items
CLEAR: gs_item2.
READ TABLE gt_esll INTO gs_esll WITH KEY packno = gs_ekpo-packno.

LOOP AT gt_esll2 INTO gs_esll2 WHERE packno = gs_esll-sub_packno.


gs_item2-sno = gs_esll2-extrow / 10.
gs_item2-maktx = gs_esll2-ktext1.
gs_item2-netpr = gs_esll2-tbtwr.
gs_item2-menge = gs_esll2-menge.
gs_item2-tot_value = gs_esll2-netwr.

READ TABLE GT_ASMD INTO GS_ASMD WITH KEY ASNUM = GS_ESLL2-SRVPOS.


If sy-subrc = 0.
gs_item2-hsn_code = GS_ASMD-TAXTARIFFCODE.
ENDIF.

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.

READ TABLE gt_t006a2 INTO gs_t006a2 WITH KEY msehi = gs_esll2-meins.


IF sy-subrc = 0.
gs_item2-uom = gs_t006a2-mseht.
ENDIF.

if gs_item2 is NOT INITIAL.


gs_item_srv-ebelp = gs_item2-sno.
gs_item_srv-MAT_CODE = gs_item2-mat_code.
gs_item_srv-MAKTX = gs_item2-maktx.
* gs_item_srv-DRAWING_NO = gs_item2-.
* gs_item_srv-VERSION = gs_item2-version.
* gs_item_srv-CHAPTERID = gs_item2-chapterid.
gs_item_srv-DEL_DATE = gs_item2-del_date.
gs_item_srv-MENGE = gs_item2-menge.
gs_item_srv-UOM = gs_item2-uom.
gs_item_srv-NETPR = gs_item2-netpr.
* gs_item_srv-PEINH = gs_item2-peinh.
gs_item_srv-TOT_VALUE = gs_item2-tot_value.
gs_item_srv-DISCOUNT = gs_item2-discount.
gs_item_srv-NETPR1 = gs_esll2-netwr / gs_esll2-menge.
gs_item_srv-HSN_CODE = gs_item2-hsn_code .

append gs_item_srv to gt_item_srv.


CLEAR:gs_item_srv.
endif.
APPEND: gs_item2 TO gt_item2.
CLEAR: gs_esll2, gs_item2, gs_t006a2, gs_esll1, gs_ekpo1,GS_ASMD.
ENDLOOP.
CLEAR: gs_ekpo, gs_price, gs_t006a, gs_eket.
ENDLOOP.
ENDFORM. " sub_read_final

FORM pdf_form.

DATA : gs_fp_outputparams TYPE sfpoutputparams,


gs_fp_docparams TYPE sfpdocparams,
* gs_formoutput TYPE fpformoutput,
gs_return1 TYPE ddshretval,
gs_dynpread TYPE dynpread,
gv_function_name TYPE rs38l_fnam,
gv_rcx_rep TYPE REF TO cx_fp_api_repository.

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.

CLEAR : gs_fp_outputparams, gs_fp_docparams.


IF sy-batch IS NOT INITIAL.
* gs_fp_outputparams-device = 'PRINTER'.
gs_fp_outputparams-nodialog = 'X'.
gs_fp_outputparams-NOPREVIEW = 'X'.
gs_fp_outputparams-getpdf = 'X'.
* gs_fp_outputparams-reqnew = 'X'.
* gs_fp_outputparams-reqfinal = 'X'.
* gs_fp_outputparams-covtitle = gc_country_heading.
gs_fp_docparams-langu = sy-langu.
ENDIF.
gs_fp_outputparams-nodialog = abap_true."'X'.
gs_fp_outputparams-getpdf = abap_true." 'X'.
gs_fp_docparams-langu = sy-langu.
*gs_outputpar-nodialog = abap_true.
* gs_outputpar-getpdf = abap_true.
**************Set Output Parameters and Open Spool Job****************
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = gs_fp_outputparams
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 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 Adobe Form for PDF Output*********************

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

IF lv_mail1 is NOT INITIAL .


CLASS cl_bcs DEFINITION LOAD.
DATA:
lo_send_request1 TYPE REF TO cl_bcs VALUE IS INITIAL.
lo_send_request1 = cl_bcs=>create_persistent( ).
* Message body and subject
DATA:
lt_message_body1 TYPE bcsy_text VALUE IS INITIAL,
lo_document1 TYPE REF TO cl_document_bcs VALUE IS INITIAL.
APPEND 'Dear,' TO lt_message_body1.
append ' ' to lt_message_body1.
APPEND 'Please find the attached Po. and send it to the concerned vendor.' TO
lt_message_body1.
append ' ' to lt_message_body1.
append 'Note: It is an auto-generated mail do not reply.' to lt_message_body1.
APPEND 'Thank You,' TO lt_message_body1.
APPEND ' ' TO lt_message_body1.
APPEND 'Regards' TO lt_message_body1.
APPEND 'GreyOrange Team' TO lt_message_body1.
lo_document1 = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_message_body1
i_subject = 'Purchase order from GreyOrange india Pvt. Ltd').
DATA: lx_document_bcs1 TYPE REF TO cx_document_bcs VALUE IS INITIAL.
TRY.
lo_document1->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_bcs1.
ENDTRY.
* Add attachment
* Pass the document to send request
lo_send_request1->set_document( lo_document1 ).
* Create sender
DATA:
lo_sender1 TYPE REF TO if_sender_bcs VALUE IS INITIAL.
lo_sender1 = cl_sapuser_bcs=>create( sy-uname ).
* Set sender
lo_send_request1->set_sender(
EXPORTING
i_sender = lo_sender1 ).
* Create recipient
DATA:
lo_recipient1 TYPE REF TO if_recipient_bcs VALUE IS INITIAL.
* lo_recipient = cl_sapuser_bcs=>create( sy-uname ).
lo_recipient1 = cl_cam_address_bcs=>create_internet_address( lv_mail1 ).
** Set recipient
lo_send_request1->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = 'X' ).
* Send email
DATA: lv_sent_to_all1(1) TYPE c VALUE IS INITIAL.
lo_send_request1->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = lv_sent_to_all1 ).
COMMIT WORK.
IF lv_sent_to_all1 IS INITIAL.
MESSAGE i500(sbcoms) WITH lv_mail1.
ELSE.
MESSAGE s022(so).
ENDIF.

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.

APPEND space TO main_text.


* CLEAR lv_body.
append 'Note: It is an auto-generated mail do not reply.' to
main_text.
* CONCATENATE 'Please find attached your overdue status as on'
lv_dates '.' INTO lv_body SEPARATED BY space.
APPEND space TO main_text.

APPEND space TO main_text.


APPEND 'Regards' TO main_text.
APPEND 'GreyOrange Team' TO main_text.
CLEAR : str1.
CONCATENATE 'Po No.' wa_ekko-ebeln 'Released in SAP' INTO str1 SEPARATED BY
space.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = main_text
i_subject = str1 ).
send_request->set_document( document ).

* --------- ADD RECIPIENT (E-MAIL ADDRESS) -----------------------


* CREATE RECIPIENT OBJECT
recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
* ADD RECIPIENT OBJECT TO SEND REQUEST
send_request->add_recipient( recipient ).

* ---------- SEND DOCUMENT ---------------------------------------


sent_to_all = send_request->send( i_with_error_screen = 'X' ).

COMMIT WORK.

IF sent_to_all IS INITIAL.
MESSAGE i500(sbcoms) WITH mailto.
ELSE.
MESSAGE s022(so).
ENDIF.
SKIP.
ENDIF.
ENDFORM.

You might also like