Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Author: Kaleemullah
Submitted: 4/12/2007

The Code basically generates Payment Advice (F110), and sends through mail to the vender as PDF attachment.

  1. Post an Open Item through F-43.
  2. Run F110 (Auto Payment Run) Partially till the Proposals are created.
  3. Then Run the Below Program in order to Post the Open Items Cross Company wise, and Generate the Payment Advices.
  4. The Program Logic does the following things.
      • Deletes the Proposal (Kill Run ID) Fromm F110.
      • Updates the Custom Table ZREGUH, and ZREGUP.
      • Runs the Transaction F-53 to Post the respective open item.
      • Calls the transaction FBZ5 to Generate the Spool for the Posted Entry.
      • FBZ5 in turn generates number.
      • Capture the Time Stamp for the each spool generated.
      • The Converts the spool(Payment Advice) to PDF Format.
      • Sends the Payment Advice in PDF Format as an attachment to the Vendors vial Mail.

FBZP Screen Where Configuration needs to be done in all Tab Buttons. 
 The Corresponding Configuration settings for F110 needs to be checked out in FBZP Transaction, Assignment of Payment methods, forms and Print Programs.

RFFOEDI01 - Use to Configure to send via EDI as well through mail.

But the Given Code specifically works in Cross company Posting scenario, which Standard SAP doesn't provide.

Error rendering macro 'code': Invalid value specified for parameter 'lang'
REPORT zfpbccp_ihk  NO STANDARD PAGE HEADING
                    LINE-COUNT 65 LINE-SIZE 255.
INCLUDE zbbdclib.                      "Added for ITH
TABLES:
t100,
reguh,  "Settlement data from payment program
regup,  "Processed items from payment program
regus,  "Vendor locking table during payment run
t042i,  "Bank information for payement method
payr, bseg, bkpf, lfa1,
zregup, zreguh,    "Added for ITH to store info as in REGUH/P
somlreci1.                            "kaleem
*bkaleem

TYPES: BEGIN OF t_tbtcp.
        INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.

TYPES :
BEGIN OF t_t042i,
zbukr TYPE t042i-zbukr, "paying company code
hbkid TYPE t042i-hbkid, "short KEY for a house bank
zlsch TYPE t042i-zlsch, "payment method
waers TYPE t042i-waers, "currency KEY
hktid TYPE t042i-hktid, "id for account details
ukont TYPE t042i-ukont, "g/l account to be posted
END OF t_t042i,

BEGIN OF t_reguh,
laufd TYPE reguh-laufd,   "Date program is to be run
laufi TYPE reguh-laufi,   "Additional identification
xvorl TYPE reguh-xvorl,   "Indicator: Only Proposal Run?
zbukr TYPE reguh-zbukr,   "Paying company code
lifnr TYPE reguh-lifnr,   "Acc num of vendor or creditor
kunnr TYPE reguh-kunnr,   "Customer number
empfg TYPE reguh-empfg,   "Payee code
vblnr TYPE reguh-vblnr,   "Doc Num Payment Document
END OF t_reguh,

BEGIN OF t_tstamp,
rqclient TYPE tsp01-rqclient,  "Client
rqowner TYPE tsp01-rqowner,   "Spool request: Name
rqcretime TYPE tsp01-rqcretime, "Time of spool request
rqdoctype TYPE tsp01-rqdoctype, "Spool: document type
END OF t_tstamp,

BEGIN OF t_tsp01,
rqident TYPE tsp01-rqident,   "Spool request number
rqclient TYPE tsp01-rqclient,  "Client
rqowner TYPE tsp01-rqowner,   "Spool request: Name
rqcretime TYPE tsp01-rqcretime, "Time of spool request
rqdoctype TYPE tsp01-rqdoctype, "Spool: document type
END OF t_tsp01,

BEGIN OF t_buffer,
buffer LIKE soli,
END OF t_buffer.

*Tables Declaration
DATA:
i_t042i     TYPE STANDARD TABLE OF t_t042i,
i_reguh     TYPE STANDARD TABLE OF t_reguh,
i_tstamp    TYPE STANDARD TABLE OF t_tstamp,
i_tsp01     TYPE STANDARD TABLE OF t_tsp01,
*       i_buffer    TYPE STANDARD TABLE OF t_buffer,
*       i_bufff     TYPE STANDARD TABLE OF t_buffer,
*Work Area Declaration
*       wa_buffer   LIKE LINE OF i_buffer,
wa_tsp01    LIKE LINE OF i_tsp01,
wa_tstamp   LIKE LINE OF i_tstamp,
wa_reguh    LIKE LINE OF i_reguh,
wa_t042i    LIKE LINE OF i_t042i.
DATA:
it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
wa_tbtcp TYPE t_tbtcp.
*Job Runtime Parameters
DATA:
gd_eventid LIKE tbtcm-eventid,
gd_eventparm LIKE tbtcm-eventparm,
gd_external_program_active LIKE tbtcm-xpgactive,
gd_jobcount LIKE tbtcm-jobcount,
gd_jobname LIKE tbtcm-jobname,
gd_stepcount LIKE tbtcm-stepcount,
gd_error    TYPE sy-subrc,
gd_reciever TYPE sy-subrc,
w_recsize TYPE i.

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

*Spool to PDF conversions
DATA: gd_bytecount LIKE tst01-dsize,
gd_buffer TYPE string.
* Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0.
        INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.
