Vous êtes sur la page 1sur 21

& Program Name : ZFIFAGST * *& Creation Date : 03/05/2008 * *& Author : Srinivas Kata * *& Application Area

: FI-AR * *& Development Spec ID : FIF004 * *&---------------------------------------------------------------------* *& Description: : All open items are selected for a given set of* *& customers on a given date and the information * *& is formatted into a form called an Accounts * *& Receivable Statement (AR-statement) containing* *& the following information *& Customer addresses,customer number,remit to * *& address,FI document number,due date,document * *& date, customer po etc * *& *& Inputs: N/A * *& * *& Outputs: N/A * *& * *& Scheduling: N/A * *& * *& External Routines: * *& * *& Assumptions/Restriction: * *& Change History: * *&=====================================================================* *& Date | Change # | Changed By | Description * *&---------------------------------------------------------------------* *& MAR 05, 2008 | ERDK904215 | SKATA | Initial Development * *& JAN 19, 2009 | ERDK923457 | SNEEMKAR | In#10087 - Set SADR-TELF1 * *& | | " | & SADR-TELFX as 650-424-5816 and * *& | | " | 702-940-4915 resp. for Sales Orgs: * *& | | " | 0600, 0660, 0661, 0601, 0560 & 0561* *&---------------------------------------------------------------------* *& FEB 05, 2009 | ERDK924440 | KREVURI | Inc#11218 - Sort by Date * *&---------------------------------------------------------------------* *----------------------------------------------------------------------* * Modification Log * Requestor : Maureen Mundorff * Analyst : Saawan Kandregula * Incident No : 20978 * change date : 03 Feb 2010 * Programmer : BSHAIK * Transport : ERDK932571 * Description : Added print immidiate paremeter in prog *---------------------------------------------------------------------------* *---------------------------------------------------------------------------*

* Modification Log * Requestor : Diego Mendez * Analyst : Ravi pasumarthy * Incident No : CHG0031882 * change date : 05 Oct 2010 * Programmer : PANGAJAL * Transport : ERDK941486 * Description : Added Noted items check box in selection screen * and remit-to address for company code 0392 *---------------------------------------------------------------------------* * Modification Log * Requestor : Rupal Shah * Analyst : Ankur Chandra * Change Request : CHG0038730 * change date : 19 Aug 2011 * Programmer : VPASULA * Transport : ERDK950215 * Description : PO Box address has priority over Street address . *---------------------------------------------------------------------------* * Modification Log * Requestor : Rupal Shah * Analyst : Ankur Chandra * Change Request : CHG0039329 * change date : 26 Aug 2011 * Programmer : VPASULA * Transport : ERDK950450 * Description : PO Box address has priority over Street address . * Other city on output *---------------------------------------------------------------------------* ************************************************************************ REPORT zfifagst.