*ekaleem
DATA:
invoiceno(13)     TYPE c,
invoicedate(11)   TYPE c,
invoice-date      LIKE sy-datum,
*     INVOICE-DATE(10)  TYPE C,
invoiceamt(16)    TYPE c,
num-invoiceamt(13) TYPE n,
dec-invoiceamt(13) TYPE p DECIMALS 5,
ourrefno(13)      TYPE c,
flength           TYPE i,
item_count        TYPE i,
cr(02)            TYPE x VALUE '0D0A',
ccode(03)         TYPE c VALUE 'ITH',
vendorkey(11)     TYPE c,
*Begin of SR#15676 with DEVK951083
*       HSEBANK(03)       TYPE C,
hsebank(05)       TYPE c,
*End of SR#15676 with DEVK951083
bankacct(05)      TYPE c,
pattern1(01)      VALUE '.',
rep-str1(01)      VALUE ',',
lead-zero1(16)    VALUE '0000000000000000',
char-wrbtr(16)    TYPE c,
char-transamt(16) TYPE c,
num-transamt(16)  TYPE n,
lead-zero2(08)    VALUE '00000000',
lead-zero3(15)    VALUE '000000000000000',
lead-zero4(05)    VALUE '00000',
lead-zero5(03)    VALUE '000',
char-itemcnt(05)  TYPE c,
char-totrec(06)   TYPE c,
char-refno(03)    TYPE c,
newrun(01)        TYPE c,
a                 TYPE i,
b                 TYPE i,
cmsg(15)          TYPE c,
dmsg(10)          TYPE c,
a01               VALUE '`',
a02               VALUE '~',
a03               VALUE '!',
a04               VALUE '@',
a05               VALUE '#',
a06               VALUE '$',
a07               VALUE '%',
a08               VALUE '^',
a09               VALUE '&',
a10               VALUE '*',
a11               VALUE '+',
a12               VALUE '_',
a13               VALUE '=',
a14               VALUE '|',
a15               VALUE '\',
a16               VALUE '[',
a17               VALUE ']',
a18               VALUE '{',
a19               VALUE '}',
a20               VALUE ';',
a21               VALUE ':',
a22               VALUE '''',
a23               VALUE '"',
a24               VALUE '<',
a25               VALUE '?',
sdata(35)         TYPE c,
errcnt            TYPE i.
*----------- TO SET FOR ITH OR IHK DECISION ---
DATA  : BEGIN OF messtab OCCURS 100.
        INCLUDE STRUCTURE bdcmsgcoll.
DATA  : END OF messtab.
DATA  : BEGIN OF it_reguh OCCURS 100.
        INCLUDE STRUCTURE reguh.
DATA  : END OF it_reguh.
DATA  : BEGIN OF it_regup OCCURS 100.
        INCLUDE STRUCTURE regup.
DATA  : END OF it_regup.
* Begin of SR#15676 with DEVK951403
DATA: v_bukrs LIKE t001-bukrs.
*End of SR#15676 with DEVK951403
DATA:
ws_prop VALUE 'X',
paycurr(4),
*                                                 DEVK912327
*      W_PAYMETH TYPE N,       "PM J for ACH in EG
w_paymeth TYPE c,
*                                                 DEVK912327
payacct(10),
wf_fail_trans VALUE 'Y',
ws_text(100),
ws_paydoc(10),
ws_payco(3).

*bkaleem
*Data Declarations
DATA:
gd_recsize TYPE i,
v_pmail TYPE somlreci1-receiver,
v_smail TYPE somlreci1-receiver.

CONSTANTS:
c_no(1)               TYPE c   VALUE ' ',
c_device(4)           TYPE c   VALUE 'LOCL',
c_sender(21)          TYPE c   VALUE 'Asia_AP@Celestica.com',
c_pdf(3)              TYPE c   VALUE 'PDF'.

SELECTION-SCREEN BEGIN OF BLOCK a0 WITH FRAME TITLE text-002.
PARAMETERS: p_zbukr  LIKE t042i-zbukr DEFAULT 'IHK' NO-DISPLAY.
PARAMETERS: p_hbkid  LIKE t042i-hbkid DEFAULT 'BOA' NO-DISPLAY.
*PARAMETERS: p_waers  LIKE t042i-waers  OBLIGATORY.
SELECTION-SCREEN END OF BLOCK a0.
*ekaleem

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE c_co1.
*Begin of SR#15676 with DEVK951403
*PARAMETERS: payforco LIKE bkpf-bukrs.
PARAMETERS: payforco LIKE bkpf-bukrs OBLIGATORY.
*End of SR#15676 with DEVK951403
PARAMETERS: paymeth        DEFAULT '1'.          "kaleem
PARAMETERS: paym TYPE num1  DEFAULT '1' NO-DISPLAY.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE c_co2.
PARAMETERS:
effdate        LIKE sy-datum DEFAULT sy-datum,
checklot       LIKE pcec-stapl DEFAULT 1,
print_to       LIKE tsp03-padest DEFAULT 'CKHK'.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 01(31) c_print.
SELECTION-SCREEN POSITION POS_LOW.
PARAMETERS  printnow       AS CHECKBOX DEFAULT ' '.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b3.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS:     payrdate LIKE sy-datum DEFAULT sy-datum,"'19990525',
payriden LIKE reguh-laufi.  "  DEFAULT 'DLU02'.
*                p_delspl  AS CHECKBOX.          "bkaleem
SELECTION-SCREEN END OF BLOCK b2.

INITIALIZATION.
  c_co1 = 'PAY FOR COMPANY'.
  c_co2 = 'PAYING COMPANY'.
  c_print = 'PRINT NOW'.

AT SELECTION-SCREEN.
  MESSAGE e000.
*Begin of SR#15676 with DEVK951403
AT SELECTION-SCREEN ON payforco.
  PERFORM check_bukrs.
*bkaleem
AT SELECTION-SCREEN ON p_zbukr.
  IF p_zbukr NE 'IHK'.
    WRITE:/ 'Paying Company Code should always be IHK'(k34).        "kaleem
    MESSAGE e039(z1) WITH 'Paying Company code is IHK'(004).
  ENDIF.
*ekaleem

*---------------------------------------------------------------------
*&      Form  check_bukrs
*---------------------------------------------------------------------
*       Authority check for Company code
*----------------------------------------------------------------------
FORM check_bukrs.
  CLEAR v_bukrs.
  SELECT SINGLE bukrs INTO v_bukrs
  FROM t001 WHERE  bukrs EQ payforco.
  IF sy-subrc NE 0.
    MESSAGE e039(z1) WITH 'Company Code Not Found'(001).
*Check Authorization for Company Code
  ELSE.
    AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
    ID 'BUKRS' FIELD v_bukrs       "  Company Code
    ID 'ACTVT' FIELD '03'.         "  Activity
    IF sy-subrc <> 0.  "sorry, you have no auth!!!
*bkaleem
      WRITE:/ 'You are not authorized for Company Code:'(003), v_bukrs.
*ekaleem
      MESSAGE e398(00) WITH
      'You are not authorized for Company Code:'(003)
      v_bukrs space space.
    ENDIF.
  ENDIF.
ENDFORM.                    " check_bukrs
*End of SR#15676 with DEVK951403
*----------- END OF BLOCK ---------------------
START-OF-SELECTION.
*                                                 DEVK912327
  CLEAR w_paymeth.

  MOVE paymeth TO paym.                      "kaleem

  IF payforco = 'ITH' OR payforco = 'CMY'.
    payment method "0" for ITH & CMY           "UATK917009
    payment method 'J' for ach in eg                devk912327
*    IF PAYMETH <> '0'.
    if paymeth <> '0' and paymeth <> 'J'.
    IF paymeth <> 0 AND paymeth <> 'J'.          "kaleem  DEVK912327
*                                            "UATK917009
*        IF paymeth > '5' OR paymeth < '1'.
      IF paym > 5 OR paym < 1.        "kaleem
        WRITE :/ 'Payment Method Not Allowed'(k33).
        MESSAGE s035.
        STOP.
      ENDIF.
    ENDIF.
    w_paymeth = paymeth.
  ELSEIF payforco = 'IDG'.
*      IF paymeth > '6' OR paymeth < '2'.
    IF paym > 6 OR paym < 2.         "kaleem

      WRITE :/ 'Payment Method Not Allowed'(k33).
      MESSAGE s035.
      STOP.
    ENDIF.
*      w_paymeth = paymeth - 1.
    w_paymeth = paym - 1.         "kaleem
  ELSEIF payforco = 'IUS'.
*      IF     paymeth <> '3' AND paymeth <> '2'
*         AND paymeth <> '5' AND paymeth <> '6'.
    IF     paym <> 3 AND paym <> 2             "kaleem
    AND paym <> 5 AND paym <> 6.            "kaleem

      WRITE :/ 'Payment Method Not Allowed'(k33).

      MESSAGE s035.
      STOP.
    ENDIF.
    w_paymeth = paym - 1.
  ELSE.

    WRITE :/ 'Company Code Not Allowed'(k32).
    MESSAGE s039 WITH 'COMPANY CODE NOT ALLOWED'.
    STOP.
  ENDIF.
  ws_prop = 'X'.
  newrun = ' '.
*bkaleem
*  SELECT        * FROM  t042i
*         WHERE  zbukr       = 'IHK'    "_Paying company code
*         AND    zlsch       = w_paymeth. "_PAYMENT METHOD
*    hsebank  = t042i-hbkid.            " ID FOR ONE HOUSE BANK
*    bankacct = t042i-hktid.            " ID FOR ACCOUNT DETAILS
*    paycurr  = t042i-waers.            " CURRENCY KEY
*    payacct  = t042i-ukont.            " G/L ACCOUNT TO BE POSTED TO
*  ENDSELECT.

  SELECT  zbukr
  hbkid
  zlsch
  waers
  hktid
  ukont
  FROM t042i INTO TABLE i_t042i
  WHERE zbukr = p_zbukr
  AND   hbkid = p_hbkid
  AND   zlsch = w_paymeth.

*ekaleem
  PERFORM get_batch_rec.
  IF item_count = 0.
    WRITE: / '*** Err: No batch data found'(k01).
    EXIT.
*  ENDIF.                                        "kaleem
  ELSE.                                          "kaleem
    PERFORM delete_proposal.
    PERFORM batch_input_payment.
*bkaleem
*Get the Respective spools generated by payment run
*Reference with Owner, Creation Time Stamp
*    PERFORM get_spool.
  ENDIF.                                         "kaleem
*ekaleem
END-OF-SELECTION.
*  EXIT.                                         "kaleem
*bkaleem
*Sending Mails
*  IF NOT i_tsp01[] IS INITIAL.
*    PERFORM sendmails.
*  ELSE.
*    WRITE :/ 'Corresponding Spools are Missing'(005).
*  ENDIF.
*ekaleem
*---------------------------------------------------------------------
*       FORM GET_BATCH_DETAIL                                         *
*---------------------------------------------------------------------
*       ........                                                      *
*---------------------------------------------------------------------
FORM get_batch_rec.
*  DATA: wf_dtl_found VALUE 'N'.              "kaleem
  REFRESH it_reguh.
  REFRESH it_regup.
*bkaleem
*Code Commented Due Performance and Logic Bug
*  SELECT * FROM reguh WHERE laufi = payriden
*        AND laufd = payrdate
*        AND xvorl = ws_prop
*        AND zbukr = payforco
*        AND waers = paycurr
*        AND rzawe = paymeth
*        AND hbkid = hsebank
*        AND hktid = bankacct
*        AND NOT vblnr = space.
*    MOVE reguh TO it_reguh.
*    wf_dtl_found = 'N'.
*    SELECT * FROM regup WHERE
*             laufd = reguh-laufd
*        AND  laufi = reguh-laufi
*        AND  xvorl = reguh-xvorl
*        AND  zbukr = reguh-zbukr
*        AND  lifnr = reguh-lifnr
*        AND  kunnr = reguh-kunnr
*        AND  empfg = reguh-empfg
*        AND  vblnr = reguh-vblnr.
*      MOVE regup TO it_regup.
*      wf_dtl_found = 'Y'.
*      APPEND it_regup.
*      ADD 1 TO item_count.
*    ENDSELECT.
*    IF wf_dtl_found = 'Y'.
*      APPEND it_reguh.
*    ENDIF.
*  ENDSELECT.
*Code Written
  IF NOT i_t042i[] IS INITIAL.
    SELECT  *  FROM reguh
    INTO TABLE it_reguh
    FOR ALL ENTRIES IN i_t042i
    WHERE     laufd EQ payrdate
    AND     laufi EQ payriden
    AND     xvorl EQ ws_prop
    AND     zbukr EQ payforco
    AND     vblnr NE space
    AND     waers EQ i_t042i-waers
    AND     rzawe EQ i_t042i-zlsch
    AND     hktid EQ i_t042i-hktid
    AND     hbkid EQ i_t042i-hbkid.

    IF sy-subrc EQ 0.

      SORT it_reguh BY laufd laufi zbukr lifnr.

      SELECT * FROM regup
      INTO TABLE it_regup
      FOR ALL ENTRIES IN it_reguh
      WHERE    laufd = it_reguh-laufd
      AND    laufi = it_reguh-laufi
      AND    xvorl = it_reguh-xvorl
      AND    zbukr = it_reguh-zbukr
      AND    lifnr = it_reguh-lifnr
      AND    kunnr = it_reguh-kunnr
      AND    empfg = it_reguh-empfg
      AND    vblnr = it_reguh-vblnr.

      IF sy-subrc EQ 0.

        SORT it_regup BY laufd laufi zbukr lifnr.

        ADD 1 TO item_count.
      ENDIF.

    ENDIF.
  ENDIF.
*ekaleem
ENDFORM.                    "get_batch_rec
*---------------------------------------------------------------------
*       FORM DELETE_PROPOSAL                                          *
*---------------------------------------------------------------------
*       ........                                                      *
*---------------------------------------------------------------------
FORM delete_proposal.
  DATA: kill_id(5).
  kill_id = payriden.
  wf_fail_trans = 'N'.
  REFRESH bdcdata.
  PERFORM bdc_record_del_prop_f110.
  REFRESH messtab.
*CALL TRANSACTION 'F110' USING BDCDATA MODE 'A' UPDATE 'S'
  CALL TRANSACTION 'F110' USING bdcdata MODE 'N' UPDATE 'S'
  MESSAGES INTO messtab.
  IF sy-subrc NE 0.
    wf_fail_trans = 'Y'.
    PERFORM trans_mess.
    WRITE: / 'MESSTAB-MSGV1', messtab-msgv1.
    WRITE: / 'MESSTAB-MSGV2', messtab-msgv2.
    WRITE: / 'MESSTAB-MSGV3', messtab-msgv3.
    WRITE: / 'MESSTAB-MSGV4', messtab-msgv4.
    WRITE: ws_text.
    WRITE: / '*** Error: Failed to delete payment proposal'(k02),
    kill_id.
    LOOP AT messtab.
      WRITE: / messtab.
    ENDLOOP.
  ENDIF.
  WRITE: / 'Deleting proposal', payrdate, payriden.
  DELETE FROM regus WHERE laufd = payrdate AND laufi = payriden.
  IF sy-subrc NE 0.
    WRITE: / '** Error: deleting regus record'(k03).
  ENDIF.
ENDFORM.                    "delete_proposal
DATA:
paid_doc(10),
paid_doc_item(10),
trans_ttl_amount(13),
bdc_netamount(13).
*---------------------------------------------------------------------
*       FORM BATCH_INPUT_PAYMENT                                      *
*---------------------------------------------------------------------
*       ........                                                      *
*---------------------------------------------------------------------
FORM batch_input_payment.
  DATA: w_amount LIKE it_reguh-rwbtr.
  LOOP AT it_reguh.
*bkaleem
    READ TABLE i_t042i INTO wa_t042i WITH KEY hbkid = it_reguh-hbkid
    zlsch = it_reguh-rzawe
    hktid = it_reguh-hktid.
*ekaleem
    REFRESH bdcdata.
    trans_ttl_amount = 0.
    PERFORM bdc_screen_hdr.
    WRITE: / 'Processing check data for :'(k15).
    IF it_reguh-waers = 'USD'.
      w_amount = it_reguh-rwbtr / 1000.
*bkaleem
*      WRITE: / 'NET AMOUNT :'(k04), w_amount.
      WRITE: / 'NET AMOUNT :'(k04), w_amount CURRENCY it_reguh-waers.
*ekaleem
    ELSE.
*bkaleem
*      WRITE: / 'NET AMOUNT :'(k04), it_reguh-rwbtr.
      WRITE: / 'NET AMOUNT :'(k04), it_reguh-rwbtr CURRENCY it_reguh-waers.
*ekaleem
    ENDIF.
    WRITE: / 'VENDORNO  :'(k05), it_reguh-lifnr.
    LOOP AT it_regup
    WHERE  laufd = it_reguh-laufd
    AND laufi = it_reguh-laufi
    AND xvorl = it_reguh-xvorl
    AND zbukr = it_reguh-zbukr
    AND lifnr = it_reguh-lifnr
    AND kunnr = it_reguh-kunnr
    AND empfg = it_reguh-empfg
    AND vblnr = it_reguh-vblnr.
      PERFORM bdc_screen_dtl.
      paid_doc = it_regup-belnr.
      paid_doc_item = it_regup-buzei.
    ENDLOOP.
    PERFORM bdc_screen_1102_save.
    REFRESH messtab.
    IF sy-sysid = 'UAT'.
      CALL TRANSACTION 'F-53' USING bdcdata MODE 'E' UPDATE 'S'
*     CALL TRANSACTION 'F-53' USING BDCDATA MODE 'N' UPDATE 'S'
      MESSAGES INTO messtab.
    ELSE.
      CALL TRANSACTION 'F-53' USING bdcdata MODE 'E' UPDATE 'S'
      MESSAGES INTO messtab.
    ENDIF.
    IF sy-subrc = 0.
      WRITE: / 'Payment doc done for vendor:'(k06), it_reguh-lifnr.
*     WRITE: / '---- Detail : ', IT_REGUH.
*     WRITE: / '----', /   'BSEG::'.
*     WRITE: / 'PAID DOC IS', PAID_DOC.
*     WRITE: / 'PAID DOC ITEM IS', PAID_DOC_ITEM.
      SELECT * FROM bseg
      WHERE belnr = paid_doc
      AND buzei = paid_doc_item
      AND bukrs = payforco .
      ENDSELECT.
*       WRITE: / '----', /   'BKPF::'.
      SELECT * FROM bkpf
      WHERE bukrs = payforco AND belnr = bseg-augbl.
        CHECK bkpf-bldat = bseg-augdt.
*         WRITE: / 'AUGDT = ', BKPF-BLDAT.
*         WRITE: / 'BVORG = ', BKPF-BVORG(10).
        ws_paydoc = bkpf-bvorg(10).
        ws_payco  = bkpf-bvorg+10(3).
      ENDSELECT.
      WRITE: / 'Paying document is'(k07), ws_payco, ws_paydoc.
      SKIP.
      REFRESH bdcdata.
      PERFORM bdc_record_print_check.
*bkaleem
*Create Spool Detials Table with Time Stamps
      REFRESH i_tstamp[].
      PERFORM get_timestamps.
*ekaleem
      IF sy-sysid = 'UAT'.
*       CALL TRANSACTION 'FBZ5' USING BDCDATA MODE 'A' UPDATE 'S'
        CALL TRANSACTION 'FBZ5' USING bdcdata MODE 'N' UPDATE 'S'
        MESSAGES INTO messtab.
      ELSE.
        CALL TRANSACTION 'FBZ5' USING bdcdata MODE 'N' UPDATE 'S'
        MESSAGES INTO messtab.
      ENDIF.
      IF sy-subrc NE 0 AND sy-subrc NE 1001.
        WRITE: / '***Error'(k08), sy-subrc,
        'occurred when printing check, '(k09),
        'Please check IHK payment document'(k10), ws_paydoc.
        PERFORM trans_mess.
        WRITE: / messtab-msgv1.
        WRITE: / messtab-msgv2.
        WRITE: / messtab-msgv3.
        WRITE: / messtab-msgv4.
        WRITE: / 'WS_TEXT FOR PAY DOC#', ws_text.
      ELSE.
*bkaleem
        WRITE: / 'Spools Generated Sucessfully'(k39).          "kaleem
        COMMIT WORK.
        WAIT UP TO 3 SECONDS.                  "Ensure Tables Updated

*Get the Respective spools generated by payment run
*Reference with Owner, Creation Time Stamp
        PERFORM get_spool.

        IF NOT i_tsp01[] IS INITIAL.
          PERFORM sendmails.
        ELSE.
          WRITE :/ 'Corresponding Spools are Missing'(005).
        ENDIF.
*ekaleem
        MOVE it_reguh TO zreguh.
        zreguh-xvorl = ' '.
        zreguh-vblnr = ws_paydoc.
        INSERT zreguh.
        COMMIT WORK.
        LOOP AT it_regup
        WHERE  laufd = it_reguh-laufd
        AND laufi = it_reguh-laufi
        AND xvorl = it_reguh-xvorl
        AND zbukr = it_reguh-zbukr
        AND lifnr = it_reguh-lifnr
        AND kunnr = it_reguh-kunnr
        AND empfg = it_reguh-empfg
        AND vblnr = it_reguh-vblnr.
          MOVE it_regup TO zregup.
          zregup-xvorl = ' '.
          zregup-vblnr = ws_paydoc.
          INSERT zregup.
          COMMIT WORK.
        ENDLOOP.
      ENDIF.
    ELSE.
*      PERFORM TRANS_MESS.
*      WRITE: / MESSTAB-MSGV1.
*      WRITE: / MESSTAB-MSGV2.
*      WRITE: / MESSTAB-MSGV3.
*      WRITE: / MESSTAB-MSGV4.
      WRITE: / 'WS_TEXT FOR PAY DOC#'(k11), ws_text.
      PERFORM trans_mess.
      WRITE: / '*** Error : processing record for '(k12),
      it_reguh-lifnr.
      WRITE: / '**** Message: '(k13), ws_text.
      LOOP AT it_reguh.
        WRITE: / '**** Detail : '(k14).
        WRITE: / it_reguh.
      ENDLOOP.
    ENDIF.
*     LOOP AT BDCDATA.
*       WRITE: / BDCDATA.
*     ENDLOOP.
  ENDLOOP.
ENDFORM.                    "batch_input_payment
*---------------------------------------------------------------------
*       FORM BDC_SESSION                                              *
*---------------------------------------------------------------------
*       ........                                                      *
*---------------------------------------------------------------------
FORM bdc_screen_hdr.
  DATA: bdc_date(8),
  bdc_vendorno(10).
  PERFORM bdc_dynpro      USING 'SAPMF05A' '0103'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'PA'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'RF05A-XMULK'.
*Correct the value date & posting date for posting entry     UATK920230
*  BDC_DATE+0(4) = SY-DATUM+4(4).
*  BDC_DATE+4(4) = SY-DATUM+0(4).
  bdc_date+0(4) = it_reguh-zaldt+4(4).
  bdc_date+4(4) = it_reguh-zaldt+0(4).
*                                                             UATK920230
  PERFORM bdc_field       USING 'BKPF-BLDAT' bdc_date.
  PERFORM bdc_field       USING 'BKPF-BLART' 'KZ'.
  PERFORM bdc_field       USING 'BKPF-BUKRS' 'IHK'.
*Correct the value date & posting date for posting entry     UATK920230
*  BDC_DATE+0(4) = SY-DATUM+4(4).
*  BDC_DATE+4(4) = SY-DATUM+0(4).
  bdc_date+0(4) = it_reguh-zaldt+4(4).
  bdc_date+4(4) = it_reguh-zaldt+0(4).
*                                                             UATK920230
  PERFORM bdc_field       USING 'BKPF-BUDAT' bdc_date.
*  PERFORM bdc_field       USING 'BKPF-WAERS' paycurr.
  PERFORM bdc_field       USING 'BKPF-WAERS' wa_t042i-waers.
  PERFORM bdc_field       USING 'BKPF-XBLNR' 'CC PAYMENT'.
*  PERFORM bdc_field       USING 'RF05A-KONTO' payacct.
  PERFORM bdc_field       USING 'RF05A-KONTO' wa_t042i-ukont.
  PERFORM bdc_field       USING 'BSEG-WRBTR' '1'.  "Nominal Amount
*Correct the value date & posting date for posting entry     UATK920230
*  BDC_DATE+0(4) = SY-DATUM+4(4).
*  BDC_DATE+4(4) = SY-DATUM+0(4).
  bdc_date+0(4) = it_reguh-valut+4(4).
  bdc_date+4(4) = it_reguh-valut+0(4).
*                                                             UATK920230
  PERFORM bdc_field       USING 'BSEG-VALUT' bdc_date.
  PERFORM bdc_field       USING 'RF05A-AGKOA' 'K'.
  PERFORM bdc_field       USING 'RF05A-XMULK' 'X'.
  PERFORM bdc_dynpro      USING 'SAPMF05A' '0609'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'GO'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'RF05A-XNOPS(01)'.
  bdc_vendorno =            it_reguh-lifnr.
  PERFORM bdc_field       USING 'RF05A-AGKON(01)' bdc_vendorno.
  PERFORM bdc_field       USING 'RF05A-AGKOA(01)' 'K'.
  PERFORM bdc_field       USING 'RF05A-AGBUK(01)' payforco.
  PERFORM bdc_field       USING 'RF05A-XNOPS(01)' 'X'.
ENDFORM.                    "bdc_screen_hdr
*---------------------------------------------------------------------
*       FORM BDC_SCREEN_1102                                          *
*---------------------------------------------------------------------
*       ........                                                      *
*---------------------------------------------------------------------
FORM bdc_screen_dtl.
  DATA: w_discount(13), w_disc_rate(6).
  bdc_netamount = it_regup-wrbtr - it_regup-wskto.
  TRANSLATE bdc_netamount USING ',.'.
  WRITE: / 'BDC_NETAMOUNT', bdc_netamount.
  IF it_regup-shkzg = 'S'.
    SUBTRACT bdc_netamount FROM trans_ttl_amount.
    w_discount = it_regup-wskto.
  ELSE.
    ADD      bdc_netamount TO   trans_ttl_amount.
    w_discount = it_regup-wskto * -1.
  ENDIF.
  IF it_regup-waers = 'USD'.
    w_discount = w_discount / 1000.
  ENDIF.
  PERFORM bdc_dynpro      USING 'SAPDF05X' '1102'.
  PERFORM bdc_dynpro      USING 'SAPDF05X' '3100'.
  PERFORM bdc_field       USING 'BDC_SUBSCR' 'SAPDF05X'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'OSU'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'DF05B-PSSKT(01)'.
  PERFORM bdc_dynpro      USING 'SAPDF05X' '2000'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'GO'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'RF05A-XPOS1(03)'.
  PERFORM bdc_field       USING 'RF05A-XPOS1(01)' ''.
  PERFORM bdc_field       USING 'RF05A-XPOS1(03)' 'X'.
  PERFORM bdc_dynpro      USING 'SAPDF05X' '0731'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'GO'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'RF05A-SEL01(01)'.
  PERFORM bdc_field       USING 'RF05A-SEL01(01)' it_regup-belnr.
* perform bdc_dynpro      using 'SAPDF05X' '1102'.
  PERFORM bdc_dynpro      USING 'SAPDF05X' '3100'.
  PERFORM bdc_field       USING 'BDC_SUBSCR' 'SAPDF05X'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'OSU'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'DF05B-PSSKT(01)'.
  PERFORM bdc_dynpro      USING 'SAPDF05X' '2000'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'GO'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'RF05A-XPOS1(04)'.
  PERFORM bdc_field       USING 'RF05A-XPOS1(01)' ''.
  PERFORM bdc_field       USING 'RF05A-XPOS1(04)' 'X'.
  PERFORM bdc_dynpro      USING 'SAPDF05X' '0731'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'GO'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'RF05A-SEL01(01)'.
  PERFORM bdc_field       USING 'RF05A-SEL01(01)' it_regup-buzei.
* perform bdc_dynpro      using 'SAPDF05X' '1102'.
  PERFORM bdc_dynpro      USING 'SAPDF05X' '3100'.
  PERFORM bdc_field       USING 'BDC_SUBSCR' 'SAPDF05X'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'OMX'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'DF05B-PSSKT(01)'.
  w_disc_rate = it_regup-zbdxp.
  PERFORM bdc_dynpro      USING 'SAPDF05X' '1102'.
  PERFORM bdc_dynpro      USING 'SAPDF05X' '3100'.
  PERFORM bdc_field       USING 'BDC_SUBSCR' 'SAPDF05X'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'Z+'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'DF05B-PSSKT(01)'.
* perform bdc_dynpro      using 'SAPDF05X' '1102'.
  PERFORM bdc_dynpro      USING 'SAPDF05X' '3100'.
  PERFORM bdc_field       USING 'BDC_SUBSCR' 'SAPDF05X'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'OSE'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'DF05B-PSSKT(01)'.
  PERFORM bdc_field       USING 'DF05B-PSSKT(01)' w_discount.
  PERFORM bdc_field       USING 'DF05B-PSSKP(01)' w_disc_rate.
* perform bdc_dynpro      using 'SAPDF05X' '1102'.
  PERFORM bdc_dynpro      USING 'SAPDF05X' '3100'.
  PERFORM bdc_field       USING 'BDC_SUBSCR' 'SAPDF05X'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'OSE'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'DF05B-PSSKT(01)'.
ENDFORM.                    "bdc_screen_dtl
*---------------------------------------------------------------------
*       FORM BDC_SCREEN_1102_SAVE                                     *
*---------------------------------------------------------------------
*       ........                                                      *
*---------------------------------------------------------------------
FORM bdc_screen_1102_save.
  PERFORM bdc_dynpro      USING 'SAPDF05X' '1102'.
  PERFORM bdc_dynpro      USING 'SAPDF05X' '3100'.
  PERFORM bdc_field       USING 'BDC_SUBSCR' 'SAPDF05X'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'AB'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'DF05B-PSBET(01)'.
  PERFORM bdc_dynpro      USING 'SAPMF05A' '0701'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'PI'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'RF05A-AZEI1(01)'.
  PERFORM bdc_dynpro      USING 'SAPMF05A' '0300'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'BU'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'BSEG-WRBTR'.
*  IF paycurr = 'USD'.
  IF wa_t042i-waers = 'USD'.
    trans_ttl_amount = trans_ttl_amount / 1000.
  ELSE.
    PERFORM bdc_field       USING 'BSEG-DMBTR' ' '.
  ENDIF.
  PERFORM bdc_field       USING 'BSEG-WRBTR' trans_ttl_amount.
  PERFORM bdc_dynpro      USING 'SAPLKACB' '0002'.
  PERFORM bdc_field       USING 'BDC_SUBSCR' 'SAPLKACB'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'ENTE'.
ENDFORM.                    "bdc_screen_1102_save
*---------------------------------------------------------------------
*       FORM BDC_RECORD_DEL_PROP_F110                                *
*---------------------------------------------------------------------
*       ........                                                      *
*---------------------------------------------------------------------
FORM bdc_record_del_prop_f110.
  DATA: bdcdate(8), kill_id(5).
  bdcdate+0(4) = payrdate+4(4).
  bdcdate+4(4) = payrdate+0(4).
  kill_id = payriden.
  PERFORM bdc_dynpro      USING 'SAPF110V' '0200'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'F110V-LAUFI'.
  PERFORM bdc_field       USING 'BDC_OKCODE' '=VODE'.
  PERFORM bdc_field       USING 'F110V-LAUFD' bdcdate.
  PERFORM bdc_field       USING 'F110V-LAUFI' kill_id.
  PERFORM bdc_dynpro      USING 'SAPLSPO1' '0100'.
  PERFORM bdc_field       USING 'BDC_OKCODE' '=YES'.
*  perform bdc_dynpro      using 'SAPF110V' '0099'.
*  perform bdc_field       using 'BDC_OKCODE' 'STA'.
*  perform bdc_field       using 'BDC_CURSOR' 'F110V-LAUFI'.
*  perform bdc_field       using 'F110V-LAUFD' BDCDATE.
*  perform bdc_field       using 'F110V-LAUFI' KILL_ID.

*  perform bdc_dynpro      using 'SAPF110V' '0100'.
*  perform bdc_field       using 'BDC_OKCODE' 'VODE'.
*  perform bdc_field       using 'BDC_CURSOR' 'F110V-LAUFD'.

*  perform bdc_dynpro      using 'SAPLSPO1' '0100'.
*  perform bdc_field       using 'BDC_OKCODE' 'YES'.

*  perform bdc_dynpro      using 'SAPF110V' '0100'.
*  perform bdc_field       using 'BDC_OKCODE' 'STA'.

*  perform bdc_dynpro      using 'SAPF110V' '0100'.
*  perform bdc_field       using 'BDC_OKCODE' 'EEND'.
ENDFORM.                    "bdc_record_del_prop_f110
*---------------------------------------------------------------------
*       FORM BDC_SESSION_PRINT_CHECK_FBZ5                             *
*---------------------------------------------------------------------
*       ........                                                      *
*---------------------------------------------------------------------
FORM bdc_record_print_check.
  PERFORM bdc_dynpro      USING 'SAPMFCHK' '0750'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'DRUK'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'OPAYF-PPRIZ'.
  PERFORM bdc_field       USING 'BKPF-BELNR' ws_paydoc.
  PERFORM bdc_field       USING 'OPAYF-BUKRS' 'IHK'.
  PERFORM bdc_field       USING 'BKPF-GJAHR' '1999'.
  PERFORM bdc_field       USING 'OPAYF-RZAWE' w_paymeth.
  PERFORM bdc_field       USING 'OPAYF-PSTAP' checklot.
  PERFORM bdc_field       USING 'OPAYF-PPRIZ' print_to.
  PERFORM bdc_field       USING 'OPAYF-PSOFO' printnow.
  PERFORM bdc_dynpro      USING 'SAPLF028' '0100'.
  PERFORM bdc_field       USING 'BDC_OKCODE' 'PI'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'LFA1-NAME1(02)'.
  PERFORM bdc_dynpro      USING 'SAPMSSY0' '0120'.
  PERFORM bdc_field       USING 'BDC_OKCODE' '%EX'.
  PERFORM bdc_dynpro      USING 'SAPMFCHK' '0750'.
  PERFORM bdc_field       USING 'BDC_OKCODE' '/EEND'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'BKPF-BELNR'.
ENDFORM.                    "bdc_record_print_check
*---------------------------------------------------------------------
*       FORM TRANS_MESS                                               *
*---------------------------------------------------------------------
*       ........                                                      *
*---------------------------------------------------------------------
FORM trans_mess.
  LOOP AT messtab WHERE msgtyp = 'E' OR msgtyp = 'A' OR msgtyp = 'S'.
    REFRESH messtab.
    SELECT SINGLE text INTO (ws_text) FROM t100
    WHERE sprsl = sy-langu
    AND arbgb = messtab-msgid
    AND msgnr = messtab-msgnr.
*some message have variables.  Replace the & with the variables.
    REPLACE '&' WITH messtab-msgv1 INTO ws_text.
    REPLACE '&' WITH messtab-msgv2 INTO ws_text.
    REPLACE '&' WITH messtab-msgv3 INTO ws_text.
    REPLACE '&' WITH messtab-msgv4 INTO ws_text.
  ENDLOOP.
ENDFORM.                    "trans_mess
*Selection texts
*---------------
*SCHECKLOT        CHECK LOT
*SEFFDATE         EFFECTIVE DATE
*SPAYMETH         PAYMENT METHOD
*SPAYRIDEN        PAYMENT RUN IDENTIFIER
*SPRINT_TO        PRINTER TO
*Messages
*-------------
*Message class: Z1
*035 Payment method not allowed.
*039 &1
*---------------------------------------------------------------------
*&                      Form  get_timestamps
*---------------------------------------------------------------------
*               Create Time Stamps To Get Right Spool
*----------------------------------------------------------------------
FORM get_timestamps.

  DATA: v_tst TYPE timestamp,
  v_ctst(19).

  wa_tstamp-rqclient  = sy-mandt.
  wa_tstamp-rqowner   = sy-uname.
  wa_tstamp-rqdoctype = 'OTF'.

  GET TIME STAMP FIELD v_tst.       "short form

  WRITE v_tst TO v_ctst LEFT-JUSTIFIED.

  DO.
    REPLACE ',' WITH '' INTO v_ctst.
    IF sy-subrc NE 0.
      EXIT.
    ENDIF.
  ENDDO.
  CONDENSE v_ctst NO-GAPS.

  wa_tstamp-rqcretime = v_ctst.

  APPEND wa_tstamp TO i_tstamp.
  CLEAR v_ctst.

ENDFORM.                    " get_timestamps

*---------------------------------------------------------------------
*&                        Form  get_spool
*---------------------------------------------------------------------
*      Get The Spools Generated from current payment run Cross Comp
*----------------------------------------------------------------------
FORM get_spool.

  SELECT
  rqident         "Spool request number
  rqclient         "Client
  rqowner         "Spool request: Name
  rqcretime  "Time of spool request
  rqdoctype  "Spool: document type
  FROM tsp01
  INTO TABLE i_tsp01
  FOR ALL ENTRIES IN i_tstamp
  WHERE rqclient  EQ i_tstamp-rqclient
  AND   rqowner   EQ i_tstamp-rqowner
  AND   rqcretime GE i_tstamp-rqcretime
  AND   rqdoctype EQ i_tstamp-rqdoctype
  AND   rqtitle   EQ 'Payment advices'(k36).

  IF sy-subrc EQ 0.
    SORT i_tsp01 BY rqident.
  ENDIF.

ENDFORM.                    " get_spool
*---------------------------------------------------------------------
*&                        Form  sendmails
*---------------------------------------------------------------------
*                   Send Payment Advices Via Mail
*----------------------------------------------------------------------
FORM sendmails.

*Get spool id from program called above

  LOOP AT i_tsp01 INTO wa_tsp01.
*Get Spool Info for Vendors mail ID to be Sent

    PERFORM convert_spool_to_pdf.

    PERFORM process_email.

*Ensure All Mails Are Sent
    WAIT UP TO 3 SECONDS.
*Connect to SAP Office
    SUBMIT rsconn01 WITH mode   = 'INT'
    WITH output = 'X'
    AND RETURN.

    IF ( gd_reciever NE 0 ) OR ( sy-subrc NE 0 ).
*Resend the Mail To Asia AP, As Unsucessfull Delivery....
      PERFORM display_records.
    ELSE.
      WRITE:/ 'Mails Sent Succesfully To'(008), v_pmail, v_smail.
    ENDIF.

  ENDLOOP.

ENDFORM.                    " sendmails
*---------------------------------------------------------------------
*&                    Form  convert_spool_to_pdf
*---------------------------------------------------------------------
*                     Convert Spools to PDF Files
*----------------------------------------------------------------------
FORM convert_spool_to_pdf.

  CLEAR gd_bytecount.

  CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
    EXPORTING
      src_spoolid              = wa_tsp01-rqident
      no_dialog                = c_no
      dst_device               = c_device
    IMPORTING
      pdf_bytecount            = gd_bytecount
    TABLES
      pdf                      = it_pdf_output
    EXCEPTIONS
      err_no_otf_spooljob      = 1
      err_no_spooljob          = 2
      err_no_permission        = 3
      err_conv_not_possible    = 4
      err_bad_dstdevice        = 5
      user_cancelled           = 6
      err_spoolerror           = 7
      err_temseerror           = 8
      err_btcjob_open_failed   = 9
      err_btcjob_submit_failed = 10
      err_btcjob_close_failed  = 11
      OTHERS                   = 12.

  IF sy-subrc NE 0.
    WRITE:/ 'Failed While converting to PDF'(k31).
  ENDIF.
  CHECK sy-subrc = 0.

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

  REFRESH it_pdf_output.

  TRANSLATE gd_buffer USING '~ '.

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

ENDFORM.                    " convert_spool_to_pdf
*---------------------------------------------------------------------
*&                        Form  process_email
*---------------------------------------------------------------------
*                        Process Emails via PDF
*----------------------------------------------------------------------
FORM process_email.

  DATA: v_mail TYPE STANDARD TABLE OF somlreci1-receiver,
  wa_mail LIKE LINE OF v_mail,
  v_lmail TYPE somlreci1-receiver,
  v_flag TYPE c.

  DESCRIBE TABLE it_mess_att LINES gd_recsize.
  CHECK gd_recsize > 0.

  CLEAR v_flag.

  SELECT SINGLE intad INTO v_lmail
  FROM lfb1
  WHERE lifnr EQ bseg-lifnr
  AND   bukrs EQ bseg-bukrs.
  IF sy-subrc EQ 0.
    SPLIT v_lmail AT ',' INTO v_pmail v_smail.
    SPLIT v_lmail AT ',' INTO TABLE v_mail.

    PERFORM send_email TABLES v_mail USING v_flag.
*If Vendors mail ID not found, then send mail to Celestica Inc
  ELSE.
    v_flag = 'X'.
    wa_mail = 'Asia_AP@Celestica.com'(k25).
    APPEND wa_mail TO v_mail.
    wa_mail = 'Asia_Interco@Celestica.com'(k24).
    APPEND wa_mail TO v_mail.
    PERFORM send_email TABLES v_mail USING v_flag.
  ENDIF.

ENDFORM.                    " process_email
*---------------------------------------------------------------------
*&      Form  send_email
*---------------------------------------------------------------------
FORM send_email TABLES p_email USING p_v_flag TYPE c.

  REFRESH it_mess_bod.

*Default subject matter
  gd_subject         = 'Please find Attached Payment Advice.'(k29).
  gd_attachment_desc = 'Payment Advice'(k28).

  IF p_v_flag EQ ' '.
*Asia_AP@Celestica.com.  Or Asia_Interco@Celestica.com,
    it_mess_bod    = 'Please Find The Attached Payment Advice File.'(k27).
    APPEND it_mess_bod.
    CLEAR it_mess_bod.
    it_mess_bod      = ' Reply Payment Advice Related Quiries to :'(k26).
    APPEND it_mess_bod.
    CLEAR it_mess_bod.
    it_mess_bod        = '(Asia_AP@Celestica.com)'(k50).
    APPEND it_mess_bod.
    CLEAR it_mess_bod.
    it_mess_bod        = ' OR (Asia_Interco@Celestica.com)'(k51).
    APPEND it_mess_bod.
    CLEAR it_mess_bod.
  ELSE.
    it_mess_bod  = 'Mail ID of the Vendor Does not exists.'(k23).
    APPEND it_mess_bod.
    CLEAR it_mess_bod.
    it_mess_bod        = ' Plese Check Vendor Data.'(k22).
    APPEND it_mess_bod.
    CLEAR it_mess_bod.
    it_mess_bod        = ' Please Resend to Vendor.'(k21).
    APPEND it_mess_bod.
    CLEAR it_mess_bod.
  ENDIF.

  gd_sender_type  = 'INT'.

  send file by email as .pdf
  perform send_file_as_email_attachment
  tables   it_mess_bod
  it_mess_att
  p_email
  using
  'Payment advices'(k36)
  c_pdf
  gd_attachment_name
  gd_attachment_desc
  c_sender
  gd_sender_type
  changing
  gd_reciever.

ENDFORM.                    " send_email
*---------------------------------------------------------------------
*&              Form  send_file_as_email_attachment
*---------------------------------------------------------------------
*                          Process Mailing
*----------------------------------------------------------------------
FORM send_file_as_email_attachment
                    TABLES  it_message
                            it_attach
                            p_email
                    USING   p_mtitle
                            p_format
                            p_filename
                            p_attdescription
                            p_sender_address
                            p_sender_addres_type
                    CHANGING p_reciever.

  DATA:
  ld_error    TYPE sy-subrc,
  ld_reciever TYPE sy-subrc,
  ld_mtitle LIKE sodocchgi1-obj_descr,
  ld_format TYPE  so_obj_tp ,
  ld_attdescription TYPE  so_obj_nam ,
  ld_attfilename TYPE  so_obj_des ,
  ld_sender_address LIKE  soextreci1-receiver,
  ld_sender_address_type LIKE  soextreci1-adr_typ,
  ld_receiver LIKE  sy-subrc.
  DATA:
  t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
  t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
  t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
  w_cnt TYPE i,
  w_sent_all(1) TYPE c,
  w_doc_data LIKE sodocchgi1,
  wa_mail LIKE somlreci1-receiver.

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

*Fill the document data.
  w_doc_data-doc_size = 1.
*Populate the subject/generic message attributes
  w_doc_data-obj_langu = sy-langu.
  w_doc_data-obj_name  = 'SAPRPT'.
  w_doc_data-obj_descr = ld_mtitle .
  w_doc_data-sensitivty = 'F'.
*Fill the document data and get size of attachment
  CLEAR w_doc_data.
  READ TABLE it_attach INDEX w_cnt.
  w_doc_data-doc_size =
  ( w_cnt - 1 ) * 255 + strlen( it_attach ).
  w_doc_data-obj_langu  = sy-langu.
  w_doc_data-obj_name   = 'SAPRPT'.
  w_doc_data-obj_descr  = ld_mtitle.
  w_doc_data-sensitivty = 'F'.
  CLEAR t_attachment.
  REFRESH t_attachment.
  t_attachment[] = it_attach[].
*Describe the body of the message
  CLEAR t_packing_list.
  REFRESH t_packing_list.
  t_packing_list-transf_bin = space.
  t_packing_list-head_start = 1.
  t_packing_list-head_num = 0.
  t_packing_list-body_start = 1.
  DESCRIBE TABLE it_message LINES t_packing_list-body_num.
  t_packing_list-doc_type = 'RAW'.
  APPEND t_packing_list.
*Create attachment notification
  t_packing_list-transf_bin = 'X'.
  t_packing_list-head_start = 1.
  t_packing_list-head_num   = 1.
  t_packing_list-body_start = 1.

  DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
  t_packing_list-doc_type   =  ld_format.
  t_packing_list-obj_descr  =  ld_attdescription.
  t_packing_list-obj_name   =  ld_attfilename.
  t_packing_list-doc_size   =  t_packing_list-body_num * 255.
  APPEND t_packing_list.
*Add the recipients email address
  CLEAR t_receivers.
  REFRESH t_receivers.

  LOOP AT p_email INTO wa_mail.
    t_receivers-receiver = wa_mail.
    t_receivers-rec_type = 'U'.
    t_receivers-com_type = 'INT'.
    t_receivers-notif_del = 'X'.
    t_receivers-notif_ndel = 'X'.
    APPEND t_receivers.
  ENDLOOP.

  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data              = w_doc_data
      put_in_outbox              = 'X'
      sender_address             = ld_sender_address
      sender_address_type        = ld_sender_address_type
    IMPORTING
      sent_to_all                = w_sent_all
    TABLES
      packing_list               = t_packing_list
      contents_bin               = t_attachment
      contents_txt               = it_message
      receivers                  = t_receivers
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      document_type_not_exist    = 3
      operation_no_authorization = 4
      parameter_error            = 5
      x_error                    = 6
      enqueue_error              = 7
      OTHERS                     = 8.

  IF sy-subrc NE 0.
    WRITE:/ 'Error While Sending the mail'(k20).
  ENDIF.
*Populate zerror return code
  ld_error = sy-subrc.
  p_reciever = sy-subrc.

ENDFORM.                    " send_file_as_email_attachment
*---------------------------------------------------------------------
*&                  Form  send_failure_mail
*---------------------------------------------------------------------
*          If Mails are Failed, Then Resend the Same
*----------------------------------------------------------------------
FORM display_records.

  DATA: v_chect TYPE payr-chect,
  v_mail1 TYPE STANDARD TABLE OF somlreci1-receiver,
  wa_mail LIKE LINE OF v_mail1.

  WRITE:/ 'The Below Payment advices are Undeliverd'(k37),
        / 'Please Resend the Spool'(k38),  wa_tsp01-rqident.

  ULINE.

  WRITE :/2 'Document No'(007),
          14 'Invoice Date'(k40),
          25   'Invoice No'(k41),
          46 'Payment Run Dt'(k42),
          66 'Payment Proposal'(k43),
          84 'Check No'(k44),
          94 'Amount'(k45),
          115 'Vendor Code'(k46),
          128 'Vendor Email Address'(k47),
          160 'Type Of Error'(k48).

*Get Check Number
  SELECT SINGLE chect INTO v_chect
  FROM payr
  WHERE zbukr EQ p_zbukr
  AND   hbkid EQ p_hbkid
  AND   rzawe EQ w_paymeth
  AND   laufd EQ payrdate
  AND   lifnr EQ bseg-lifnr
  AND   vblnr EQ ws_paydoc.

  ULINE.

  WRITE :/
  ws_paydoc  UNDER text-007,                  "Document No
  bkpf-bldat UNDER text-k40,                  "Invoice Date
  bkpf-belnr UNDER text-k41,                  "Invoice No
  payrdate   UNDER text-k42,                  "Payment Run Dt
  payriden   UNDER text-k43,                  "Payment Proposal
  v_chect    UNDER text-k44,                  "Check No
  bseg-dmbtr CURRENCY bkpf-waers UNDER text-k45,  "Amount
  bseg-lifnr UNDER text-k46,                  "Vendor Code
  v_pmail(30) UNDER text-k47,                 "Vendor Email address
  'Mail Delivery Failure'(k49) UNDER text-k48. "Type Of Error

*Append Mail ID For Failure Delivery To Be Resent
  wa_mail = 'Asia_AP@Celestica.com'(k25).
  APPEND wa_mail TO v_mail1.
  wa_mail = 'Asia_Interco@Celestica.com'(k24).
  APPEND wa_mail TO v_mail1.
*Default subject matter
  gd_subject         = 'Payment Advice Delivery Failure'(k52).
  gd_attachment_desc = 'No File'(k54).

*Asia_AP@Celestica.com.  Or Asia_Interco@Celestica.com,
  i_mess_bodf    = 'Failed To Deliver the Mail.'(k55).
  APPEND i_mess_bodf.
  CLEAR i_mess_bodf.
  i_mess_bodf      = v_pmail.
  APPEND i_mess_bodf.
  CLEAR i_mess_bodf.
  i_mess_bodf        = 'Document Number As Below'(k56).
  APPEND i_mess_bodf.
  CLEAR i_mess_bodf.
  i_mess_bodf        = ws_paydoc.
  APPEND i_mess_bodf.
  CLEAR i_mess_bodf.

*Send file by email as .PDF
  PERFORM send_file_as_email_attachment
  TABLES   i_mess_bodf
  i_mess_attf
  v_mail1
  USING
  gd_subject
  'TXT'
  gd_attachment_name
  gd_attachment_desc
  c_sender
  gd_sender_type
  CHANGING
  gd_reciever.

*Ensure All Mails Are Sent
  WAIT UP TO 3 SECONDS.
  connect to sap office
  submit rsconn01 with mode   = 'INT'
  with output = 'X'
  and return.
  IF ( gd_reciever NE 0 ) OR ( sy-subrc NE 0 ).
*Resend the Mail To Asia AP, As Unsucessfull Delivery....
    SKIP 2.
    ULINE.
    WRITE:/ 'Mails Failed Again'(k53).
  ENDIF.

ENDFORM.                    " send_failure_mail
  • No labels

2 Comments

  1. Kindly specify code for include
    INCLUDE zbbdclib.

    Further what does ITH means here

  2. As a Basis-guy i have to recommend NOT to trigger the RSCONN01 within the ABAP.

    Connect to SAP Office
      SUBMIT rsconn01 WITH mode   = 'INT'
                      WITH output = 'X'
                      AND RETURN.

    The SCOT-sendout is triggered and scheduled by a batch-job and will send out your mail when i runs.

    Best regards

    Christian