********************************************************************** * T A B L E S * ********************************************************************** TABLES: tvko, kna1, knb1, knb4, knc1, knc3, bsid, "Organizational Unit: Sales Organizations "General Data in Customer Master "Customer Master record Company Segment "Customer Payment History "Customer Master(monthly debit & credit) "Customer Master(Special G/L Transactions/Credit "Accounting: Secondary Index for Customers

bkpf, "Accounting Document Header bseg, "Accounting Document Segment bsega. "Document Segment Enhancement Part *----------------------------------------------------------------------* * T Y P E S D E C L A R A T I O N S * *----------------------------------------------------------------------* TYPES: BEGIN OF type_itab, bukrs TYPE bkpf-bukrs, kunnr TYPE bseg-kunnr, past_due TYPE i, stage TYPE i, netdt TYPE bsega-netdt, zfbdt TYPE bseg-zfbdt, bldat TYPE bkpf-bldat, blart TYPE bkpf-blart, belnr TYPE bkpf-belnr, gjahr TYPE bkpf-gjahr, waers TYPE bkpf-waers, buzei TYPE bseg-buzei, vbeln TYPE vbrk-vbeln, ltext TYPE t003t-ltext, dmbtr TYPE bseg-dmbtr, wrbtr TYPE bseg-wrbtr, koart TYPE bseg-koart, name1 TYPE lfa1-name1, name2 TYPE lfa1-name2, name3 TYPE lfa1-name3, name4 TYPE lfa1-name4, adrnr TYPE kna1-adrnr, pfach TYPE lfa1-pfach, stras TYPE lfa1-stras, pstlz TYPE lfa1-pstlz, ort01 TYPE lfa1-ort01, ort02 TYPE lfa1-ort02, land1 TYPE lfa1-land1, regio TYPE lfa1-regio, bstnk TYPE vbak-bstnk, allgstid TYPE rfpdo-allgstid, vgart TYPE am07m-vgart, END OF type_itab, tt_itab TYPE STANDARD TABLE OF type_itab. *Type for Address TYPES: BEGIN OF type_address_no, vkorg TYPE vkorg, bukrs TYPE vkbuk, adrnr TYPE adrnr, END OF type_address_no, tt_address_no TYPE STANDARD TABLE OF type_address_no.

*Type for Sender Address TYPES: BEGIN OF type_send_addrs, adrnr TYPE cadnr, "Address No anred TYPE anred, "Title pstlz TYPE pstlz_bas, "Postal Code ort01 TYPE ort01_gp, "City stras TYPE stras_gp, "House number and street regio TYPE regio, "Region (State, Province, County) teltx TYPE teltx, "Teletex number telx1 TYPE telx1, "Telex number END OF type_send_addrs, tt_send_addrs TYPE STANDARD TABLE OF type_send_addrs. *Type for Remit Address TYPES: BEGIN OF type_remit_addrs, sales_org TYPE vkorg, *Modifications begins MDABBUGU on 24Aug2009 ERDK929173 address1 TYPE NAME1_GP, "name1, address2 TYPE NAME1_GP, "name1, address3 TYPE NAME1_GP, "name1, address4 TYPE NAME1_GP, "name1, address5 TYPE NAME1_GP, "name1, *Modifications Ends MDABBUGU on 24Aug2009 ERDK929173 END OF type_remit_addrs, tt_remit_addrs TYPE STANDARD TABLE OF type_remit_addrs. *Type for Country details TYPES: BEGIN OF type_country_name, land1 TYPE land1, "Country Key landx TYPE landx, "Country Name END OF type_country_name, tt_country_name TYPE STANDARD TABLE OF type_country_name. *Type for Currency key details TYPES: BEGIN OF type_currency_key, currkey TYPE sycurr, currdec TYPE currdec, END OF type_currency_key, tt_currency_key TYPE STANDARD TABLE OF type_currency_key. *Modification Begins VPASULA 19Aug2011 ERDK950215 TYPES: BEGIN OF type_pobox_addr, addrnumber TYPE adrc-addrnumber, "Address number post_code2 TYPE adrc-post_code2, "PO box postal code po_box TYPE adrc-po_box, "PO Box po_box_loc TYPE adrc-po_box_loc, "PO Box City po_box_reg TYPE adrc-po_box_reg, "PO Box Region po_box_cty TYPE adrc-po_box_cty, "PO box country po_box_lobby TYPE adrc-po_box_lobby, "PO Box Lobby END OF type_pobox_addr. *Modification Ends VPASULA 19Aug2011 ERDK950215 *----------------------------------------------------------------------*

* D A T A D E C L A R A T I O N S * *----------------------------------------------------------------------* * Variable Declarations DATA: gv_contact_information(132) TYPE c, gv_rcount TYPE bseg-wrbtr, gv_ztag1 TYPE t052-ztag1, gv_aubel TYPE vbrp-aubel, gv_bstnk TYPE vbak-bstnk, gv_vtweg TYPE vbak-vtweg, gv_fmname TYPE rs38l_fnam, gv_sav_waers TYPE bkpf-waers, gv_count TYPE tcurx-currdec, gv_subtot1 TYPE bseg-wrbtr, gv_subtot2 TYPE bseg-wrbtr, gv_subtot3 TYPE bseg-wrbtr, gv_subtot4 TYPE bseg-wrbtr, gv_inv_no TYPE vbrk-vbeln, fl_flag_curr TYPE char1 VALUE 'X', gv_interface TYPE fpinterfacetype. * Internal Table Declarations DATA: gt_itab TYPE tt_itab, gt_address_no TYPE tt_address_no, gt_send_addrs TYPE tt_send_addrs, gt_remit_addrs TYPE tt_remit_addrs, gt_country_name TYPE tt_country_name, gt_zsfi_ar TYPE zsfi_ar, gt_zsfi_address TYPE zsfi_address, gt_zsfi_ar1 TYPE zsfi_ar, gt_currency_key TYPE tt_currency_key. *Modification Begins VPASULA 19Aug2011 ERDK950215 DATA: gt_pobox_addr TYPE STANDARD TABLE OF type_pobox_addr. *Modification Ends VPASULA 19Aug2011 ERDK950215 *Work area Declaration DATA: gx_itab TYPE type_itab, gx_address_no TYPE type_address_no, * Begin of MOD - 04.07.2008 - GGUDA * gx_send_addrs TYPE sadr, "type_send_addrs, gx_send_addrs TYPE type_send_addrs, * End of MOD - 04.07.2008 - GGUDA gx_remit_addrs TYPE type_remit_addrs, gx_country_name TYPE type_country_name, gx_zsfi_ar LIKE LINE OF gt_zsfi_ar, gx_zsfi_address LIKE LINE OF gt_zsfi_address, gx_sfpoutputparams TYPE sfpoutputparams, gx_currency_key TYPE type_currency_key, gx_fp_docparams TYPE sfpdocparams, gv_docc_curr TYPE bkpf-waers. *Modification Begins VPASULA 19Aug2011 ERDK950215 DATA: gx_pobox_addr TYPE type_pobox_addr.

*Modification Ends VPASULA 19Aug2011 ERDK950215 *----------------------------------------------------------------------* * C O N S T A N T S D E C L A R A T I O N S * *----------------------------------------------------------------------* CONSTANTS: gc_x TYPE c VALUE 'X', gc_printer TYPE itcpp-tddevice VALUE 'PRINTER', gc_shkzg_h TYPE bseg-shkzg VALUE 'H', gc_value_negative TYPE char2 VALUE '-1'. DATA: gc_fpname TYPE fpname VALUE 'Z_FIF_ARSTATEMENT'.

*----------------------------------------------------------------------* * S E L E C T I O N S C R E E N * *----------------------------------------------------------------------* *Sales Organization * Addition by PANGAJAL CHG0031882 SELECTION-SCREEN begin of BLOCK noted WITH FRAME TITLE text-102. PARAMETERS: c_noted as CHECKBOX. SELECTION-SCREEN END OF BLOCK noted. *End of addition by PANGAJAL SELECTION-SCREEN BEGIN OF BLOCK special1 WITH FRAME TITLE text-101. SELECT-OPTIONS: s_vkorg FOR tvko-vkorg OBLIGATORY DEFAULT '0530'. SELECTION-SCREEN END OF BLOCK special1. SELECTION-SCREEN BEGIN OF BLOCK special WITH FRAME TITLE text-100. PARAMETERS: rb_wmsg RADIOBUTTON GROUP one, rb_womsg RADIOBUTTON GROUP one. PARAMETERS: p_text(132) TYPE c. SELECTION-SCREEN END OF BLOCK special. SELECTION-SCREEN BEGIN OF BLOCK output WITH FRAME TITLE text-sop. PARAMETERS: p_dbdis AS CHECKBOX. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 1(31) text-011 FOR FIELD p_device. PARAMETERS : p_device TYPE itcpp-tddevice DEFAULT 'PRINTER'. SELECTION-SCREEN POSITION 50. PARAMETERS: p_name TYPE pri_params-pdest. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN END OF BLOCK output. IF rb_wmsg = gc_x. gv_contact_information = p_text. ENDIF. *----------------------------------------------------------------------* * A T S E L E C T I O N S C R E E N O N * *----------------------------------------------------------------------* AT SELECTION-SCREEN. PERFORM sub_validate_slctnscrn.

*----------------------------------------------------------------------* * S T A R T O F S E L E C T I O N * *----------------------------------------------------------------------* START-OF-SELECTION. *Get the KNA1 GET kna1. *Get the BSID GET bsid. GET bkpf. *Compare the Documet date CHECK bkpf-bldat LE dd_stida. GET bseg. * Change by PANGAJAL CHG0031882 if c_noted ne 'X' and bsid-bstat ne 'S'. PERFORM sub_move_data_to_itab. endif. if c_noted eq 'X'. PERFORM sub_move_data_to_itab. endif. * END of Change by PANGAJAL CHG0031882 *----------------------------------------------------------------------* * E N D - O F - S E L E C T I O N * *----------------------------------------------------------------------* END-OF-SELECTION. PERFORM sub_get_sender_address. PERFORM sub_adobe_output.

*&---------------------------------------------------------------------* *& Form SUB_VALIDATE_SLCTNSCRN *&---------------------------------------------------------------------* *Restrict customer selection to one customer for non-printer o/p * *devices *----------------------------------------------------------------------* FORM sub_validate_slctnscrn . DATA: lv_count TYPE i. IF p_device NE gc_printer. SELECT COUNT(*) INTO lv_count FROM kna1 WHERE kunnr IN dd_kunnr. IF lv_count > 1. "sy-dbcnt MESSAGE e999(zfivvp) WITH 'Selection restricted to 1 customer'(so1)

'when output device is'(so2) p_device. ENDIF. ENDIF.

ENDFORM. " SUB_VALIDATE_SLCTNSCRN *&---------------------------------------------------------------------* *& Form SUB_MOVE_DATA_TO_ITAB *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM sub_move_data_to_itab . MOVE-CORRESPONDING bkpf TO gx_itab. MOVE-CORRESPONDING bseg TO gx_itab. MOVE-CORRESPONDING bsega TO gx_itab. * Check that Clearing Date is either greater than Key Date or is blank. CHECK bseg-augdt > dd_stida OR bseg-augdt = 0. * * Not used anymore gx_itab-stage = ( gx_itab-bldat - dd_stida ).

* Determine nbr of days allowed before payment is delinquent ZTAT1 * for payment terms ZTERM. SELECT ztag1 INTO gv_ztag1 FROM t052 UP TO 1 ROWS WHERE zterm EQ bseg-zterm. ENDSELECT. IF sy-subrc EQ 0. * Days delinquent = key date - BaseLine date - days from BL date allowed gx_itab-past_due = ( dd_stida - bseg-zfbdt - gv_ztag1 ). ELSE. gx_itab-past_due = ( dd_stida - bseg-zfbdt ). ENDIF. * Begin of MOD - 04.07.2008 - GGUDA * Change the INVOICE number column to select from BELNR not XBLNR * MOVE bkpf-xblnr TO gx_itab-vbeln. MOVE bkpf-belnr TO gx_itab-vbeln. * End of MOD - 04.07.2008 - GGUDA *Get the Sales Document SELECT aubel INTO gv_aubel FROM vbrp UP TO 1 ROWS WHERE vbeln EQ bsid-belnr. ENDSELECT.

IF sy-subrc EQ 0. *Get the Customer PO details SELECT SINGLE vtweg bstnk INTO (gv_vtweg, gv_bstnk) FROM vbak WHERE vbeln EQ gv_aubel. IF sy-subrc EQ 0. MOVE: gv_vtweg TO gx_itab-vgart, gv_bstnk TO gx_itab-bstnk. ELSE. MOVE space TO gx_itab-bstnk. ENDIF. ENDIF. *Compare debit/credit indicator,if it is -ve sign *Multyply with '-1'. IF bseg-shkzg = gc_shkzg_h. gx_itab-wrbtr = bseg-wrbtr * gc_value_negative. gx_itab-dmbtr = bseg-dmbtr * gc_value_negative. ENDIF. MOVE-CORRESPONDING kna1 TO gx_itab. MOVE dd_stida TO gx_itab-allgstid. gv_rcount = gv_rcount + 1. APPEND gx_itab TO gt_itab. CLEAR gx_itab. ENDFORM. " SUB_MOVE_DATA_TO_ITAB *&---------------------------------------------------------------------* *& Form SUB_GET_SENDER_ADDRESS *&---------------------------------------------------------------------* * Get the Sender Address *----------------------------------------------------------------------* FORM sub_get_sender_address . DATA:lx_addr1_sel TYPE addr1_sel, lx_sadr TYPE sadr. IF NOT gt_itab IS INITIAL. *Get the Company Code and Address No SELECT vkorg bukrs adrnr INTO TABLE gt_address_no FROM tvko FOR ALL ENTRIES IN gt_itab WHERE bukrs EQ gt_itab-bukrs. ENDIF. *Get the Title,Postal code,City,House number and street, *Region(State,Province,County),Teletex number,Telex number IF NOT gt_address_no IS INITIAL. LOOP AT gt_address_no INTO gx_address_no.

lx_addr1_sel-addrnumber = gx_address_no-adrnr. lx_addr1_sel-nation = space. CALL FUNCTION 'ADDR_GET' EXPORTING address_selection = lx_addr1_sel IMPORTING sadr = lx_sadr EXCEPTIONS parameter_error = 1 address_not_exist = 2 version_not_exist = 3 internal_error = 4 OTHERS = 5. IF sy-subrc EQ 0. gx_send_addrs-adrnr = lx_sadr-adrnr. gx_send_addrs-anred = lx_sadr-anred. gx_send_addrs-pstlz = lx_sadr-pstlz. gx_send_addrs-ort01 = lx_sadr-ort01. gx_send_addrs-stras = lx_sadr-stras. gx_send_addrs-regio = lx_sadr-regio. Begin of MOD - 04.07.2008 - GGUDA gx_send_addrs-teltx = lx_sadr-teltx. TELF1 gx_send_addrs-telx1 = lx_sadr-telx1. TELFX "Begin - SNEEMKAR - 01/16/2009 - In#10087 IF gx_address_no-vkorg EQ '0600' OR gx_address_no-vkorg EQ '0601' OR gx_address_no-vkorg EQ '0661' OR gx_address_no-vkorg EQ '0660' OR gx_address_no-vkorg EQ '0560' OR gx_address_no-vkorg EQ '0561'. gx_send_addrs-teltx = '650-424-5816'. gx_send_addrs-telx1 = '702-940-4915'. ELSE. gx_send_addrs-teltx = lx_sadr-telf1. gx_send_addrs-telx1 = lx_sadr-telfx. ENDIF. "End - SNEEMKAR - 01/16/2009 - In#10087 End of MOD - 04.07.2008 - GGUDA APPEND gx_send_addrs TO gt_send_addrs. CLEAR lx_sadr. ENDIF. ENDLOOP.

* * *

*Get the REMIT To Address. SELECT sales_org address1

address2 address3 address4 address5 INTO TABLE gt_remit_addrs FROM zremt FOR ALL ENTRIES IN gt_address_no WHERE sales_org = gt_address_no-vkorg.

ENDIF. *Modification Begins VPASULA 19Aug2011 ERDK950215 IF NOT gt_itab[] IS INITIAL. SELECT addrnumber "Address number post_code2 "PO box postal code po_box "PO Box po_box_loc "PO Box City po_box_reg "PO Box Region po_box_cty "PO box country po_box_lobby "PO Box Lobby FROM adrc INTO TABLE gt_pobox_addr FOR ALL ENTRIES IN gt_itab WHERE addrnumber = gt_itab-adrnr. ENDIF. *Modification Ends VPASULA 19Aug2011 ERDK950215 *Get the Country key and Country Name IF NOT gt_itab IS INITIAL. SELECT land1 landx INTO TABLE gt_country_name FROM t005t FOR ALL ENTRIES IN gt_itab WHERE spras EQ sy-langu AND land1 EQ gt_itab-land1. *Get the Currency Key and Number of decimal places SELECT currkey currdec INTO TABLE gt_currency_key FROM tcurx FOR ALL ENTRIES IN gt_itab WHERE currkey EQ gt_itab-waers. ENDIF. data: lv_name(132) type c. data: lv_mail(132) type c. IF NOT gv_contact_information IS INITIAL.

* Change by PANGAJAL CHG0031882 SPLIT gv_contact_information at ':' INTO lv_name lv_mail. TRANSLATE lv_mail to LOWER CASE. CONCATENATE lv_name lv_mail INTO gv_contact_information SEPARATED BY ':'. * End of Change by PANGAJAL CHG0031882 gx_zsfi_address-contact_information = gv_contact_information. ENDIF. *Move the total data to Final internal table. SORT gt_itab BY kunnr ASCENDING bukrs ASCENDING vbeln DESCENDING. SORT gt_address_no BY bukrs adrnr DESCENDING. SORT gt_send_addrs BY adrnr ASCENDING. SORT gt_remit_addrs BY sales_org ASCENDING. SORT gt_country_name BY land1 ASCENDING. SORT gt_currency_key BY currkey ASCENDING. LOOP AT gt_itab INTO gx_itab. IF NOT gx_itab-vbeln IS INITIAL.

IF fl_flag_curr = gc_x. IF NOT gx_itab-waers IS INITIAL. gv_sav_waers = gx_itab-waers. ENDIF. PERFORM address_details. PERFORM sub_move_head_addrs. APPEND gx_zsfi_address TO gt_zsfi_address. gv_inv_no = gx_itab-vbeln. fl_flag_curr = gc_x. ENDIF. *For Different Currencies. IF gv_sav_waers NE gx_itab-waers. PERFORM sub_get_currency_details. APPEND gx_zsfi_ar TO gt_zsfi_ar. PERFORM sub_move_head_addrs. APPEND gx_zsfi_address TO gt_zsfi_address. gv_inv_no = gx_itab-vbeln. gv_sav_waers = gx_itab-waers. fl_flag_curr = gc_x. ENDIF.

IF gv_inv_no NE gx_itab-vbeln. gv_sav_waers = gx_itab-waers. PERFORM sub_get_currency_details. APPEND gx_zsfi_ar TO gt_zsfi_ar. gv_inv_no = gx_itab-vbeln. PERFORM move_main_zsfi_ar. CLEAR: fl_flag_curr. ELSE. PERFORM move_main_zsfi_ar.

CLEAR: fl_flag_curr. ENDIF. AT END OF kunnr. PERFORM sub_get_currency_details. APPEND gx_zsfi_ar TO gt_zsfi_ar. fl_flag_curr = gc_x. ENDAT. ENDLOOP. ENDFORM. " SUB_GET_SENDER_ADDRESS *&---------------------------------------------------------------------* *& Form SUB_ADOBE_OUTPUT *&---------------------------------------------------------------------* * Printing the Form *----------------------------------------------------------------------* FORM sub_adobe_output . DATA: lv_oref TYPE REF TO cx_root, "#EC NEEDED lv_err_txt TYPE string.

SORT gt_zsfi_address BY kunnr ASCENDING bukrs ASCENDING. SORT gt_zsfi_ar BY kunnr ASCENDING bukrs ASCENDING. DELETE ADJACENT DUPLICATES FROM gt_zsfi_address COMPARING kunnr bukrs. TRY. CALL FUNCTION 'FP_FUNCTION_MODULE_NAME' EXPORTING i_name = gc_fpname IMPORTING e_funcname = gv_fmname e_interface_type = gv_interface. CATCH cx_fp_api_repository INTO CALL METHOD lv_oref->get_text RECEIVING result = lv_err_txt. CATCH cx_fp_api_usage INTO CLEAR:lv_err_txt. CALL METHOD lv_oref->get_text RECEIVING result = lv_err_txt. CATCH cx_fp_api_internal INTO CLEAR:lv_err_txt. CALL METHOD lv_oref->get_text RECEIVING result = lv_err_txt. lv_oref.

lv_oref.

lv_oref.

ENDTRY.

IF p_device EQ gc_printer. gx_sfpoutputparams-dest = p_name. ENDIF. gx_sfpoutputparams-device = p_device. * Device parameters gx_sfpoutputparams-nodialog = 'X'. gx_sfpoutputparams-nodialog = 'X'. gx_sfpoutputparams-preview = 'X'. gx_sfpoutputparams-reqnew = 'X'. "<<SN#01/21/09"D#3951 * Modifications begins BSHAIK 03Feb2010 ERDK932571 gx_sfpoutputparams-reqimm = 'X'. * Modifications ends BSHAIK 03Feb2010 ERDK932571 * Call the Open Job CALL FUNCTION 'FP_JOB_OPEN' CHANGING ie_outputparams = gx_sfpoutputparams 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. DATA: lx_address TYPE zsfi_address_details, lx_itab TYPE type_itab.

LOOP AT gt_zsfi_address INTO lx_address. REFRESH: gt_zsfi_ar1[].

gt_zsfi_ar1[] = gt_zsfi_ar[]. DELETE gt_zsfi_ar1 WHERE bukrs <> lx_address-bukrs OR kunnr <> lx_address-kunnr. *Changes made on 7/9/2008 by Challa *Merna don't want this ocuntry to be printer on the form lx_address-anred = ''. *End of changes

**Begin of chnage by amantena on 18-sept-2008 **Reason forr different date formats for us & other countires DATA: lx_zsfi_ari TYPE zsfi_ar_statement, lv_index TYPE sy-tabix, lv_land1 TYPE t001-land1. SELECT SINGLE land1 FROM t001 INTO lv_land1 WHERE bukrs = lx_address-bukrs.

LOOP AT gt_zsfi_ar1 INTO lx_zsfi_ari. lv_index = sy-tabix. IF lv_land1 EQ 'US'. lx_zsfi_ari-bldat2+0(2) lx_zsfi_ari-bldat2+2(1) lx_zsfi_ari-bldat2+3(2) lx_zsfi_ari-bldat2+5(1) lx_zsfi_ari-bldat2+6(4) lx_zsfi_ari-zfbdt2+0(2) lx_zsfi_ari-zfbdt2+2(1) lx_zsfi_ari-zfbdt2+3(2) lx_zsfi_ari-zfbdt2+5(1) lx_zsfi_ari-zfbdt2+6(4) lx_zsfi_ari-netdt2+0(2) lx_zsfi_ari-netdt2+2(1) lx_zsfi_ari-netdt2+3(2) lx_zsfi_ari-netdt2+5(1) lx_zsfi_ari-netdt2+6(4) lx_address-valdt2+0(2) lx_address-valdt2+2(1) lx_address-valdt2+3(2) lx_address-valdt2+5(1) lx_address-valdt2+6(4) MODIFY gt_zsfi_ar1 FROM ELSE. lx_zsfi_ari-bldat2+0(2) lx_zsfi_ari-bldat2+2(1) lx_zsfi_ari-bldat2+3(2) lx_zsfi_ari-bldat2+5(1) lx_zsfi_ari-bldat2+6(4) = = = = =

= = = = = = = = = = = = = = =

lx_zsfi_ari-bldat+4(2). '/'. lx_zsfi_ari-bldat+6(2). '/'. lx_zsfi_ari-bldat+0(4). lx_zsfi_ari-zfbdt+4(2). '/'. lx_zsfi_ari-zfbdt+6(2). '/'. lx_zsfi_ari-zfbdt+0(4). lx_zsfi_ari-netdt+4(2). '/'. lx_zsfi_ari-netdt+6(2). '/'. lx_zsfi_ari-netdt+0(4). lx_address-valdt+4(2). '/'. lx_address-valdt+6(2). '/'. lx_address-valdt+0(4).

lx_zsfi_ari = = = = =

INDEX lv_index.

lx_zsfi_ari-bldat+6(2). '-'. lx_zsfi_ari-bldat+4(2). '-'. lx_zsfi_ari-bldat+0(4).

lx_zsfi_ari-zfbdt2+0(2) = lx_zsfi_ari-zfbdt+6(2).

lx_zsfi_ari-zfbdt2+2(1) lx_zsfi_ari-zfbdt2+3(2) lx_zsfi_ari-zfbdt2+5(1) lx_zsfi_ari-zfbdt2+6(4) lx_zsfi_ari-netdt2+0(2) lx_zsfi_ari-netdt2+2(1) lx_zsfi_ari-netdt2+3(2) lx_zsfi_ari-netdt2+5(1) lx_zsfi_ari-netdt2+6(4)

= = = = = = = = =

'-'. lx_zsfi_ari-zfbdt+4(2). '-'. lx_zsfi_ari-zfbdt+0(4). lx_zsfi_ari-netdt+6(2). '-'. lx_zsfi_ari-netdt+4(2). '-'. lx_zsfi_ari-netdt+0(4).

lx_address-valdt2+0(2) = lx_address-valdt+6(2). lx_address-valdt2+2(1) = '-'. lx_address-valdt2+3(2) = lx_address-valdt+4(2). lx_address-valdt2+5(1) = '-'. lx_address-valdt2+6(4) = lx_address-valdt+0(4). MODIFY gt_zsfi_ar1 FROM lx_zsfi_ari INDEX lv_index. ENDIF. ENDLOOP.

READ TABLE gt_itab INTO lx_itab WITH KEY bukrs = lx_address-bukrs kunnr = lx_address-kunnr. **End of change by amantena on 18-sept-2008 * Begin of change : KREVURI : FEB 05, 2009 : Incident # 11218 * Reason : Sort the output by Due Date instead of Invoice. SORT gt_zsfi_ar1 BY netdt vbeln. * End of Change: KREVURI CALL FUNCTION gv_fmname EXPORTING /1bcdwb/docparams = gx_fp_docparams p_dbdis = p_dbdis rb_wmsg = rb_wmsg gt_zsfi_address = lx_address gt_zsfi_ar_statement = gt_zsfi_ar1 docc_curr = lx_itab-waers * IMPORTING * /1BCDWB/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. ENDLOOP. CALL FUNCTION 'FP_JOB_CLOSE' * IMPORTING * E_RESULT = 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. " SUB_ADOBE_OUTPUT *&---------------------------------------------------------------------* *& Form ADDRESS_DETAILS *&---------------------------------------------------------------------* * Retrieve the Address details *----------------------------------------------------------------------* FORM address_details . DATA lx_adrnr TYPE adrnr. *Read the Address no READ TABLE gt_address_no INTO gx_address_no WITH KEY bukrs = gx_itab-bukrs BINARY SEARCH. IF sy-subrc EQ 0. *Read the address details for corresponding Address no READ TABLE gt_send_addrs INTO gx_send_addrs WITH KEY adrnr = gx_address_n o-adrnr BINARY SEARCH. IF sy-subrc EQ 0. gx_zsfi_address-anred = gx_send_addrs-anred. gx_zsfi_address-pstlz = gx_send_addrs-pstlz. gx_zsfi_address-ort01 = gx_send_addrs-ort01. gx_zsfi_address-stras = gx_send_addrs-stras. gx_zsfi_address-regio = gx_send_addrs-regio. gx_zsfi_address-teltx = gx_send_addrs-teltx. gx_zsfi_address-telx1 = gx_send_addrs-telx1. ENDIF. READ TABLE gt_remit_addrs INTO gx_remit_addrs WITH KEY sales_org = gx_add ress_no-vkorg BINARY SEARCH. IF sy-subrc EQ 0. gx_zsfi_address-address1 = gx_remit_addrs-address1. gx_zsfi_address-address2 = gx_remit_addrs-address2. gx_zsfi_address-address3 = gx_remit_addrs-address3. gx_zsfi_address-address4 = gx_remit_addrs-address4.

gx_zsfi_address-address5 = gx_remit_addrs-address5. ENDIF. * Begin of MOD - 09/23/2008 - NEMMADI gx_zsfi_address-vkorg = gx_address_no-vkorg. IF gx_address_no-vkorg EQ '0530'. SELECT SINGLE adrnr FROM t001 INTO lx_adrnr WHERE bukrs EQ '0053'. IF sy-subrc EQ 0. SELECT SINGLE fax_number FROM adrc INTO gx_zsfi_address-telx1 WHERE addrnumber EQ lx_adrnr. ENDIF. ENDIF. * End of MOD - 09/23/2008 - NEMMADI ENDIF.

ENDFORM. " ADDRESS_DETAILS *&---------------------------------------------------------------------* *& Form CURRENCY_CHANGE *&---------------------------------------------------------------------* * Move the address and total into final internal table *----------------------------------------------------------------------* FORM sub_move_head_addrs. DATA: lv_zterm TYPE dzterm, lv_text1 TYPE text1_052. * perform sub_get_currency_details. MOVE: gx_itab-name1 TO gx_zsfi_address-name1, gx_itab-name2 TO gx_zsfi_address-name2, gx_itab-name3 TO gx_zsfi_address-name3, gx_itab-name4 TO gx_zsfi_address-name4, gx_itab-pfach TO gx_zsfi_address-pfach, gx_itab-stras TO gx_zsfi_address-stras_adrs, gx_itab-pstlz TO gx_zsfi_address-pstlz_adrs, * Begin of MOD - 04.07.2008 - GGUDA * gx_itab-ort01 TO gx_zsfi_address-ort01, gx_itab-ort01 TO gx_zsfi_address-ort01_adrs, * End of MOD - 04.07.2008 - GGUDA gx_itab-ort02 TO gx_zsfi_address-ort02, gx_itab-land1 TO gx_zsfi_address-land1, gx_itab-land1 TO gx_zsfi_address-anred_adrs, gx_itab-regio TO gx_zsfi_address-regio_adrs, gx_itab-adrnr TO gx_zsfi_address-adrnr. *Modification Begins VPASULA 19Aug2011 ERDK950215 CLEAR: gx_pobox_addr. READ TABLE gt_pobox_addr INTO gx_pobox_addr WITH KEY addrnumber = gx_itab-adrnr.

IF sy-subrc EQ 0. IF NOT gx_pobox_addr-po_box IS INITIAL. CLEAR gx_zsfi_address-stras_adrs. CONCATENATE 'PO Box'(001) gx_pobox_addr-po_box INTO gx_zsfi_address-stras_adrs SEPARATED BY space. ENDIF. IF NOT gx_pobox_addr-post_code2 IS INITIAL. CLEAR gx_zsfi_address-pstlz_adrs. MOVE gx_pobox_addr-post_code2 TO gx_zsfi_address-pstlz_adrs. ENDIF. IF NOT gx_pobox_addr-po_box_loc IS INITIAL. CLEAR gx_zsfi_address-ort01_adrs. * MOVE gx_pobox_addr-po_box_loc TO gx_pobox_addr-po_box_loc. 950450 MOVE gx_pobox_addr-po_box_loc TO gx_zsfi_address-ort01_adrs. 950450 ENDIF. IF NOT gx_pobox_addr-po_box_reg IS INITIAL. CLEAR gx_zsfi_address-regio_adrs. MOVE gx_pobox_addr-po_box_reg TO gx_zsfi_address-regio_adrs. ENDIF. IF NOT gx_pobox_addr-po_box_cty IS INITIAL. CLEAR gx_zsfi_address-land1. MOVE gx_pobox_addr-po_box_cty TO gx_zsfi_address-land1. ENDIF. ENDIF. *Modification Ends VPASULA 19Aug2011 ERDK950215 MOVE gx_itab-allgstid TO gx_zsfi_address-valdt.

"ERDK "ERDK

READ TABLE gt_country_name INTO gx_country_name WITH KEY land1 = gx_itabland1 BINARY SEARCH. IF sy-subrc EQ 0. MOVE gx_country_name-landx TO gx_zsfi_address-anred. ENDIF. MOVE: gx_itab-kunnr TO gx_zsfi_address-kunnr, gx_itab-bukrs TO gx_zsfi_address-bukrs. * Begin of MOD - 09/23/2008 - NEMMADI * To print the payment terms text SELECT SINGLE zterm FROM knvv INTO lv_zterm WHERE kunnr EQ gx_itab-kunnr AND vkorg EQ gx_zsfi_address-vkorg. IF sy-subrc EQ 0. SELECT SINGLE text1 FROM t052u INTO lv_text1 WHERE spras EQ sy-langu AND zterm EQ lv_zterm. IF sy-subrc EQ 0. MOVE: lv_text1 TO gx_zsfi_address-text1.

ENDIF. ENDIF. * End of MOD - 09/23/2008 - NEMMADI ENDFORM. " CURRENCY_CHANGE *&---------------------------------------------------------------------* *& Form SUB_GET_CURRENCY_DETAILS *&---------------------------------------------------------------------* * Check the Currency Key *----------------------------------------------------------------------* FORM sub_get_currency_details . gv_count = 2. READ TABLE gt_currency_key INTO gx_currency_key WITH KEY currkey = gv_sav_w aers BINARY SEARCH. IF sy-subrc = 0. gv_count = gx_currency_key-currdec. IF gv_count = 0. MOVE gv_subtot1 TO gx_zsfi_ar-stceg. MOVE gv_subtot2 TO gx_zsfi_ar-stceg_t001. MOVE gv_subtot3 TO gx_zsfi_ar-inco1_bez. MOVE gv_subtot4 TO gx_zsfi_ar-vsbed_bez. ELSEIF gv_count = 3. MOVE gv_subtot1 TO gx_zsfi_ar-stceg. MOVE gv_subtot2 TO gx_zsfi_ar-stceg_t001. MOVE gv_subtot3 TO gx_zsfi_ar-inco1_bez. MOVE gv_subtot4 TO gx_zsfi_ar-vsbed_bez. ENDIF. ELSE. MOVE gv_subtot1 TO gx_zsfi_ar-stceg. MOVE gv_subtot2 TO gx_zsfi_ar-stceg_t001. MOVE gv_subtot3 TO gx_zsfi_ar-inco1_bez. MOVE gv_subtot4 TO gx_zsfi_ar-vsbed_bez. ENDIF. CLEAR: gv_subtot1, gv_subtot2, gv_subtot3, gv_subtot4. ENDFORM. " SUB_GET_CURRENCY_DETAILS *&---------------------------------------------------------------------* *& Form MOVE_MAIN_ZSFI_AR *&---------------------------------------------------------------------* * Move the Item details to Final Internal table *----------------------------------------------------------------------* FORM move_main_zsfi_ar .

MOVE: gx_itab-kunnr TO gx_zsfi_ar-kunnr, gx_itab-bukrs TO gx_zsfi_ar-bukrs, gx_itab-vbeln TO gx_zsfi_ar-vbeln, gx_itab-bstnk TO gx_zsfi_ar-bstnk. MOVE gx_itab-netdt TO gx_zsfi_ar-netdt. "lv_date1 MM/DD/YYYY. MOVE gx_itab-bldat TO gx_zsfi_ar-bldat. "lv_date2 MM/DD/YYYY.

* Based upon the number of days PAST_DUE, add dollars to specific col. IF gx_itab-past_due LE 0. "OR * gx_itab-past_due GE -30. gv_subtot1 = gv_subtot1 + gx_itab-wrbtr. ELSEIF gx_itab-past_due LE 30. "OR * gx_itab-past_due GE -60. gv_subtot2 = gv_subtot2 + gx_itab-wrbtr. ELSEIF gx_itab-past_due LE 60. "OR * gx_itab-past_due GE -90. gv_subtot3 = gv_subtot3 + gx_itab-wrbtr. ELSE. gv_subtot4 = gv_subtot4 + gx_itab-wrbtr. ENDIF.

ENDFORM.

" MOVE_MAIN_ZSFI_AR