Skip to Content
avatar image
Former Member

deleting PO items using BAPI_PO_CHANGE

Dear experts.

I have a problem while deleting po items using FM BAPI_PO_CHANGE. The deletion indicator is not getting updated in table EKPO even after using FM BAPI_TRANSACTION_COMMIT. But this program worked for changing delivery date in table EKET.

Also, please let me know

1) Whether I can delete all PO items by setting deletion indicator in PO header.

2) What are the parameters to be passed for deleting individual items and for deleting po as whole?

3) What is the value to be passed for the delete ind in EKKO & EKPO. Is it 'X' or 'L'?

Regards

Sathar

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Nov 12, 2007 at 10:50 AM

    Hi Sathar,

    You Can use this FM for Deleting PO "BBP_PO_DELETE"

    Here You can Specify PO Number and List of Item Numbers to be deleted as well.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 13, 2007 at 07:26 AM

    Hi,

    You can try this option:

    IF NOT poitem-delete_ind IS INITIAL. "delete ind marked.

    *For item deletion to work properly

    *indicator should be 'D'. webmethods passes indicator 'X'.

    poitem-delete_ind = 'D'.

    CLEAR poitem-final_inv.

    MODIFY poitem.

    READ TABLE poitemx WITH KEY po_item = poitem-po_item.

    IF sy-subrc = 0.

    poitemx-final_inv = c_checked. "X

    MODIFY poitemx INDEX sy-tabix.

    ENDIF.

    else.

    ENDIF.

    cheers

    Aveek

    FUNCTION Z_BC1_BAPI_PO_CHANGE02.

    *"----


    ""Local Interface:

    *" IMPORTING

    *" VALUE(PURCHASEORDER) TYPE BAPIMEPOHEADER-PO_NUMBER

    *" VALUE(POADDRVENDOR) TYPE BAPIMEPOADDRVENDOR

    *" VALUE(TESTRUN) TYPE BAPIFLAG-BAPIFLAG

    *" VALUE(MEMORY_UNCOMPLETE) TYPE BAPIFLAG-BAPIFLAG

    *" VALUE(MEMORY_COMPLETE) TYPE BAPIFLAG-BAPIFLAG

    *" VALUE(POEXPIMPHEADER) TYPE BAPIEIKP

    *" VALUE(POEXPIMPHEADERX) TYPE BAPIEIKPX

    *" VALUE(VERSIONS) TYPE BAPIMEDCM

    *" VALUE(NO_MESSAGING) TYPE BAPIFLAG-BAPIFLAG

    *" VALUE(NO_MESSAGE_REQ) TYPE BAPIFLAG-BAPIFLAG

    *" VALUE(NO_AUTHORITY) TYPE BAPIFLAG-BAPIFLAG

    *" VALUE(NO_PRICE_FROM_PO) TYPE BAPIFLAG-BAPIFLAG

    *" EXPORTING

    *" VALUE(EXPHEADER) TYPE BAPIMEPOHEADER

    *" VALUE(EXPPOEXPIMPHEADER) TYPE BAPIEIKPX

    *" TABLES

    *" RETURN STRUCTURE BAPIRET2

    *" POITEM STRUCTURE BAPIMEPOITEM

    *" POITEMX STRUCTURE BAPIMEPOITEMX

    *" POADDRDELIVERY STRUCTURE BAPIMEPOADDRDELIVERY

    *" POSCHEDULE STRUCTURE BAPIMEPOSCHEDULE

    *" POSCHEDULEX STRUCTURE BAPIMEPOSCHEDULX

    *" POACCOUNT STRUCTURE BAPIMEPOACCOUNT

    *" POACCOUNTPROFITSEGMENT STRUCTURE BAPIMEPOACCOUNTPROFITSEGMENT

    *" POACCOUNTX STRUCTURE BAPIMEPOACCOUNTX

    *" POCONDHEADER STRUCTURE BAPIMEPOCONDHEADER

    *" POCONDHEADERX STRUCTURE BAPIMEPOCONDHEADERX

    *" POCOND STRUCTURE BAPIMEPOCOND

    *" POCONDX STRUCTURE BAPIMEPOCONDX

    *" POLIMITS STRUCTURE BAPIESUHC

    *" POCONTRACTLIMITS STRUCTURE BAPIESUCC

    *" POSERVICES STRUCTURE BAPIESLLC

    *" POSRVACCESSVALUES STRUCTURE BAPIESKLC

    *" POSERVICESTEXT STRUCTURE BAPIESLLTX

    *" EXTENSIONIN STRUCTURE BAPIPAREX

    *" EXTENSIONOUT STRUCTURE BAPIPAREX

    *" POEXPIMPITEM STRUCTURE BAPIEIPO

    *" POEXPIMPITEMX STRUCTURE BAPIEIPOX

    *" POTEXTHEADER STRUCTURE BAPIMEPOTEXTHEADER

    *" POTEXTITEM STRUCTURE BAPIMEPOTEXT

    *" ALLVERSIONS STRUCTURE BAPIMEDCM_ALLVERSIONS

    *" POPARTNER STRUCTURE BAPIEKKOP

    *" POCOMPONENTS STRUCTURE BAPIMEPOCOMPONENT

    *" POCOMPONENTSX STRUCTURE BAPIMEPOCOMPONENTX

    *" POSHIPPING STRUCTURE BAPIITEMSHIP

    *" POSHIPPINGX STRUCTURE BAPIITEMSHIPX

    *" POSHIPPINGEXP STRUCTURE BAPIMEPOSHIPPEXP

    *" POHISTORY STRUCTURE BAPIEKBE

    *" POHISTORY_TOTALS STRUCTURE BAPIEKBES

    *" POCONFIRMATION STRUCTURE BAPIEKES

    *" NFMETALLITMS STRUCTURE /NFM/BAPIDOCITM

    *" CHANGING

    *" VALUE(POHEADER) TYPE BAPIMEPOHEADER

    *" VALUE(POHEADERX) TYPE BAPIMEPOHEADERX

    *"----


    ************************************************************************

    • PROGRAM Z_BC1_BAPI_PO_CHANGE

    • TITLE Function module to Change PO using BAPI

    • AUTHOR Aveek Ghose

    • DATE WRITTEN 24.05.2006

    • R/3 RELEASE 4.6C

    *----


    • COPIED FROM N/A

    *

    • This function module is called during PO change in Ariba.

    • The call to this function module is from WebMethods. The function

    • module performs custom validations on data provided from Ariba and

    • then calls BAPI_PO_CHANGE. The error messages are returned to Ariba.

    *

    *----


    • PROGRAM TYPE Function module

    • DEV. CLASS ZP2P

    • LOGICAL DB N/A

    *----


    • SCREENS N/A

    • GUl TITLE N/A

    • GUl STATUS N/A

    • TRANSACTIONS N/A

    • USER EXITS N/A

    *----


    *----


    ----


    • DB-Tables

    ----


    TABLES: ekkn, "Account Assignment in Purchasing Document

    ekbe. "History per Purchasing Document

    • zconstants_new. "Constants for various interfaces

    • & programs with comp code

    ----


    • Global variables

    ----


    DATA: g_cnt_poaccount TYPE i, "No. of records in POACCOUNT

    g_cnt_ekkn TYPE i, "No. of records in EKKN

    g_msgv1 LIKE sy-msgv1. "Message variable1

    ----


    • Internal Tables

    ----


    DATA: g_t_poaccount_tmp LIKE poaccount OCCURS 0 WITH HEADER LINE,

    g_t_poaccount1 LIKE poaccount OCCURS 0 WITH HEADER LINE,

    g_t_poaccountx1 LIKE poaccountx OCCURS 0 WITH HEADER LINE,

    g_t_poaccount LIKE poaccount OCCURS 0 WITH HEADER LINE,

    *PVU-20-May-2004 - Changes for SCR1

    g_t_itemx_tmp LIKE poitemx OCCURS 0 WITH HEADER LINE,

    g_t_schdx_tmp LIKE poschedulex OCCURS 0 WITH HEADER LINE,

    g_t_accntx_tmp LIKE poaccountx OCCURS 0 WITH HEADER LINE,

    g_t_condx_tmp LIKE pocondx OCCURS 0 WITH HEADER LINE.

    • T_Zconstants LIKE ZCONSTANTS_NEW OCCURS 0 WITH HEADER LINE.

    *RD1K911982

    *PVU-20-May-2004 - End Changes for SCR1

    ----


    • Structure

    ----


    DATA: g_w_hdrx_tmp LIKE poheaderx. "PVU-20-May-2004 - Changes for SCR1

    • DATA: p_constname TYPE zconstname, "Constant Name

    • g_constval TYPE zconstval, "Constant Value

    • c_po_ehub_var LIKE ZCONSTANTS_NEW-CONSTname value 'EHUB_POS%'.

    DATA : L_CONST_NAME LIKE SY-MSGV1, "Constant name

    L_COMP_CODE LIKE SY-MSGV2. "Company code

    DATA: L_WA_TIMESTAMP TYPE ZP2P_TIMESTAMP.

    data: l_waers type waers.

    DATA: L_EKORG TYPE EKORG.

    DATA: L_SERIAL TYPE I.

    DATA : L_VEND_ACTGRP(30) TYPE C, "Vendor Account Group

    L_VEND_PAYTRM(30) TYPE C, "Vendor Payment Terms

    L_VEND_RECON(30) TYPE C, "Vendor Reconciliation Account

    L_MSGV1 LIKE SY-MSGV1, "Message variable1

    L_WBS_EXTERNAL LIKE BAPIMEPOACCOUNT-WBS_ELEMENT,

    "WBS external format

    L_WBS_INTERNAL LIKE BAPIMEPOACCOUNT-WBS_ELEMENT,

    L_bukrs type bukrs.

    • Ranges :r_ehub_pos for t_zconstants-constvalu.

    • Begin of Change SVALIDET(RD1K911990)

  • SELECT *

  • FROM zconstants_new

  • INTO TABLE t_zconstants

  • WHERE constname LIKE c_po_ehub_var. " EHUB_POS%

  • *

    • IF sy-subrc = 0.

    • SORT t_zconstants BY constvalu ASCENDING.

    • DELETE ADJACENT DUPLICATES FROM t_zconstants

    • COMPARING constvalu.

    • LOOP AT t_zconstants.

    • r_ehub_pos-sign = 'I'.

    • r_ehub_pos-option = 'EQ'.

    • r_ehub_pos-low = t_zconstants-constvalu.

    • APPEND r_ehub_pos.

    • CLEAR: r_ehub_pos,

    • t_zconstants.

    • ENDLOOP.

    • ENDIF.

    **End of Change SVALIDET(RD1K911990)

    *

      • Srini 18-May-2005 Start of changes

      • Developer Flexibility to debug issues

    • p_constname = 'BAPI_PO_CHANGE2'.

    • *

      • do.

      • CALL FUNCTION 'ZXA_GET_CONSTANT'

      • EXPORTING

      • const_name = p_constname

      • comp_code =

    • IMPORTING

    • const_value = g_constval

    • EXCEPTIONS

    • no_value_found = 1

    • null_value = 2

    • OTHERS = 3.

    • if g_constval NE 'X'.

    • exit.

    • endif.

    • enddo.

    • *Begin of comment RD1Kk911990

      • IF PURCHASEORDER+0(3) EQ '099' AND POHEADER-DOC_TYPE EQ 'ZEHS'.

      • POHEADER-DOC_TYPE = 'ZEH'.

      • ENDIF.

      *End of comment RD1K911990

      **********************************************************

      *mod-003

      **********************************************************

        • if not poheader-comp_code is initial.

      • if poheader-comp_code is initial.

      • clear: l_bukrs.

      • select single companycode

      • into l_bukrs

      • from zcompanycodes01

        • where companycode = poheader-comp_code and

      • where FSID = poheader-fsid and

      • le = poheader-le and

      • frmrc = poheader-frmrc.

      • *

        • if sy-subrc ne 0.

        • CLEAR L_MSGV1.

        • L_MSGV1 = POHEADER-DOC_TYPE.

        • Please Enter an Account number for line

      • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

      • EXPORTING

      • TYPE = C_MSGTYPE_E

      • CL = C_MSGID_Z001

      • NUMBER = C_MSGNR_618

      • PAR1 = L_MSGV1

      • IMPORTING

      • RETURN = RETURN.

      • *

        • APPEND RETURN.

        • CLEAR RETURN.

        • else.

        • poheader-comp_code = l_bukrs.

        • endif.

        • endif.

        **********************************************************

        *mod-003

        **********************************************************

        • IF POHEADER-DOC_TYPE EQ 'ZEHS'.

        • POHEADER-DOC_TYPE = 'ZEH'.

        • ENDIF.

        • SORT poaccount BY po_item serial_no.

        *Clear internal tables and global variables

        REFRESH: g_t_poaccount_tmp,

        g_t_poaccount1,

        g_t_poaccountx1,

        g_t_poaccount,

        return,

        • g_t_idoc_data,

        g_t_itemx_tmp,

        g_t_schdx_tmp,

        g_t_accntx_tmp,

        g_t_condx_tmp.

        CLEAR: g_cnt_poaccount,

        g_cnt_ekkn,

        g_msgv1.

        • g_distr_perc,

        • g_distr_perc1,

        • g_adjust_perc,

        • g_idoc_no,

        • g_w_hdrx_tmp.

        IF poheader-po_number+0(1) = 'C'.

        poheader-doc_type = 'ZAC'.

        ENDIF.

        IF poheader-po_number+0(1) = 'P'.

        poheader-doc_type = 'ZAP'.

        ENDIF.

        IF poheader-po_number IS INITIAL.

        poheader-doc_type = 'ZAPS'.

        ENDIF.

        IF purchaseorder(3) <> c_pco.

        g_t_poaccount[] = poaccount[].

        • To retrieve the line items with blank GL Account Number

        • PERFORM filter_items TABLES g_t_poaccount.

        LOOP AT g_t_poaccount.

        CLEAR g_msgv1.

        g_msgv1 = g_t_poaccount-po_item.

        • Please Enter an Account number for line

        CALL FUNCTION 'BALW_BAPIRETURN_GET2'

        EXPORTING

        type = c_msgtype_e "E

        cl = c_msgid_z001 "Z001

        number = c_msgnr_037 "037

        par1 = g_msgv1

        IMPORTING

        return = return.

        APPEND return.

        CLEAR return.

        loop at return.

        l_wa_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

        l_wa_ZERRORS-serial_no = sy-tabix.

        l_wa_ZERRORS-COMP_CODE = poheader-comp_code.

        l_wa_ZERRORS-zid = return-id.

        l_wa_ZERRORS-znumber = return-number.

        l_wa_ZERRORS-BEACON_DOC_NO = poheader-po_number.

        l_wa_ZERRORS-SRC_DOC_NO = poheader-po_number.

        l_wa_ZERRORS-ZDATE = sy-datum.

        l_wa_ZERRORS-ERR_MSG = return-message.

        append l_wa_ZERRORS to t_errors.

        • insert into ZP2P_ERRORS values l_wa_ZP2P_ERRORS.

        clear: L_WA_ZERRORS.

        endloop.

        CLEAR g_msgv1.

        ENDLOOP.

        SORT return BY type.

        • On Error, exit the function module

        READ TABLE return

        WITH KEY type = c_msgtype_e "E

        BINARY SEARCH.

        IF sy-subrc EQ 0.

        EXIT.

        ENDIF.

        ***Begin of Change - BVIJAYA 01-July-2004 TPR-2239

        • If line item is marked for deletion, Clear the final_inv indicator,

        • so that the condition value[conditions tab(po header)] reflects the

        • correct gross price for the remaining items.

        SORT poitem BY po_item.

        SORT poitemx BY po_item.

        LOOP AT poitem.

        IF NOT poitem-delete_ind IS INITIAL. "delete ind marked.

        • sraman2 07/17/04

        *For item deletion to work properly

        *indicator should be 'D'. webmethods passes indicator 'X'.

        poitem-delete_ind = 'D'.

        • sraman2 07/17/04

        CLEAR poitem-final_inv.

        MODIFY poitem.

        READ TABLE poitemx WITH KEY po_item = poitem-po_item.

        IF sy-subrc = 0.

        poitemx-final_inv = c_checked. "X

        MODIFY poitemx INDEX sy-tabix.

        ENDIF.

        else.

        ENDIF.

        ENDLOOP.

        endif.

        ****************************************************

        *mod-003

        ****************************************************

        DATA: L_TABIX TYPE SY-TABIX.

        LOOP AT POITEM.

        TBX = SY-TABIX.

        l_wa_timestamp-mandt = SY-MANDT.

        l_wa_timestamp-EBELN = POHEADER-PO_NUMBER.

        l_wa_timestamp-EBELP = POITEM-PO_ITEM.

        l_wa_timestamp-CHANGE_IND = ' '.

        l_wa_timestamp-DATE_TIME_STMP = POITEM-ARIBACRTTIMESTMP.

        insert into ZP2P_TIMESTAMP values l_wa_timestamp.

        clear: poheader-ARIBACRTTIMESTMP,

        poheader-ARIBACHGTIMESTMP.

        IF NOT POITEM-DISTRIB IS INITIAL.

        CLEAR : L_CONST_NAME,

        L_COMP_CODE.

        READ TABLE POACCOUNT INDEX L_TABIX.

        IF SY-SUBRC EQ 0.

        L_CONST_NAME = POACCOUNT-GL_ACCOUNT.

        L_COMP_CODE = L_comp_code.

        CALL FUNCTION 'BALW_BAPIRETURN_GET2'

        EXPORTING

        type = c_msgtype_e "E

        cl = c_msgid_z001

        number = c_msgnr_613

        PAR1 = L_CONST_NAME

        PAR2 = L_COMP_CODE

        IMPORTING

        return = t_yreturn.

        APPEND t_yreturn.

        CLEAR t_yreturn.

        loop at t_yreturn.

        L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

        L_WA_ZERRORS-serial_no = sy-tabix.

        L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

        L_WA_ZERRORS-zid = t_yreturn-id.

        L_WA_ZERRORS-znumber = t_yreturn-number.

        L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

        L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

        L_WA_ZERRORS-ZDATE = sy-datum.

        L_WA_ZERRORS-ERR_MSG = t_yreturn-message.

        append L_WA_ZERRORS to t_errors.

        • insert into ZP2P_ERRORS values L_WA_ZERRORS.

        clear: L_WA_ZERRORS.

        endloop.

        ENDIF.

        ENDIF.

        ENDLOOP.

        if not poheader-currency is initial.

        if not poheader-vendor is initial.

        loop at pocond.

        SELECT SINGLE WAERS

        INTO L_WAERS

        FROM LFM1 WHERE

        LIFNR = POHEADER-VENDOR

        AND EKORG = POHEADER-PURCH_ORG.

        IF SY-SUBRC NE 0.

        IF L_WAERS NE poheader-currency.

        pocond-cond_value = 'PBXX'.

        pocond-currency = l_waers.

        modify pocond transporting cond_value currency.

        endif.

        ENDIF.

        endloop.

        ENDIF.

        ENDIF.

        IF NOT TESTRUN IS INITIAL.

        POHEADER-VENDOR = '4259999999'.

        poheader-doc_type = 'ZAPS'.

        ENDIF.

        • IF NOT POHEADER-PURCH_ORG IS INITIAL.

        • IF POHEADER-PURCH_ORG IS INITIAL.

        • SELECT SINGLE PUR_ORG

        • INTO L_EKORG

        • FROM ZPUR_ORG

        • WHERE LE = POHEADER-LE AND

        • FRMRC = POHEADER-FRMRC AND

        • FSID = POHEADER-FSID.

        *

        • IF SY-SUBRC NE 0.

        • CLEAR : L_CONST_NAME,

        • L_COMP_CODE.

        *

        • L_CONST_NAME = C_p2p_pur_ORG.

        • L_COMP_CODE = POHEADER-COMP_CODE.

        *

        • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

        • EXPORTING

        • TYPE = c_msgtype_e

        • CL = c_msgid_z001

        • NUMBER = c_msgnr_619

        • PAR1 = L_CONST_NAME

        • PAR2 = L_COMP_CODE

        • IMPORTING

        • RETURN = RETURN.

        *

        • APPEND RETURN.

        • CLEAR RETURN.

        *

        • loop at t_yreturn.

        • L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

        • L_WA_ZERRORS-serial_no = sy-tabix.

        • L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

        • L_WA_ZERRORS-zid = t_yreturn-id.

        • L_WA_ZERRORS-znumber = t_yreturn-number.

        • L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

        • L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

        • L_WA_ZERRORS-ZDATE = sy-datum.

        • L_WA_ZERRORS-ERR_MSG = t_yreturn-message.

        • append L_WA_ZERRORS to t_errors.

        • insert into ZP2P_ERRORS values L_WA_ZERRORS.

        • clear: L_WA_ZERRORS.

        • endloop.

        • EXIT.

        • ELSE.

        • POHEADER-PURCH_ORG = L_EKORG.

        • ENDIF.

        • ENDIF.

        • IF NOT POHEADER-PUR_GROUP IS INITIAL.

        • IF POHEADER-PUR_GROUP IS INITIAL.

        • clear: g_constval.

        • CALL FUNCTION 'ZXA_GET_CONSTANT'

        • EXPORTING

        • const_name = c_p2p_pur_org

        • comp_code = POHEADER-COMP_CODE

        • IMPORTING

        • const_value = g_constval

        • EXCEPTIONS

        • no_value_found = 1

        • null_value = 2

        • OTHERS = 3.

        *

        *

        • IF SY-SUBRC NE 0.

        • CLEAR : L_CONST_NAME,

        • L_COMP_CODE.

        *

        • L_CONST_NAME = C_p2p_pur_org.

        • L_COMP_CODE = POHEADER-COMP_CODE.

        *

        • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

        • EXPORTING

        • TYPE = c_msgtype_e

        • CL = c_msgid_z001

        • NUMBER = c_msgnr_046

        • PAR1 = L_CONST_NAME

        • PAR2 = L_COMP_CODE

        • IMPORTING

        • RETURN = RETURN.

        *

        • APPEND RETURN.

        • CLEAR RETURN.

        *

        • loop at t_yreturn.

        • L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

        • L_WA_ZERRORS-serial_no = sy-tabix.

        • L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

        • L_WA_ZERRORS-zid = t_yreturn-id.

        • L_WA_ZERRORS-znumber = t_yreturn-number.

        • L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

        • L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

        • L_WA_ZERRORS-ZDATE = sy-datum.

        • L_WA_ZERRORS-ERR_MSG = t_yreturn-message.

        • append L_WA_ZERRORS to t_errors.

        • insert into ZP2P_ERRORS values L_WA_ZERRORS.

      • clear: L_WA_ZERRORS.

      • endloop.

      • EXIT.

      • ELSE.

      • POHEADER-PUR_GROUP = G_CONSTVAL.

      • ENDIF.

      • ENDIF.

      • *

        • data: l_werks1 type werks_d.

        • LOOP AT poitem.

        • if poitem-plant is initial.

        • clear: l_werks1.

        • select single plant

        • into l_werks1

        • from zpo_plantmapping

        • where COMPANY_CODE = poheader-comp_code and

        • PUR_ORG = poheader-purch_org and

        • PUR_GROUP = poheader-pur_group and

        • LE = poheader-le and

        • FSID = poheader-fsid and

        • FRMRC = poheader-frmrc.

        • if sy-subrc ne 0.

        • PERFORM ERROR_HANDLING_PLANT USING POHEADER

        • poheader-comp_code

        • L_WA_ZERRORS.

        • EXIT.

        • else.

        • poitem-plant = l_werks1.

        • CLEAR: L_WERKS1.

        • endif.

        • endif.

        • IF POITEM-NET_PRICE NE POHEADER-CURRENCY.

        • POITEM-NET_PRICE = POHEADER-CURRENCY.

        • ENDIF.

        *

        • IF POITEM-net_price NE 0.

        • POITEM-IR_IND = 'X'.

        • ENDIF.

        *

        • POITEM-UNLIMITED_DLV = 'X'.

        • POITEM-UNDER_DLV_TOL = 0.

        • clear: poitem-ARIBACRTTIMESTMP,

        • poitem-ARIBAUPDTIMESTMP.

        *

        • MODIFY POITEM TRANSPORTING UNLIMITED_DLV

        • UNDER_DLV_TOL

        • PLANT

        • IR_IND

        • ARIBACRTTIMESTMP

        • ARIBAUPDTIMESTMP.

        *

        *

        • ENDLOOP.

        **********************************************************

        *mod-003

        ***********************************************************

        if not poheader-currency is initial.

        if not poheader-vendor is initial.

        loop at pocond.

        SELECT SINGLE WAERS

        INTO L_WAERS

        FROM LFM1 WHERE

        LIFNR = POHEADER-VENDOR

        AND EKORG = POHEADER-PURCH_ORG.

        IF SY-SUBRC NE 0.

        IF L_WAERS NE poheader-currency.

        pocond-cond_value = 'PBXX'.

        pocond-currency = l_waers.

        modify pocond transporting cond_value currency.

        endif.

        ENDIF.

        endloop.

        ENDIF.

        ENDIF.

        IF NOT TESTRUN IS INITIAL.

        POHEADER-VENDOR = '4259999999'.

        poheader-doc_type = 'ZAPS'.

        ENDIF.

        • IF NOT POHEADER-PURCH_ORG IS INITIAL.

        • IF POHEADER-PURCH_ORG IS INITIAL.

        • SELECT SINGLE PUR_ORG

        • INTO L_EKORG

        • FROM ZPUR_ORG

        • WHERE LE = POHEADER-LE AND

        • FRMRC = POHEADER-FRMRC AND

        • FSID = POHEADER-FSID.

        *

        • IF SY-SUBRC NE 0.

        • CLEAR : L_CONST_NAME,

        • L_COMP_CODE.

        *

        • L_CONST_NAME = C_p2p_pur_ORG.

        • L_COMP_CODE = POHEADER-COMP_CODE.

        *

        • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

        • EXPORTING

        • TYPE = c_msgtype_e

        • CL = c_msgid_z001

        • NUMBER = c_msgnr_619

        • PAR1 = L_CONST_NAME

        • PAR2 = L_COMP_CODE

        • IMPORTING

        • RETURN = RETURN.

        *

        • APPEND RETURN.

        • CLEAR RETURN.

        *

        • loop at t_yreturn.

        • L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

        • L_WA_ZERRORS-serial_no = sy-tabix.

        • L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

        • L_WA_ZERRORS-zid = t_yreturn-id.

        • L_WA_ZERRORS-znumber = t_yreturn-number.

        • L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

        • L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

        • L_WA_ZERRORS-ZDATE = sy-datum.

        • L_WA_ZERRORS-ERR_MSG = t_yreturn-message.

        • append L_WA_ZERRORS to t_errors.

        • insert into ZP2P_ERRORS values L_WA_ZERRORS.

      • clear: L_WA_ZERRORS.

      • endloop.

      • EXIT.

      • ELSE.

      • POHEADER-PURCH_ORG = L_EKORG.

      • ENDIF.

      • ENDIF.

      • *

          • IF NOT POHEADER-PUR_GROUP IS INITIAL.

        • IF POHEADER-PUR_GROUP IS INITIAL.

        • clear: g_constval.

        • CALL FUNCTION 'ZXA_GET_CONSTANT'

        • EXPORTING

        • const_name = c_p2p_pur_org

        • comp_code = POHEADER-COMP_CODE

        • IMPORTING

        • const_value = g_constval

        • EXCEPTIONS

        • no_value_found = 1

        • null_value = 2

        • OTHERS = 3.

        • *

          *

          • IF SY-SUBRC NE 0.

          • CLEAR : L_CONST_NAME,

          • L_COMP_CODE.

          *

          • L_CONST_NAME = C_p2p_pur_org.

          • L_COMP_CODE = POHEADER-COMP_CODE.

          *

          • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

          • EXPORTING

          • TYPE = c_msgtype_e

          • CL = c_msgid_z001

          • NUMBER = c_msgnr_046

          • PAR1 = L_CONST_NAME

          • PAR2 = L_COMP_CODE

          • IMPORTING

          • RETURN = RETURN.

          *

          • APPEND RETURN.

          • CLEAR RETURN.

          *

          • loop at return.

          • L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

          • L_WA_ZERRORS-serial_no = sy-tabix.

          • L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

          • L_WA_ZERRORS-zid = return-id.

          • L_WA_ZERRORS-znumber = return-number.

          • L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

          • L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

          • L_WA_ZERRORS-ZDATE = sy-datum.

          • L_WA_ZERRORS-ERR_MSG = return-message.

          • append L_WA_ZERRORS to t_errors.

          • insert into ZP2P_ERRORS values L_WA_ZERRORS.

        • clear: L_WA_ZERRORS.

        • endloop.

        • EXIT.

        • ELSE.

        • POHEADER-PUR_GROUP = G_CONSTVAL.

        • ENDIF.

        • ENDIF.

        • **********************************************************

          *mod-003

          ***********************************************************

          *-- Retrieve Account Assignment

          PERFORM get_account_assignment TABLES poitem

          poitemx

          poaccount

          poaccountx

          t_yreturn

          USING poheader-comp_code

          poheader.

          ****************************************************

          *mod-003

          ****************************************************

          IF NOT t_yreturn[] IS INITIAL.

          APPEND LINES OF t_yreturn TO RETURN.

          loop at return.

          L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

          L_WA_ZERRORS-serial_no = sy-tabix.

          L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

          L_WA_ZERRORS-zid = return-id.

          L_WA_ZERRORS-znumber = return-number.

          L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

          L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

          L_WA_ZERRORS-ZDATE = sy-datum.

          L_WA_ZERRORS-ERR_MSG = return-message.

          append L_WA_ZERRORS to t_errors.

          clear: L_WA_ZERRORS.

          endloop.

          SELECT max( serial_no )

          INTO L_SERIAL

          FROM ZP2P_ERRORS.

          LOOP AT T_ERRORS.

          L_SERIAL = L_SERIAL + 1.

          T_ERRORS-serial_no = L_SERIAL.

          MODIFY T_ERRORS TRANSPORTING serial_no.

          ENDLOOP.

          INSERT ZP2P_ERRORS FROM TABLE T_ERRORS.

          ENDIF.

          READ TABLE t_yreturn WITH KEY type = 'E'.

          IF sy-subrc = 0.

          EXIT.

          ENDIF.

          *For Non-PCO Orders, do not update the GR and IR Indicator if the

          *indicator passed in the current run is same as in PO.

          SORT poitem BY po_item.

          SORT poitemx BY po_item.

          LOOP AT poitem.

          SELECT SINGLE wepos "Goods receipt indicator

          repos "Invoice receipt indicator

          INTO (ekpo-wepos, ekpo-repos)

          FROM ekpo

          WHERE ebeln = purchaseorder AND

          ebelp = poitem-po_item.

          IF sy-subrc EQ 0.

          IF ekpo-wepos EQ poitem-gr_ind.

          READ TABLE poitemx

          WITH KEY po_item = poitem-po_item

          BINARY SEARCH.

          IF sy-subrc EQ 0.

          CLEAR poitemx-gr_ind.

          MODIFY poitemx INDEX sy-tabix.

          ENDIF.

          ENDIF.

          IF ekpo-repos EQ poitem-ir_ind.

          READ TABLE poitemx

          WITH KEY po_item = poitem-po_item

          BINARY SEARCH.

          IF sy-subrc EQ 0.

          CLEAR poitemx-ir_ind.

          MODIFY poitemx INDEX sy-tabix.

          ENDIF.

          ENDIF.

          ENDIF.

          ENDLOOP.

          *Logic for addition, deletion and change of records in

          *account assignment

          LOOP AT poaccount.

          CLEAR g_t_poaccount_tmp.

          MOVE-CORRESPONDING poaccount TO g_t_poaccount_tmp.

          APPEND g_t_poaccount_tmp.

          ADD 1 TO g_cnt_poaccount.

          AT END OF po_item.

          SORT g_t_poaccount_tmp.

          • For single account assignment, if the goods receipt is not posted,

          • set the non-valuated indicator to blank.

          IF g_cnt_poaccount EQ 1.

          SELECT belnr "History per Purchasing Document

          INTO ekbe-belnr

          FROM ekbe

          UP TO 1 ROWS

          WHERE ebeln = purchaseorder AND

          ebelp = g_t_poaccount_tmp-po_item AND

          vgabe = 1.

          ENDSELECT.

          IF sy-subrc NE 0.

          *PVU-08-May-2004 - Set the no valuated GR indicator to blank in POITEM

          READ TABLE poitem

          WITH KEY po_item = g_t_poaccount_tmp-po_item

          BINARY SEARCH.

          IF sy-subrc EQ 0.

          CLEAR poitem-gr_non_val .

          MODIFY poitem INDEX sy-tabix.

          ENDIF.

          *PVU-08-May-2004 - End of Set the no valuated GR indicator to blank

          READ TABLE poitemx

          WITH KEY po_item = g_t_poaccount_tmp-po_item

          BINARY SEARCH.

          IF sy-subrc EQ 0.

          poitemx-gr_non_val = c_checked.

          MODIFY poitemx INDEX sy-tabix.

          ENDIF.

          ENDIF.

          ENDIF.

          CLEAR: ekkn.

          SELECT * FROM ekkn

          WHERE ebeln = purchaseorder AND

          ebelp = poaccount-po_item

          ORDER BY zekkn.

          ADD 1 TO g_cnt_ekkn.

          **BV-12-July-2004- Begin of change - split line accounting

          *clear the headerline before data population

          CLEAR : g_t_poaccount1,

          g_t_poaccountx1.

          **BV-12-July-2004- End of change - split line accounting

          READ TABLE g_t_poaccount_tmp INDEX g_cnt_ekkn.

          IF sy-subrc EQ 0.

          g_t_poaccount1-po_item = g_t_poaccount_tmp-po_item.

          g_t_poaccount1-serial_no = ekkn-zekkn.

          g_t_poaccount1-quantity = g_t_poaccount_tmp-quantity.

          g_t_poaccount1-gl_account = g_t_poaccount_tmp-gl_account.

          READ TABLE poitem

          WITH KEY po_item = poaccount-po_item. "dd

          *PVU-11-May-2004-Set cost center or WBS element depending on acc.assgn.

          IF poitem-acctasscat = c_costcenter. "K

          g_t_poaccount1-costcenter = g_t_poaccount_tmp-costcenter .

          ELSEIF poitem-acctasscat = c_wbs. "P

          g_t_poaccount1-wbs_element = g_t_poaccount_tmp-wbs_element.

          ENDIF.

          *PVU-11-May-2004-End of set cost center or WBS element.

          g_t_poaccount1-orderid = g_t_poaccount_tmp-orderid.

          g_t_poaccount1-distr_perc = g_t_poaccount_tmp-distr_perc.

          APPEND g_t_poaccount1.

          g_t_poaccountx1-po_item = g_t_poaccount_tmp-po_item.

          g_t_poaccountx1-serial_no = ekkn-zekkn.

          g_t_poaccountx1-po_itemx = c_checked.

          g_t_poaccountx1-quantity = c_checked.

          g_t_poaccountx1-gl_account = c_checked.

          *PVU-11-May-2004-Set cost center or WBS element depending on acc.assgn.

          IF poitem-acctasscat = c_costcenter. "K

          g_t_poaccountx1-costcenter = c_checked.

          ELSEIF poitem-acctasscat = c_wbs. "P

          g_t_poaccountx1-wbs_element = c_checked.

          ENDIF.

          *PVU-11-May-2004-End of set cost center or WBS element.

          g_t_poaccountx1-orderid = c_checked.

          g_t_poaccountx1-distr_perc = c_checked.

          APPEND g_t_poaccountx1.

          *If line is deleted from account assignment in Ariba

          *then delete that line from SAP PO

          ELSE.

          g_t_poaccount1-po_item = g_t_poaccount_tmp-po_item.

          g_t_poaccount1-serial_no = ekkn-zekkn.

          g_t_poaccount1-delete_ind = c_checked.

          g_t_poaccount1-quantity = ekkn-menge.

          g_t_poaccount1-gl_account = ekkn-sakto.

          *PVU-11-May-2004-Set cost center or WBS element depending on acc.assgn.

          IF poitem-acctasscat = c_costcenter. "K

          g_t_poaccount1-costcenter = ekkn-kostl.

          ELSEIF poitem-acctasscat = c_wbs. "P

          g_t_poaccount1-wbs_element = ekkn-ps_psp_pnr.

          ENDIF.

          *PVU-11-May-2004-End of set cost center or WBS element.

          g_t_poaccount1-orderid = ekkn-aufnr.

          APPEND g_t_poaccount1.

          g_t_poaccountx1-po_item = g_t_poaccount_tmp-po_item.

          g_t_poaccountx1-serial_no = ekkn-zekkn.

          g_t_poaccountx1-po_itemx = c_checked.

          g_t_poaccountx1-delete_ind = c_checked.

          g_t_poaccountx1-quantity = c_checked.

          g_t_poaccountx1-gl_account = c_checked.

          *PVU-11-May-2004-Set cost center or WBS element depending on acc.assgn.

          IF poitem-acctasscat = c_costcenter. "K

          g_t_poaccountx1-costcenter = c_checked.

          ELSEIF poitem-acctasscat = c_wbs. "P

          g_t_poaccountx1-wbs_element = c_checked.

          ENDIF.

          *PVU-11-May-2004-End of set cost center or WBS element.

          g_t_poaccountx1-orderid = c_checked.

          APPEND g_t_poaccountx1.

          ENDIF.

          SUBTRACT 1 FROM g_cnt_poaccount.

          ENDSELECT.

          **BV-12-July-2004- Begin of change - split line accounting

          *clear the headerline before data population

          CLEAR : g_t_poaccount1,

          g_t_poaccountx1.

          **BV-12-July-2004- End of change - split line accounting

          • If new lines are added to account assignment in Ariba

          • add those lines to SAP PO

          IF g_cnt_poaccount GT 0.

          g_cnt_ekkn = ekkn-zekkn.

          SORT g_t_poaccount_tmp DESCENDING BY serial_no.

          LOOP AT g_t_poaccount_tmp.

          ADD 1 TO g_cnt_ekkn.

          g_t_poaccount1-po_item = g_t_poaccount_tmp-po_item.

          g_t_poaccount1-serial_no = g_cnt_ekkn.

          g_t_poaccount1-quantity = g_t_poaccount_tmp-quantity.

          g_t_poaccount1-gl_account = g_t_poaccount_tmp-gl_account.

          *PVU-11-May-2004-Set cost center or WBS element depending on acc.assgn.

          IF poitem-acctasscat = c_costcenter. "K

          g_t_poaccount1-costcenter = g_t_poaccount_tmp-costcenter.

          ELSEIF poitem-acctasscat = c_wbs. "P

          g_t_poaccount1-wbs_element = g_t_poaccount_tmp-wbs_element.

          ENDIF.

          *PVU-11-May-2004-End of set cost center or WBS element.

          g_t_poaccount1-orderid = g_t_poaccount_tmp-orderid.

          g_t_poaccount1-distr_perc = g_t_poaccount_tmp-distr_perc.

          APPEND g_t_poaccount1.

          g_t_poaccountx1-po_item = g_t_poaccount_tmp-po_item.

          g_t_poaccountx1-serial_no = g_cnt_ekkn.

          g_t_poaccountx1-po_itemx = c_checked.

          g_t_poaccountx1-quantity = c_checked.

          g_t_poaccountx1-gl_account = c_checked.

          *PVU-11-May-2004-Set cost center or WBS element depending on acc.assgn.

          IF poitem-acctasscat = c_costcenter. "K

          g_t_poaccountx1-costcenter = c_checked.

          ELSEIF poitem-acctasscat = c_wbs. "P

          g_t_poaccountx1-wbs_element = c_checked.

          ENDIF.

          *PVU-11-May-2004-End of set cost center or WBS element.

          g_t_poaccountx1-orderid = c_checked.

          g_t_poaccountx1-distr_perc = c_checked.

          APPEND g_t_poaccountx1.

          SUBTRACT 1 FROM g_cnt_poaccount.

          IF g_cnt_poaccount EQ 0.

          EXIT.

          ENDIF.

          ENDLOOP.

          ENDIF.

          CLEAR: g_cnt_poaccount, g_cnt_ekkn.

          REFRESH g_t_poaccount_tmp.

          ENDAT.

          ENDLOOP.

          REFRESH: poaccount, poaccountx.

          CLEAR: poaccount, poaccountx.

          APPEND LINES OF g_t_poaccount1 TO poaccount.

          APPEND LINES OF g_t_poaccountx1 TO poaccountx.

          REFRESH: g_t_poaccount1, g_t_poaccountx1.

          SORT: poaccount, poaccountx.

          *For POs Converted from legacy system, populate the item quantity and

          *price based on the original purchase order qty/price. Also, populate

          *the actual qty and price passed by Ariba in the Net weight and gross

          *weight fields.

          LOOP AT poitem.

          CLEAR: ekpo.

          SELECT SINGLE menge "Purchase order quantity

          netpr "Net price in PO

          INTO (ekpo-menge, ekpo-netpr)

          FROM ekpo

          WHERE ebeln EQ purchaseorder AND

          ebelp EQ poitem-po_item. "AND

          IF sy-subrc EQ 0.

          • Turn off Final Invoice Indicator if net price or quantity is higher

          • than the existing value.

          IF poitem-quantity GT ekpo-menge OR

          poitem-net_price GT ekpo-netpr.

          CLEAR poitem-final_inv.

          READ TABLE poitemx

          WITH KEY po_item = poitem-po_item

          BINARY SEARCH.

          IF sy-subrc EQ 0.

          poitemx-final_inv = c_checked.

          MODIFY poitemx INDEX sy-tabix.

          ENDIF.

          ENDIF.

          MODIFY poitem.

          ENDIF.

          ENDLOOP.

          *endif.

          ****Start of changes by Balaji V - 08-June-04

          ****Zero Pad and Prefix 1 to Vendor.

          DATA : L_LENGTH TYPE I.

          "Vendor string length.

          • L_MSGV1 LIKE SY-MSGV1. "Message variable1

          IF NOT POHEADER-VENDOR IS INITIAL.

          *remove any leading zeros for vendor populated from webmethods

          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

          EXPORTING

          INPUT = POHEADER-VENDOR

          IMPORTING

          OUTPUT = POHEADER-VENDOR.

          L_LENGTH = STRLEN( POHEADER-VENDOR ).

          IF L_LENGTH < 10.

          *To pad leading zeros to Vendor

          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

          EXPORTING

          INPUT = POHEADER-VENDOR

          IMPORTING

          OUTPUT = POHEADER-VENDOR.

          *To replace first character with 1.

          MOVE '1' TO POHEADER-VENDOR(1).

          ELSE. "Vendor is 10 char in length

          CLEAR L_MSGV1.

          L_MSGV1 = POHEADER-VENDOR.

          *Zero Padding and Prefixing 1 Not possible.Vendor is 10 Character

          *length

          CALL FUNCTION 'BALW_BAPIRETURN_GET2'

          EXPORTING

          TYPE = C_MSGTYPE_I "I

          CL = C_MSGID_Z001 "Z001

          NUMBER = C_MSGNR_040 "040

          PAR1 = L_MSGV1

          IMPORTING

          RETURN = RETURN.

          APPEND RETURN.

          CLEAR RETURN.

          loop at return.

          L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

          L_WA_ZERRORS-serial_no = sy-tabix.

          L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

          L_WA_ZERRORS-zid = return-id.

          L_WA_ZERRORS-znumber = return-number.

          L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

          L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

          L_WA_ZERRORS-ZDATE = sy-datum.

          L_WA_ZERRORS-ERR_MSG = return-message.

          append L_WA_ZERRORS to t_errors.

          • insert into ZP2P_ERRORS values L_WA_ZERRORS.

          clear: L_WA_ZERRORS.

          endloop.

          ENDIF.

          ENDIF.

          ****End of changes by Balaji V - 08-June-04

          **********************************************************

          *mod-003

          ***********************************************************

          ****************************************************

          *mod-003

          ****************************************************

          • if not poheader-comp_code is initial.

          • select single companycode

          • into l_bukrs

          • from zcompanycodes01

          • where companycode = poheader-comp_code and

          • FSID = poheader-fsid and

          • le = poheader-le and

          • frmrc = poheader-frmrc.

          *

          • if sy-subrc ne 0.

          • CLEAR L_MSGV1.

          • L_MSGV1 = POACCOUNT-PO_ITEM.

          • Please Enter an Account number for line

        • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

        • EXPORTING

        • TYPE = C_MSGTYPE_E

        • CL = C_MSGID_Z001

        • NUMBER = C_MSGNR_618

        • PAR1 = L_MSGV1

        • IMPORTING

        • RETURN = RETURN.

        • *

          • APPEND RETURN.

          • CLEAR RETURN.

          • loop at return.

          • L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

          • L_WA_ZERRORS-serial_no = sy-tabix.

          • L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

          • L_WA_ZERRORS-zid = return-id.

          • L_WA_ZERRORS-znumber = return-number.

          • L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

          • L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

          • L_WA_ZERRORS-ZDATE = sy-datum.

          • L_WA_ZERRORS-ERR_MSG = return-message.

          • append L_WA_ZERRORS to t_errors.

          • insert into ZP2P_ERRORS values L_WA_ZERRORS.

        • clear: L_WA_ZERRORS.

        • endloop.

        • *

          • ELSE.

          • poheader-comp_code = l_bukrs.

          • endif.

          • endif.

          **********************************************************

          *mod-003

          ***********************************************************

          if not poheader-currency is initial.

          if not poheader-vendor is initial.

          loop at pocond.

          SELECT SINGLE WAERS

          INTO L_WAERS

          FROM LFM1 WHERE

          LIFNR = POHEADER-VENDOR

          AND EKORG = POHEADER-PURCH_ORG.

          IF SY-SUBRC NE 0.

          IF L_WAERS NE poheader-currency.

          pocond-cond_value = 'PBXX'.

          pocond-currency = l_waers.

          modify pocond transporting cond_value currency.

          endif.

          ENDIF.

          endloop.

          ENDIF.

          ENDIF.

          **********************************************************

          *mod-003

          ***********************************************************

          • IF NOT TESTRUN IS INITIAL.

          • POHEADER-VENDOR = '4259999999'.

          • poheader-doc_type = 'ZAP'.

          • ENDIF.

          **********************************************************

          *mod-003

          ***********************************************************

          **********************************************************

          *mod-003

          ***********************************************************

          • IF NOT POHEADER-PURCH_ORG IS INITIAL.

          • SELECT SINGLE PUR_ORG

          • INTO L_EKORG

          • FROM ZPUR_ORG

          • WHERE LE = POHEADER-LE AND

          • FRMRC = POHEADER-FRMRC AND

          • FSID = POHEADER-FSID.

          *

          • IF SY-SUBRC NE 0.

          • CLEAR : L_CONST_NAME,

          • L_COMP_CODE.

          *

          • L_CONST_NAME = C_p2p_pur_ORG.

          • L_COMP_CODE = POHEADER-COMP_CODE.

          *

          • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

          • EXPORTING

          • TYPE = c_msgtype_e

          • CL = c_msgid_z001

          • NUMBER = c_msgnr_619

          • PAR1 = L_CONST_NAME

          • PAR2 = L_COMP_CODE

          • IMPORTING

          • RETURN = RETURN.

          *

          • APPEND RETURN.

          • CLEAR RETURN.

          *

          • loop at return.

          • L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

          • L_WA_ZERRORS-serial_no = sy-tabix.

          • L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

          • L_WA_ZERRORS-zid = return-id.

          • L_WA_ZERRORS-znumber = return-number.

          • L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

          • L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

          • L_WA_ZERRORS-ZDATE = sy-datum.

          • L_WA_ZERRORS-ERR_MSG = return-message.

          • append L_WA_ZERRORS to t_errors.

          • insert into ZP2P_ERRORS values L_WA_ZERRORS.

        • clear: L_WA_ZERRORS.

        • endloop.

        • EXIT.

        • ELSE.

        • POHEADER-PURCH_ORG = L_EKORG.

        • ENDIF.

        • ENDIF.

        • **********************************************************

          *mod-003

          **********************************************************

          LOOP AT POITEM.

          l_wa_timestamp-mandt = SY-MANDT.

          l_wa_timestamp-EBELN = POHEADER-PO_NUMBER.

          l_wa_timestamp-EBELP = POITEM-PO_ITEM.

          l_wa_timestamp-CHANGE_IND = ' '.

          l_wa_timestamp-DATE_TIME_STMP = POHEADER-ARIBACHGTIMESTMP.

          insert into ZP2P_TIMESTAMP values l_wa_timestamp.

          ENDLOOP.

          DATA: g_constval(10) type c.

          IF NOT POHEADER-PUR_GROUP IS INITIAL.

          clear: g_constval.

          CALL FUNCTION 'ZXA_GET_CONSTANT'

          EXPORTING

          const_name = c_p2p_pur_org

          comp_code = POHEADER-COMP_CODE

          IMPORTING

          const_value = g_constval

          EXCEPTIONS

          no_value_found = 1

          null_value = 2

          OTHERS = 3.

          IF SY-SUBRC NE 0.

          CLEAR : L_CONST_NAME,

          L_COMP_CODE.

          L_CONST_NAME = C_p2p_pur_org.

          L_COMP_CODE = POHEADER-COMP_CODE.

          CALL FUNCTION 'BALW_BAPIRETURN_GET2'

          EXPORTING

          TYPE = c_msgtype_e

          CL = c_msgid_z001

          NUMBER = c_msgnr_619

          PAR1 = L_CONST_NAME

          PAR2 = L_COMP_CODE

          IMPORTING

          RETURN = RETURN.

          APPEND RETURN.

          CLEAR RETURN.

          loop at return.

          L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

          L_WA_ZERRORS-serial_no = sy-tabix.

          L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

          L_WA_ZERRORS-zid = return-id.

          L_WA_ZERRORS-znumber = return-number.

          L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

          L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

          L_WA_ZERRORS-ZDATE = sy-datum.

          L_WA_ZERRORS-ERR_MSG = return-message.

          append L_WA_ZERRORS to t_errors.

          • insert into ZP2P_ERRORS values L_WA_ZERRORS.

          clear: L_WA_ZERRORS.

          endloop.

          EXIT.

          ELSE.

          POHEADER-PUR_GROUP = G_CONSTVAL.

          ENDIF.

          ENDIF.

          **********************************************************

          *mod-003

          **********************************************************

          IF purchaseorder(3) = c_pco. "PCO

          &----


          &

          *& Begin of Change: 26-Sep-2005 SDUTTARO RD1K910989 *&

          &----


          &
          • Map the external fields for ALZA with account assignment

          • IF poheader-comp_code = c_bukrs_alza. "@SDR

          **-- Retrieve Account Assignment

          PERFORM get_account_assignment TABLES poitem "@SDR

          poitemx "@SDR

          poaccount "@SDR

          poaccountx "@SDR

          t_yreturn "@SDR

          USING poheader-comp_code "@SDR

          poheader. "@SDR

          • ENDIF. "@SDR

          &----


          &

          **& Begin of Change: 26-Sep-2005 SDUTTARO RD1K910989 *&

          *&----


          &

            • For PCO Order, populate the PO and accounting data into a Z table and

            • exit the program run.

          • PERFORM populate_nonpo_document TABLES poitem

          • return

          • potextheader

          • USING purchaseorder

          • poheader.

          • PERFORM populate_nonpo_accounting TABLES poaccount

          • return

          • USING poheader.

          • **&&---Begin of Addition: Soumya D Roy: 03/10/2006

              • To make sure that the ztables do not get updated in case of

              • checkpoints 1, 2 and get updated only after approval

            • IF testrun IS INITIAL. "SDR

            • **&&---End of Addition: Soumya D Roy: 03/10/2006

              • PERFORM update_nonpodocument.

              **&&---Begin of Addition: Soumya D Roy: 03/10/2006

                • To delete PCOs. No deletion code is required for CRs & UTs

                • as these two cannot be deleted

              • ENDIF. "@SDR

              • **&&---End of Addition: Soumya D Roy: 03/10/2006

                • LOOP AT t_return.

                • MOVE: t_return-type TO return-type,

                • t_return-number TO return-number,

                • t_return-message TO return-message.

                • APPEND return.

                • CLEAR return.

                • ENDLOOP.

                *&&&&&---- Begin of Addition: Soumya D Roy: 03/02/2006

                • Code to build the message table for output to Ariba

                • for PCOs

                *GENERATE CUSTOM RETURN MESSAGES BASED ON MESSAGE ID AND NUMBER FROM

                *maintenance table ZMESSAGES

                • CALL FUNCTION 'Z_MM_BUILD_MESSAGES'

                • TABLES

                • return = return.

                *

                • SORT return BY type id number.

                • READ TABLE return

                • WITH KEY id = space

                • number = c_msgnr_000 "000

                • BINARY SEARCH.

                *

                • IF sy-subrc EQ 0 AND sy-tabix NE 1.

                • DELETE return INDEX sy-tabix.

                • INSERT return INDEX 1.

                • ENDIF.

                **&&&&----- End of Addition: Soumya D Roy: 03/02/2006

                • EXIT.

                ENDIF.

                *

                *-- Round off to 100 percent due to small difference in one decimal

                *-- point rounding (in Ariba/wM)

                SORT poaccount BY po_item distr_perc.

                LOOP AT poaccount.

                ADD poaccount-distr_perc TO g_distr_perc.

                AT END OF po_item.

                *-- Round off to 100 percent due to small difference in one decimal

                *-- point rounding (in Ariba/wM)

                IF g_distr_perc GT 0.

                g_distr_perc = 100 - g_distr_perc.

                g_adjust_perc = c_checked.

                ENDIF.

                ENDAT.

                IF g_adjust_perc = c_checked.

                g_distr_perc1 = g_distr_perc + poaccount-distr_perc.

                IF g_distr_perc1 = 100.

                poaccount-distr_perc = 0.

                ELSE.

                poaccount-distr_perc = g_distr_perc1.

                ENDIF.

                MODIFY poaccount.

                CLEAR poaccount.

                CLEAR: g_distr_perc, g_distr_perc1.

                ENDIF.

                CLEAR g_adjust_perc.

                ENDLOOP.

                SORT poaccount.

                SORT poschedule BY po_item sched_line.

                SORT poschedulex BY po_item sched_line.

                *PVU-20-May-2004 - Start Changes for SCR1

                ***************************************************

                **MOD-003

                **************************************************

                *Populate the change indicator structures before calling BAPI_PO_CHANGE

                *so that IDOC can be populated with this data

                IF NOT poheaderx IS INITIAL.

                g_w_hdrx_tmp = poheaderx.

                ENDIF.

                IF NOT poitemx[] IS INITIAL.

                g_t_itemx_tmp[] = poitemx[].

                ENDIF.

                IF NOT poschedulex[] IS INITIAL.

                g_t_schdx_tmp[] = poschedulex[].

                ENDIF.

                IF NOT poaccountx[] IS INITIAL.

                g_t_accntx_tmp[] = poaccountx[].

                ENDIF.

                IF NOT pocondx[] IS INITIAL.

                g_t_condx_tmp[] = pocondx[].

                ENDIF.

                ***************************************************

                **MOD-003

                **************************************************

                *PVU-20-May-2004 - End Changes for SCR1

                *sraman2 06/28/04

                *-- Default the Material Group to 99 if the incoming commodity

                *-- code don't exist in SAP

                LOOP AT poitem.

                SELECT SINGLE matkl INTO t023-matkl FROM t023

                WHERE matkl = poitem-matl_group.

                IF sy-subrc NE 0.

                MOVE: '99' TO poitem-matl_group.

                MODIFY poitem.

                ENDIF.

                CLEAR poitem.

                ENDLOOP.

                *sraman2 06/28/04

                *&---Begin of Addition: Soumya D Roy: 03/27/2006

                • Logic for PO changes which are listed in table ZCONVERTEDPOS.

                • ZCONVERTEDPOS contains Purchase Orders ie. both Material and

                • Service which have either NONVAL GR checked or GR checked respectively

                • and are invoiced. Any changes to these POs from Ariba would not let

                • other quantity or amount or text description changes to flow into SAP.

                • This piece of code will keep the Indicators' status same as in SAP

                • and also let the user perform the change.

                *Begin of change by svalidet RD1K911990

                • IF purchaseorder+0(3) = '099'.

                • IF purchaseorder+0(3) in r_ehub_pos[].

                *End of change by svalidet RD1K911990

                CALL FUNCTION 'Z_CONVERTED_POS'

                EXPORTING

                P_PURCHASEORDER = purchaseorder

                P_POHEADER = poheader

                TABLES

                P_POITEM = poitem

                P_POITEMX = poitemx.

                • ENDIF.

                **************************************************************

                *mod-003

                **************************************************************

                • perform get_uom_conversion tables poitem

                • POITEMX

                • poaccount

                • poaccountx

                • poschedule

                • poschedulex

                • changing poheader

                • poheaderx.

                perform get_uom_conversion tables poitem

                POITEMX

                poaccount

                poaccountx

                poschedule

                poschedulex

                pocond

                pocondx

                Pocondheader

                pocondheaderx

                changing poheader

                poheaderx.

                **************************************************************

                *mod-003

                **************************************************************

                *Populate the change indicator structures before calling BAPI_PO_CHANGE

                *so that IDOC can be populated with this data

                IF NOT poheaderx IS INITIAL.

                g_w_hdrx_tmp = poheaderx.

                ENDIF.

                IF NOT poitemx[] IS INITIAL.

                g_t_itemx_tmp[] = poitemx[].

                ENDIF.

                IF NOT poschedulex[] IS INITIAL.

                g_t_schdx_tmp[] = poschedulex[].

                ENDIF.

                IF NOT poaccountx[] IS INITIAL.

                g_t_accntx_tmp[] = poaccountx[].

                ENDIF.

                IF NOT pocondx[] IS INITIAL.

                g_t_condx_tmp[] = pocondx[].

                ENDIF.

                ***************************************************

                **MOD-003

                **************************************************

                CALL FUNCTION 'BAPI_PO_CHANGE'

                EXPORTING

                purchaseorder = purchaseorder

                poheader = poheader

                poheaderx = poheaderx

                poaddrvendor = poaddrvendor

                testrun = testrun

                memory_uncomplete = memory_uncomplete

                memory_complete = memory_complete

                • poexpimpheader = poexpimpheader

                • poexpimpheaderx = poexpimpheaderx

                • versions = versions

                • no_messaging = no_messaging

                • no_message_req = no_message_req

                • no_authority = no_authority

                • no_price_from_po = no_price_from_po

                IMPORTING

                expheader = expheader

                • exppoexpimpheader = exppoexpimpheader

                TABLES

                return = return

                poitem = poitem

                poitemx = poitemx

                poaddrdelivery = poaddrdelivery

                poschedule = poschedule

                poschedulex = poschedulex

                poaccount = poaccount

                poaccountprofitsegment = poaccountprofitsegment

                poaccountx = poaccountx

                pocondheader = pocondheader

                pocondheaderx = pocondheaderx

                pocond = pocond

                pocondx = pocondx

                polimits = polimits

                pocontractlimits = pocontractlimits

                poservices = poservices

                posrvaccessvalues = posrvaccessvalues

                poservicestext = poservicestext

                extensionin = extensionin

                extensionout = extensionout

                • poexpimpitem = poexpimpitem

                • poexpimpitemx = poexpimpitemx

                potextheader = potextheader

                potextitem = potextitem .

                • allversions = allversions

                • popartner = popartner.

                • Code inserted to commit work

                SORT return BY type.

                IF testrun IS INITIAL.

                READ TABLE return

                WITH KEY type = c_msgtype_e "E.

                BINARY SEARCH.

                IF sy-subrc NE 0.

                CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

                ELSE.

                CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

                **PVU-20-May-2004 - Start Changes for SCR1

                **To generate inbound IDOC for failed PO

                • perform idoc_create tables poitem

                • g_t_itemx_tmp

                • poaddrdelivery

                • poschedule

                • g_t_schdx_tmp

                • poaccount

                • poaccountprofitsegment

                • g_t_accntx_tmp

                • pocond

                • g_t_condx_tmp

                • polimits

                • pocontractlimits

                • poservices

                • posrvaccessvalues

                • poservicestext

                • extensionin

                • return

                • using c_flg_pochange "CHNG

                • purchaseorder

                • poheader

                • g_w_hdrx_tmp

                • poaddrvendor

                • testrun

                • memory_uncomplete

                • memory_complete .

                *

                *PVU-20-May-2004 - End Changes for SCR1

                loop at return.

                L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

                L_WA_ZERRORS-serial_no = sy-tabix.

                L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

                L_WA_ZERRORS-zid = return-id.

                L_WA_ZERRORS-znumber = return-number.

                L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

                L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

                L_WA_ZERRORS-ZDATE = sy-datum.

                L_WA_ZERRORS-ERR_MSG = return-message.

                append L_WA_ZERRORS to t_errors.

                • insert into ZP2P_ERRORS values L_WA_ZERRORS.

                clear: L_WA_ZERRORS.

                endloop.

                SELECT max( serial_no )

                INTO L_SERIAL

                FROM ZP2P_ERRORS.

                LOOP AT T_ERRORS.

                L_SERIAL = L_SERIAL + 1.

                T_ERRORS-serial_no = L_SERIAL.

                MODIFY T_ERRORS TRANSPORTING serial_no.

                ENDLOOP.

                INSERT ZP2P_ERRORS FROM TABLE T_ERRORS.

                ENDIF.

                ELSE.

                • CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

                ENDIF.

                *GENERATE CUSTOM RETURN MESSAGES BASED ON MESSAGE ID AND NUMBER FROM

                *maintenance table ZMESSAGES

                CALL FUNCTION 'Z_MM_BUILD_MESSAGES'

                TABLES

                return = return.

                SORT return BY type id number.

                READ TABLE return

                WITH KEY id = space

                number = c_msgnr_000 "000

                BINARY SEARCH.

                IF sy-subrc EQ 0 AND sy-tabix NE 1.

                DELETE return INDEX sy-tabix.

                INSERT return INDEX 1.

                ENDIF.

                SELECT max( serial_no )

                INTO L_SERIAL

                FROM ZP2P_ERRORS.

                LOOP AT T_ERRORS.

                L_SERIAL = L_SERIAL + 1.

                T_ERRORS-serial_no = L_SERIAL.

                MODIFY T_ERRORS TRANSPORTING serial_no.

                ENDLOOP.

                INSERT ZP2P_ERRORS FROM TABLE T_ERRORS.

                ENDFUNCTION.

                FUNCTION Z_BC1_BAPI_PO_CHANGE02.

                *"----


                ""Local Interface:

                *" IMPORTING

                *" VALUE(PURCHASEORDER) TYPE BAPIMEPOHEADER-PO_NUMBER

                *" VALUE(POADDRVENDOR) TYPE BAPIMEPOADDRVENDOR

                *" VALUE(TESTRUN) TYPE BAPIFLAG-BAPIFLAG

                *" VALUE(MEMORY_UNCOMPLETE) TYPE BAPIFLAG-BAPIFLAG

                *" VALUE(MEMORY_COMPLETE) TYPE BAPIFLAG-BAPIFLAG

                *" VALUE(POEXPIMPHEADER) TYPE BAPIEIKP

                *" VALUE(POEXPIMPHEADERX) TYPE BAPIEIKPX

                *" VALUE(VERSIONS) TYPE BAPIMEDCM

                *" VALUE(NO_MESSAGING) TYPE BAPIFLAG-BAPIFLAG

                *" VALUE(NO_MESSAGE_REQ) TYPE BAPIFLAG-BAPIFLAG

                *" VALUE(NO_AUTHORITY) TYPE BAPIFLAG-BAPIFLAG

                *" VALUE(NO_PRICE_FROM_PO) TYPE BAPIFLAG-BAPIFLAG

                *" EXPORTING

                *" VALUE(EXPHEADER) TYPE BAPIMEPOHEADER

                *" VALUE(EXPPOEXPIMPHEADER) TYPE BAPIEIKPX

                *" TABLES

                *" RETURN STRUCTURE BAPIRET2

                *" POITEM STRUCTURE BAPIMEPOITEM

                *" POITEMX STRUCTURE BAPIMEPOITEMX

                *" POADDRDELIVERY STRUCTURE BAPIMEPOADDRDELIVERY

                *" POSCHEDULE STRUCTURE BAPIMEPOSCHEDULE

                *" POSCHEDULEX STRUCTURE BAPIMEPOSCHEDULX

                *" POACCOUNT STRUCTURE BAPIMEPOACCOUNT

                *" POACCOUNTPROFITSEGMENT STRUCTURE BAPIMEPOACCOUNTPROFITSEGMENT

                *" POACCOUNTX STRUCTURE BAPIMEPOACCOUNTX

                *" POCONDHEADER STRUCTURE BAPIMEPOCONDHEADER

                *" POCONDHEADERX STRUCTURE BAPIMEPOCONDHEADERX

                *" POCOND STRUCTURE BAPIMEPOCOND

                *" POCONDX STRUCTURE BAPIMEPOCONDX

                *" POLIMITS STRUCTURE BAPIESUHC

                *" POCONTRACTLIMITS STRUCTURE BAPIESUCC

                *" POSERVICES STRUCTURE BAPIESLLC

                *" POSRVACCESSVALUES STRUCTURE BAPIESKLC

                *" POSERVICESTEXT STRUCTURE BAPIESLLTX

                *" EXTENSIONIN STRUCTURE BAPIPAREX

                *" EXTENSIONOUT STRUCTURE BAPIPAREX

                *" POEXPIMPITEM STRUCTURE BAPIEIPO

                *" POEXPIMPITEMX STRUCTURE BAPIEIPOX

                *" POTEXTHEADER STRUCTURE BAPIMEPOTEXTHEADER

                *" POTEXTITEM STRUCTURE BAPIMEPOTEXT

                *" ALLVERSIONS STRUCTURE BAPIMEDCM_ALLVERSIONS

                *" POPARTNER STRUCTURE BAPIEKKOP

                *" POCOMPONENTS STRUCTURE BAPIMEPOCOMPONENT

                *" POCOMPONENTSX STRUCTURE BAPIMEPOCOMPONENTX

                *" POSHIPPING STRUCTURE BAPIITEMSHIP

                *" POSHIPPINGX STRUCTURE BAPIITEMSHIPX

                *" POSHIPPINGEXP STRUCTURE BAPIMEPOSHIPPEXP

                *" POHISTORY STRUCTURE BAPIEKBE

                *" POHISTORY_TOTALS STRUCTURE BAPIEKBES

                *" POCONFIRMATION STRUCTURE BAPIEKES

                *" NFMETALLITMS STRUCTURE /NFM/BAPIDOCITM

                *" CHANGING

                *" VALUE(POHEADER) TYPE BAPIMEPOHEADER

                *" VALUE(POHEADERX) TYPE BAPIMEPOHEADERX

                *"----


                ************************************************************************

                • PROGRAM Z_BC1_BAPI_PO_CHANGE

                • TITLE Function module to Change PO using BAPI

                • AUTHOR Aveek Ghose

                • DATE WRITTEN 24.05.2006

                • R/3 RELEASE 4.6C

                *----


                • COPIED FROM N/A

                *

                • This function module is called during PO change in Ariba.

                • The call to this function module is from WebMethods. The function

                • module performs custom validations on data provided from Ariba and

                • then calls BAPI_PO_CHANGE. The error messages are returned to Ariba.

                *

                *----


                • PROGRAM TYPE Function module

                • DEV. CLASS ZP2P

                • LOGICAL DB N/A

                *----


                • SCREENS N/A

                • GUl TITLE N/A

                • GUl STATUS N/A

                • TRANSACTIONS N/A

                • USER EXITS N/A

                *----


                *----


                ----


                • DB-Tables

                ----


                TABLES: ekkn, "Account Assignment in Purchasing Document

                ekbe. "History per Purchasing Document

                • zconstants_new. "Constants for various interfaces

                • & programs with comp code

                ----


                • Global variables

                ----


                DATA: g_cnt_poaccount TYPE i, "No. of records in POACCOUNT

                g_cnt_ekkn TYPE i, "No. of records in EKKN

                g_msgv1 LIKE sy-msgv1. "Message variable1

                ----


                • Internal Tables

                ----


                DATA: g_t_poaccount_tmp LIKE poaccount OCCURS 0 WITH HEADER LINE,

                g_t_poaccount1 LIKE poaccount OCCURS 0 WITH HEADER LINE,

                g_t_poaccountx1 LIKE poaccountx OCCURS 0 WITH HEADER LINE,

                g_t_poaccount LIKE poaccount OCCURS 0 WITH HEADER LINE,

                *PVU-20-May-2004 - Changes for SCR1

                g_t_itemx_tmp LIKE poitemx OCCURS 0 WITH HEADER LINE,

                g_t_schdx_tmp LIKE poschedulex OCCURS 0 WITH HEADER LINE,

                g_t_accntx_tmp LIKE poaccountx OCCURS 0 WITH HEADER LINE,

                g_t_condx_tmp LIKE pocondx OCCURS 0 WITH HEADER LINE.

                • T_Zconstants LIKE ZCONSTANTS_NEW OCCURS 0 WITH HEADER LINE.

                *RD1K911982

                *PVU-20-May-2004 - End Changes for SCR1

                ----


                • Structure

                ----


                DATA: g_w_hdrx_tmp LIKE poheaderx. "PVU-20-May-2004 - Changes for SCR1

                • DATA: p_constname TYPE zconstname, "Constant Name

                • g_constval TYPE zconstval, "Constant Value

                • c_po_ehub_var LIKE ZCONSTANTS_NEW-CONSTname value 'EHUB_POS%'.

                DATA : L_CONST_NAME LIKE SY-MSGV1, "Constant name

                L_COMP_CODE LIKE SY-MSGV2. "Company code

                DATA: L_WA_TIMESTAMP TYPE ZP2P_TIMESTAMP.

                data: l_waers type waers.

                DATA: L_EKORG TYPE EKORG.

                DATA: L_SERIAL TYPE I.

                DATA : L_VEND_ACTGRP(30) TYPE C, "Vendor Account Group

                L_VEND_PAYTRM(30) TYPE C, "Vendor Payment Terms

                L_VEND_RECON(30) TYPE C, "Vendor Reconciliation Account

                L_MSGV1 LIKE SY-MSGV1, "Message variable1

                L_WBS_EXTERNAL LIKE BAPIMEPOACCOUNT-WBS_ELEMENT,

                "WBS external format

                L_WBS_INTERNAL LIKE BAPIMEPOACCOUNT-WBS_ELEMENT,

                L_bukrs type bukrs.

                • Ranges :r_ehub_pos for t_zconstants-constvalu.

                • Begin of Change SVALIDET(RD1K911990)

              • SELECT *

              • FROM zconstants_new

              • INTO TABLE t_zconstants

              • WHERE constname LIKE c_po_ehub_var. " EHUB_POS%

              • *

                • IF sy-subrc = 0.

                • SORT t_zconstants BY constvalu ASCENDING.

                • DELETE ADJACENT DUPLICATES FROM t_zconstants

                • COMPARING constvalu.

                • LOOP AT t_zconstants.

                • r_ehub_pos-sign = 'I'.

                • r_ehub_pos-option = 'EQ'.

                • r_ehub_pos-low = t_zconstants-constvalu.

                • APPEND r_ehub_pos.

                • CLEAR: r_ehub_pos,

                • t_zconstants.

                • ENDLOOP.

                • ENDIF.

                **End of Change SVALIDET(RD1K911990)

                *

                  • Srini 18-May-2005 Start of changes

                  • Developer Flexibility to debug issues

                • p_constname = 'BAPI_PO_CHANGE2'.

                • *

                  • do.

                  • CALL FUNCTION 'ZXA_GET_CONSTANT'

                  • EXPORTING

                  • const_name = p_constname

                  • comp_code =

                • IMPORTING

                • const_value = g_constval

                • EXCEPTIONS

                • no_value_found = 1

                • null_value = 2

                • OTHERS = 3.

                • if g_constval NE 'X'.

                • exit.

                • endif.

                • enddo.

                • *Begin of comment RD1Kk911990

                  • IF PURCHASEORDER+0(3) EQ '099' AND POHEADER-DOC_TYPE EQ 'ZEHS'.

                  • POHEADER-DOC_TYPE = 'ZEH'.

                  • ENDIF.

                  *End of comment RD1K911990

                  **********************************************************

                  *mod-003

                  **********************************************************

                    • if not poheader-comp_code is initial.

                  • if poheader-comp_code is initial.

                  • clear: l_bukrs.

                  • select single companycode

                  • into l_bukrs

                  • from zcompanycodes01

                    • where companycode = poheader-comp_code and

                  • where FSID = poheader-fsid and

                  • le = poheader-le and

                  • frmrc = poheader-frmrc.

                  • *

                    • if sy-subrc ne 0.

                    • CLEAR L_MSGV1.

                    • L_MSGV1 = POHEADER-DOC_TYPE.

                    • Please Enter an Account number for line

                  • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

                  • EXPORTING

                  • TYPE = C_MSGTYPE_E

                  • CL = C_MSGID_Z001

                  • NUMBER = C_MSGNR_618

                  • PAR1 = L_MSGV1

                  • IMPORTING

                  • RETURN = RETURN.

                  • *

                    • APPEND RETURN.

                    • CLEAR RETURN.

                    • else.

                    • poheader-comp_code = l_bukrs.

                    • endif.

                    • endif.

                    **********************************************************

                    *mod-003

                    **********************************************************

                    • IF POHEADER-DOC_TYPE EQ 'ZEHS'.

                    • POHEADER-DOC_TYPE = 'ZEH'.

                    • ENDIF.

                    • SORT poaccount BY po_item serial_no.

                    *Clear internal tables and global variables

                    REFRESH: g_t_poaccount_tmp,

                    g_t_poaccount1,

                    g_t_poaccountx1,

                    g_t_poaccount,

                    return,

                    • g_t_idoc_data,

                    g_t_itemx_tmp,

                    g_t_schdx_tmp,

                    g_t_accntx_tmp,

                    g_t_condx_tmp.

                    CLEAR: g_cnt_poaccount,

                    g_cnt_ekkn,

                    g_msgv1.

                    • g_distr_perc,

                    • g_distr_perc1,

                    • g_adjust_perc,

                    • g_idoc_no,

                    • g_w_hdrx_tmp.

                    IF poheader-po_number+0(1) = 'C'.

                    poheader-doc_type = 'ZAC'.

                    ENDIF.

                    IF poheader-po_number+0(1) = 'P'.

                    poheader-doc_type = 'ZAP'.

                    ENDIF.

                    IF poheader-po_number IS INITIAL.

                    poheader-doc_type = 'ZAPS'.

                    ENDIF.

                    IF purchaseorder(3) <> c_pco.

                    g_t_poaccount[] = poaccount[].

                    • To retrieve the line items with blank GL Account Number

                    • PERFORM filter_items TABLES g_t_poaccount.

                    LOOP AT g_t_poaccount.

                    CLEAR g_msgv1.

                    g_msgv1 = g_t_poaccount-po_item.

                    • Please Enter an Account number for line

                    CALL FUNCTION 'BALW_BAPIRETURN_GET2'

                    EXPORTING

                    type = c_msgtype_e "E

                    cl = c_msgid_z001 "Z001

                    number = c_msgnr_037 "037

                    par1 = g_msgv1

                    IMPORTING

                    return = return.

                    APPEND return.

                    CLEAR return.

                    loop at return.

                    l_wa_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

                    l_wa_ZERRORS-serial_no = sy-tabix.

                    l_wa_ZERRORS-COMP_CODE = poheader-comp_code.

                    l_wa_ZERRORS-zid = return-id.

                    l_wa_ZERRORS-znumber = return-number.

                    l_wa_ZERRORS-BEACON_DOC_NO = poheader-po_number.

                    l_wa_ZERRORS-SRC_DOC_NO = poheader-po_number.

                    l_wa_ZERRORS-ZDATE = sy-datum.

                    l_wa_ZERRORS-ERR_MSG = return-message.

                    append l_wa_ZERRORS to t_errors.

                    • insert into ZP2P_ERRORS values l_wa_ZP2P_ERRORS.

                    clear: L_WA_ZERRORS.

                    endloop.

                    CLEAR g_msgv1.

                    ENDLOOP.

                    SORT return BY type.

                    • On Error, exit the function module

                    READ TABLE return

                    WITH KEY type = c_msgtype_e "E

                    BINARY SEARCH.

                    IF sy-subrc EQ 0.

                    EXIT.

                    ENDIF.

                    ***Begin of Change - BVIJAYA 01-July-2004 TPR-2239

                    • If line item is marked for deletion, Clear the final_inv indicator,

                    • so that the condition value[conditions tab(po header)] reflects the

                    • correct gross price for the remaining items.

                    SORT poitem BY po_item.

                    SORT poitemx BY po_item.

                    LOOP AT poitem.

                    IF NOT poitem-delete_ind IS INITIAL. "delete ind marked.

                    • sraman2 07/17/04

                    *For item deletion to work properly

                    *indicator should be 'D'. webmethods passes indicator 'X'.

                    poitem-delete_ind = 'D'.

                    • sraman2 07/17/04

                    CLEAR poitem-final_inv.

                    MODIFY poitem.

                    READ TABLE poitemx WITH KEY po_item = poitem-po_item.

                    IF sy-subrc = 0.

                    poitemx-final_inv = c_checked. "X

                    MODIFY poitemx INDEX sy-tabix.

                    ENDIF.

                    else.

                    ENDIF.

                    ENDLOOP.

                    endif.

                    ****************************************************

                    *mod-003

                    ****************************************************

                    DATA: L_TABIX TYPE SY-TABIX.

                    LOOP AT POITEM.

                    TBX = SY-TABIX.

                    l_wa_timestamp-mandt = SY-MANDT.

                    l_wa_timestamp-EBELN = POHEADER-PO_NUMBER.

                    l_wa_timestamp-EBELP = POITEM-PO_ITEM.

                    l_wa_timestamp-CHANGE_IND = ' '.

                    l_wa_timestamp-DATE_TIME_STMP = POITEM-ARIBACRTTIMESTMP.

                    insert into ZP2P_TIMESTAMP values l_wa_timestamp.

                    clear: poheader-ARIBACRTTIMESTMP,

                    poheader-ARIBACHGTIMESTMP.

                    IF NOT POITEM-DISTRIB IS INITIAL.

                    CLEAR : L_CONST_NAME,

                    L_COMP_CODE.

                    READ TABLE POACCOUNT INDEX L_TABIX.

                    IF SY-SUBRC EQ 0.

                    L_CONST_NAME = POACCOUNT-GL_ACCOUNT.

                    L_COMP_CODE = L_comp_code.

                    CALL FUNCTION 'BALW_BAPIRETURN_GET2'

                    EXPORTING

                    type = c_msgtype_e "E

                    cl = c_msgid_z001

                    number = c_msgnr_613

                    PAR1 = L_CONST_NAME

                    PAR2 = L_COMP_CODE

                    IMPORTING

                    return = t_yreturn.

                    APPEND t_yreturn.

                    CLEAR t_yreturn.

                    loop at t_yreturn.

                    L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

                    L_WA_ZERRORS-serial_no = sy-tabix.

                    L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

                    L_WA_ZERRORS-zid = t_yreturn-id.

                    L_WA_ZERRORS-znumber = t_yreturn-number.

                    L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

                    L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

                    L_WA_ZERRORS-ZDATE = sy-datum.

                    L_WA_ZERRORS-ERR_MSG = t_yreturn-message.

                    append L_WA_ZERRORS to t_errors.

                    • insert into ZP2P_ERRORS values L_WA_ZERRORS.

                    clear: L_WA_ZERRORS.

                    endloop.

                    ENDIF.

                    ENDIF.

                    ENDLOOP.

                    if not poheader-currency is initial.

                    if not poheader-vendor is initial.

                    loop at pocond.

                    SELECT SINGLE WAERS

                    INTO L_WAERS

                    FROM LFM1 WHERE

                    LIFNR = POHEADER-VENDOR

                    AND EKORG = POHEADER-PURCH_ORG.

                    IF SY-SUBRC NE 0.

                    IF L_WAERS NE poheader-currency.

                    pocond-cond_value = 'PBXX'.

                    pocond-currency = l_waers.

                    modify pocond transporting cond_value currency.

                    endif.

                    ENDIF.

                    endloop.

                    ENDIF.

                    ENDIF.

                    IF NOT TESTRUN IS INITIAL.

                    POHEADER-VENDOR = '4259999999'.

                    poheader-doc_type = 'ZAPS'.

                    ENDIF.

                    • IF NOT POHEADER-PURCH_ORG IS INITIAL.

                    • IF POHEADER-PURCH_ORG IS INITIAL.

                    • SELECT SINGLE PUR_ORG

                    • INTO L_EKORG

                    • FROM ZPUR_ORG

                    • WHERE LE = POHEADER-LE AND

                    • FRMRC = POHEADER-FRMRC AND

                    • FSID = POHEADER-FSID.

                    *

                    • IF SY-SUBRC NE 0.

                    • CLEAR : L_CONST_NAME,

                    • L_COMP_CODE.

                    *

                    • L_CONST_NAME = C_p2p_pur_ORG.

                    • L_COMP_CODE = POHEADER-COMP_CODE.

                    *

                    • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

                    • EXPORTING

                    • TYPE = c_msgtype_e

                    • CL = c_msgid_z001

                    • NUMBER = c_msgnr_619

                    • PAR1 = L_CONST_NAME

                    • PAR2 = L_COMP_CODE

                    • IMPORTING

                    • RETURN = RETURN.

                    *

                    • APPEND RETURN.

                    • CLEAR RETURN.

                    *

                    • loop at t_yreturn.

                    • L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

                    • L_WA_ZERRORS-serial_no = sy-tabix.

                    • L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

                    • L_WA_ZERRORS-zid = t_yreturn-id.

                    • L_WA_ZERRORS-znumber = t_yreturn-number.

                    • L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

                    • L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

                    • L_WA_ZERRORS-ZDATE = sy-datum.

                    • L_WA_ZERRORS-ERR_MSG = t_yreturn-message.

                    • append L_WA_ZERRORS to t_errors.

                    • insert into ZP2P_ERRORS values L_WA_ZERRORS.

                    • clear: L_WA_ZERRORS.

                    • endloop.

                    • EXIT.

                    • ELSE.

                    • POHEADER-PURCH_ORG = L_EKORG.

                    • ENDIF.

                    • ENDIF.

                    • IF NOT POHEADER-PUR_GROUP IS INITIAL.

                    • IF POHEADER-PUR_GROUP IS INITIAL.

                    • clear: g_constval.

                    • CALL FUNCTION 'ZXA_GET_CONSTANT'

                    • EXPORTING

                    • const_name = c_p2p_pur_org

                    • comp_code = POHEADER-COMP_CODE

                    • IMPORTING

                    • const_value = g_constval

                    • EXCEPTIONS

                    • no_value_found = 1

                    • null_value = 2

                    • OTHERS = 3.

                    *

                    *

                    • IF SY-SUBRC NE 0.

                    • CLEAR : L_CONST_NAME,

                    • L_COMP_CODE.

                    *

                    • L_CONST_NAME = C_p2p_pur_org.

                    • L_COMP_CODE = POHEADER-COMP_CODE.

                    *

                    • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

                    • EXPORTING

                    • TYPE = c_msgtype_e

                    • CL = c_msgid_z001

                    • NUMBER = c_msgnr_046

                    • PAR1 = L_CONST_NAME

                    • PAR2 = L_COMP_CODE

                    • IMPORTING

                    • RETURN = RETURN.

                    *

                    • APPEND RETURN.

                    • CLEAR RETURN.

                    *

                    • loop at t_yreturn.

                    • L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

                    • L_WA_ZERRORS-serial_no = sy-tabix.

                    • L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

                    • L_WA_ZERRORS-zid = t_yreturn-id.

                    • L_WA_ZERRORS-znumber = t_yreturn-number.

                    • L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

                    • L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

                    • L_WA_ZERRORS-ZDATE = sy-datum.

                    • L_WA_ZERRORS-ERR_MSG = t_yreturn-message.

                    • append L_WA_ZERRORS to t_errors.

                    • insert into ZP2P_ERRORS values L_WA_ZERRORS.

                  • clear: L_WA_ZERRORS.

                  • endloop.

                  • EXIT.

                  • ELSE.

                  • POHEADER-PUR_GROUP = G_CONSTVAL.

                  • ENDIF.

                  • ENDIF.

                  • *

                    • data: l_werks1 type werks_d.

                    • LOOP AT poitem.

                    • if poitem-plant is initial.

                    • clear: l_werks1.

                    • select single plant

                    • into l_werks1

                    • from zpo_plantmapping

                    • where COMPANY_CODE = poheader-comp_code and

                    • PUR_ORG = poheader-purch_org and

                    • PUR_GROUP = poheader-pur_group and

                    • LE = poheader-le and

                    • FSID = poheader-fsid and

                    • FRMRC = poheader-frmrc.

                    • if sy-subrc ne 0.

                    • PERFORM ERROR_HANDLING_PLANT USING POHEADER

                    • poheader-comp_code

                    • L_WA_ZERRORS.

                    • EXIT.

                    • else.

                    • poitem-plant = l_werks1.

                    • CLEAR: L_WERKS1.

                    • endif.

                    • endif.

                    • IF POITEM-NET_PRICE NE POHEADER-CURRENCY.

                    • POITEM-NET_PRICE = POHEADER-CURRENCY.

                    • ENDIF.

                    *

                    • IF POITEM-net_price NE 0.

                    • POITEM-IR_IND = 'X'.

                    • ENDIF.

                    *

                    • POITEM-UNLIMITED_DLV = 'X'.

                    • POITEM-UNDER_DLV_TOL = 0.

                    • clear: poitem-ARIBACRTTIMESTMP,

                    • poitem-ARIBAUPDTIMESTMP.

                    *

                    • MODIFY POITEM TRANSPORTING UNLIMITED_DLV

                    • UNDER_DLV_TOL

                    • PLANT

                    • IR_IND

                    • ARIBACRTTIMESTMP

                    • ARIBAUPDTIMESTMP.

                    *

                    *

                    • ENDLOOP.

                    **********************************************************

                    *mod-003

                    ***********************************************************

                    if not poheader-currency is initial.

                    if not poheader-vendor is initial.

                    loop at pocond.

                    SELECT SINGLE WAERS

                    INTO L_WAERS

                    FROM LFM1 WHERE

                    LIFNR = POHEADER-VENDOR

                    AND EKORG = POHEADER-PURCH_ORG.

                    IF SY-SUBRC NE 0.

                    IF L_WAERS NE poheader-currency.

                    pocond-cond_value = 'PBXX'.

                    pocond-currency = l_waers.

                    modify pocond transporting cond_value currency.

                    endif.

                    ENDIF.

                    endloop.

                    ENDIF.

                    ENDIF.

                    IF NOT TESTRUN IS INITIAL.

                    POHEADER-VENDOR = '4259999999'.

                    poheader-doc_type = 'ZAPS'.

                    ENDIF.

                    • IF NOT POHEADER-PURCH_ORG IS INITIAL.

                    • IF POHEADER-PURCH_ORG IS INITIAL.

                    • SELECT SINGLE PUR_ORG

                    • INTO L_EKORG

                    • FROM ZPUR_ORG

                    • WHERE LE = POHEADER-LE AND

                    • FRMRC = POHEADER-FRMRC AND

                    • FSID = POHEADER-FSID.

                    *

                    • IF SY-SUBRC NE 0.

                    • CLEAR : L_CONST_NAME,

                    • L_COMP_CODE.

                    *

                    • L_CONST_NAME = C_p2p_pur_ORG.

                    • L_COMP_CODE = POHEADER-COMP_CODE.

                    *

                    • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

                    • EXPORTING

                    • TYPE = c_msgtype_e

                    • CL = c_msgid_z001

                    • NUMBER = c_msgnr_619

                    • PAR1 = L_CONST_NAME

                    • PAR2 = L_COMP_CODE

                    • IMPORTING

                    • RETURN = RETURN.

                    *

                    • APPEND RETURN.

                    • CLEAR RETURN.

                    *

                    • loop at t_yreturn.

                    • L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

                    • L_WA_ZERRORS-serial_no = sy-tabix.

                    • L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

                    • L_WA_ZERRORS-zid = t_yreturn-id.

                    • L_WA_ZERRORS-znumber = t_yreturn-number.

                    • L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

                    • L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

                    • L_WA_ZERRORS-ZDATE = sy-datum.

                    • L_WA_ZERRORS-ERR_MSG = t_yreturn-message.

                    • append L_WA_ZERRORS to t_errors.

                    • insert into ZP2P_ERRORS values L_WA_ZERRORS.

                  • clear: L_WA_ZERRORS.

                  • endloop.

                  • EXIT.

                  • ELSE.

                  • POHEADER-PURCH_ORG = L_EKORG.

                  • ENDIF.

                  • ENDIF.

                  • *

                      • IF NOT POHEADER-PUR_GROUP IS INITIAL.

                    • IF POHEADER-PUR_GROUP IS INITIAL.

                    • clear: g_constval.

                    • CALL FUNCTION 'ZXA_GET_CONSTANT'

                    • EXPORTING

                    • const_name = c_p2p_pur_org

                    • comp_code = POHEADER-COMP_CODE

                    • IMPORTING

                    • const_value = g_constval

                    • EXCEPTIONS

                    • no_value_found = 1

                    • null_value = 2

                    • OTHERS = 3.

                    • *

                      *

                      • IF SY-SUBRC NE 0.

                      • CLEAR : L_CONST_NAME,

                      • L_COMP_CODE.

                      *

                      • L_CONST_NAME = C_p2p_pur_org.

                      • L_COMP_CODE = POHEADER-COMP_CODE.

                      *

                      • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

                      • EXPORTING

                      • TYPE = c_msgtype_e

                      • CL = c_msgid_z001

                      • NUMBER = c_msgnr_046

                      • PAR1 = L_CONST_NAME

                      • PAR2 = L_COMP_CODE

                      • IMPORTING

                      • RETURN = RETURN.

                      *

                      • APPEND RETURN.

                      • CLEAR RETURN.

                      *

                      • loop at return.

                      • L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

                      • L_WA_ZERRORS-serial_no = sy-tabix.

                      • L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

                      • L_WA_ZERRORS-zid = return-id.

                      • L_WA_ZERRORS-znumber = return-number.

                      • L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

                      • L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

                      • L_WA_ZERRORS-ZDATE = sy-datum.

                      • L_WA_ZERRORS-ERR_MSG = return-message.

                      • append L_WA_ZERRORS to t_errors.

                      • insert into ZP2P_ERRORS values L_WA_ZERRORS.

                    • clear: L_WA_ZERRORS.

                    • endloop.

                    • EXIT.

                    • ELSE.

                    • POHEADER-PUR_GROUP = G_CONSTVAL.

                    • ENDIF.

                    • ENDIF.

                    • **********************************************************

                      *mod-003

                      ***********************************************************

                      *-- Retrieve Account Assignment

                      PERFORM get_account_assignment TABLES poitem

                      poitemx

                      poaccount

                      poaccountx

                      t_yreturn

                      USING poheader-comp_code

                      poheader.

                      ****************************************************

                      *mod-003

                      ****************************************************

                      IF NOT t_yreturn[] IS INITIAL.

                      APPEND LINES OF t_yreturn TO RETURN.

                      loop at return.

                      L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

                      L_WA_ZERRORS-serial_no = sy-tabix.

                      L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

                      L_WA_ZERRORS-zid = return-id.

                      L_WA_ZERRORS-znumber = return-number.

                      L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

                      L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

                      L_WA_ZERRORS-ZDATE = sy-datum.

                      L_WA_ZERRORS-ERR_MSG = return-message.

                      append L_WA_ZERRORS to t_errors.

                      clear: L_WA_ZERRORS.

                      endloop.

                      SELECT max( serial_no )

                      INTO L_SERIAL

                      FROM ZP2P_ERRORS.

                      LOOP AT T_ERRORS.

                      L_SERIAL = L_SERIAL + 1.

                      T_ERRORS-serial_no = L_SERIAL.

                      MODIFY T_ERRORS TRANSPORTING serial_no.

                      ENDLOOP.

                      INSERT ZP2P_ERRORS FROM TABLE T_ERRORS.

                      ENDIF.

                      READ TABLE t_yreturn WITH KEY type = 'E'.

                      IF sy-subrc = 0.

                      EXIT.

                      ENDIF.

                      *For Non-PCO Orders, do not update the GR and IR Indicator if the

                      *indicator passed in the current run is same as in PO.

                      SORT poitem BY po_item.

                      SORT poitemx BY po_item.

                      LOOP AT poitem.

                      SELECT SINGLE wepos "Goods receipt indicator

                      repos "Invoice receipt indicator

                      INTO (ekpo-wepos, ekpo-repos)

                      FROM ekpo

                      WHERE ebeln = purchaseorder AND

                      ebelp = poitem-po_item.

                      IF sy-subrc EQ 0.

                      IF ekpo-wepos EQ poitem-gr_ind.

                      READ TABLE poitemx

                      WITH KEY po_item = poitem-po_item

                      BINARY SEARCH.

                      IF sy-subrc EQ 0.

                      CLEAR poitemx-gr_ind.

                      MODIFY poitemx INDEX sy-tabix.

                      ENDIF.

                      ENDIF.

                      IF ekpo-repos EQ poitem-ir_ind.

                      READ TABLE poitemx

                      WITH KEY po_item = poitem-po_item

                      BINARY SEARCH.

                      IF sy-subrc EQ 0.

                      CLEAR poitemx-ir_ind.

                      MODIFY poitemx INDEX sy-tabix.

                      ENDIF.

                      ENDIF.

                      ENDIF.

                      ENDLOOP.

                      *Logic for addition, deletion and change of records in

                      *account assignment

                      LOOP AT poaccount.

                      CLEAR g_t_poaccount_tmp.

                      MOVE-CORRESPONDING poaccount TO g_t_poaccount_tmp.

                      APPEND g_t_poaccount_tmp.

                      ADD 1 TO g_cnt_poaccount.

                      AT END OF po_item.

                      SORT g_t_poaccount_tmp.

                      • For single account assignment, if the goods receipt is not posted,

                      • set the non-valuated indicator to blank.

                      IF g_cnt_poaccount EQ 1.

                      SELECT belnr "History per Purchasing Document

                      INTO ekbe-belnr

                      FROM ekbe

                      UP TO 1 ROWS

                      WHERE ebeln = purchaseorder AND

                      ebelp = g_t_poaccount_tmp-po_item AND

                      vgabe = 1.

                      ENDSELECT.

                      IF sy-subrc NE 0.

                      *PVU-08-May-2004 - Set the no valuated GR indicator to blank in POITEM

                      READ TABLE poitem

                      WITH KEY po_item = g_t_poaccount_tmp-po_item

                      BINARY SEARCH.

                      IF sy-subrc EQ 0.

                      CLEAR poitem-gr_non_val .

                      MODIFY poitem INDEX sy-tabix.

                      ENDIF.

                      *PVU-08-May-2004 - End of Set the no valuated GR indicator to blank

                      READ TABLE poitemx

                      WITH KEY po_item = g_t_poaccount_tmp-po_item

                      BINARY SEARCH.

                      IF sy-subrc EQ 0.

                      poitemx-gr_non_val = c_checked.

                      MODIFY poitemx INDEX sy-tabix.

                      ENDIF.

                      ENDIF.

                      ENDIF.

                      CLEAR: ekkn.

                      SELECT * FROM ekkn

                      WHERE ebeln = purchaseorder AND

                      ebelp = poaccount-po_item

                      ORDER BY zekkn.

                      ADD 1 TO g_cnt_ekkn.

                      **BV-12-July-2004- Begin of change - split line accounting

                      *clear the headerline before data population

                      CLEAR : g_t_poaccount1,

                      g_t_poaccountx1.

                      **BV-12-July-2004- End of change - split line accounting

                      READ TABLE g_t_poaccount_tmp INDEX g_cnt_ekkn.

                      IF sy-subrc EQ 0.

                      g_t_poaccount1-po_item = g_t_poaccount_tmp-po_item.

                      g_t_poaccount1-serial_no = ekkn-zekkn.

                      g_t_poaccount1-quantity = g_t_poaccount_tmp-quantity.

                      g_t_poaccount1-gl_account = g_t_poaccount_tmp-gl_account.

                      READ TABLE poitem

                      WITH KEY po_item = poaccount-po_item. "dd

                      *PVU-11-May-2004-Set cost center or WBS element depending on acc.assgn.

                      IF poitem-acctasscat = c_costcenter. "K

                      g_t_poaccount1-costcenter = g_t_poaccount_tmp-costcenter .

                      ELSEIF poitem-acctasscat = c_wbs. "P

                      g_t_poaccount1-wbs_element = g_t_poaccount_tmp-wbs_element.

                      ENDIF.

                      *PVU-11-May-2004-End of set cost center or WBS element.

                      g_t_poaccount1-orderid = g_t_poaccount_tmp-orderid.

                      g_t_poaccount1-distr_perc = g_t_poaccount_tmp-distr_perc.

                      APPEND g_t_poaccount1.

                      g_t_poaccountx1-po_item = g_t_poaccount_tmp-po_item.

                      g_t_poaccountx1-serial_no = ekkn-zekkn.

                      g_t_poaccountx1-po_itemx = c_checked.

                      g_t_poaccountx1-quantity = c_checked.

                      g_t_poaccountx1-gl_account = c_checked.

                      *PVU-11-May-2004-Set cost center or WBS element depending on acc.assgn.

                      IF poitem-acctasscat = c_costcenter. "K

                      g_t_poaccountx1-costcenter = c_checked.

                      ELSEIF poitem-acctasscat = c_wbs. "P

                      g_t_poaccountx1-wbs_element = c_checked.

                      ENDIF.

                      *PVU-11-May-2004-End of set cost center or WBS element.

                      g_t_poaccountx1-orderid = c_checked.

                      g_t_poaccountx1-distr_perc = c_checked.

                      APPEND g_t_poaccountx1.

                      *If line is deleted from account assignment in Ariba

                      *then delete that line from SAP PO

                      ELSE.

                      g_t_poaccount1-po_item = g_t_poaccount_tmp-po_item.

                      g_t_poaccount1-serial_no = ekkn-zekkn.

                      g_t_poaccount1-delete_ind = c_checked.

                      g_t_poaccount1-quantity = ekkn-menge.

                      g_t_poaccount1-gl_account = ekkn-sakto.

                      *PVU-11-May-2004-Set cost center or WBS element depending on acc.assgn.

                      IF poitem-acctasscat = c_costcenter. "K

                      g_t_poaccount1-costcenter = ekkn-kostl.

                      ELSEIF poitem-acctasscat = c_wbs. "P

                      g_t_poaccount1-wbs_element = ekkn-ps_psp_pnr.

                      ENDIF.

                      *PVU-11-May-2004-End of set cost center or WBS element.

                      g_t_poaccount1-orderid = ekkn-aufnr.

                      APPEND g_t_poaccount1.

                      g_t_poaccountx1-po_item = g_t_poaccount_tmp-po_item.

                      g_t_poaccountx1-serial_no = ekkn-zekkn.

                      g_t_poaccountx1-po_itemx = c_checked.

                      g_t_poaccountx1-delete_ind = c_checked.

                      g_t_poaccountx1-quantity = c_checked.

                      g_t_poaccountx1-gl_account = c_checked.

                      *PVU-11-May-2004-Set cost center or WBS element depending on acc.assgn.

                      IF poitem-acctasscat = c_costcenter. "K

                      g_t_poaccountx1-costcenter = c_checked.

                      ELSEIF poitem-acctasscat = c_wbs. "P

                      g_t_poaccountx1-wbs_element = c_checked.

                      ENDIF.

                      *PVU-11-May-2004-End of set cost center or WBS element.

                      g_t_poaccountx1-orderid = c_checked.

                      APPEND g_t_poaccountx1.

                      ENDIF.

                      SUBTRACT 1 FROM g_cnt_poaccount.

                      ENDSELECT.

                      **BV-12-July-2004- Begin of change - split line accounting

                      *clear the headerline before data population

                      CLEAR : g_t_poaccount1,

                      g_t_poaccountx1.

                      **BV-12-July-2004- End of change - split line accounting

                      • If new lines are added to account assignment in Ariba

                      • add those lines to SAP PO

                      IF g_cnt_poaccount GT 0.

                      g_cnt_ekkn = ekkn-zekkn.

                      SORT g_t_poaccount_tmp DESCENDING BY serial_no.

                      LOOP AT g_t_poaccount_tmp.

                      ADD 1 TO g_cnt_ekkn.

                      g_t_poaccount1-po_item = g_t_poaccount_tmp-po_item.

                      g_t_poaccount1-serial_no = g_cnt_ekkn.

                      g_t_poaccount1-quantity = g_t_poaccount_tmp-quantity.

                      g_t_poaccount1-gl_account = g_t_poaccount_tmp-gl_account.

                      *PVU-11-May-2004-Set cost center or WBS element depending on acc.assgn.

                      IF poitem-acctasscat = c_costcenter. "K

                      g_t_poaccount1-costcenter = g_t_poaccount_tmp-costcenter.

                      ELSEIF poitem-acctasscat = c_wbs. "P

                      g_t_poaccount1-wbs_element = g_t_poaccount_tmp-wbs_element.

                      ENDIF.

                      *PVU-11-May-2004-End of set cost center or WBS element.

                      g_t_poaccount1-orderid = g_t_poaccount_tmp-orderid.

                      g_t_poaccount1-distr_perc = g_t_poaccount_tmp-distr_perc.

                      APPEND g_t_poaccount1.

                      g_t_poaccountx1-po_item = g_t_poaccount_tmp-po_item.

                      g_t_poaccountx1-serial_no = g_cnt_ekkn.

                      g_t_poaccountx1-po_itemx = c_checked.

                      g_t_poaccountx1-quantity = c_checked.

                      g_t_poaccountx1-gl_account = c_checked.

                      *PVU-11-May-2004-Set cost center or WBS element depending on acc.assgn.

                      IF poitem-acctasscat = c_costcenter. "K

                      g_t_poaccountx1-costcenter = c_checked.

                      ELSEIF poitem-acctasscat = c_wbs. "P

                      g_t_poaccountx1-wbs_element = c_checked.

                      ENDIF.

                      *PVU-11-May-2004-End of set cost center or WBS element.

                      g_t_poaccountx1-orderid = c_checked.

                      g_t_poaccountx1-distr_perc = c_checked.

                      APPEND g_t_poaccountx1.

                      SUBTRACT 1 FROM g_cnt_poaccount.

                      IF g_cnt_poaccount EQ 0.

                      EXIT.

                      ENDIF.

                      ENDLOOP.

                      ENDIF.

                      CLEAR: g_cnt_poaccount, g_cnt_ekkn.

                      REFRESH g_t_poaccount_tmp.

                      ENDAT.

                      ENDLOOP.

                      REFRESH: poaccount, poaccountx.

                      CLEAR: poaccount, poaccountx.

                      APPEND LINES OF g_t_poaccount1 TO poaccount.

                      APPEND LINES OF g_t_poaccountx1 TO poaccountx.

                      REFRESH: g_t_poaccount1, g_t_poaccountx1.

                      SORT: poaccount, poaccountx.

                      *For POs Converted from legacy system, populate the item quantity and

                      *price based on the original purchase order qty/price. Also, populate

                      *the actual qty and price passed by Ariba in the Net weight and gross

                      *weight fields.

                      LOOP AT poitem.

                      CLEAR: ekpo.

                      SELECT SINGLE menge "Purchase order quantity

                      netpr "Net price in PO

                      INTO (ekpo-menge, ekpo-netpr)

                      FROM ekpo

                      WHERE ebeln EQ purchaseorder AND

                      ebelp EQ poitem-po_item. "AND

                      IF sy-subrc EQ 0.

                      • Turn off Final Invoice Indicator if net price or quantity is higher

                      • than the existing value.

                      IF poitem-quantity GT ekpo-menge OR

                      poitem-net_price GT ekpo-netpr.

                      CLEAR poitem-final_inv.

                      READ TABLE poitemx

                      WITH KEY po_item = poitem-po_item

                      BINARY SEARCH.

                      IF sy-subrc EQ 0.

                      poitemx-final_inv = c_checked.

                      MODIFY poitemx INDEX sy-tabix.

                      ENDIF.

                      ENDIF.

                      MODIFY poitem.

                      ENDIF.

                      ENDLOOP.

                      *endif.

                      ****Start of changes by Balaji V - 08-June-04

                      ****Zero Pad and Prefix 1 to Vendor.

                      DATA : L_LENGTH TYPE I.

                      "Vendor string length.

                      • L_MSGV1 LIKE SY-MSGV1. "Message variable1

                      IF NOT POHEADER-VENDOR IS INITIAL.

                      *remove any leading zeros for vendor populated from webmethods

                      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

                      EXPORTING

                      INPUT = POHEADER-VENDOR

                      IMPORTING

                      OUTPUT = POHEADER-VENDOR.

                      L_LENGTH = STRLEN( POHEADER-VENDOR ).

                      IF L_LENGTH < 10.

                      *To pad leading zeros to Vendor

                      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                      EXPORTING

                      INPUT = POHEADER-VENDOR

                      IMPORTING

                      OUTPUT = POHEADER-VENDOR.

                      *To replace first character with 1.

                      MOVE '1' TO POHEADER-VENDOR(1).

                      ELSE. "Vendor is 10 char in length

                      CLEAR L_MSGV1.

                      L_MSGV1 = POHEADER-VENDOR.

                      *Zero Padding and Prefixing 1 Not possible.Vendor is 10 Character

                      *length

                      CALL FUNCTION 'BALW_BAPIRETURN_GET2'

                      EXPORTING

                      TYPE = C_MSGTYPE_I "I

                      CL = C_MSGID_Z001 "Z001

                      NUMBER = C_MSGNR_040 "040

                      PAR1 = L_MSGV1

                      IMPORTING

                      RETURN = RETURN.

                      APPEND RETURN.

                      CLEAR RETURN.

                      loop at return.

                      L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

                      L_WA_ZERRORS-serial_no = sy-tabix.

                      L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

                      L_WA_ZERRORS-zid = return-id.

                      L_WA_ZERRORS-znumber = return-number.

                      L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

                      L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

                      L_WA_ZERRORS-ZDATE = sy-datum.

                      L_WA_ZERRORS-ERR_MSG = return-message.

                      append L_WA_ZERRORS to t_errors.

                      • insert into ZP2P_ERRORS values L_WA_ZERRORS.

                      clear: L_WA_ZERRORS.

                      endloop.

                      ENDIF.

                      ENDIF.

                      ****End of changes by Balaji V - 08-June-04

                      **********************************************************

                      *mod-003

                      ***********************************************************

                      ****************************************************

                      *mod-003

                      ****************************************************

                      • if not poheader-comp_code is initial.

                      • select single companycode

                      • into l_bukrs

                      • from zcompanycodes01

                      • where companycode = poheader-comp_code and

                      • FSID = poheader-fsid and

                      • le = poheader-le and

                      • frmrc = poheader-frmrc.

                      *

                      • if sy-subrc ne 0.

                      • CLEAR L_MSGV1.

                      • L_MSGV1 = POACCOUNT-PO_ITEM.

                      • Please Enter an Account number for line

                    • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

                    • EXPORTING

                    • TYPE = C_MSGTYPE_E

                    • CL = C_MSGID_Z001

                    • NUMBER = C_MSGNR_618

                    • PAR1 = L_MSGV1

                    • IMPORTING

                    • RETURN = RETURN.

                    • *

                      • APPEND RETURN.

                      • CLEAR RETURN.

                      • loop at return.

                      • L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

                      • L_WA_ZERRORS-serial_no = sy-tabix.

                      • L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

                      • L_WA_ZERRORS-zid = return-id.

                      • L_WA_ZERRORS-znumber = return-number.

                      • L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

                      • L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

                      • L_WA_ZERRORS-ZDATE = sy-datum.

                      • L_WA_ZERRORS-ERR_MSG = return-message.

                      • append L_WA_ZERRORS to t_errors.

                      • insert into ZP2P_ERRORS values L_WA_ZERRORS.

                    • clear: L_WA_ZERRORS.

                    • endloop.

                    • *

                      • ELSE.

                      • poheader-comp_code = l_bukrs.

                      • endif.

                      • endif.

                      **********************************************************

                      *mod-003

                      ***********************************************************

                      if not poheader-currency is initial.

                      if not poheader-vendor is initial.

                      loop at pocond.

                      SELECT SINGLE WAERS

                      INTO L_WAERS

                      FROM LFM1 WHERE

                      LIFNR = POHEADER-VENDOR

                      AND EKORG = POHEADER-PURCH_ORG.

                      IF SY-SUBRC NE 0.

                      IF L_WAERS NE poheader-currency.

                      pocond-cond_value = 'PBXX'.

                      pocond-currency = l_waers.

                      modify pocond transporting cond_value currency.

                      endif.

                      ENDIF.

                      endloop.

                      ENDIF.

                      ENDIF.

                      **********************************************************

                      *mod-003

                      ***********************************************************

                      • IF NOT TESTRUN IS INITIAL.

                      • POHEADER-VENDOR = '4259999999'.

                      • poheader-doc_type = 'ZAP'.

                      • ENDIF.

                      **********************************************************

                      *mod-003

                      ***********************************************************

                      **********************************************************

                      *mod-003

                      ***********************************************************

                      • IF NOT POHEADER-PURCH_ORG IS INITIAL.

                      • SELECT SINGLE PUR_ORG

                      • INTO L_EKORG

                      • FROM ZPUR_ORG

                      • WHERE LE = POHEADER-LE AND

                      • FRMRC = POHEADER-FRMRC AND

                      • FSID = POHEADER-FSID.

                      *

                      • IF SY-SUBRC NE 0.

                      • CLEAR : L_CONST_NAME,

                      • L_COMP_CODE.

                      *

                      • L_CONST_NAME = C_p2p_pur_ORG.

                      • L_COMP_CODE = POHEADER-COMP_CODE.

                      *

                      • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

                      • EXPORTING

                      • TYPE = c_msgtype_e

                      • CL = c_msgid_z001

                      • NUMBER = c_msgnr_619

                      • PAR1 = L_CONST_NAME

                      • PAR2 = L_COMP_CODE

                      • IMPORTING

                      • RETURN = RETURN.

                      *

                      • APPEND RETURN.

                      • CLEAR RETURN.

                      *

                      • loop at return.

                      • L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

                      • L_WA_ZERRORS-serial_no = sy-tabix.

                      • L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

                      • L_WA_ZERRORS-zid = return-id.

                      • L_WA_ZERRORS-znumber = return-number.

                      • L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

                      • L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

                      • L_WA_ZERRORS-ZDATE = sy-datum.

                      • L_WA_ZERRORS-ERR_MSG = return-message.

                      • append L_WA_ZERRORS to t_errors.

                      • insert into ZP2P_ERRORS values L_WA_ZERRORS.

                    • clear: L_WA_ZERRORS.

                    • endloop.

                    • EXIT.

                    • ELSE.

                    • POHEADER-PURCH_ORG = L_EKORG.

                    • ENDIF.

                    • ENDIF.

                    • **********************************************************

                      *mod-003

                      **********************************************************

                      LOOP AT POITEM.

                      l_wa_timestamp-mandt = SY-MANDT.

                      l_wa_timestamp-EBELN = POHEADER-PO_NUMBER.

                      l_wa_timestamp-EBELP = POITEM-PO_ITEM.

                      l_wa_timestamp-CHANGE_IND = ' '.

                      l_wa_timestamp-DATE_TIME_STMP = POHEADER-ARIBACHGTIMESTMP.

                      insert into ZP2P_TIMESTAMP values l_wa_timestamp.

                      ENDLOOP.

                      DATA: g_constval(10) type c.

                      IF NOT POHEADER-PUR_GROUP IS INITIAL.

                      clear: g_constval.

                      CALL FUNCTION 'ZXA_GET_CONSTANT'

                      EXPORTING

                      const_name = c_p2p_pur_org

                      comp_code = POHEADER-COMP_CODE

                      IMPORTING

                      const_value = g_constval

                      EXCEPTIONS

                      no_value_found = 1

                      null_value = 2

                      OTHERS = 3.

                      IF SY-SUBRC NE 0.

                      CLEAR : L_CONST_NAME,

                      L_COMP_CODE.

                      L_CONST_NAME = C_p2p_pur_org.

                      L_COMP_CODE = POHEADER-COMP_CODE.

                      CALL FUNCTION 'BALW_BAPIRETURN_GET2'

                      EXPORTING

                      TYPE = c_msgtype_e

                      CL = c_msgid_z001

                      NUMBER = c_msgnr_619

                      PAR1 = L_CONST_NAME

                      PAR2 = L_COMP_CODE

                      IMPORTING

                      RETURN = RETURN.

                      APPEND RETURN.

                      CLEAR RETURN.

                      loop at return.

                      L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

                      L_WA_ZERRORS-serial_no = sy-tabix.

                      L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

                      L_WA_ZERRORS-zid = return-id.

                      L_WA_ZERRORS-znumber = return-number.

                      L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

                      L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

                      L_WA_ZERRORS-ZDATE = sy-datum.

                      L_WA_ZERRORS-ERR_MSG = return-message.

                      append L_WA_ZERRORS to t_errors.

                      • insert into ZP2P_ERRORS values L_WA_ZERRORS.

                      clear: L_WA_ZERRORS.

                      endloop.

                      EXIT.

                      ELSE.

                      POHEADER-PUR_GROUP = G_CONSTVAL.

                      ENDIF.

                      ENDIF.

                      **********************************************************

                      *mod-003

                      **********************************************************

                      IF purchaseorder(3) = c_pco. "PCO

                      &----


                      &

                      *& Begin of Change: 26-Sep-2005 SDUTTARO RD1K910989 *&

                      &----


                      &
                      • Map the external fields for ALZA with account assignment

                      • IF poheader-comp_code = c_bukrs_alza. "@SDR

                      **-- Retrieve Account Assignment

                      PERFORM get_account_assignment TABLES poitem "@SDR

                      poitemx "@SDR

                      poaccount "@SDR

                      poaccountx "@SDR

                      t_yreturn "@SDR

                      USING poheader-comp_code "@SDR

                      poheader. "@SDR

                      • ENDIF. "@SDR

                      &----


                      &

                      **& Begin of Change: 26-Sep-2005 SDUTTARO RD1K910989 *&

                      *&----


                      &

                        • For PCO Order, populate the PO and accounting data into a Z table and

                        • exit the program run.

                      • PERFORM populate_nonpo_document TABLES poitem

                      • return

                      • potextheader

                      • USING purchaseorder

                      • poheader.

                      • PERFORM populate_nonpo_accounting TABLES poaccount

                      • return

                      • USING poheader.

                      • **&&---Begin of Addition: Soumya D Roy: 03/10/2006

                          • To make sure that the ztables do not get updated in case of

                          • checkpoints 1, 2 and get updated only after approval

                        • IF testrun IS INITIAL. "SDR

                        • **&&---End of Addition: Soumya D Roy: 03/10/2006

                          • PERFORM update_nonpodocument.

                          **&&---Begin of Addition: Soumya D Roy: 03/10/2006

                            • To delete PCOs. No deletion code is required for CRs & UTs

                            • as these two cannot be deleted

                          • ENDIF. "@SDR

                          • **&&---End of Addition: Soumya D Roy: 03/10/2006

                            • LOOP AT t_return.

                            • MOVE: t_return-type TO return-type,

                            • t_return-number TO return-number,

                            • t_return-message TO return-message.

                            • APPEND return.

                            • CLEAR return.

                            • ENDLOOP.

                            *&&&&&---- Begin of Addition: Soumya D Roy: 03/02/2006

                            • Code to build the message table for output to Ariba

                            • for PCOs

                            *GENERATE CUSTOM RETURN MESSAGES BASED ON MESSAGE ID AND NUMBER FROM

                            *maintenance table ZMESSAGES

                            • CALL FUNCTION 'Z_MM_BUILD_MESSAGES'

                            • TABLES

                            • return = return.

                            *

                            • SORT return BY type id number.

                            • READ TABLE return

                            • WITH KEY id = space

                            • number = c_msgnr_000 "000

                            • BINARY SEARCH.

                            *

                            • IF sy-subrc EQ 0 AND sy-tabix NE 1.

                            • DELETE return INDEX sy-tabix.

                            • INSERT return INDEX 1.

                            • ENDIF.

                            **&&&&----- End of Addition: Soumya D Roy: 03/02/2006

                            • EXIT.

                            ENDIF.

                            *

                            *-- Round off to 100 percent due to small difference in one decimal

                            *-- point rounding (in Ariba/wM)

                            SORT poaccount BY po_item distr_perc.

                            LOOP AT poaccount.

                            ADD poaccount-distr_perc TO g_distr_perc.

                            AT END OF po_item.

                            *-- Round off to 100 percent due to small difference in one decimal

                            *-- point rounding (in Ariba/wM)

                            IF g_distr_perc GT 0.

                            g_distr_perc = 100 - g_distr_perc.

                            g_adjust_perc = c_checked.

                            ENDIF.

                            ENDAT.

                            IF g_adjust_perc = c_checked.

                            g_distr_perc1 = g_distr_perc + poaccount-distr_perc.

                            IF g_distr_perc1 = 100.

                            poaccount-distr_perc = 0.

                            ELSE.

                            poaccount-distr_perc = g_distr_perc1.

                            ENDIF.

                            MODIFY poaccount.

                            CLEAR poaccount.

                            CLEAR: g_distr_perc, g_distr_perc1.

                            ENDIF.

                            CLEAR g_adjust_perc.

                            ENDLOOP.

                            SORT poaccount.

                            SORT poschedule BY po_item sched_line.

                            SORT poschedulex BY po_item sched_line.

                            *PVU-20-May-2004 - Start Changes for SCR1

                            ***************************************************

                            **MOD-003

                            **************************************************

                            *Populate the change indicator structures before calling BAPI_PO_CHANGE

                            *so that IDOC can be populated with this data

                            IF NOT poheaderx IS INITIAL.

                            g_w_hdrx_tmp = poheaderx.

                            ENDIF.

                            IF NOT poitemx[] IS INITIAL.

                            g_t_itemx_tmp[] = poitemx[].

                            ENDIF.

                            IF NOT poschedulex[] IS INITIAL.

                            g_t_schdx_tmp[] = poschedulex[].

                            ENDIF.

                            IF NOT poaccountx[] IS INITIAL.

                            g_t_accntx_tmp[] = poaccountx[].

                            ENDIF.

                            IF NOT pocondx[] IS INITIAL.

                            g_t_condx_tmp[] = pocondx[].

                            ENDIF.

                            ***************************************************

                            **MOD-003

                            **************************************************

                            *PVU-20-May-2004 - End Changes for SCR1

                            *sraman2 06/28/04

                            *-- Default the Material Group to 99 if the incoming commodity

                            *-- code don't exist in SAP

                            LOOP AT poitem.

                            SELECT SINGLE matkl INTO t023-matkl FROM t023

                            WHERE matkl = poitem-matl_group.

                            IF sy-subrc NE 0.

                            MOVE: '99' TO poitem-matl_group.

                            MODIFY poitem.

                            ENDIF.

                            CLEAR poitem.

                            ENDLOOP.

                            *sraman2 06/28/04

                            *&---Begin of Addition: Soumya D Roy: 03/27/2006

                            • Logic for PO changes which are listed in table ZCONVERTEDPOS.

                            • ZCONVERTEDPOS contains Purchase Orders ie. both Material and

                            • Service which have either NONVAL GR checked or GR checked respectively

                            • and are invoiced. Any changes to these POs from Ariba would not let

                            • other quantity or amount or text description changes to flow into SAP.

                            • This piece of code will keep the Indicators' status same as in SAP

                            • and also let the user perform the change.

                            *Begin of change by svalidet RD1K911990

                            • IF purchaseorder+0(3) = '099'.

                            • IF purchaseorder+0(3) in r_ehub_pos[].

                            *End of change by svalidet RD1K911990

                            CALL FUNCTION 'Z_CONVERTED_POS'

                            EXPORTING

                            P_PURCHASEORDER = purchaseorder

                            P_POHEADER = poheader

                            TABLES

                            P_POITEM = poitem

                            P_POITEMX = poitemx.

                            • ENDIF.

                            **************************************************************

                            *mod-003

                            **************************************************************

                            • perform get_uom_conversion tables poitem

                            • POITEMX

                            • poaccount

                            • poaccountx

                            • poschedule

                            • poschedulex

                            • changing poheader

                            • poheaderx.

                            perform get_uom_conversion tables poitem

                            POITEMX

                            poaccount

                            poaccountx

                            poschedule

                            poschedulex

                            pocond

                            pocondx

                            Pocondheader

                            pocondheaderx

                            changing poheader

                            poheaderx.

                            **************************************************************

                            *mod-003

                            **************************************************************

                            *Populate the change indicator structures before calling BAPI_PO_CHANGE

                            *so that IDOC can be populated with this data

                            IF NOT poheaderx IS INITIAL.

                            g_w_hdrx_tmp = poheaderx.

                            ENDIF.

                            IF NOT poitemx[] IS INITIAL.

                            g_t_itemx_tmp[] = poitemx[].

                            ENDIF.

                            IF NOT poschedulex[] IS INITIAL.

                            g_t_schdx_tmp[] = poschedulex[].

                            ENDIF.

                            IF NOT poaccountx[] IS INITIAL.

                            g_t_accntx_tmp[] = poaccountx[].

                            ENDIF.

                            IF NOT pocondx[] IS INITIAL.

                            g_t_condx_tmp[] = pocondx[].

                            ENDIF.

                            ***************************************************

                            **MOD-003

                            **************************************************

                            CALL FUNCTION 'BAPI_PO_CHANGE'

                            EXPORTING

                            purchaseorder = purchaseorder

                            poheader = poheader

                            poheaderx = poheaderx

                            poaddrvendor = poaddrvendor

                            testrun = testrun

                            memory_uncomplete = memory_uncomplete

                            memory_complete = memory_complete

                            • poexpimpheader = poexpimpheader

                            • poexpimpheaderx = poexpimpheaderx

                            • versions = versions

                            • no_messaging = no_messaging

                            • no_message_req = no_message_req

                            • no_authority = no_authority

                            • no_price_from_po = no_price_from_po

                            IMPORTING

                            expheader = expheader

                            • exppoexpimpheader = exppoexpimpheader

                            TABLES

                            return = return

                            poitem = poitem

                            poitemx = poitemx

                            poaddrdelivery = poaddrdelivery

                            poschedule = poschedule

                            poschedulex = poschedulex

                            poaccount = poaccount

                            poaccountprofitsegment = poaccountprofitsegment

                            poaccountx = poaccountx

                            pocondheader = pocondheader

                            pocondheaderx = pocondheaderx

                            pocond = pocond

                            pocondx = pocondx

                            polimits = polimits

                            pocontractlimits = pocontractlimits

                            poservices = poservices

                            posrvaccessvalues = posrvaccessvalues

                            poservicestext = poservicestext

                            extensionin = extensionin

                            extensionout = extensionout

                            • poexpimpitem = poexpimpitem

                            • poexpimpitemx = poexpimpitemx

                            potextheader = potextheader

                            potextitem = potextitem .

                            • allversions = allversions

                            • popartner = popartner.

                            • Code inserted to commit work

                            SORT return BY type.

                            IF testrun IS INITIAL.

                            READ TABLE return

                            WITH KEY type = c_msgtype_e "E.

                            BINARY SEARCH.

                            IF sy-subrc NE 0.

                            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

                            ELSE.

                            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

                            **PVU-20-May-2004 - Start Changes for SCR1

                            **To generate inbound IDOC for failed PO

                            • perform idoc_create tables poitem

                            • g_t_itemx_tmp

                            • poaddrdelivery

                            • poschedule

                            • g_t_schdx_tmp

                            • poaccount

                            • poaccountprofitsegment

                            • g_t_accntx_tmp

                            • pocond

                            • g_t_condx_tmp

                            • polimits

                            • pocontractlimits

                            • poservices

                            • posrvaccessvalues

                            • poservicestext

                            • extensionin

                            • return

                            • using c_flg_pochange "CHNG

                            • purchaseorder

                            • poheader

                            • g_w_hdrx_tmp

                            • poaddrvendor

                            • testrun

                            • memory_uncomplete

                            • memory_complete .

                            *

                            *PVU-20-May-2004 - End Changes for SCR1

                            loop at return.

                            L_WA_ZERRORS-OBJECT = 'PURCHASE_ORDER'.

                            L_WA_ZERRORS-serial_no = sy-tabix.

                            L_WA_ZERRORS-COMP_CODE = poheader-comp_code.

                            L_WA_ZERRORS-zid = return-id.

                            L_WA_ZERRORS-znumber = return-number.

                            L_WA_ZERRORS-BEACON_DOC_NO = poheader-po_number.

                            L_WA_ZERRORS-SRC_DOC_NO = poheader-po_number.

                            L_WA_ZERRORS-ZDATE = sy-datum.

                            L_WA_ZERRORS-ERR_MSG = return-message.

                            append L_WA_ZERRORS to t_errors.

                            • insert into ZP2P_ERRORS values L_WA_ZERRORS.

                            clear: L_WA_ZERRORS.

                            endloop.

                            SELECT max( serial_no )

                            INTO L_SERIAL

                            FROM ZP2P_ERRORS.

                            LOOP AT T_ERRORS.

                            L_SERIAL = L_SERIAL + 1.

                            T_ERRORS-serial_no = L_SERIAL.

                            MODIFY T_ERRORS TRANSPORTING serial_no.

                            ENDLOOP.

                            INSERT ZP2P_ERRORS FROM TABLE T_ERRORS.

                            ENDIF.

                            ELSE.

                            • CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

                            ENDIF.

                            *GENERATE CUSTOM RETURN MESSAGES BASED ON MESSAGE ID AND NUMBER FROM

                            *maintenance table ZMESSAGES

                            CALL FUNCTION 'Z_MM_BUILD_MESSAGES'

                            TABLES

                            return = return.

                            SORT return BY type id number.

                            READ TABLE return

                            WITH KEY id = space

                            number = c_msgnr_000 "000

                            BINARY SEARCH.

                            IF sy-subrc EQ 0 AND sy-tabix NE 1.

                            DELETE return INDEX sy-tabix.

                            INSERT return INDEX 1.

                            ENDIF.

                            SELECT max( serial_no )

                            INTO L_SERIAL

                            FROM ZP2P_ERRORS.

                            LOOP AT T_ERRORS.

                            L_SERIAL = L_SERIAL + 1.

                            T_ERRORS-serial_no = L_SERIAL.

                            MODIFY T_ERRORS TRANSPORTING serial_no.

                            ENDLOOP.

                            INSERT ZP2P_ERRORS FROM TABLE T_ERRORS.

                            ENDFUNCTION.

                            ----


                            ***INCLUDE LZAVEEKF01 .

                            ----


                            ----


                            ************************************************************************

                            • PROGRAM LZZ_M3_PURCHASEORDERF01

                            • TITLE Include containing subroutines for Function group

                            • ZZ_M3_PURCHASEORDER

                            • AUTHOR Aveek Ghose

                            • DATE WRITTEN 25.05.2006

                            • R/3 RELEASE 4.6C

                            *----


                            &----


                            *& Form filter_items

                            &----


                            • Subroutine to obtain line items which have GL Account as blank.

                            ----


                            • -->P_T_TEMP_POACCOUNT line item accounting data

                            ----


                            FORM filter_items TABLES p_t_temp_poaccount STRUCTURE bapimepoaccount.

                            IF NOT p_t_temp_poaccount[] IS INITIAL.

                            SORT p_t_temp_poaccount BY po_item.

                            DELETE p_t_temp_poaccount WHERE NOT gl_account IS initial.

                            DELETE ADJACENT DUPLICATES FROM p_t_temp_poaccount

                            COMPARING po_item.

                            ENDIF.

                            ENDFORM. " filter_items

                            &----


                            *& Form POPULATE_NONPO_DOCUMENT

                            &----


                            • Update the table ZNONPO_DOCUMENT

                            ----


                            • --> p_poitem Item data

                            • --> p_return Error Messages

                            • --> p_textheader Texts - Purchase Order

                            • --> u_po Purchase Order Number

                            • --> u_poheader Purchase Order Header Data

                            ----


                            FORM populate_nonpo_document TABLES p_poitem STRUCTURE bapimepoitem

                            p_return STRUCTURE bapiret2

                            p_textheader STRUCTURE bapimepotext

                            USING u_po

                            u_poheader STRUCTURE bapimepoheader.

                            DATA: l_price LIKE p_poitem-net_price,

                            c_poitem LIKE bapimepotext-po_item VALUE '00000'.

                            CLEAR l_price.

                            t_znonpo_document-client = sy-mandt.

                            IF u_po IS INITIAL.

                            t_znonpo_document-documentnumber = u_poheader-po_number.

                            ELSE.

                            t_znonpo_document-documentnumber = u_po.

                            ENDIF.

                            t_znonpo_document-companycode = u_poheader-comp_code.

                            t_znonpo_document-documenttype = u_poheader-doc_type.

                            t_znonpo_document-suppliernumber = u_poheader-vendor.

                            t_znonpo_document-currency = u_poheader-currency.

                            • LOOP AT p_textheader WHERE po_item = '00000'.

                            LOOP AT p_textheader WHERE po_item = c_poitem.

                            t_znonpo_document-description = p_textheader-text_line.

                            ENDLOOP.

                            LOOP AT p_poitem.

                            l_price = l_price + ( p_poitem-net_price * p_poitem-quantity ).

                            t_znonpo_document-requestor = p_poitem-preq_name.

                            ENDLOOP.

                            t_znonpo_document-amount = l_price.

                            APPEND t_znonpo_document.

                            CLEAR t_znonpo_document.

                            ENDFORM. "POPULATE_NONPO_DOCUMENT

                            &----


                            *& Form POPULATE_NONPO_ACCOUNTING

                            &----


                            • Update the table ZNONPO_ACCTG

                            ----


                            • --> p_poaccount Account Assignment data for PO

                            • --> p_return Error Messages

                            • --> u_poheader Purchase Order Header Data

                            ----


                            FORM populate_nonpo_accounting TABLES p_poaccount STRUCTURE

                            bapimepoaccount

                            p_return STRUCTURE bapiret2

                            USING u_poheader STRUCTURE

                            bapimepoheader.

                            DATA: l_serial_no LIKE p_poaccount-serial_no.

                            *begin of change by DD - 09-Aug-2004,tpr2289

                            SORT p_poaccount BY GL_ACCounT COSTCENTER wbs_element

                            &----


                            &

                            *& Begin of Addition: 26-Sep-2005 SDUTTARO RD1K911060 *&

                            &----


                            &

                            serial_no. "@SDR

                            &----


                            &

                            *& End of Addition: 26-Sep-2005 SDUTTARO RD1K911060 *&

                            &----


                            &

                            DELETE ADJACENT DUPLICATES FROM p_poaccount

                            COMPARING GL_ACCounT

                            COSTCENTER

                            wbs_element

                            &----


                            &

                            *& Begin of Addition: 26-Sep-2005 SDUTTARO RD1K911060 *&

                            &----


                            &

                            serial_no. "@SDR

                            &----


                            &

                            *& End of Addition: 26-Sep-2005 SDUTTARO RD1K911060 *&

                            &----


                            &

                            *end of change by DD - 09-Aug-2004,tpr2289

                            SORT p_poaccount BY po_item.

                            *begin of change by DD - 13-Aug-2004,tpr2289

                            CLEAR l_serial_no.

                            *end of change by DD - 13-Aug-2004,tpr2289

                            LOOP AT p_poaccount.

                            *begin of change by DD - 13-Aug-2004,tpr2289

                            • AT NEW po_item.

                            • CLEAR l_serial_no.

                            • ENDAT.

                            *end of change by DD - 13-Aug-2004,tpr2289

                            *sraman2 10/14/04

                            • ADD 1 TO l_serial_no.

                            *sraman2 10/14/04

                            t_znonpo_acctg-client = sy-mandt.

                            t_znonpo_acctg-documentnumber = u_poheader-po_number.

                            *sraman2 10/14/04

                            • t_znonpo_acctg-distnumber = l_serial_no.

                            *sraman2 10/14/04

                            t_znonpo_acctg-distnumber = p_poaccount-SERIAL_NO.

                            t_znonpo_acctg-distpercent = p_poaccount-distr_perc.

                            t_znonpo_acctg-distquantity = p_poaccount-quantity.

                            t_znonpo_acctg-glacct = p_poaccount-gl_account.

                            t_znonpo_acctg-costcenter = p_poaccount-costcenter.

                            *begin of change by DD - 24-June-2004

                            • t_znonpo_acctg-internalorder = p_poaccount-orderid.

                            t_znonpo_acctg-pspnr = p_poaccount-wbs_element.

                            *end of change by DD - 24-June-2004

                            &----


                            &

                            *& Begin of Addition: 26-Sep-2005 SDUTTARO RD1K910316 *&

                            &----


                            &

                            t_znonpo_acctg-ex_pro_no = p_poaccount-unload_pt. "@SDR

                            &----


                            &

                            *& End of Addition: 26-Sep-2005 SDUTTARO RD1K910316 *&

                            &----


                            &

                            APPEND t_znonpo_acctg.

                            CLEAR t_znonpo_acctg.

                            ENDLOOP.

                            ENDFORM. "POPULATE_NONPO_ACCOUNTING

                            &----


                            *& Form UPDATE_NONPODOCUMENT

                            &----


                            • Update the Non PO Document

                            ----


                            • --> t_RETURN Error Messages

                            ----


                            FORM update_nonpodocument.

                            CALL FUNCTION 'Z_P2P_INT_IN_NONPODOCUMENT'

                            EXPORTING

                            BYPASS_VENDOR = 'X' "add TPR2220 DDUTTA 08-Jul-2004

                            TABLES

                            p_nonpodoc = t_znonpo_document

                            p_nonpoacctg = t_znonpo_acctg

                            return = t_return.

                            ENDFORM. "UPDATE_NONPODOCUMENT

                            &----


                            *& Form EXTRACT_MESSAGES

                            &----


                            • Select data from table zmessages

                            ----


                            *FORM extract_messages .

                            *

                            • SELECT * FROM zmessages INTO TABLE t_messages.

                            *

                            *ENDFORM. " EXTRACT_MESSAGES

                            &----


                            *& Form extract_longtext

                            &----


                            • Extract the long text

                            ----


                            • --> u_id Message class

                            • --> u_number Message number

                            • --> u_msgv1 Message variable

                            • --> u_msgv2 Message variable

                            • --> u_msgv3 Message variable

                            • --> u_msgv4 Message variable

                            • --> u_override Override flag

                            • --> u_shorttext Shorttext flag

                            • --> u_longtext Longtext flag

                            • --> u_message Message text

                            ----


                            FORM extract_longtext USING u_id

                            u_number

                            u_msgv1

                            u_msgv2

                            u_msgv3

                            u_msgv4

                            u_override

                            u_shorttext

                            u_longtext

                            CHANGING u_message.

                            DATA: l_object LIKE doktl-object,

                            l_initial TYPE c,

                            l_variable(20) TYPE c,

                            l_length type i.

                            CLEAR: l_initial,

                            l_variable,

                            l_object.

                            IF u_override IS INITIAL AND

                            NOT u_longtext IS INITIAL.

                            • extract long text

                            CONCATENATE u_id u_number INTO

                            l_object.

                            SELECT * FROM doktl WHERE

                            id EQ c_na AND "'NA'

                            object EQ l_object AND

                            langu EQ c_e. "E

                            IF doktl-doktext EQ c_cause. " '&CAUSE&'

                            l_initial = c_x. " 'X'

                            CLEAR u_message.

                            ELSE.

                            IF l_initial EQ c_x. "'X'

                            IF doktl-dokformat NE c_as AND " 'AS'

                            doktl-dokformat NE space.

                            EXIT.

                            ELSE.

                            DO.

                            REPLACE c_ampv INTO doktl-doktext WITH c_amp. " '&V' '&'

                            IF sy-subrc NE 0.

                            EXIT.

                            ENDIF.

                            ENDDO.

                            CONCATENATE u_message doktl-doktext

                            INTO u_message

                            SEPARATED BY space.

                            ENDIF.

                            ENDIF.

                            ENDIF.

                            ENDSELECT.

                            IF sy-subrc EQ 0.

                            SHIFT u_message LEFT DELETING LEADING space.

                            ENDIF.

                            ENDIF.

                            • replace variables in the long text with the return message variables

                            DO.

                            l_variable = sy-index.

                            CONDENSE l_variable NO-GAPS.

                            CONCATENATE c_amp l_variable c_amp INTO l_variable. " '&'

                            l_length = strlen( l_variable ).

                            CASE sy-index.

                            WHEN 1.

                            REPLACE l_variable length l_length WITH u_msgv1 into u_message.

                            condense u_message.

                            IF sy-subrc NE 0.

                            EXIT.

                            ENDIF.

                            WHEN 2.

                            REPLACE l_variable length l_length INTO u_message WITH u_msgv2.

                            condense u_msgv2.

                            IF sy-subrc NE 0.

                            EXIT.

                            ENDIF.

                            WHEN 3.

                            REPLACE l_variable length l_length INTO u_message WITH u_msgv3.

                            condense u_msgv3.

                            IF sy-subrc NE 0.

                            EXIT.

                            ENDIF.

                            WHEN 4.

                            REPLACE l_variable length l_length INTO u_message WITH u_msgv4.

                            condense u_msgv4.

                            IF sy-subrc NE 0.

                            EXIT.

                            ENDIF.

                            WHEN OTHERS.

                            EXIT.

                            ENDCASE.

                            ENDDO.

                            ENDFORM. " extract_longtext

                            *PVU-20-May-2004 - Start Changes for SCR1

                            &----


                            *& Form get_constant

                            &----


                            • Get the constant value from table ZCONSTANTS_NEW

                            ----


                            • -->U_CONST_NAME Name of constant

                            • -->U_COMP_CODE Company code

                            • <--CH_CONST_VAL Value of constant

                            • <--CH_RET SY-SUBRC value

                            ----


                            FORM get_constant USING u_const_name TYPE zconstname

                            u_comp_code TYPE bukrs

                            CHANGING ch_const_val TYPE zconstval

                            ch_ret TYPE sy-subrc.

                            *The constant value retrieval function module

                            CALL FUNCTION 'ZXA_GET_CONSTANT'

                            EXPORTING

                            const_name = u_const_name

                            comp_code = u_comp_code

                            IMPORTING

                            const_value = ch_const_val

                            EXCEPTIONS

                            no_value_found = 1

                            null_value = 2

                            OTHERS = 3.

                            IF sy-subrc <> 0.

                            ch_ret = sy-subrc.

                            ELSE.

                            ch_ret = 0.

                            ENDIF.

                            ENDFORM. " get_constant

                            &----


                            *& Form idoc_create

                            &----


                            • Create IDOC if BAPI fails

                            ----


                            *FORM idoc_create TABLES t_poitem STRUCTURE bapimepoitem

                            • t_itemx_tmp STRUCTURE bapimepoitemx

                            • t_poaddrdelivery STRUCTURE bapimepoaddrdelivery

                            • t_poschedule STRUCTURE bapimeposchedule

                            • t_schdx_tmp STRUCTURE bapimeposchedulx

                            • t_poaccount STRUCTURE bapimepoaccount

                            • t_poaccountprofitsegment STRUCTURE

                            • bapimepoaccountprofitsegment

                            • t_accntx_tmp STRUCTURE bapimepoaccountx

                            • t_pocond STRUCTURE bapimepocond

                            • t_condx_tmp STRUCTURE bapimepocondx

                            • t_polimits STRUCTURE bapiesuhc

                            • t_pocontractlimits STRUCTURE bapiesucc

                            • t_poservices STRUCTURE bapiesllc

                            • t_posrvaccessvalues STRUCTURE bapiesklc

                            • t_poservicestext STRUCTURE bapieslltx

                            • t_extensionin STRUCTURE bapiparex

                            • t_return_msg STRUCTURE bapiret2

                            • USING

                            • u_flg_create_change TYPE c

                            • u_purchaseorder LIKE bapimepoheader-po_number

                            • u_poheader STRUCTURE bapimepoheader

                            • u_hdrx_tmp STRUCTURE bapimepoheaderx

                            • u_poaddrvendor STRUCTURE bapimepoaddrvendor

                            • u_testrun LIKE bapiflag-bapiflag

                            • u_memory_uncomplete LIKE bapiflag-bapiflag

                            • u_memory_complete LIKE bapiflag-bapiflag.

                            *

                            **----


                            **

                              • Local variables

                              **----


                              **

                              • DATA: l_bukrs_val TYPE zconstval, "Company Code value

                              • l_bukrs TYPE bukrs, "Company code

                              • l_sndpor TYPE zconstval, "Sender Port

                              • l_sndprt TYPE zconstval, "Sender Partner Type

                              • l_sndprn TYPE zconstval, "Sender Partner No

                              • l_rcvpor TYPE zconstval, "Receiver Port

                              • l_rcvprt TYPE zconstval, "Receiver Partner Type

                              • l_rcvprn TYPE zconstval, "Receiver Partner No

                              • l_dist_list TYPE zconstval, "Distribution List

                              • l_sy_subrc LIKE sy-subrc, "Return value

                              • l_subline(35) TYPE c, "Subject Line

                              • l_errmsg(200) TYPE c. "Error Message

                              *

                              **----


                              **

                                • Internal Tables/Ranges

                                **----


                                **

                                  • Table to store error messages

                                • RANGES : t_errmsg FOR l_errmsg.

                                • *

                                  *

                                    • create IDoc control-record

                                  • CASE u_flg_create_change.

                                  • WHEN c_flg_pocreate. "CREA

                                  • w_idoc_comm-idoctyp = c_create_idoctyp. "ZMMPOC01

                                  • w_idoc_comm-mestyp = c_create_mestyp. "ZMMPOC

                                  • WHEN c_flg_pochange. "CHNG

                                  • w_idoc_comm-idoctyp = c_change_idoctyp. "ZMMPOH01

                                  • w_idoc_comm-mestyp = c_change_mestyp. "ZMMPOH

                                  • ENDCASE.

                                  • w_idoc_comm-mandt = sy-mandt.

                                  • w_idoc_comm-docrel = c_saprel. "46C

                                  • w_idoc_comm-direct = c_idoc_dir. "2

                                  • *

                                      • Get constant value of Company Code

                                    • PERFORM get_constant USING c_bukrs "ZRP_COMPCODE

                                    • u_poheader-comp_code

                                    • CHANGING l_bukrs_val

                                    • l_sy_subrc.

                                    • IF l_sy_subrc = 0.

                                      • Get constant value of Sender Port

                                    • l_bukrs = l_bukrs_val.

                                    • PERFORM get_constant USING c_sndpor "ZRP_SNDPOR

                                    • l_bukrs

                                    • CHANGING l_sndpor

                                    • l_sy_subrc.

                                    • IF l_sy_subrc = 0.

                                    • w_idoc_comm-sndpor = l_sndpor.

                                    • ENDIF.

                                    • *

                                        • Get constant value of Sender Partner type

                                      • PERFORM get_constant USING c_sndprt "ZRP_SNDPRT

                                      • l_bukrs

                                      • CHANGING l_sndprt

                                      • l_sy_subrc.

                                      • IF l_sy_subrc = 0.

                                      • w_idoc_comm-sndprt = l_sndprt.

                                      • ENDIF.

                                      • *

                                          • Get constant value of sender partner number

                                        • PERFORM get_constant USING c_sndprn "ZRP_SNDPRN

                                        • l_bukrs

                                        • CHANGING l_sndprn

                                        • l_sy_subrc.

                                        • IF l_sy_subrc = 0.

                                        • w_idoc_comm-sndprn = l_sndprn.

                                        • ENDIF.

                                        • *

                                            • Get constant value of Receiver port

                                          • PERFORM get_constant USING c_rcvpor "ZRP_RCVPOR

                                          • l_bukrs

                                          • CHANGING l_rcvpor

                                          • l_sy_subrc.

                                          • IF l_sy_subrc = 0.

                                          • w_idoc_comm-rcvpor = l_rcvpor.

                                          • ENDIF.

                                          • *

                                              • Get constant value of Receiver partner type

                                            • PERFORM get_constant USING c_rcvprt "ZRP_RCVPRT

                                            • l_bukrs

                                            • CHANGING l_rcvprt

                                            • l_sy_subrc.

                                            • IF l_sy_subrc = 0.

                                            • w_idoc_comm-rcvprt = l_rcvprt.

                                            • ENDIF.

                                            • *

                                                • Get constant value of Receiver partner number

                                              • PERFORM get_constant USING c_rcvprn "ZRP_RCVPRN

                                              • l_bukrs

                                              • CHANGING l_rcvprn

                                              • l_sy_subrc.

                                              • IF l_sy_subrc = 0.

                                              • w_idoc_comm-rcvprn = l_rcvprn.

                                              • ENDIF.

                                              • ENDIF.

                                              • *

                                                • CLEAR: w_syst_info, g_t_idoc_data.

                                                • REFRESH g_t_idoc_data.

                                                *

                                                  • call subroutine to create IDoc data-record

                                                • IF u_flg_create_change = c_flg_pocreate. "CREA

                                                • PERFORM zidoc_po_create1

                                                • TABLES

                                                • t_poitem

                                                • t_itemx_tmp

                                                • t_poaddrdelivery

                                                • t_poschedule

                                                • t_schdx_tmp

                                                • t_poaccount

                                                • t_poaccountprofitsegment

                                                • t_accntx_tmp

                                                • t_pocond

                                                • t_condx_tmp

                                                • t_polimits

                                                • t_pocontractlimits

                                                • t_poservices

                                                • t_posrvaccessvalues

                                                • t_poservicestext

                                                • t_extensionin

                                                • g_t_idoc_data

                                                • USING

                                                • u_poheader

                                                • u_hdrx_tmp

                                                • u_poaddrvendor

                                                • u_testrun

                                                • u_memory_uncomplete

                                                • u_memory_complete

                                                • w_syst_info.

                                                • *

                                                  • ELSEIF u_flg_create_change = c_flg_pochange. "CHNG

                                                  • PERFORM zidoc_po_change

                                                  • TABLES

                                                  • t_poitem

                                                  • t_itemx_tmp

                                                  • t_poaddrdelivery

                                                  • t_poschedule

                                                  • t_schdx_tmp

                                                  • t_poaccount

                                                  • t_poaccountprofitsegment

                                                  • t_accntx_tmp

                                                  • t_pocond

                                                  • t_condx_tmp

                                                  • t_polimits

                                                  • t_pocontractlimits

                                                  • t_poservices

                                                  • t_posrvaccessvalues

                                                  • t_poservicestext

                                                  • t_extensionin

                                                  • g_t_idoc_data

                                                  • USING

                                                  • u_purchaseorder

                                                  • u_poheader

                                                  • u_hdrx_tmp

                                                  • u_poaddrvendor

                                                  • u_testrun

                                                  • u_memory_uncomplete

                                                  • u_memory_complete

                                                  • w_syst_info.

                                                  *

                                                  • ENDIF.

                                                  *

                                                  *

                                                  **Call Function to create and post the IDOC

                                                  • CALL FUNCTION 'IDOC_INBOUND_SINGLE'

                                                  • EXPORTING

                                                  • pi_idoc_control_rec_40 = w_idoc_comm

                                                  • IMPORTING

                                                  • pe_idoc_number = g_idoc_no

                                                  • TABLES

                                                  • pt_idoc_data_records_40 = g_t_idoc_data

                                                  • EXCEPTIONS

                                                  • idoc_not_saved = 1

                                                  • OTHERS = 2.

                                                  *

                                                  • IF sy-subrc <> 0.

                                                  • IDOC_INBOUND_SINGLE failed. IDOC can not be created.

                                                • MESSAGE e000(z001) WITH text-004.

                                                • ELSE.

                                                  • Get constant value of Distribution list

                                                • PERFORM get_constant USING c_dist_list "ZRP_DISTLIST

                                                • l_bukrs

                                                • CHANGING l_dist_list

                                                • l_sy_subrc.

                                                • IF l_sy_subrc <> 0.

                                                  • Distribution list does not exist

                                                • MESSAGE e000(z001) WITH text-001.

                                                • ELSE.

                                                • **Subject Line

                                                  • CASE u_flg_create_change.

                                                  • WHEN c_flg_pocreate. "CREA

                                                  **PO CREATE failed for PO

                                                  • CONCATENATE text-005

                                                  • u_poheader-po_number

                                                  • INTO l_subline

                                                  • SEPARATED BY space.

                                                  • WHEN c_flg_pochange. "CHNG

                                                  **PO change failed for PO

                                                  • CONCATENATE text-002

                                                  • u_purchaseorder

                                                  • INTO l_subline

                                                  • SEPARATED BY space.

                                                  • ENDCASE.

                                                  *

                                                  **Generate Error Message table to display along with message in inbox.

                                                  *

                                                  • CLEAR t_errmsg.

                                                  • REFRESH t_errmsg.

                                                  *

                                                  • t_errmsg-sign = c_sign. "I

                                                  • t_errmsg-option = c_option. "EQ

                                                  *

                                                  **Error Messages :

                                                  • t_errmsg-low = text-006.

                                                  • APPEND t_errmsg.

                                                  *

                                                  • CLEAR t_errmsg-low.

                                                  • LOOP AT t_return_msg

                                                  • WHERE type = c_msgtype_e. "E

                                                  • t_errmsg-low = t_return_msg-message.

                                                  • APPEND t_errmsg.

                                                  • CLEAR t_errmsg-low.

                                                  • ENDLOOP.

                                                  *

                                                  **IDOC number posted is

                                                  • CONCATENATE text-003

                                                  • g_idoc_no

                                                  • INTO l_errmsg

                                                  • SEPARATED BY space.

                                                  *

                                                  • t_errmsg-low = l_errmsg.

                                                  • APPEND t_errmsg.

                                                  *

                                                  **Notify users in distribution list of the failure

                                                  • SUBMIT z_util_notify_distlist AND RETURN

                                                  • WITH p_rgroup = l_dist_list

                                                  • WITH p_objdes = l_subline

                                                  • WITH s_msg IN t_errmsg

                                                  • WITH p_idocno = g_idoc_no.

                                                  • ENDIF.

                                                  • ENDIF.

                                                  *ENDFORM. " idoc_create

                                                  &----


                                                  *& Form ZIDOC_PO_CHANGE

                                                  &----


                                                  • CREATE IDOC DATA RECORD FOR PO CHANGE

                                                  ----


                                                  *FORM zidoc_po_change

                                                  • TABLES poitem STRUCTURE bapimepoitem

                                                  • poitemx STRUCTURE bapimepoitemx

                                                  • poaddrdelivery STRUCTURE bapimepoaddrdelivery

                                                  • poschedule STRUCTURE bapimeposchedule

                                                  • poschedulex STRUCTURE bapimeposchedulx

                                                  • poaccount STRUCTURE bapimepoaccount

                                                  • poaccountprofitsegment STRUCTURE

                                                  • bapimepoaccountprofitsegment

                                                  • poaccountx STRUCTURE bapimepoaccountx

                                                  • pocond STRUCTURE bapimepocond

                                                  • pocondx STRUCTURE bapimepocondx

                                                  • polimits STRUCTURE bapiesuhc

                                                  • pocontractlimits STRUCTURE bapiesucc

                                                  • poservices STRUCTURE bapiesllc

                                                  • posrvaccessvalues STRUCTURE bapiesklc

                                                  • poservicestext STRUCTURE bapieslltx

                                                  • extensionin STRUCTURE bapiparex

                                                  • idoc_data STRUCTURE edi_dd40

                                                  • USING

                                                  • purchaseorder LIKE bapimepoheader-po_number

                                                  • poheader LIKE bapimepoheader

                                                  • poheaderx LIKE bapimepoheaderx

                                                  • poaddrvendor LIKE bapimepoaddrvendor

                                                  • testrun LIKE bapiflag-bapiflag

                                                  • memoryuncomplete LIKE bapiflag-bapiflag

                                                  • memorycomplete LIKE bapiflag-bapiflag

                                                  • syst_info LIKE syst .

                                                  *

                                                  • DATA: z1zmmpoh LIKE z1zmmpoh.

                                                  • DATA: z1bpmepoheader LIKE z1bpmepoheader.

                                                  • DATA: z1bpmepoheaderx LIKE z1bpmepoheaderx.

                                                  • DATA: z1bpmepoaddrvendor LIKE z1bpmepoaddrvendor.

                                                  • DATA: z1bpmepoaddrvendor1 LIKE z1bpmepoaddrvendor1.

                                                  • DATA: z1bpmepoitem LIKE z1bpmepoitem.

                                                  • DATA: z1bpmepoitemx LIKE z1bpmepoitemx.

                                                  • DATA: z1bpmepoaddrdelivery LIKE z1bpmepoaddrdelivery.

                                                  • DATA: z1bpmepoaddrdelivery1 LIKE z1bpmepoaddrdelivery1.

                                                  • DATA: z1bpmeposchedule LIKE z1bpmeposchedule.

                                                  • DATA: z1bpmeposchedulx LIKE z1bpmeposchedulx.

                                                  • DATA: z1bpmepoaccount LIKE z1bpmepoaccount.

                                                  • DATA: z1bpmepoaccountprofitsegmen LIKE z1bpmepoaccountprofitsegmen.

                                                  • DATA: z1bpmepoaccountx LIKE z1bpmepoaccountx.

                                                  • DATA: z1bpmepocond LIKE z1bpmepocond.

                                                  • DATA: z1bpmepocondx LIKE z1bpmepocondx.

                                                  • DATA: e1bpesuhc LIKE e1bpesuhc.

                                                  • DATA: e1bpesucc LIKE e1bpesucc.

                                                  • DATA: e1bpesllc LIKE e1bpesllc.

                                                  • DATA: e1bpesklc LIKE e1bpesklc.

                                                  • DATA: e1bpeslltx LIKE e1bpeslltx.

                                                  • DATA: e1bpparex LIKE e1bpparex.

                                                  *

                                                    • go through all IDoc-segments

                                                    **

                                                    *

                                                      • for segment 'Z1ZMMPOH'

                                                      **

                                                      • CLEAR: z1zmmpoh,

                                                      • idoc_data.

                                                      • MOVE purchaseorder

                                                      • TO z1zmmpoh-purchaseorder.

                                                      • MOVE testrun

                                                      • TO z1zmmpoh-testrun.

                                                      • MOVE memoryuncomplete

                                                      • TO z1zmmpoh-memory_uncomplete.

                                                      • MOVE memorycomplete

                                                      • TO z1zmmpoh-memory_complete.

                                                      • idoc_data-sdata = z1zmmpoh.

                                                      • idoc_data-segnam = c_z1zmmpoh. "Z1ZMMPOH

                                                      • APPEND idoc_data.

                                                      *

                                                      *

                                                        • for segment 'Z1BPMEPOHEADER'

                                                        **

                                                        • CLEAR: z1bpmepoheader,

                                                        • idoc_data.

                                                        • MOVE-CORRESPONDING poheader

                                                        • TO z1bpmepoheader.

                                                        • IF NOT z1bpmepoheader IS INITIAL.

                                                        • CONDENSE z1bpmepoheader-dscnt1_to.

                                                        • CONDENSE z1bpmepoheader-dscnt2_to.

                                                        • CONDENSE z1bpmepoheader-dscnt3_to.

                                                        • CONDENSE z1bpmepoheader-dsct_pct1.

                                                        • CONDENSE z1bpmepoheader-dsct_pct2.

                                                        • CONDENSE z1bpmepoheader-exch_rate.

                                                        • idoc_data-sdata = z1bpmepoheader.

                                                        • idoc_data-segnam = c_z1bpmepoheader. "Z1BPMEPOHEADER

                                                        • APPEND idoc_data.

                                                        • ENDIF.

                                                        *

                                                          • for segment 'Z1BPMEPOHEADERX'

                                                          **

                                                          • CLEAR: z1bpmepoheaderx,

                                                          • idoc_data.

                                                          • MOVE-CORRESPONDING poheaderx

                                                          • TO z1bpmepoheaderx.

                                                          • IF NOT z1bpmepoheaderx IS INITIAL.

                                                          • idoc_data-sdata = z1bpmepoheaderx.

                                                          • idoc_data-segnam = c_z1bpmepoheaderx. "Z1BPMEPOHEADERX.

                                                          • APPEND idoc_data.

                                                          • ENDIF.

                                                          *

                                                            • for segment 'Z1BPMEPOADDRVENDOR'

                                                            **

                                                            • CLEAR: z1bpmepoaddrvendor,

                                                            • idoc_data.

                                                            • MOVE-CORRESPONDING poaddrvendor

                                                            • TO z1bpmepoaddrvendor.

                                                            • idoc_data-sdata = z1bpmepoaddrvendor.

                                                            • idoc_data-segnam = c_z1bpmepoaddrvendor. "Z1BPMEPOADDRVENDOR

                                                            • APPEND idoc_data.

                                                            *

                                                              • for segment 'Z1BPMEPOADDRVENDOR1'

                                                              **

                                                              • CLEAR: z1bpmepoaddrvendor1,

                                                              • idoc_data.

                                                              • MOVE-CORRESPONDING poaddrvendor

                                                              • TO z1bpmepoaddrvendor1.

                                                              • idoc_data-sdata = z1bpmepoaddrvendor1.

                                                              • idoc_data-segnam = c_z1bpmepoaddrvendor1.

                                                              *"Z1BPMEPOADDRVENDOR1

                                                              • APPEND idoc_data.

                                                              *

                                                                • for segment 'Z1BPMEPOITEM'

                                                                **

                                                                • LOOP AT poitem

                                                                • .

                                                                • CLEAR: z1bpmepoitem,

                                                                • idoc_data.

                                                                • MOVE-CORRESPONDING poitem

                                                                • TO z1bpmepoitem.

                                                                • CONDENSE z1bpmepoitem-quantity.

                                                                • CONDENSE z1bpmepoitem-conv_num1.

                                                                • CONDENSE z1bpmepoitem-conv_den1.

                                                                • CONDENSE z1bpmepoitem-net_price.

                                                                • CONDENSE z1bpmepoitem-price_unit.

                                                                • CONDENSE z1bpmepoitem-gr_pr_time.

                                                                • CONDENSE z1bpmepoitem-reminder1.

                                                                • CONDENSE z1bpmepoitem-reminder2.

                                                                • CONDENSE z1bpmepoitem-reminder3.

                                                                • CONDENSE z1bpmepoitem-over_dlv_tol.

                                                                • CONDENSE z1bpmepoitem-under_dlv_tol.

                                                                • CONDENSE z1bpmepoitem-plan_del.

                                                                • CONDENSE z1bpmepoitem-net_weight.

                                                                • CONDENSE z1bpmepoitem-gross_wt.

                                                                • CONDENSE z1bpmepoitem-volume.

                                                                • CONDENSE z1bpmepoitem-points.

                                                                • CONDENSE z1bpmepoitem-minremlife.

                                                                • idoc_data-sdata = z1bpmepoitem.

                                                                • idoc_data-segnam = c_z1bpmepoitem. "Z1BPMEPOITEM

                                                                • APPEND idoc_data.

                                                                • ENDLOOP.

                                                                *

                                                                *

                                                                  • for segment 'Z1BPMEPOITEMX'

                                                                  **

                                                                  • LOOP AT poitemx

                                                                  • .

                                                                  • CLEAR: z1bpmepoitemx,

                                                                  • idoc_data.

                                                                  • MOVE-CORRESPONDING poitemx

                                                                  • TO z1bpmepoitemx.

                                                                  • idoc_data-sdata = z1bpmepoitemx.

                                                                  • idoc_data-segnam = c_z1bpmepoitemx. "Z1BPMEPOITEMX

                                                                  • APPEND idoc_data.

                                                                  • ENDLOOP.

                                                                  *

                                                                  *

                                                                    • for segment 'Z1BPMEPOADDRDELIVERY'

                                                                    **

                                                                    • LOOP AT poaddrdelivery

                                                                    • .

                                                                    • CLEAR: z1bpmepoaddrdelivery,

                                                                    • idoc_data.

                                                                    • MOVE-CORRESPONDING poaddrdelivery

                                                                    • TO z1bpmepoaddrdelivery.

                                                                    • idoc_data-sdata = z1bpmepoaddrdelivery.

                                                                    • idoc_data-segnam = c_z1bpmepoaddrdelivery.

                                                                    *"Z1BPMEPOADDRDELIVERY

                                                                    • APPEND idoc_data.

                                                                    *

                                                                      • for segment 'Z1BPMEPOADDRDELIVERY1'

                                                                      **

                                                                      • CLEAR: z1bpmepoaddrdelivery1,

                                                                      • idoc_data.

                                                                      • MOVE-CORRESPONDING poaddrdelivery

                                                                      • TO z1bpmepoaddrdelivery1.

                                                                      • idoc_data-sdata = z1bpmepoaddrdelivery1.

                                                                      • idoc_data-segnam = c_z1bpmepoaddrdelivery1. "Z1BPMEPOADDRDELIVERY1

                                                                      • APPEND idoc_data.

                                                                      • ENDLOOP.

                                                                      *

                                                                      *

                                                                        • for segment 'Z1BPMEPOSCHEDULE'

                                                                        **

                                                                        • LOOP AT poschedule

                                                                        • .

                                                                        • CLEAR: z1bpmeposchedule,

                                                                        • idoc_data.

                                                                        • MOVE-CORRESPONDING poschedule

                                                                        • TO z1bpmeposchedule.

                                                                        • CONDENSE z1bpmeposchedule-quantity.

                                                                        • idoc_data-sdata = z1bpmeposchedule.

                                                                        • idoc_data-segnam = c_z1bpmeposchedule. "Z1BPMEPOSCHEDULE

                                                                        • APPEND idoc_data.

                                                                        • ENDLOOP.

                                                                        *

                                                                        *

                                                                          • for segment 'Z1BPMEPOSCHEDULX'

                                                                          **

                                                                          • LOOP AT poschedulex

                                                                          • .

                                                                          • CLEAR: z1bpmeposchedulx,

                                                                          • idoc_data.

                                                                          • MOVE-CORRESPONDING poschedulex

                                                                          • TO z1bpmeposchedulx.

                                                                          • idoc_data-sdata = z1bpmeposchedulx.

                                                                          • idoc_data-segnam = c_z1bpmeposchedulx. "Z1BPMEPOSCHEDULX

                                                                          • APPEND idoc_data.

                                                                          • ENDLOOP.

                                                                          *

                                                                          *

                                                                            • for segment 'Z1BPMEPOACCOUNT'

                                                                            **

                                                                            • LOOP AT poaccount

                                                                            • .

                                                                            • CLEAR: z1bpmepoaccount,

                                                                            • idoc_data.

                                                                            • MOVE-CORRESPONDING poaccount

                                                                            • TO z1bpmepoaccount.

                                                                            • CONDENSE z1bpmepoaccount-quantity.

                                                                            • CONDENSE z1bpmepoaccount-distr_perc.

                                                                            • CONDENSE z1bpmepoaccount-net_value.

                                                                            • CONDENSE z1bpmepoaccount-nond_itax.

                                                                            • idoc_data-sdata = z1bpmepoaccount.

                                                                            • idoc_data-segnam = c_z1bpmepoaccount. "Z1BPMEPOACCOUNT

                                                                            • APPEND idoc_data.

                                                                            • ENDLOOP.

                                                                            *

                                                                            *

                                                                              • for segment 'Z1BPMEPOACCOUNTPROFITSEGMEN'

                                                                              **

                                                                              • LOOP AT poaccountprofitsegment

                                                                              • .

                                                                              • CLEAR: z1bpmepoaccountprofitsegmen,

                                                                              • idoc_data.

                                                                              • MOVE-CORRESPONDING poaccountprofitsegment

                                                                              • TO z1bpmepoaccountprofitsegmen.

                                                                              • idoc_data-sdata = z1bpmepoaccountprofitsegmen.

                                                                              • "Z1BPMEPOACCOUNTPROFITSEGMEN

                                                                            • idoc_data-segnam = c_z1bpmepoaccountprofitsegmen.

                                                                            • APPEND idoc_data.

                                                                            • ENDLOOP.

                                                                            • *

                                                                              *

                                                                                • for segment 'Z1BPMEPOACCOUNTX'

                                                                                **

                                                                                • LOOP AT poaccountx

                                                                                • .

                                                                                • CLEAR: z1bpmepoaccountx,

                                                                                • idoc_data.

                                                                                • MOVE-CORRESPONDING poaccountx

                                                                                • TO z1bpmepoaccountx.

                                                                                • idoc_data-sdata = z1bpmepoaccountx.

                                                                                • idoc_data-segnam = c_z1bpmepoaccountx. "Z1BPMEPOACCOUNTX

                                                                                • APPEND idoc_data.

                                                                                • ENDLOOP.

                                                                                *

                                                                                *

                                                                                  • for segment 'Z1BPMEPOCOND'

                                                                                  **

                                                                                  • LOOP AT pocond

                                                                                  • .

                                                                                  • CLEAR: z1bpmepocond,

                                                                                  • idoc_data.

                                                                                  • MOVE-CORRESPONDING pocond

                                                                                  • TO z1bpmepocond.

                                                                                  • CONDENSE z1bpmepocond-cond_value.

                                                                                  • CONDENSE z1bpmepocond-cond_p_unt.

                                                                                  • CONDENSE z1bpmepocond-conbaseval.

                                                                                  • CONDENSE z1bpmepocond-conexchrat.

                                                                                  • CONDENSE z1bpmepocond-numconvert.

                                                                                  • CONDENSE z1bpmepocond-denominato.

                                                                                  • CONDENSE z1bpmepocond-scalbasval.

                                                                                  • idoc_data-sdata = z1bpmepocond.

                                                                                  • idoc_data-segnam = c_z1bpmepocond. "Z1BPMEPOCOND

                                                                                  • APPEND idoc_data.

                                                                                  • ENDLOOP.

                                                                                  *

                                                                                  *

                                                                                    • for segment 'Z1BPMEPOCONDX'

                                                                                    **

                                                                                    • LOOP AT pocondx

                                                                                    • .

                                                                                    • CLEAR: z1bpmepocondx,

                                                                                    • idoc_data.

                                                                                    • MOVE-CORRESPONDING pocondx

                                                                                    • TO z1bpmepocondx.

                                                                                    • idoc_data-sdata = z1bpmepocondx.

                                                                                    • idoc_data-segnam = c_z1bpmepocondx. "Z1BPMEPOCONDX

                                                                                    • APPEND idoc_data.

                                                                                    • ENDLOOP.

                                                                                    *

                                                                                    *

                                                                                      • for segment 'E1BPESUHC'

                                                                                      **

                                                                                      • LOOP AT polimits

                                                                                      • .

                                                                                      • CLEAR: e1bpesuhc,

                                                                                      • idoc_data.

                                                                                      • MOVE-CORRESPONDING polimits

                                                                                      • TO e1bpesuhc.

                                                                                      • CONDENSE e1bpesuhc-limit.

                                                                                      • CONDENSE e1bpesuhc-exp_value.

                                                                                      • CONDENSE e1bpesuhc-free_limit.

                                                                                      • CONDENSE e1bpesuhc-ssc_limit.

                                                                                      • CONDENSE e1bpesuhc-ssc_perc.

                                                                                      • CONDENSE e1bpesuhc-tmp_limit.

                                                                                      • CONDENSE e1bpesuhc-tmp_perc.

                                                                                      • CONDENSE e1bpesuhc-cont_perc.

                                                                                      • idoc_data-sdata = e1bpesuhc.

                                                                                      • idoc_data-segnam = c_e1bpesuhc. "E1BPESUHC

                                                                                      • APPEND idoc_data.

                                                                                      • ENDLOOP.

                                                                                      *

                                                                                      *

                                                                                        • for segment 'E1BPESUCC'

                                                                                        **

                                                                                        • LOOP AT pocontractlimits

                                                                                        • .

                                                                                        • CLEAR: e1bpesucc,

                                                                                        • idoc_data.

                                                                                        • MOVE-CORRESPONDING pocontractlimits

                                                                                        • TO e1bpesucc.

                                                                                        • CONDENSE e1bpesucc-limit.

                                                                                        • idoc_data-sdata = e1bpesucc.

                                                                                        • idoc_data-segnam = c_e1bpesucc. "E1BPESUCC

                                                                                        • APPEND idoc_data.

                                                                                        • ENDLOOP.

                                                                                        *

                                                                                        *

                                                                                          • for segment 'E1BPESLLC'

                                                                                          **

                                                                                          • LOOP AT poservices

                                                                                          • .

                                                                                          • CLEAR: e1bpesllc,

                                                                                          • idoc_data.

                                                                                          • MOVE-CORRESPONDING poservices

                                                                                          • TO e1bpesllc.

                                                                                          • CONDENSE e1bpesllc-outl_level.

                                                                                          • CONDENSE e1bpesllc-quantity.

                                                                                          • CONDENSE e1bpesllc-ovf_tol.

                                                                                          • CONDENSE e1bpesllc-price_unit.

                                                                                          • CONDENSE e1bpesllc-gr_price.

                                                                                          • CONDENSE e1bpesllc-target_val.

                                                                                          • CONDENSE e1bpesllc-form_val1.

                                                                                          • CONDENSE e1bpesllc-form_val2.

                                                                                          • CONDENSE e1bpesllc-form_val3.

                                                                                          • CONDENSE e1bpesllc-form_val4.

                                                                                          • CONDENSE e1bpesllc-form_val5.

                                                                                          • CONDENSE e1bpesllc-userf2_num.

                                                                                          • idoc_data-sdata = e1bpesllc.

                                                                                          • idoc_data-segnam = c_e1bpesllc. "E1BPESLLC

                                                                                          • APPEND idoc_data.

                                                                                          • ENDLOOP.

                                                                                          *

                                                                                          *

                                                                                            • for segment 'E1BPESKLC'

                                                                                            **

                                                                                            • LOOP AT posrvaccessvalues

                                                                                            • .

                                                                                            • CLEAR: e1bpesklc,

                                                                                            • idoc_data.

                                                                                            • MOVE-CORRESPONDING posrvaccessvalues

                                                                                            • TO e1bpesklc.

                                                                                            • CONDENSE e1bpesklc-percentage.

                                                                                            • idoc_data-sdata = e1bpesklc.

                                                                                            • idoc_data-segnam = c_e1bpesklc. "E1BPESKLC

                                                                                            • APPEND idoc_data.

                                                                                            • ENDLOOP.

                                                                                            *

                                                                                            *

                                                                                              • for segment 'E1BPESLLTX'

                                                                                              **

                                                                                              • LOOP AT poservicestext

                                                                                              • .

                                                                                              • CLEAR: e1bpeslltx,

                                                                                              • idoc_data.

                                                                                              • MOVE-CORRESPONDING poservicestext

                                                                                              • TO e1bpeslltx.

                                                                                              • idoc_data-sdata = e1bpeslltx.

                                                                                              • idoc_data-segnam = c_e1bpeslltx. "E1BPESLLTX

                                                                                              • APPEND idoc_data.

                                                                                              • ENDLOOP.

                                                                                              *

                                                                                              *

                                                                                                • for segment 'E1BPPAREX'

                                                                                                **

                                                                                                • LOOP AT extensionin

                                                                                                • .

                                                                                                • CLEAR: e1bpparex,

                                                                                                • idoc_data.

                                                                                                • MOVE-CORRESPONDING extensionin

                                                                                                • TO e1bpparex.

                                                                                                • idoc_data-sdata = e1bpparex.

                                                                                                • idoc_data-segnam = c_e1bpparex. "E1BPPAREX

                                                                                                • APPEND idoc_data.

                                                                                                • ENDLOOP.

                                                                                                *

                                                                                                *

                                                                                                  • end of through all IDoc-segments

                                                                                                  **

                                                                                                  *

                                                                                                  *ENDFORM. " ZIDOC_PO_CHANGE

                                                                                                  &----


                                                                                                  *& Form ZIDOC_PO_CREATE1

                                                                                                  &----


                                                                                                  • CREATE IDOC DATA RECORD FOR PO CREATE1

                                                                                                  ----


                                                                                                  *FORM zidoc_po_create1

                                                                                                  • TABLES poitem STRUCTURE bapimepoitem

                                                                                                  • poitemx STRUCTURE bapimepoitemx

                                                                                                  • poaddrdelivery STRUCTURE bapimepoaddrdelivery

                                                                                                  • poschedule STRUCTURE bapimeposchedule

                                                                                                  • poschedulex STRUCTURE bapimeposchedulx

                                                                                                  • poaccount STRUCTURE bapimepoaccount

                                                                                                  • poaccountprofitsegment STRUCTURE

                                                                                                  • bapimepoaccountprofitsegment

                                                                                                  • poaccountx STRUCTURE bapimepoaccountx

                                                                                                  • pocond STRUCTURE bapimepocond

                                                                                                  • pocondx STRUCTURE bapimepocondx

                                                                                                  • polimits STRUCTURE bapiesuhc

                                                                                                  • pocontractlimits STRUCTURE bapiesucc

                                                                                                  • poservices STRUCTURE bapiesllc

                                                                                                  • posrvaccessvalues STRUCTURE bapiesklc

                                                                                                  • poservicestext STRUCTURE bapieslltx

                                                                                                  • extensionin STRUCTURE bapiparex

                                                                                                  • idoc_data STRUCTURE edi_dd40

                                                                                                  • USING poheader LIKE bapimepoheader

                                                                                                  • poheaderx LIKE bapimepoheaderx

                                                                                                  • poaddrvendor LIKE bapimepoaddrvendor

                                                                                                  • testrun LIKE bapiflag-bapiflag

                                                                                                  • memoryuncomplete LIKE bapiflag-bapiflag

                                                                                                  • memorycomplete LIKE bapiflag-bapiflag

                                                                                                  • syst_info LIKE syst .

                                                                                                  *

                                                                                                  • DATA: z1zmmpoc LIKE z1zmmpoc.

                                                                                                  • DATA: z1bpmepoheader LIKE z1bpmepoheader.

                                                                                                  • DATA: z1bpmepoheaderx LIKE z1bpmepoheaderx.

                                                                                                  • DATA: z1bpmepoaddrvendor LIKE z1bpmepoaddrvendor.

                                                                                                  • DATA: z1bpmepoaddrvendor1 LIKE z1bpmepoaddrvendor1.

                                                                                                  • DATA: z1bpmepoitem LIKE z1bpmepoitem.

                                                                                                  • DATA: z1bpmepoitemx LIKE z1bpmepoitemx.

                                                                                                  • DATA: z1bpmepoaddrdelivery LIKE z1bpmepoaddrdelivery.

                                                                                                  • DATA: z1bpmepoaddrdelivery1 LIKE z1bpmepoaddrdelivery1.

                                                                                                  • DATA: z1bpmeposchedule LIKE z1bpmeposchedule.

                                                                                                  • DATA: z1bpmeposchedulx LIKE z1bpmeposchedulx.

                                                                                                  • DATA: z1bpmepoaccount LIKE z1bpmepoaccount.

                                                                                                  • DATA: z1bpmepoaccountprofitsegmen LIKE z1bpmepoaccountprofitsegmen.

                                                                                                  • DATA: z1bpmepoaccountx LIKE z1bpmepoaccountx.

                                                                                                  • DATA: z1bpmepocond LIKE z1bpmepocond.

                                                                                                  • DATA: z1bpmepocondx LIKE z1bpmepocondx.

                                                                                                  • DATA: e1bpesuhc LIKE e1bpesuhc.

                                                                                                  • DATA: e1bpesucc LIKE e1bpesucc.

                                                                                                  • DATA: e1bpesllc LIKE e1bpesllc.

                                                                                                  • DATA: e1bpesklc LIKE e1bpesklc.

                                                                                                  • DATA: e1bpeslltx LIKE e1bpeslltx.

                                                                                                  • DATA: e1bpparex LIKE e1bpparex.

                                                                                                  *

                                                                                                    • go through all IDoc-segments

                                                                                                    **

                                                                                                    *

                                                                                                      • for segment 'Z1ZMMPOC'

                                                                                                      **

                                                                                                      • CLEAR: z1zmmpoc,

                                                                                                      • idoc_data.

                                                                                                      • MOVE testrun

                                                                                                      • TO z1zmmpoc-testrun.

                                                                                                      • MOVE memoryuncomplete

                                                                                                      • TO z1zmmpoc-memory_uncomplete.

                                                                                                      • MOVE memorycomplete

                                                                                                      • TO z1zmmpoc-memory_complete.

                                                                                                      • idoc_data-sdata = z1zmmpoc.

                                                                                                      • idoc_data-segnam = c_z1zmmpoc. "Z1ZMMPOC

                                                                                                      • APPEND idoc_data.

                                                                                                      *

                                                                                                      *

                                                                                                        • for segment 'Z1BPMEPOHEADER'

                                                                                                        **

                                                                                                        • CLEAR: z1bpmepoheader,

                                                                                                        • idoc_data.

                                                                                                        • MOVE-CORRESPONDING poheader

                                                                                                        • TO z1bpmepoheader.

                                                                                                        • IF NOT z1bpmepoheader IS INITIAL.

                                                                                                        • CONDENSE z1bpmepoheader-dscnt1_to.

                                                                                                        • CONDENSE z1bpmepoheader-dscnt2_to.

                                                                                                        • CONDENSE z1bpmepoheader-dscnt3_to.

                                                                                                        • CONDENSE z1bpmepoheader-dsct_pct1.

                                                                                                        • CONDENSE z1bpmepoheader-dsct_pct2.

                                                                                                        • CONDENSE z1bpmepoheader-exch_rate.

                                                                                                        • idoc_data-sdata = z1bpmepoheader.

                                                                                                        • idoc_data-segnam = c_z1bpmepoheader. "Z1BPMEPOHEADER

                                                                                                        • APPEND idoc_data.

                                                                                                        • ENDIF.

                                                                                                        *

                                                                                                          • for segment 'Z1BPMEPOHEADERX'

                                                                                                          **

                                                                                                          • CLEAR: z1bpmepoheaderx,

                                                                                                          • idoc_data.

                                                                                                          • MOVE-CORRESPONDING poheaderx

                                                                                                          • TO z1bpmepoheaderx.

                                                                                                          • IF NOT z1bpmepoheaderx IS INITIAL.

                                                                                                          • idoc_data-sdata = z1bpmepoheaderx.

                                                                                                          • idoc_data-segnam = c_z1bpmepoheaderx. "Z1BPMEPOHEADERX

                                                                                                          • APPEND idoc_data.

                                                                                                          • ENDIF.

                                                                                                          *

                                                                                                            • for segment 'Z1BPMEPOADDRVENDOR'

                                                                                                            **

                                                                                                            • CLEAR: z1bpmepoaddrvendor,

                                                                                                            • idoc_data.

                                                                                                            • MOVE-CORRESPONDING poaddrvendor

                                                                                                            • TO z1bpmepoaddrvendor.

                                                                                                            • idoc_data-sdata = z1bpmepoaddrvendor.

                                                                                                            • idoc_data-segnam = c_z1bpmepoaddrvendor. "Z1BPMEPOADDRVENDOR

                                                                                                            • APPEND idoc_data.

                                                                                                            *

                                                                                                              • for segment 'Z1BPMEPOADDRVENDOR1'

                                                                                                              **

                                                                                                              • CLEAR: z1bpmepoaddrvendor1,

                                                                                                              • idoc_data.

                                                                                                              • MOVE-CORRESPONDING poaddrvendor

                                                                                                              • TO z1bpmepoaddrvendor1.

                                                                                                              • idoc_data-sdata = z1bpmepoaddrvendor1.

                                                                                                              • idoc_data-segnam = c_z1bpmepoaddrvendor1. "Z1BPMEPOADDRVENDOR1

                                                                                                              • APPEND idoc_data.

                                                                                                              *

                                                                                                                • for segment 'Z1BPMEPOITEM'

                                                                                                                **

                                                                                                                • LOOP AT poitem

                                                                                                                • .

                                                                                                                • CLEAR: z1bpmepoitem,

                                                                                                                • idoc_data.

                                                                                                                • MOVE-CORRESPONDING poitem

                                                                                                                • TO z1bpmepoitem.

                                                                                                                • CONDENSE z1bpmepoitem-quantity.

                                                                                                                • CONDENSE z1bpmepoitem-conv_num1.

                                                                                                                • CONDENSE z1bpmepoitem-conv_den1.

                                                                                                                • CONDENSE z1bpmepoitem-net_price.

                                                                                                                • CONDENSE z1bpmepoitem-price_unit.

                                                                                                                • CONDENSE z1bpmepoitem-gr_pr_time.

                                                                                                                • CONDENSE z1bpmepoitem-reminder1.

                                                                                                                • CONDENSE z1bpmepoitem-reminder2.

                                                                                                                • CONDENSE z1bpmepoitem-reminder3.

                                                                                                                • CONDENSE z1bpmepoitem-over_dlv_tol.

                                                                                                                • CONDENSE z1bpmepoitem-under_dlv_tol.

                                                                                                                • CONDENSE z1bpmepoitem-plan_del.

                                                                                                                • CONDENSE z1bpmepoitem-net_weight.

                                                                                                                • CONDENSE z1bpmepoitem-gross_wt.

                                                                                                                • CONDENSE z1bpmepoitem-volume.

                                                                                                                • CONDENSE z1bpmepoitem-points.

                                                                                                                • CONDENSE z1bpmepoitem-minremlife.

                                                                                                                • idoc_data-sdata = z1bpmepoitem.

                                                                                                                • idoc_data-segnam = c_z1bpmepoitem. "Z1BPMEPOITEM

                                                                                                                • APPEND idoc_data.

                                                                                                                • ENDLOOP.

                                                                                                                *

                                                                                                                *

                                                                                                                  • for segment 'Z1BPMEPOITEMX'

                                                                                                                  **

                                                                                                                  • LOOP AT poitemx

                                                                                                                  • .

                                                                                                                  • CLEAR: z1bpmepoitemx,

                                                                                                                  • idoc_data.

                                                                                                                  • MOVE-CORRESPONDING poitemx

                                                                                                                  • TO z1bpmepoitemx.

                                                                                                                  • idoc_data-sdata = z1bpmepoitemx.

                                                                                                                  • idoc_data-segnam = c_z1bpmepoitemx. "Z1BPMEPOITEMX

                                                                                                                  • APPEND idoc_data.

                                                                                                                  • ENDLOOP.

                                                                                                                  *

                                                                                                                  *

                                                                                                                    • for segment 'Z1BPMEPOADDRDELIVERY'

                                                                                                                    **

                                                                                                                    • LOOP AT poaddrdelivery

                                                                                                                    • .

                                                                                                                    • CLEAR: z1bpmepoaddrdelivery,

                                                                                                                    • idoc_data.

                                                                                                                    • MOVE-CORRESPONDING poaddrdelivery

                                                                                                                    • TO z1bpmepoaddrdelivery.

                                                                                                                    • idoc_data-sdata = z1bpmepoaddrdelivery.

                                                                                                                    • idoc_data-segnam = c_z1bpmepoaddrdelivery. "Z1BPMEPOADDRDELIVERY

                                                                                                                    • APPEND idoc_data.

                                                                                                                    *

                                                                                                                      • for segment 'Z1BPMEPOADDRDELIVERY1'

                                                                                                                      **

                                                                                                                      • CLEAR: z1bpmepoaddrdelivery1,

                                                                                                                      • idoc_data.

                                                                                                                      • MOVE-CORRESPONDING poaddrdelivery

                                                                                                                      • TO z1bpmepoaddrdelivery1.

                                                                                                                      • idoc_data-sdata = z1bpmepoaddrdelivery1.

                                                                                                                      • Z1BPMEPOADDRDELIVERY1

                                                                                                                    • idoc_data-segnam = c_z1bpmepoaddrdelivery1.

                                                                                                                    • APPEND idoc_data.

                                                                                                                    • ENDLOOP.

                                                                                                                    • *

                                                                                                                        • for segment 'Z1BPMEPOSCHEDULE'

                                                                                                                        **

                                                                                                                        • LOOP AT poschedule

                                                                                                                        • .

                                                                                                                        • CLEAR: z1bpmeposchedule,

                                                                                                                        • idoc_data.

                                                                                                                        • MOVE-CORRESPONDING poschedule

                                                                                                                        • TO z1bpmeposchedule.

                                                                                                                        • CONDENSE z1bpmeposchedule-quantity.

                                                                                                                        • idoc_data-sdata = z1bpmeposchedule.

                                                                                                                        • idoc_data-segnam = c_z1bpmeposchedule. "Z1BPMEPOSCHEDULE

                                                                                                                        • APPEND idoc_data.

                                                                                                                        • ENDLOOP.

                                                                                                                        *

                                                                                                                          • for segment 'Z1BPMEPOSCHEDULX'

                                                                                                                          **

                                                                                                                          • LOOP AT poschedulex

                                                                                                                          • .

                                                                                                                          • CLEAR: z1bpmeposchedulx,

                                                                                                                          • idoc_data.

                                                                                                                          • MOVE-CORRESPONDING poschedulex

                                                                                                                          • TO z1bpmeposchedulx.

                                                                                                                          • idoc_data-sdata = z1bpmeposchedulx.

                                                                                                                          • idoc_data-segnam = c_z1bpmeposchedulx. "Z1BPMEPOSCHEDULX

                                                                                                                          • APPEND idoc_data.

                                                                                                                          • ENDLOOP.

                                                                                                                          *

                                                                                                                            • for segment 'Z1BPMEPOACCOUNT'

                                                                                                                            **

                                                                                                                            • LOOP AT poaccount

                                                                                                                            • .

                                                                                                                            • CLEAR: z1bpmepoaccount,

                                                                                                                            • idoc_data.

                                                                                                                            • MOVE-CORRESPONDING poaccount

                                                                                                                            • TO z1bpmepoaccount.

                                                                                                                            • CONDENSE z1bpmepoaccount-quantity.

                                                                                                                            • CONDENSE z1bpmepoaccount-distr_perc.

                                                                                                                            • CONDENSE z1bpmepoaccount-net_value.

                                                                                                                            • CONDENSE z1bpmepoaccount-nond_itax.

                                                                                                                            • idoc_data-sdata = z1bpmepoaccount.

                                                                                                                            • idoc_data-segnam = c_z1bpmepoaccount. "Z1BPMEPOACCOUNT

                                                                                                                            • APPEND idoc_data.

                                                                                                                            • ENDLOOP.

                                                                                                                            *

                                                                                                                              • for segment 'Z1BPMEPOACCOUNTPROFITSEGMEN'

                                                                                                                              **

                                                                                                                              • LOOP AT poaccountprofitsegment

                                                                                                                              • .

                                                                                                                              • CLEAR: z1bpmepoaccountprofitsegmen,

                                                                                                                              • idoc_data.

                                                                                                                              • MOVE-CORRESPONDING poaccountprofitsegment

                                                                                                                              • TO z1bpmepoaccountprofitsegmen.

                                                                                                                              • idoc_data-sdata = z1bpmepoaccountprofitsegmen.

                                                                                                                              • Z1BPMEPOACCOUNTPROFITSEGMEN

                                                                                                                            • idoc_data-segnam = c_z1bpmepoaccountprofitsegmen.

                                                                                                                            • APPEND idoc_data.

                                                                                                                            • ENDLOOP.

                                                                                                                            • *

                                                                                                                                • for segment 'Z1BPMEPOACCOUNTX'

                                                                                                                                **

                                                                                                                                • LOOP AT poaccountx

                                                                                                                                • .

                                                                                                                                • CLEAR: z1bpmepoaccountx,

                                                                                                                                • idoc_data.

                                                                                                                                • MOVE-CORRESPONDING poaccountx

                                                                                                                                • TO z1bpmepoaccountx.

                                                                                                                                • idoc_data-sdata = z1bpmepoaccountx.

                                                                                                                                • idoc_data-segnam = c_z1bpmepoaccountx. "Z1BPMEPOACCOUNTX

                                                                                                                                • APPEND idoc_data.

                                                                                                                                • ENDLOOP.

                                                                                                                                *

                                                                                                                                  • for segment 'Z1BPMEPOCOND'

                                                                                                                                  **

                                                                                                                                  • LOOP AT pocond

                                                                                                                                  • .

                                                                                                                                  • CLEAR: z1bpmepocond,

                                                                                                                                  • idoc_data.

                                                                                                                                  • MOVE-CORRESPONDING pocond

                                                                                                                                  • TO z1bpmepocond.

                                                                                                                                  • CONDENSE z1bpmepocond-cond_value.

                                                                                                                                  • CONDENSE z1bpmepocond-cond_p_unt.

                                                                                                                                  • CONDENSE z1bpmepocond-conbaseval.

                                                                                                                                  • CONDENSE z1bpmepocond-conexchrat.

                                                                                                                                  • CONDENSE z1bpmepocond-numconvert.

                                                                                                                                  • CONDENSE z1bpmepocond-denominato.

                                                                                                                                  • CONDENSE z1bpmepocond-scalbasval.

                                                                                                                                  • idoc_data-sdata = z1bpmepocond.

                                                                                                                                  • idoc_data-segnam = c_z1bpmepocond. "Z1BPMEPOCOND

                                                                                                                                  • APPEND idoc_data.

                                                                                                                                  • ENDLOOP.

                                                                                                                                  *

                                                                                                                                    • for segment 'Z1BPMEPOCONDX'

                                                                                                                                    **

                                                                                                                                    • LOOP AT pocondx

                                                                                                                                    • .

                                                                                                                                    • CLEAR: z1bpmepocondx,

                                                                                                                                    • idoc_data.

                                                                                                                                    • MOVE-CORRESPONDING pocondx

                                                                                                                                    • TO z1bpmepocondx.

                                                                                                                                    • idoc_data-sdata = z1bpmepocondx.

                                                                                                                                    • idoc_data-segnam = c_z1bpmepocondx. "Z1BPMEPOCONDX

                                                                                                                                    • APPEND idoc_data.

                                                                                                                                    • ENDLOOP.

                                                                                                                                    *

                                                                                                                                      • for segment 'E1BPESUHC'

                                                                                                                                      **

                                                                                                                                      • LOOP AT polimits

                                                                                                                                      • .

                                                                                                                                      • CLEAR: e1bpesuhc,

                                                                                                                                      • idoc_data.

                                                                                                                                      • MOVE-CORRESPONDING polimits

                                                                                                                                      • TO e1bpesuhc.

                                                                                                                                      • CONDENSE e1bpesuhc-limit.

                                                                                                                                      • CONDENSE e1bpesuhc-exp_value.

                                                                                                                                      • CONDENSE e1bpesuhc-free_limit.

                                                                                                                                      • CONDENSE e1bpesuhc-ssc_limit.

                                                                                                                                      • CONDENSE e1bpesuhc-ssc_perc.

                                                                                                                                      • CONDENSE e1bpesuhc-tmp_limit.

                                                                                                                                      • CONDENSE e1bpesuhc-tmp_perc.

                                                                                                                                      • CONDENSE e1bpesuhc-cont_perc.

                                                                                                                                      • idoc_data-sdata = e1bpesuhc.

                                                                                                                                      • idoc_data-segnam = c_e1bpesuhc. "E1BPESUHC

                                                                                                                                      • APPEND idoc_data.

                                                                                                                                      • ENDLOOP.

                                                                                                                                      *

                                                                                                                                        • for segment 'E1BPESUCC'

                                                                                                                                        **

                                                                                                                                        • LOOP AT pocontractlimits

                                                                                                                                        • .

                                                                                                                                        • CLEAR: e1bpesucc,

                                                                                                                                        • idoc_data.

                                                                                                                                        • MOVE-CORRESPONDING pocontractlimits

                                                                                                                                        • TO e1bpesucc.

                                                                                                                                        • CONDENSE e1bpesucc-limit.

                                                                                                                                        • idoc_data-sdata = e1bpesucc.

                                                                                                                                        • idoc_data-segnam = c_e1bpesucc. "E1BPESUCC

                                                                                                                                        • APPEND idoc_data.

                                                                                                                                        • ENDLOOP.

                                                                                                                                        *

                                                                                                                                          • for segment 'E1BPESLLC'

                                                                                                                                          **

                                                                                                                                          • LOOP AT poservices

                                                                                                                                          • .

                                                                                                                                          • CLEAR: e1bpesllc,

                                                                                                                                          • idoc_data.

                                                                                                                                          • MOVE-CORRESPONDING poservices

                                                                                                                                          • TO e1bpesllc.

                                                                                                                                          • CONDENSE e1bpesllc-outl_level.

                                                                                                                                          • CONDENSE e1bpesllc-quantity.

                                                                                                                                          • CONDENSE e1bpesllc-ovf_tol.

                                                                                                                                          • CONDENSE e1bpesllc-price_unit.

                                                                                                                                          • CONDENSE e1bpesllc-gr_price.

                                                                                                                                          • CONDENSE e1bpesllc-target_val.

                                                                                                                                          • CONDENSE e1bpesllc-form_val1.

                                                                                                                                          • CONDENSE e1bpesllc-form_val2.

                                                                                                                                          • CONDENSE e1bpesllc-form_val3.

                                                                                                                                          • CONDENSE e1bpesllc-form_val4.

                                                                                                                                          • CONDENSE e1bpesllc-form_val5.

                                                                                                                                          • CONDENSE e1bpesllc-userf2_num.

                                                                                                                                          • idoc_data-sdata = e1bpesllc.

                                                                                                                                          • idoc_data-segnam = c_e1bpesllc. "E1BPESLLC

                                                                                                                                          • APPEND idoc_data.

                                                                                                                                          • ENDLOOP.

                                                                                                                                          *

                                                                                                                                            • for segment 'E1BPESKLC'

                                                                                                                                            **

                                                                                                                                            • LOOP AT posrvaccessvalues

                                                                                                                                            • .

                                                                                                                                            • CLEAR: e1bpesklc,

                                                                                                                                            • idoc_data.

                                                                                                                                            • MOVE-CORRESPONDING posrvaccessvalues

                                                                                                                                            • TO e1bpesklc.

                                                                                                                                            • CONDENSE e1bpesklc-percentage.

                                                                                                                                            • idoc_data-sdata = e1bpesklc.

                                                                                                                                            • idoc_data-segnam = c_e1bpesklc. "E1BPESKLC

                                                                                                                                            • APPEND idoc_data.

                                                                                                                                            • ENDLOOP.

                                                                                                                                            *

                                                                                                                                              • for segment 'E1BPESLLTX'

                                                                                                                                              **

                                                                                                                                              • LOOP AT poservicestext

                                                                                                                                              • .

                                                                                                                                              • CLEAR: e1bpeslltx,

                                                                                                                                              • idoc_data.

                                                                                                                                              • MOVE-CORRESPONDING poservicestext

                                                                                                                                              • TO e1bpeslltx.

                                                                                                                                              • idoc_data-sdata = e1bpeslltx.

                                                                                                                                              • idoc_data-segnam = c_e1bpeslltx. "E1BPESLLTX

                                                                                                                                              • APPEND idoc_data.

                                                                                                                                              • ENDLOOP.

                                                                                                                                              *

                                                                                                                                                • for segment 'E1BPPAREX'

                                                                                                                                                **

                                                                                                                                                • LOOP AT extensionin

                                                                                                                                                • .

                                                                                                                                                • CLEAR: e1bpparex,

                                                                                                                                                • idoc_data.

                                                                                                                                                • MOVE-CORRESPONDING extensionin

                                                                                                                                                • TO e1bpparex.

                                                                                                                                                • idoc_data-sdata = e1bpparex.

                                                                                                                                                • idoc_data-segnam = c_e1bpparex. "E1BPPAREX

                                                                                                                                                • APPEND idoc_data.

                                                                                                                                                • ENDLOOP.

                                                                                                                                                *

                                                                                                                                                  • end of through all IDoc-segments

                                                                                                                                                  **

                                                                                                                                                  *

                                                                                                                                                  *ENDFORM. " ZIDOC_PO_CREATE1

                                                                                                                                                  *

                                                                                                                                                  *PVU-20-May-2004 - End Changes for SCR1

                                                                                                                                                  ***BV-27-May-2004 - Begin of Changes for SCR2***

                                                                                                                                                  &----


                                                                                                                                                  *& Form get_account_assignment

                                                                                                                                                  &----


                                                                                                                                                  • Retrieve the account assignment value from Z table zacctasgmnt

                                                                                                                                                  • and modify the poitem and poitemx data.

                                                                                                                                                  ----


                                                                                                                                                  • -->T_POITEM PO item data

                                                                                                                                                  • -->T_POITEMX PO itemx data

                                                                                                                                                  • -->T_POACCOUNT PO account data

                                                                                                                                                  • -->T_COMPCODE Company code

                                                                                                                                                  ----


                                                                                                                                                  FORM get_account_assignment TABLES t_poitem STRUCTURE bapimepoitem

                                                                                                                                                  t_poitemx STRUCTURE bapimepoitemx

                                                                                                                                                  t_poaccount STRUCTURE bapimepoaccount

                                                                                                                                                  t_poaccountx STRUCTURE bapimepoaccountx

                                                                                                                                                  t_yreturn STRUCTURE bapiret2

                                                                                                                                                  USING t_compcode TYPE bukrs

                                                                                                                                                  t_poheader TYPE bapimepoheader.

                                                                                                                                                  DATA: t_acct_assignmt LIKE zacctasgmnt OCCURS 0 WITH HEADER LINE.

                                                                                                                                                  DATA: l_acct_present(1) TYPE c,

                                                                                                                                                  l_cc_present(1) TYPE c,

                                                                                                                                                  l_wbs_present(1) TYPE c,

                                                                                                                                                  l_acct_assign TYPE zconstval,

                                                                                                                                                  l_wa_poaccount type bapimepoaccount,

                                                                                                                                                  l_flag(1) type c,

                                                                                                                                                  L_flag1(1) type c,

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  *& Begin of Addition: 26-Sep-2005 SDUTTARO RD1K910316 *&

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  l_index TYPE sy-tabix, "@SDR

                                                                                                                                                  l_itemindex TYPE sy-tabix, "@SDR

                                                                                                                                                  l_msgv1 TYPE sy-msgv1, "@SDR

                                                                                                                                                  l_msgv2 TYPE sy-msgv2, "@SDR

                                                                                                                                                  l_constname TYPE zconstname VALUE 'CONVERSION', "@SDR

                                                                                                                                                  l_constval TYPE zconstval , "@SDR

                                                                                                                                                  l_conv_val TYPE zconstval , "@SDR

                                                                                                                                                  l_constname_gr TYPE zconstname VALUE 'NONVAL_GRIR' , "@SDR

                                                                                                                                                  l_constval_gr TYPE zconstval , "@SDR

                                                                                                                                                  l_ex_pro_no TYPE ABLAD , "@SDR

                                                                                                                                                  l_ex_cc TYPE Kostl , "@SDR

                                                                                                                                                  l_ex_acc_no TYPE SAKNR , "@SDR

                                                                                                                                                  l_costcenter TYPE kostl , "@SDR

                                                                                                                                                  l_reference TYPE ablad , "@SDR

                                                                                                                                                  l_psga_glacct TYPE zconstname VALUE 'PSGA_ACCOUNT'. "@SDR

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  *& End of Addition: 26-Sep-2005 SDUTTARO RD1K910316 *&

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  *BV-08-July-2004 -Begin - Change error handling for zxa_get_constant

                                                                                                                                                  DATA : L_CONST_NAME LIKE SY-MSGV1, "Constant name

                                                                                                                                                  L_COMP_CODE LIKE SY-MSGV2, "Company code

                                                                                                                                                  l_acct_assmnt TYPE knttp.

                                                                                                                                                  *BV-08-July-2004 -End - Change error handling for zxa_get_constant

                                                                                                                                                  • Retrieve Account assignment category

                                                                                                                                                  SELECT * FROM zacctasgmnt

                                                                                                                                                  INTO TABLE t_acct_assignmt

                                                                                                                                                  WHERE comp_code EQ t_compcode.

                                                                                                                                                  IF sy-subrc = 0.

                                                                                                                                                  • Retrieve Account assignment constant

                                                                                                                                                  CALL FUNCTION 'ZXA_GET_CONSTANT'

                                                                                                                                                  EXPORTING

                                                                                                                                                  const_name = c_acct_assign

                                                                                                                                                  comp_code = t_compcode

                                                                                                                                                  IMPORTING

                                                                                                                                                  const_value = l_acct_assign

                                                                                                                                                  EXCEPTIONS

                                                                                                                                                  no_value_found = 1

                                                                                                                                                  null_value = 2

                                                                                                                                                  OTHERS = 3.

                                                                                                                                                  IF sy-subrc <> 0.

                                                                                                                                                  **BV-08-July-2004 -Begin - Change error handling for zxa_get_constant

                                                                                                                                                  *Constant not defined for company code.

                                                                                                                                                  CLEAR : L_CONST_NAME,

                                                                                                                                                  L_COMP_CODE.

                                                                                                                                                  L_CONST_NAME = c_acct_assign. "ZRP_ACCT_ASSIGN

                                                                                                                                                  L_COMP_CODE = t_compcode.

                                                                                                                                                  **BV-08-July-2004 -End - Change error handling for zxa_get_constant

                                                                                                                                                  CALL FUNCTION 'BALW_BAPIRETURN_GET2'

                                                                                                                                                  EXPORTING

                                                                                                                                                  type = c_msgtype_e "E

                                                                                                                                                  cl = c_msgid_z001

                                                                                                                                                  **BV-08-July-2004 -Begin - Change error handling for zxa_get_constant

                                                                                                                                                  • number = c_msgnr_045 "045

                                                                                                                                                  number = c_msgnr_046 "046

                                                                                                                                                  PAR1 = L_CONST_NAME "ZRP_ACCT_ASSIGN

                                                                                                                                                  PAR2 = L_COMP_CODE

                                                                                                                                                  **BV-08-July-2004 -End - Change error handling for zxa_get_constant

                                                                                                                                                  IMPORTING

                                                                                                                                                  return = t_yreturn.

                                                                                                                                                  APPEND t_yreturn.

                                                                                                                                                  CLEAR t_yreturn.

                                                                                                                                                  loop at t_yreturn.

                                                                                                                                                  l_wa_zerrors-OBJECT = 'PURCHASE_ORDER'.

                                                                                                                                                  l_wa_zerrors-serial_no = sy-tabix.

                                                                                                                                                  l_wa_zerrors-zid = t_yreturn-id.

                                                                                                                                                  l_wa_zerrors-type = t_yreturn-type.

                                                                                                                                                  l_wa_zerrors-znumber = t_yreturn-number.

                                                                                                                                                  l_wa_zerrors-COMP_CODE = t_compcode.

                                                                                                                                                  l_wa_zerrors-BEACON_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-SRC_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-ZDATE = sy-datum.

                                                                                                                                                  l_wa_zerrors-ERR_MSG = t_yreturn-message.

                                                                                                                                                  append l_wa_zerrors to t_errors.

                                                                                                                                                  • insert into zerrors values l_wa_zerrors.

                                                                                                                                                  clear: l_wa_zerrors.

                                                                                                                                                  endloop.

                                                                                                                                                  EXIT.

                                                                                                                                                  ENDIF.

                                                                                                                                                  ENDIF.

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  *& Begin of Addition: 26-Sep-2005 SDUTTARO RD1K910316 *&

                                                                                                                                                  &----


                                                                                                                                                  &
                                                                                                                                                  • Requirement very specific to Alza

                                                                                                                                                  IF t_compcode = c_bukrs_alza. " 1155 "@SDR

                                                                                                                                                  • Check whether the conversion check is switched on for the specific

                                                                                                                                                  • business unit.

                                                                                                                                                  CLEAR: l_constval. "@SDR

                                                                                                                                                  CALL FUNCTION 'ZXA_GET_CONSTANT' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  const_name = l_constname "@SDR

                                                                                                                                                  comp_code = t_compcode "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  const_value = l_conv_val "@SDR

                                                                                                                                                  EXCEPTIONS "@SDR

                                                                                                                                                  no_value_found = 1 "@SDR

                                                                                                                                                  null_value = 2 "@SDR

                                                                                                                                                  OTHERS = 3. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  IF sy-subrc <> 0. "@SDR

                                                                                                                                                  CLEAR l_conv_val. "@SDR

                                                                                                                                                  l_msgv1 = l_constname. "@SDR

                                                                                                                                                  l_msgv2 = t_compcode. "@SDR

                                                                                                                                                  CALL FUNCTION 'BALW_BAPIRETURN_GET2' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  TYPE = c_msgtype_e "@SDR

                                                                                                                                                  CL = c_msgid_z001 "@SDR

                                                                                                                                                  NUMBER = c_msgnr_046 "@SDR

                                                                                                                                                  PAR1 = l_msgv1 "CONVERSION "@SDR

                                                                                                                                                  PAR2 = l_msgv2 "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  RETURN = t_yreturn. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  APPEND t_yreturn. "@SDR

                                                                                                                                                  CLEAR: t_yreturn , "@SDR

                                                                                                                                                  l_conv_val, "@SDR

                                                                                                                                                  l_msgv1 , "@SDR

                                                                                                                                                  l_msgv2 .

                                                                                                                                                  loop at t_yreturn.

                                                                                                                                                  l_wa_zerrors-OBJECT = 'PURCHASE_ORDER'.

                                                                                                                                                  l_wa_zerrors-serial_no = sy-tabix.

                                                                                                                                                  l_wa_zerrors-COMP_CODE = t_compcode.

                                                                                                                                                  l_wa_zerrors-zid = t_yreturn-id.

                                                                                                                                                  l_wa_zerrors-type = t_yreturn-type.

                                                                                                                                                  l_wa_zerrors-znumber = t_yreturn-number.

                                                                                                                                                  l_wa_zerrors-BEACON_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-SRC_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-ZDATE = sy-datum.

                                                                                                                                                  l_wa_zerrors-ERR_MSG = t_yreturn-message.

                                                                                                                                                  append l_wa_zerrors to t_errors.

                                                                                                                                                  • insert into zerrors values l_wa_zerrors.

                                                                                                                                                  clear: l_wa_zerrors.

                                                                                                                                                  endloop.

                                                                                                                                                  EXIT. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  • Check whether the Non-valuated GR indicator is Switched ON or OFF

                                                                                                                                                  CLEAR: l_constval_gr. "@SDR

                                                                                                                                                  CALL FUNCTION 'ZXA_GET_CONSTANT' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  const_name = l_constname_gr "@SDR

                                                                                                                                                  comp_code = t_compcode "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  const_value = l_constval_gr "@SDR

                                                                                                                                                  EXCEPTIONS "@SDR

                                                                                                                                                  no_value_found = 1 "@SDR

                                                                                                                                                  null_value = 2 "@SDR

                                                                                                                                                  OTHERS = 3. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  IF sy-subrc <> 0. "@SDR

                                                                                                                                                  CLEAR l_constval_gr. "@SDR

                                                                                                                                                  l_msgv1 = l_constname_gr. "@SDR

                                                                                                                                                  l_msgv2 = t_compcode. "@SDR

                                                                                                                                                  CALL FUNCTION 'BALW_BAPIRETURN_GET2' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  TYPE = c_msgtype_e "@SDR

                                                                                                                                                  CL = c_msgid_z001 "@SDR

                                                                                                                                                  NUMBER = c_msgnr_046 "@SDR

                                                                                                                                                  PAR1 = l_msgv1 "CONVERSION "@SDR

                                                                                                                                                  PAR2 = l_msgv2 "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  RETURN = t_yreturn. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  APPEND t_yreturn. "@SDR

                                                                                                                                                  CLEAR: t_yreturn , "@SDR

                                                                                                                                                  l_constval_gr, "@SDR

                                                                                                                                                  l_msgv1 , "@SDR

                                                                                                                                                  l_msgv2 . "@SDR

                                                                                                                                                  loop at t_yreturn.

                                                                                                                                                  l_wa_zerrors-OBJECT = 'PURCHASE_ORDER'.

                                                                                                                                                  l_wa_zerrors-serial_no = sy-tabix.

                                                                                                                                                  l_wa_zerrors-COMP_CODE = t_compcode.

                                                                                                                                                  l_wa_zerrors-zid = t_yreturn-id.

                                                                                                                                                  l_wa_zerrors-type = t_yreturn-type.

                                                                                                                                                  l_wa_zerrors-znumber = t_yreturn-number.

                                                                                                                                                  l_wa_zerrors-BEACON_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-SRC_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-ZDATE = sy-datum.

                                                                                                                                                  l_wa_zerrors-ERR_MSG = t_yreturn-message.

                                                                                                                                                  append l_wa_zerrors to t_errors.

                                                                                                                                                  • insert into zerrors values l_wa_zerrors.

                                                                                                                                                  clear: l_wa_zerrors.

                                                                                                                                                  endloop.

                                                                                                                                                  EXIT. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  *& End of Addition: 26-Sep-2005 SDUTTARO RD1K910316 *&

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  LOOP AT t_poitem.

                                                                                                                                                  CLEAR: l_acct_present, l_cc_present, l_wbs_present.

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  *& Begin of Addition: 26-Sep-2005 SDUTTARO RD1K910316 *&

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  l_itemindex = sy-tabix. "@SDR

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  *& End of Addition: 26-Sep-2005 SDUTTARO RD1K910316 *&

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  LOOP AT t_poaccount WHERE po_item = t_poitem-po_item.

                                                                                                                                                  CLEAR: t_acct_assignmt.

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  *& Begin of Addition: 26-Sep-2005 SDUTTARO RD1K910316 *&

                                                                                                                                                  &----


                                                                                                                                                  &
                                                                                                                                                  • Requirement very specific to Alza

                                                                                                                                                  IF t_compcode = c_bukrs_alza. " 1155 "@SDR

                                                                                                                                                  • Arrest the cuurent record number for the loop.

                                                                                                                                                  l_index = sy-tabix. "@SDR

                                                                                                                                                  • If the conversion switch is on for the specific business unit

                                                                                                                                                  • use custom mapping tables to fetch the corresponding WBS

                                                                                                                                                  • Elements, GL accounts and Cost Centers

                                                                                                                                                  IF l_conv_val = 'X'. " Conversion is switched ON "@SDR

                                                                                                                                                  • Use the below custom FM to retrieve the corresponding GL

                                                                                                                                                  • account from SAP fro the external GL Account Number

                                                                                                                                                  IF ( NOT t_compcode IS INITIAL ) "@SDR

                                                                                                                                                  AND ( NOT t_poaccount-gl_account IS INITIAL ). "@SDR

                                                                                                                                                  IF NOT t_poaccount-costcenter IS INITIAL. "@SDR

                                                                                                                                                  SHIFT t_poaccount-costcenter LEFT "@SDR

                                                                                                                                                  DELETING LEADING c_zeros. "@SDR

                                                                                                                                                  l_ex_cc = t_poaccount-costcenter. "@SDR

                                                                                                                                                  CALL FUNCTION 'Z_COSTCTR_GET' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  P_BUKRS = t_compcode "@SDR

                                                                                                                                                  P_EX_CC = l_ex_cc "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  P_COSTCTR = l_costcenter "@SDR

                                                                                                                                                  EXCEPTIONS "@SDR

                                                                                                                                                  NO_VALUE_FOUND = 1 "@SDR

                                                                                                                                                  NULL_VALUE_FOUND = 2 "@SDR

                                                                                                                                                  OTHERS = 3. "@SDR

                                                                                                                                                  IF sy-subrc <> 0. "@SDR

                                                                                                                                                  t_poaccount-costcenter = space. "@SDR

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING costcenter. "@SDR

                                                                                                                                                  READ TABLE t_poaccountx WITH "@SDR

                                                                                                                                                  KEY po_item = t_poaccount-po_item "@SDR

                                                                                                                                                  serial_no = t_poaccount-serial_no. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poaccountx-costcenter = space. "@SDR

                                                                                                                                                  MODIFY t_poaccountx INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING costcenter. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  l_msgv1 = l_costcenter. "@SDR

                                                                                                                                                  l_msgv2 = t_compcode. "@SDR

                                                                                                                                                  CALL FUNCTION 'BALW_BAPIRETURN_GET2' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  TYPE = c_msgtype_e "@SDR

                                                                                                                                                  CL = c_msgid_z001 "@SDR

                                                                                                                                                  NUMBER = c_msgnr_072 "@SDR

                                                                                                                                                  PAR1 = l_msgv1 "@SDR

                                                                                                                                                  PAR2 = l_msgv2 "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  RETURN = t_yreturn. "@SDR

                                                                                                                                                  CLEAR: l_index, "@SDR

                                                                                                                                                  l_costcenter. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  APPEND t_yreturn. "@SDR

                                                                                                                                                  CLEAR: t_yreturn, "@SDR

                                                                                                                                                  l_constval, "@SDR

                                                                                                                                                  l_msgv1 , "@SDR

                                                                                                                                                  l_msgv2 . "@SDR

                                                                                                                                                  loop at t_yreturn.

                                                                                                                                                  l_wa_zerrors-OBJECT = 'PURCHASE_ORDER'.

                                                                                                                                                  l_wa_zerrors-serial_no = sy-tabix.

                                                                                                                                                  l_wa_zerrors-COMP_CODE = t_compcode.

                                                                                                                                                  l_wa_zerrors-zid = t_yreturn-id.

                                                                                                                                                  l_wa_zerrors-type = t_yreturn-type.

                                                                                                                                                  l_wa_zerrors-znumber = t_yreturn-number.

                                                                                                                                                  l_wa_zerrors-BEACON_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-SRC_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-ZDATE = sy-datum.

                                                                                                                                                  l_wa_zerrors-ERR_MSG = t_yreturn-message.

                                                                                                                                                  append l_wa_zerrors to t_errors.

                                                                                                                                                  • insert into zerrors values l_wa_zerrors.

                                                                                                                                                  clear: l_wa_zerrors.

                                                                                                                                                  endloop.

                                                                                                                                                  EXIT. "@SDR

                                                                                                                                                  ELSE. "@SDR

                                                                                                                                                  SHIFT l_costcenter LEFT "@SDR

                                                                                                                                                  DELETING LEADING c_zeros. "@SDR

                                                                                                                                                  IF l_costcenter = c_psgaw_cc. " 54123 "@SDR

                                                                                                                                                  CLEAR: l_constval. "@SDR

                                                                                                                                                  CALL FUNCTION 'ZXA_GET_CONSTANT' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  const_name = l_psga_glacct "@SDR

                                                                                                                                                  comp_code = t_compcode "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  const_value = l_constval "@SDR

                                                                                                                                                  EXCEPTIONS "@SDR

                                                                                                                                                  no_value_found = 1 "@SDR

                                                                                                                                                  null_value = 2 "@SDR

                                                                                                                                                  OTHERS = 3. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  IF sy-subrc <> 0. "@SDR

                                                                                                                                                  t_poaccount-gl_account = space. "@SDR

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING gl_account. "@SDR

                                                                                                                                                  READ TABLE t_poaccountx WITH KEY "@SDR

                                                                                                                                                  po_item = t_poaccount-po_item "@SDR

                                                                                                                                                  serial_no = t_poaccount-serial_no. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poaccountx-gl_account = space. "@SDR

                                                                                                                                                  MODIFY t_poaccountx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING gl_account. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  CLEAR l_constval. "@SDR

                                                                                                                                                  l_msgv1 = l_constname. "@SDR

                                                                                                                                                  l_msgv2 = t_compcode. "@SDR

                                                                                                                                                  CALL FUNCTION 'BALW_BAPIRETURN_GET2' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  TYPE = c_msgtype_e "@SDR

                                                                                                                                                  CL = c_msgid_z001 "@SDR

                                                                                                                                                  NUMBER = c_msgnr_046 "@SDR

                                                                                                                                                  PAR1 = l_msgv1 "CONVERSION "@SDR

                                                                                                                                                  PAR2 = l_msgv2 "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  RETURN = t_yreturn. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  APPEND t_yreturn. "@SDR

                                                                                                                                                  CLEAR: t_yreturn , "@SDR

                                                                                                                                                  l_constval, "@SDR

                                                                                                                                                  l_msgv1 , "@SDR

                                                                                                                                                  l_msgv2 . "@SDR

                                                                                                                                                  loop at t_yreturn.

                                                                                                                                                  l_wa_zerrors-OBJECT = 'PURCHASE_ORDER'.

                                                                                                                                                  l_wa_zerrors-serial_no = sy-tabix.

                                                                                                                                                  l_wa_zerrors-COMP_CODE = t_compcode.

                                                                                                                                                  l_wa_zerrors-zid = t_yreturn-id.

                                                                                                                                                  l_wa_zerrors-type = t_yreturn-type.

                                                                                                                                                  l_wa_zerrors-znumber = t_yreturn-number.

                                                                                                                                                  l_wa_zerrors-BEACON_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-SRC_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-ZDATE = sy-datum.

                                                                                                                                                  l_wa_zerrors-ERR_MSG = t_yreturn-message.

                                                                                                                                                  append l_wa_zerrors to t_errors.

                                                                                                                                                  • insert into zerrors values l_wa_zerrors.

                                                                                                                                                  clear: l_wa_zerrors.

                                                                                                                                                  endloop.

                                                                                                                                                  EXIT. "@SDR

                                                                                                                                                  ELSE. "@SDR

                                                                                                                                                  MOVE l_constval TO "@SDR

                                                                                                                                                  t_poaccount-gl_account. "@SDR

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  INPUT = t_poaccount-gl_account

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  OUTPUT = t_poaccount-gl_account.

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING gl_account. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ELSE. "@SDR

                                                                                                                                                  SHIFT t_poaccount-gl_account LEFT "@SDR

                                                                                                                                                  DELETING LEADING c_zeros. "@SDR

                                                                                                                                                  SHIFT t_poaccount-gl_account "@SDR

                                                                                                                                                  BY 1 PLACES RIGHT. "@SDR

                                                                                                                                                  t_poaccount-gl_account+0(1) = 'P'. "@SDR

                                                                                                                                                  l_ex_acc_no = t_poaccount-gl_account. "@SDR

                                                                                                                                                  CALL FUNCTION 'Z_GLACCT_GET' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  P_BUKRS = t_compcode "@SDR

                                                                                                                                                  P_EX_ACC_NO = l_ex_acc_no "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  P_GLACCT = "@SDR

                                                                                                                                                  t_poaccount-gl_account "@SDR

                                                                                                                                                  EXCEPTIONS "@SDR

                                                                                                                                                  NO_VALUE_FOUND = 1 "@SDR

                                                                                                                                                  NULL_VALUE_FOUND = 2 "@SDR

                                                                                                                                                  OTHERS = 3. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  • Assign the retrieved GL Account from SAP to the

                                                                                                                                                  • account assignment strcuture after the mapping

                                                                                                                                                  • is successful

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  INPUT = t_poaccount-gl_account

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  OUTPUT = t_poaccount-gl_account.

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING gl_account. "@SDR

                                                                                                                                                  ELSE. "@SDR

                                                                                                                                                  t_poaccount-gl_account = space. "@SDR

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING gl_account. "@SDR

                                                                                                                                                  READ TABLE t_poaccountx WITH KEY "@SDR

                                                                                                                                                  po_item = t_poaccount-po_item "@SDR

                                                                                                                                                  serial_no = t_poaccount-serial_no. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poaccountx-gl_account = space. "@SDR

                                                                                                                                                  MODIFY t_poaccountx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING gl_account. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  • Issue an error message that the mapping of the

                                                                                                                                                  • external Reference Number to SAP GL Account has

                                                                                                                                                  • not been possible as no mapping or null mapping

                                                                                                                                                  • has been maintained in the custom mapping table

                                                                                                                                                  l_msgv1 = t_poaccount-gl_account. "@SDR

                                                                                                                                                  l_msgv2 = t_compcode. "@SDR

                                                                                                                                                  CALL FUNCTION 'BALW_BAPIRETURN_GET2' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  TYPE = c_msgtype_e "@SDR

                                                                                                                                                  CL = c_msgid_z001 "@SDR

                                                                                                                                                  NUMBER = c_msgnr_071 "@SDR

                                                                                                                                                  PAR1 = l_msgv1 "@SDR

                                                                                                                                                  PAR2 = l_msgv2 "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  RETURN = t_yreturn. "@SDR

                                                                                                                                                  CLEAR: l_index, "@SDR

                                                                                                                                                  t_poaccount-gl_account. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  APPEND t_yreturn. "@SDR

                                                                                                                                                  CLEAR: t_yreturn, "@SDR

                                                                                                                                                  l_constval, "@SDR

                                                                                                                                                  l_msgv1 , "@SDR

                                                                                                                                                  l_msgv2 . "@SDR

                                                                                                                                                  loop at t_yreturn.

                                                                                                                                                  l_wa_zerrors-OBJECT = 'PURCHASE_ORDER'.

                                                                                                                                                  l_wa_zerrors-serial_no = sy-tabix.

                                                                                                                                                  l_wa_zerrors-COMP_CODE = t_compcode.

                                                                                                                                                  l_wa_zerrors-zid = t_yreturn-id.

                                                                                                                                                  l_wa_zerrors-type = t_yreturn-type.

                                                                                                                                                  l_wa_zerrors-znumber = t_yreturn-number.

                                                                                                                                                  l_wa_zerrors-BEACON_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-SRC_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-ZDATE = sy-datum.

                                                                                                                                                  l_wa_zerrors-ERR_MSG = t_yreturn-message.

                                                                                                                                                  append l_wa_zerrors to t_errors.

                                                                                                                                                  • insert into zerrors values l_wa_zerrors.

                                                                                                                                                  clear: l_wa_zerrors.

                                                                                                                                                  endloop.

                                                                                                                                                  EXIT. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ELSE. "@SDR

                                                                                                                                                  t_poaccount-gl_account = space. "@SDR

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING gl_account. "@SDR

                                                                                                                                                  READ TABLE t_poaccountx "@SDR

                                                                                                                                                  WITH KEY po_item = t_poaccount-po_item "@SDR

                                                                                                                                                  serial_no = t_poaccount-serial_no. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poaccountx-gl_account = space. "@SDR

                                                                                                                                                  MODIFY t_poaccountx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING gl_account. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  IF l_costcenter = c_psgaw_cc. " 54123 "@SDR

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  INPUT = l_costcenter "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  OUTPUT = l_costcenter. "@SDR

                                                                                                                                                  t_poaccount-costcenter = l_costcenter. "@SDR

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING costcenter. "@SDR

                                                                                                                                                  t_poaccount-wbs_element = space. "@SDR

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING wbs_element. "@SDR

                                                                                                                                                  READ TABLE t_poaccountx "@SDR

                                                                                                                                                  WITH KEY po_item = t_poaccount-po_item "@SDR

                                                                                                                                                  serial_no = t_poaccount-serial_no. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poaccountx-wbs_element = space. "@SDR

                                                                                                                                                  MODIFY t_poaccountx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING wbs_element. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ELSE. "@SDR

                                                                                                                                                  • Check whether REFERENCE field is the same as Department

                                                                                                                                                  MOVE t_poaccount-unload_pt TO l_reference. "@SDR

                                                                                                                                                  SHIFT l_reference LEFT DELETING LEADING c_zeros. "@SDR

                                                                                                                                                  • Check for external GL accounts starting with P164, P165 or

                                                                                                                                                  • P169 and Reference is blank or starts with 4 zeros

                                                                                                                                                  IF ( ( l_ex_acc_no+0(4) = c_p164 "P164 "@SDR

                                                                                                                                                  OR l_ex_acc_no+0(4) = c_p165 "P165 "@SDR

                                                                                                                                                  OR l_ex_acc_no+0(4) = c_p169 ) "P169 "@SDR

                                                                                                                                                  AND ( l_reference IS INITIAL "@SDR

                                                                                                                                                  OR ( t_poaccount-unload_pt+0(4) = c_4zeros ) ) ). "@SDR

                                                                                                                                                  CLEAR: l_constval. "@SDR

                                                                                                                                                  CALL FUNCTION 'ZXA_GET_CONSTANT' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  const_name = c_wbs_default "@SDR

                                                                                                                                                  comp_code = t_compcode "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  const_value = l_constval "@SDR

                                                                                                                                                  EXCEPTIONS "@SDR

                                                                                                                                                  no_value_found = 1 "@SDR

                                                                                                                                                  null_value = 2 "@SDR

                                                                                                                                                  OTHERS = 3. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  IF sy-subrc <> 0. "@SDR

                                                                                                                                                  t_poaccount-wbs_element = space. "@SDR

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING wbs_element. "@SDR

                                                                                                                                                  READ TABLE t_poaccountx WITH KEY "@SDR

                                                                                                                                                  po_item = t_poaccount-po_item "@SDR

                                                                                                                                                  serial_no = t_poaccount-serial_no. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poaccountx-wbs_element = space. "@SDR

                                                                                                                                                  MODIFY t_poaccountx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING wbs_element. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  CLEAR l_constval. "@SDR

                                                                                                                                                  l_msgv1 = l_constname. "@SDR

                                                                                                                                                  l_msgv2 = t_compcode. "@SDR

                                                                                                                                                  CALL FUNCTION 'BALW_BAPIRETURN_GET2' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  TYPE = c_msgtype_e "@SDR

                                                                                                                                                  CL = c_msgid_z001 "@SDR

                                                                                                                                                  NUMBER = c_msgnr_046 "@SDR

                                                                                                                                                  PAR1 = l_msgv1 "CONVERSION "@SDR

                                                                                                                                                  PAR2 = l_msgv2 "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  RETURN = t_yreturn. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  APPEND t_yreturn. "@SDR

                                                                                                                                                  CLEAR: t_yreturn , "@SDR

                                                                                                                                                  l_constval, "@SDR

                                                                                                                                                  l_msgv1 , "@SDR

                                                                                                                                                  l_msgv2 . "@SDR

                                                                                                                                                  loop at t_yreturn.

                                                                                                                                                  l_wa_zerrors-OBJECT = 'PURCHASE_ORDER'.

                                                                                                                                                  l_wa_zerrors-serial_no = sy-tabix.

                                                                                                                                                  l_wa_zerrors-COMP_CODE = t_compcode.

                                                                                                                                                  l_wa_zerrors-zid = t_yreturn-id.

                                                                                                                                                  l_wa_zerrors-type = t_yreturn-type.

                                                                                                                                                  l_wa_zerrors-znumber = t_yreturn-number.

                                                                                                                                                  l_wa_zerrors-BEACON_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-SRC_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-ZDATE = sy-datum.

                                                                                                                                                  l_wa_zerrors-ERR_MSG = t_yreturn-message.

                                                                                                                                                  append l_wa_zerrors to t_errors.

                                                                                                                                                  • insert into zerrors values l_wa_zerrors.

                                                                                                                                                  clear: l_wa_zerrors.

                                                                                                                                                  endloop.

                                                                                                                                                  EXIT. "@SDR

                                                                                                                                                  ELSE. "@SDR

                                                                                                                                                  t_poaccount-wbs_element = l_constval. "@SDR

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING wbs_element. "@SDR

                                                                                                                                                  READ TABLE t_poaccountx WITH KEY "@SDR

                                                                                                                                                  po_item = t_poaccount-po_item "@SDR

                                                                                                                                                  serial_no = t_poaccount-serial_no. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poaccountx-wbs_element = 'X'. "@SDR

                                                                                                                                                  MODIFY t_poaccountx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING wbs_element. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  t_poaccount-costcenter = space. "@SDR

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING costcenter. "@SDR

                                                                                                                                                  READ TABLE t_poaccountx WITH KEY "@SDR

                                                                                                                                                  po_item = t_poaccount-po_item "@SDR

                                                                                                                                                  serial_no = t_poaccount-serial_no. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poaccountx-costcenter = space. "@SDR

                                                                                                                                                  MODIFY t_poaccountx INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING costcenter. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ELSE. "@SDR

                                                                                                                                                  IF t_poaccount-costcenter = l_reference. "@SDR

                                                                                                                                                  • Map the Popelsoft Cost Center into SAP Cost Center

                                                                                                                                                  IF ( NOT t_compcode IS INITIAL ) "@SDR

                                                                                                                                                  AND ( NOT t_poaccount-costcenter IS INITIAL ). "@SDR

                                                                                                                                                  SHIFT t_poaccount-costcenter LEFT "@SDR

                                                                                                                                                  DELETING LEADING c_zeros. "@SDR

                                                                                                                                                  l_ex_cc = t_poaccount-costcenter. "@SDR

                                                                                                                                                  CALL FUNCTION 'Z_COSTCTR_GET' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  P_BUKRS = t_compcode "@SDR

                                                                                                                                                  P_EX_CC = l_ex_cc "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  P_COSTCTR = "@SDR

                                                                                                                                                  t_poaccount-costcenter "@SDR

                                                                                                                                                  EXCEPTIONS "@SDR

                                                                                                                                                  NO_VALUE_FOUND = 1 "@SDR

                                                                                                                                                  NULL_VALUE_FOUND = 2 "@SDR

                                                                                                                                                  OTHERS = 3. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  • Assign the retrieved Cost Center from SAP to the

                                                                                                                                                  • account assignment strcuture after the mapping is

                                                                                                                                                  • successful

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  INPUT = t_poaccount-costcenter

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  OUTPUT = t_poaccount-costcenter.

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING costcenter. "@SDR

                                                                                                                                                  ELSE. "@SDR

                                                                                                                                                  READ TABLE t_poaccountx WITH KEY "@SDR

                                                                                                                                                  po_item = t_poaccount-po_item "@SDR

                                                                                                                                                  serial_no = t_poaccount-serial_no. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poaccountx-costcenter = space. "@SDR

                                                                                                                                                  MODIFY t_poaccountx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING costcenter. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  • Issue an error message that the mapping of the

                                                                                                                                                  • external Reference Number to SAP WBS Element has

                                                                                                                                                  • not been possible as no mapping or null mapping

                                                                                                                                                  • has been maintained in the custom mapping table

                                                                                                                                                  l_msgv1 = t_poaccount-costcenter. "@SDR

                                                                                                                                                  l_msgv2 = t_compcode. "@SDR

                                                                                                                                                  CALL FUNCTION 'BALW_BAPIRETURN_GET2' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  TYPE = c_msgtype_e "@SDR

                                                                                                                                                  CL = c_msgid_z001 "@SDR

                                                                                                                                                  NUMBER = c_msgnr_072 "@SDR

                                                                                                                                                  PAR1 = l_msgv1 "@SDR

                                                                                                                                                  PAR2 = l_msgv2 "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  RETURN = t_yreturn. "@SDR

                                                                                                                                                  CLEAR: l_index, "@SDR

                                                                                                                                                  t_poaccount-costcenter. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  APPEND t_yreturn. "@SDR

                                                                                                                                                  CLEAR: t_yreturn, "@SDR

                                                                                                                                                  l_constval, "@SDR

                                                                                                                                                  l_msgv1 , "@SDR

                                                                                                                                                  l_msgv2 . "@SDR

                                                                                                                                                  loop at t_yreturn.

                                                                                                                                                  l_wa_zerrors-OBJECT = 'PURCHASE_ORDER'.

                                                                                                                                                  l_wa_zerrors-serial_no = sy-tabix.

                                                                                                                                                  l_wa_zerrors-COMP_CODE = t_compcode.

                                                                                                                                                  l_wa_zerrors-zid = t_yreturn-id.

                                                                                                                                                  l_wa_zerrors-type = t_yreturn-type.

                                                                                                                                                  l_wa_zerrors-znumber = t_yreturn-number.

                                                                                                                                                  l_wa_zerrors-BEACON_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-SRC_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-ZDATE = sy-datum.

                                                                                                                                                  l_wa_zerrors-ERR_MSG = t_yreturn-message.

                                                                                                                                                  append l_wa_zerrors to t_errors.

                                                                                                                                                  • insert into zerrors values l_wa_zerrors.

                                                                                                                                                  clear: l_wa_zerrors.

                                                                                                                                                  endloop.

                                                                                                                                                  EXIT. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ELSE. "@SDR

                                                                                                                                                  • IF the first 4 digits of the Reference field is 0, even

                                                                                                                                                  • then charge it to a cost center else to a project

                                                                                                                                                  IF ( NOT t_poaccount-unload_pt IS INITIAL ) "@SDR

                                                                                                                                                  AND ( NOT t_compcode IS INITIAL ). "@SDR

                                                                                                                                                  IF t_poaccount-unload_pt+0(4) = c_4zeros. "@SDR

                                                                                                                                                  IF NOT t_poaccount-costcenter IS INITIAL. "@SDR

                                                                                                                                                  SHIFT t_poaccount-costcenter LEFT "@SDR

                                                                                                                                                  DELETING LEADING c_zeros. "@SDR

                                                                                                                                                  l_ex_cc = t_poaccount-costcenter. "@SDR

                                                                                                                                                  CALL FUNCTION 'Z_COSTCTR_GET' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  P_BUKRS = t_compcode "@SDR

                                                                                                                                                  P_EX_CC = l_ex_cc "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  P_COSTCTR = "@SDR

                                                                                                                                                  t_poaccount-costcenter "@SDR

                                                                                                                                                  EXCEPTIONS "@SDR

                                                                                                                                                  NO_VALUE_FOUND = 1 "@SDR

                                                                                                                                                  NULL_VALUE_FOUND = 2 "@SDR

                                                                                                                                                  OTHERS = 3. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  • Assign the retrieved Cost Center from SAP to the

                                                                                                                                                  • account assignment strcuture after the mapping is

                                                                                                                                                  • successful

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  INPUT = t_poaccount-costcenter

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  OUTPUT = t_poaccount-costcenter.

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING costcenter. "@SDR

                                                                                                                                                  ELSE. "@SDR

                                                                                                                                                  READ TABLE t_poaccountx WITH KEY "@SDR

                                                                                                                                                  po_item = t_poaccount-po_item "@SDR

                                                                                                                                                  serial_no = t_poaccount-serial_no. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poaccountx-costcenter = space. "@SDR

                                                                                                                                                  MODIFY t_poaccountx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING costcenter. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  • Issue an error message that the mapping of the

                                                                                                                                                  • external Reference Number to SAP WBS Element has

                                                                                                                                                  • not been possible as no mapping or null mapping

                                                                                                                                                  • has been maintained in the custom mapping table

                                                                                                                                                  l_msgv1 = t_poaccount-costcenter. "@SDR

                                                                                                                                                  l_msgv2 = t_compcode. "@SDR

                                                                                                                                                  CALL FUNCTION 'BALW_BAPIRETURN_GET2' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  TYPE = c_msgtype_e "@SDR

                                                                                                                                                  CL = c_msgid_z001 "@SDR

                                                                                                                                                  NUMBER = c_msgnr_072 "@SDR

                                                                                                                                                  PAR1 = l_msgv1 "@SDR

                                                                                                                                                  PAR2 = l_msgv2 "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  RETURN = t_yreturn. "@SDR

                                                                                                                                                  CLEAR: l_index, "@SDR

                                                                                                                                                  t_poaccount-costcenter. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  APPEND t_yreturn. "@SDR

                                                                                                                                                  CLEAR: t_yreturn, "@SDR

                                                                                                                                                  l_constval, "@SDR

                                                                                                                                                  l_msgv1 , "@SDR

                                                                                                                                                  l_msgv2 . "@SDR

                                                                                                                                                  loop at t_yreturn.

                                                                                                                                                  l_wa_zerrors-OBJECT = 'PURCHASE_ORDER'.

                                                                                                                                                  l_wa_zerrors-serial_no = sy-tabix.

                                                                                                                                                  l_wa_zerrors-COMP_CODE = t_compcode.

                                                                                                                                                  l_wa_zerrors-zid = t_yreturn-id.

                                                                                                                                                  l_wa_zerrors-type = t_yreturn-type.

                                                                                                                                                  l_wa_zerrors-znumber = t_yreturn-number.

                                                                                                                                                  l_wa_zerrors-BEACON_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-SRC_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-ZDATE = sy-datum.

                                                                                                                                                  l_wa_zerrors-ERR_MSG = t_yreturn-message.

                                                                                                                                                  append l_wa_zerrors to t_errors.

                                                                                                                                                  • insert into zerrors values l_wa_zerrors.

                                                                                                                                                  clear: l_wa_zerrors.

                                                                                                                                                  endloop.

                                                                                                                                                  EXIT. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ELSE.

                                                                                                                                                  • Use the below custom FM to retrieve the corresponding

                                                                                                                                                  • WBS element from SAP for the external Reference number

                                                                                                                                                  • available if at all

                                                                                                                                                  l_ex_pro_no = t_poaccount-unload_pt. "@SDR

                                                                                                                                                  CALL FUNCTION 'Z_WBSELEM_GET' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  P_BUKRS = t_compcode "@SDR

                                                                                                                                                  P_EX_PRO_NO = l_ex_pro_no "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  P_WBS_ELEMENT = "@SDR

                                                                                                                                                  t_poaccount-wbs_element "@SDR

                                                                                                                                                  EXCEPTIONS "@SDR

                                                                                                                                                  NO_VALUE_FOUND = 1 "@SDR

                                                                                                                                                  NULL_VALUE_FOUND = 2 "@SDR

                                                                                                                                                  OTHERS = 3. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  • Assign the retrieved WBS Element from SAP to the

                                                                                                                                                  • account assignment strcuture after the mapping is

                                                                                                                                                  • successful

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING wbs_element. "@SDR

                                                                                                                                                  READ TABLE t_poaccountx WITH KEY "@SDR

                                                                                                                                                  po_item = t_poaccount-po_item "@SDR

                                                                                                                                                  serial_no = t_poaccount-serial_no. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poaccountx-wbs_element = 'X'. "@SDR

                                                                                                                                                  MODIFY t_poaccountx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING wbs_element. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  t_poaccount-costcenter = space. "@SDR

                                                                                                                                                  MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  TRANSPORTING costcenter. "@SDR

                                                                                                                                                  READ TABLE t_poaccountx "@SDR

                                                                                                                                                  WITH KEY po_item = t_poaccount-po_item "@SDR

                                                                                                                                                  serial_no = t_poaccount-serial_no."@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poaccountx-costcenter = space. "@SDR

                                                                                                                                                  MODIFY t_poaccountx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING costcenter. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ELSE. "@SDR

                                                                                                                                                  • Issue an error message that the mapping of the

                                                                                                                                                  • external Reference Number to SAP WBS Element has

                                                                                                                                                  • not been possible as no mapping or null mapping

                                                                                                                                                  • has been maintained in the custom mapping table

                                                                                                                                                  l_msgv1 = t_poaccount-unload_pt. "@SDR

                                                                                                                                                  l_msgv2 = t_compcode. "@SDR

                                                                                                                                                  CALL FUNCTION 'BALW_BAPIRETURN_GET2' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  TYPE = c_msgtype_e "@SDR

                                                                                                                                                  CL = c_msgid_z001 "@SDR

                                                                                                                                                  NUMBER = c_msgnr_066 "@SDR

                                                                                                                                                  PAR1 = l_msgv1 "@SDR

                                                                                                                                                  PAR2 = l_msgv2 "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  RETURN = t_yreturn. "@SDR

                                                                                                                                                  CLEAR: l_index, "@SDR

                                                                                                                                                  t_poaccount-wbs_element. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  APPEND t_yreturn. "@SDR

                                                                                                                                                  CLEAR: t_yreturn, "@SDR

                                                                                                                                                  l_constval, "@SDR

                                                                                                                                                  l_msgv1 , "@SDR

                                                                                                                                                  l_msgv2 . "@SDR

                                                                                                                                                  loop at t_yreturn.

                                                                                                                                                  l_wa_zerrors-OBJECT = 'PURCHASE_ORDER'.

                                                                                                                                                  l_wa_zerrors-serial_no = sy-tabix.

                                                                                                                                                  l_wa_zerrors-COMP_CODE = t_compcode.

                                                                                                                                                  l_wa_zerrors-zid = t_yreturn-id.

                                                                                                                                                  l_wa_zerrors-type = t_yreturn-type.

                                                                                                                                                  l_wa_zerrors-znumber = t_yreturn-number.

                                                                                                                                                  l_wa_zerrors-BEACON_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-SRC_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-ZDATE = sy-datum.

                                                                                                                                                  l_wa_zerrors-ERR_MSG = t_yreturn-message.

                                                                                                                                                  append l_wa_zerrors to t_errors.

                                                                                                                                                  • insert into zerrors values l_wa_zerrors.

                                                                                                                                                  clear: l_wa_zerrors.

                                                                                                                                                  endloop.

                                                                                                                                                  EXIT. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  • IF t_poaccount-wbs_element IS INITIAL. "@SDR

                                                                                                                                                  • ELSE. "@SDR

                                                                                                                                                  • CLEAR t_poaccount-costcenter. "@SDR

                                                                                                                                                  • MODIFY t_poaccount INDEX l_index "@SDR

                                                                                                                                                  • TRANSPORTING costcenter. "@SDR

                                                                                                                                                  • READ TABLE t_poaccountx "@SDR

                                                                                                                                                  • WITH KEY po_item = t_poaccount-po_item. "@SDR

                                                                                                                                                  • IF sy-subrc = 0. "@SDR

                                                                                                                                                  • t_poaccountx-costcenter = space. "@SDR

                                                                                                                                                  • MODIFY t_poaccountx INDEX sy-tabix TRANSPORTING "@SDR

                                                                                                                                                  • costcenter. "@SDR

                                                                                                                                                  *

                                                                                                                                                  • ENDIF. "@SDR

                                                                                                                                                  • ENDIF. "@SDR

                                                                                                                                                  ELSE. " Conversion is switched OFF "@SDR

                                                                                                                                                  • If the conversion switch is OFF, issue a warning message

                                                                                                                                                  • saying that the Division/Location, Subcode and Reference

                                                                                                                                                  • fields are no longer used for Alza; contents will be

                                                                                                                                                  • ignored

                                                                                                                                                  IF NOT t_poaccount-unload_pt IS INITIAL.

                                                                                                                                                  CALL FUNCTION 'BALW_BAPIRETURN_GET2' "@SDR

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  TYPE = c_msgtype_w "@SDR

                                                                                                                                                  CL = c_msgid_z001 "@SDR

                                                                                                                                                  NUMBER = c_msgnr_067 "@SDR

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  RETURN = t_yreturn. "@SDR

                                                                                                                                                  "@SDR

                                                                                                                                                  APPEND t_yreturn. "@SDR

                                                                                                                                                  CLEAR: t_yreturn, "@SDR

                                                                                                                                                  l_constval. "@SDR

                                                                                                                                                  loop at t_yreturn.

                                                                                                                                                  l_wa_zerrors-OBJECT = 'PURCHASE_ORDER'.

                                                                                                                                                  l_wa_zerrors-serial_no = sy-tabix.

                                                                                                                                                  l_wa_zerrors-COMP_CODE = t_compcode.

                                                                                                                                                  l_wa_zerrors-zid = t_yreturn-id.

                                                                                                                                                  l_wa_zerrors-type = t_yreturn-type.

                                                                                                                                                  l_wa_zerrors-znumber = t_yreturn-number.

                                                                                                                                                  l_wa_zerrors-BEACON_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-SRC_DOC_NO = t_poheader-po_number.

                                                                                                                                                  l_wa_zerrors-ZDATE = sy-datum.

                                                                                                                                                  l_wa_zerrors-ERR_MSG = t_yreturn-message.

                                                                                                                                                  append l_wa_zerrors to t_errors.

                                                                                                                                                  • insert into zerrors values l_wa_zerrors.

                                                                                                                                                  clear: l_wa_zerrors.

                                                                                                                                                  endloop.

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  *& End of Addition: 26-Sep-2005 SDUTTARO RD1K910316 *&

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  IF NOT t_poaccount-costcenter IS INITIAL.

                                                                                                                                                  l_cc_present = c_x. "X

                                                                                                                                                  ENDIF.

                                                                                                                                                  IF NOT t_poaccount-wbs_element IS INITIAL.

                                                                                                                                                  l_wbs_present = c_x. "X

                                                                                                                                                  ENDIF.

                                                                                                                                                  IF NOT t_poaccount-gl_account IS INITIAL.

                                                                                                                                                  l_acct_present = c_x. "X

                                                                                                                                                  ENDIF.

                                                                                                                                                  READ TABLE t_acct_assignmt WITH KEY

                                                                                                                                                  cost_center = l_cc_present

                                                                                                                                                  wbs_element = l_wbs_present

                                                                                                                                                  gl_account = l_acct_present.

                                                                                                                                                  IF t_acct_assignmt-acct_assgmnt = l_acct_assign. "F

                                                                                                                                                  EXIT.

                                                                                                                                                  ENDIF.

                                                                                                                                                  ENDLOOP.

                                                                                                                                                  IF sy-subrc EQ 0.

                                                                                                                                                  t_poitem-acctasscat = t_acct_assignmt-acct_assgmnt.

                                                                                                                                                  MODIFY t_poitem.

                                                                                                                                                  READ TABLE t_poitemx WITH KEY po_item = t_poitem-po_item.

                                                                                                                                                  IF sy-subrc EQ 0.

                                                                                                                                                  t_poitemx-acctasscat = c_x. "X

                                                                                                                                                  MODIFY t_poitemx INDEX sy-tabix.

                                                                                                                                                  ENDIF.

                                                                                                                                                  ENDIF.

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  *& Begin of Addition: 21-oct-2005 SDUTTARO RD1K910316 *&

                                                                                                                                                  &----


                                                                                                                                                  &
                                                                                                                                                  • Final Invoice Indicator checked for all POs for conversion

                                                                                                                                                  IF t_compcode = c_bukrs_alza AND l_constval_gr = c_x. "@SDR

                                                                                                                                                  t_poitem-final_inv = c_x. "@SDR

                                                                                                                                                  MODIFY t_poitem INDEX l_itemindex TRANSPORTING final_inv. "@SDR

                                                                                                                                                  READ TABLE t_poitemx WITH KEY po_item = t_poitem-po_item. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poitemx-final_inv = c_x. "@SDR

                                                                                                                                                  MODIFY t_poitemx INDEX sy-tabix TRANSPORTING final_inv."@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  • NON VALUATED GR Indicator

                                                                                                                                                  • Case1: NONVAL GR (Active) GR from Ariba (Active) With Split

                                                                                                                                                  IF t_compcode = c_bukrs_alza "1155 "@SDR

                                                                                                                                                  AND l_constval_gr = c_x "X "@SDR

                                                                                                                                                  AND t_poitem-gr_ind = c_x "X "@SDR

                                                                                                                                                  AND NOT t_poitem-distrib IS INITIAL . "@SDR

                                                                                                                                                  • GR Flag (Active) Non val GR (active)

                                                                                                                                                  t_poitem-gr_non_val = c_x. "X "@SDR

                                                                                                                                                  MODIFY t_poitem INDEX l_itemindex "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  READ TABLE t_poitemx "@SDR

                                                                                                                                                  WITH KEY po_item = t_poitem-po_item. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poitemx-gr_non_val = c_x. "X "@SDR

                                                                                                                                                  MODIFY t_poitemx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  • Case 2: NONVAL GR (Active) GR from Ariba (Active) Without Split

                                                                                                                                                  ELSEIF t_compcode = c_bukrs_alza "1155 "@SDR

                                                                                                                                                  AND l_constval_gr = c_x "X "@SDR

                                                                                                                                                  AND t_poitem-gr_ind = c_x "X "@SDR

                                                                                                                                                  AND t_poitem-distrib IS INITIAL . "@SDR

                                                                                                                                                  • GR Flag (Active) Non val GR (active)

                                                                                                                                                  t_poitem-gr_non_val = c_x. "X "@SDR

                                                                                                                                                  MODIFY t_poitem INDEX l_itemindex "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  READ TABLE t_poitemx "@SDR

                                                                                                                                                  WITH KEY po_item = t_poitem-po_item. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poitemx-gr_non_val = c_x. "X "@SDR

                                                                                                                                                  MODIFY t_poitemx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  • Case 3: NONVAL GR (Active) GR from Ariba (InActive) With Split

                                                                                                                                                  ELSEIF t_compcode = c_bukrs_alza "1155 "@SDR

                                                                                                                                                  AND l_constval_gr = c_x "X "@SDR

                                                                                                                                                  AND t_poitem-gr_ind IS INITIAL "@SDR

                                                                                                                                                  AND NOT t_poitem-distrib IS INITIAL . "@SDR

                                                                                                                                                  • GR Flag (InActive) Non val GR (Inactive)

                                                                                                                                                  t_poitem-gr_non_val = space. "@SDR

                                                                                                                                                  MODIFY t_poitem INDEX l_itemindex "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  READ TABLE t_poitemx "@SDR

                                                                                                                                                  WITH KEY po_item = t_poitem-po_item. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poitemx-gr_non_val = space. "@SDR

                                                                                                                                                  MODIFY t_poitemx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  • Case 4: NONVAL GR (Active) GR from Ariba (InActive) Without Split

                                                                                                                                                  ELSEIF t_compcode = c_bukrs_alza "1155 "@SDR

                                                                                                                                                  AND l_constval_gr = c_x "X "@SDR

                                                                                                                                                  AND t_poitem-gr_ind IS INITIAL "@SDR

                                                                                                                                                  AND t_poitem-distrib IS INITIAL . "@SDR

                                                                                                                                                  • GR Flag (InActive) Non val GR (Inactive)

                                                                                                                                                  t_poitem-gr_non_val = space. "@SDR

                                                                                                                                                  MODIFY t_poitem INDEX l_itemindex "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  READ TABLE t_poitemx "@SDR

                                                                                                                                                  WITH KEY po_item = t_poitem-po_item. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poitemx-gr_non_val = space. "@SDR

                                                                                                                                                  MODIFY t_poitemx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  • Case 5: NONVAL GR (InActive) GR from Ariba (Active) With Split

                                                                                                                                                  ELSEIF t_compcode = c_bukrs_alza "1155 "@SDR

                                                                                                                                                  AND l_constval_gr = 'Y' "@SDR

                                                                                                                                                  AND t_poitem-gr_ind = c_x "X "@SDR

                                                                                                                                                  AND NOT t_poitem-distrib IS INITIAL . "@SDR

                                                                                                                                                  • GR Flag (Active) Non val GR (active)

                                                                                                                                                  t_poitem-gr_non_val = c_x. "X "@SDR

                                                                                                                                                  MODIFY t_poitem INDEX l_itemindex "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  READ TABLE t_poitemx "@SDR

                                                                                                                                                  WITH KEY po_item = t_poitem-po_item. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poitemx-gr_non_val = c_x. "X "@SDR

                                                                                                                                                  MODIFY t_poitemx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  • Case 6: NONVAL GR (InActive) GR from Ariba (Active) Without Split

                                                                                                                                                  ELSEIF t_compcode = c_bukrs_alza "1155 "@SDR

                                                                                                                                                  AND l_constval_gr = 'Y' "@SDR

                                                                                                                                                  AND t_poitem-gr_ind = c_x "X "@SDR

                                                                                                                                                  AND t_poitem-distrib IS INITIAL . "@SDR

                                                                                                                                                  • GR Flag (Active) Non val GR (Inactive)

                                                                                                                                                  t_poitem-gr_non_val = space. "@SDR

                                                                                                                                                  MODIFY t_poitem INDEX l_itemindex "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  READ TABLE t_poitemx "@SDR

                                                                                                                                                  WITH KEY po_item = t_poitem-po_item. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poitemx-gr_non_val = space. "@SDR

                                                                                                                                                  MODIFY t_poitemx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  • Case 7: NONVAL GR (InActive) GR from Ariba (InActive) With Split

                                                                                                                                                  ELSEIF t_compcode = c_bukrs_alza "1155 "@SDR

                                                                                                                                                  AND l_constval_gr = 'Y' "@SDR

                                                                                                                                                  AND t_poitem-gr_ind IS INITIAL "@SDR

                                                                                                                                                  AND NOT t_poitem-distrib IS INITIAL . "@SDR

                                                                                                                                                  • GR Flag (InActive) Non val GR (Inactive)

                                                                                                                                                  t_poitem-gr_non_val = space. "@SDR

                                                                                                                                                  MODIFY t_poitem INDEX l_itemindex "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  READ TABLE t_poitemx "@SDR

                                                                                                                                                  WITH KEY po_item = t_poitem-po_item. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poitemx-gr_non_val = space. "@SDR

                                                                                                                                                  MODIFY t_poitemx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  • Case 8: NONVAL GR (InActive) GR from Ariba (InActive) W/O Split

                                                                                                                                                  ELSEIF t_compcode = c_bukrs_alza "1155 "@SDR

                                                                                                                                                  AND l_constval_gr = 'Y' "@SDR

                                                                                                                                                  AND t_poitem-gr_ind IS INITIAL "@SDR

                                                                                                                                                  AND t_poitem-distrib IS INITIAL . "@SDR

                                                                                                                                                  • GR Flag (InActive) Non val GR (Inactive)

                                                                                                                                                  t_poitem-gr_non_val = space. "@SDR

                                                                                                                                                  MODIFY t_poitem INDEX l_itemindex "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  READ TABLE t_poitemx "@SDR

                                                                                                                                                  WITH KEY po_item = t_poitem-po_item. "@SDR

                                                                                                                                                  IF sy-subrc = 0. "@SDR

                                                                                                                                                  t_poitemx-gr_non_val = space. "@SDR

                                                                                                                                                  MODIFY t_poitemx INDEX sy-tabix "@SDR

                                                                                                                                                  TRANSPORTING gr_non_val. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  ENDIF. "@SDR

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  *& End of Addition: 21-oct-2005 SDUTTARO RD1K910316 *&

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  *& Begin of Addition: -Sep-2005 SDUTTARO RD1K910316 *&

                                                                                                                                                  &----


                                                                                                                                                  &
                                                                                                                                                  • Clear all the local variables.

                                                                                                                                                  CLEAR: l_index , "@SDR

                                                                                                                                                  l_constval , "@SDR

                                                                                                                                                  l_itemindex, "@SDR

                                                                                                                                                  l_ex_pro_no. "@SDR

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  *& End of Addition: -Sep-2005 SDUTTARO RD1K910316 *&

                                                                                                                                                  &----


                                                                                                                                                  &

                                                                                                                                                  ENDLOOP.

                                                                                                                                                  ************************************************************

                                                                                                                                                  • MOD-003

                                                                                                                                                  ***********************************************************

                                                                                                                                                  DATA: L_TABIX TYPE SY-TABIX.

                                                                                                                                                  • Retrieve Account assignment category

                                                                                                                                                  • SELECT * FROM zacctasgmnt

                                                                                                                                                  • INTO TABLE t_acct_assignmt

                                                                                                                                                  • WHERE comp_code EQ t_compcode.

                                                                                                                                                  *

                                                                                                                                                  • IF sy-subrc = 0.

                                                                                                                                                  • Retrieve Account assignment constant

                                                                                                                                                • CALL FUNCTION 'ZXA_GET_CONSTANT'

                                                                                                                                                • EXPORTING

                                                                                                                                                • const_name = c_acct_assign

                                                                                                                                                • comp_code = t_compcode

                                                                                                                                                • IMPORTING

                                                                                                                                                • const_value = l_acct_assign

                                                                                                                                                • EXCEPTIONS

                                                                                                                                                • no_value_found = 1

                                                                                                                                                • null_value = 2

                                                                                                                                                • OTHERS = 3.

                                                                                                                                                • IF sy-subrc <> 0.

                                                                                                                                                • CLEAR : L_CONST_NAME,

                                                                                                                                                • L_COMP_CODE.

                                                                                                                                                • *

                                                                                                                                                  • L_CONST_NAME = c_acct_assign. "ZRP_ACCT_ASSIGN

                                                                                                                                                  • L_COMP_CODE = t_compcode.

                                                                                                                                                  • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

                                                                                                                                                  • EXPORTING

                                                                                                                                                  • type = c_msgtype_e "E

                                                                                                                                                  • cl = c_msgid_z001

                                                                                                                                                  • number = c_msgnr_046 "046

                                                                                                                                                  • PAR1 = L_CONST_NAME "ZRP_ACCT_ASSIGN

                                                                                                                                                  • PAR2 = L_COMP_CODE

                                                                                                                                                  • IMPORTING

                                                                                                                                                  • return = t_yreturn.

                                                                                                                                                  *

                                                                                                                                                  • APPEND t_yreturn.

                                                                                                                                                  • CLEAR t_yreturn.

                                                                                                                                                  *

                                                                                                                                                  • EXIT.

                                                                                                                                                  • ENDIF.

                                                                                                                                                  • ENDIF.

                                                                                                                                                  data: l_prart type ps_prart,

                                                                                                                                                  l_belkz type ps_belkz,

                                                                                                                                                  l_glaccount type ZCONSTVAL,

                                                                                                                                                  l_anln1 type anln1,

                                                                                                                                                  l_anln2 type anln2,

                                                                                                                                                  P_XSPEB type xspeb_anla.

                                                                                                                                                  constants: c_gl_acc_po type ZCONSTname value 'Z_P2P_GL_ACC_PO'.

                                                                                                                                                  DATA: L_werks type werks_d.

                                                                                                                                                  data: l_location type stort_t499s.

                                                                                                                                                  data: l_prev_item type ebelp.

                                                                                                                                                  data: l_glacc(10) type c.

                                                                                                                                                  data: l_cost(10) type c.

                                                                                                                                                  LOOP AT t_poitem.

                                                                                                                                                  CLEAR: l_acct_present, l_cc_present, l_wbs_present.

                                                                                                                                                  l_itemindex = sy-tabix. "@SDR

                                                                                                                                                  CLEAR: t_acct_assignmt.

                                                                                                                                                  LOOP AT t_poaccount WHERE po_item = t_poitem-po_item.

                                                                                                                                                  l_tabix = sy-tabix.

                                                                                                                                                  CLEAR: L_ACCT_ASSMNT.

                                                                                                                                                  SELECT SINGLE ACCT_ASSGMNT

                                                                                                                                                  INTO L_ACCT_ASSMNT

                                                                                                                                                  FROM ZP2P_ACCTASSCATG

                                                                                                                                                  WHERE ZACCT_TYPE = T_POACCOUNT-ZACCT_TYPE.

                                                                                                                                                  if sy-subrc = 0.

                                                                                                                                                  t_poitem-acctasscat = l_acct_assmnt.

                                                                                                                                                  modify t_poitem transporting acctasscat.

                                                                                                                                                  endif.

                                                                                                                                                  ENDLOOP.

                                                                                                                                                  ENDLOOP.

                                                                                                                                                  LOOP AT t_poitem.

                                                                                                                                                  CLEAR: l_acct_present, l_cc_present, l_wbs_present.

                                                                                                                                                  l_itemindex = sy-tabix. "@SDR

                                                                                                                                                  CLEAR: t_acct_assignmt.

                                                                                                                                                  LOOP AT t_poaccount WHERE po_item = t_poitem-po_item.

                                                                                                                                                  l_tabix = sy-tabix.

                                                                                                                                                  *MOD-004

                                                                                                                                                  IF NOT t_poaccount-costcenter IS INITIAL.

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  EXPORTING

                                                                                                                                                  INPUT = t_poaccount-costcenter

                                                                                                                                                  IMPORTING

                                                                                                                                                  OUTPUT = l_cost.

                                                                                                                                                  IF L_COST NE '0000000000'.

                                                                                                                                                  MOVE: L_COST TO T_POACCOUNT-COSTCENTER.

                                                                                                                                                  ENDIF.

                                                                                                                                                  ENDIF.

                                                                                                                                                  IF NOT t_poaccount-gl_account IS INITIAL.

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  EXPORTING

                                                                                                                                                  INPUT = t_poaccount-gl_account

                                                                                                                                                  IMPORTING

                                                                                                                                                  OUTPUT = l_glacc.

                                                                                                                                                  IF L_GLACC NE '0000000000'.

                                                                                                                                                  MOVE: L_GLACC TO T_POACCOUNT-GL_ACCOUNT.

                                                                                                                                                  ENDIF.

                                                                                                                                                  ENDIF.

                                                                                                                                                  *MOD-004

                                                                                                                                                  **MOD-003

                                                                                                                                                  • if l_tabix > 1.

                                                                                                                                                  • perform check_split_accounts using t_poaccount-gl_account

                                                                                                                                                  • l_glaccount

                                                                                                                                                  • t_poheader

                                                                                                                                                  • t_compcode

                                                                                                                                                  • l_prev_item

                                                                                                                                                  • t_poitem-po_item.

                                                                                                                                                  • endif.

                                                                                                                                                  *MOD-003

                                                                                                                                                  • Split Accounting check

                                                                                                                                                  • if t_poaccount-gl_account = l_glaccount.

                                                                                                                                                  • CLEAR : L_CONST_NAME,

                                                                                                                                                  • L_COMP_CODE.

                                                                                                                                                  *

                                                                                                                                                  • L_CONST_NAME = l_glaccount.

                                                                                                                                                  • L_COMP_CODE = t_compcode.

                                                                                                                                                  • CALL FUNCTION 'BALW_BAPIRETURN_GET2'

                                                                                                                                                  • EXPORTING

                                                                                                                                                  • type = c_msgtype_e "E

                                                                                                                                                  • cl = c_msgid_z001

                                                                                                                                                  • number = c_msgnr_613

                                                                                                                                                  • PAR1 = L_CONST_NAME

                                                                                                                                                  • PAR2 = L_COMP_CODE

                                                                                                                                                  • IMPORTING

                                                                                                                                                  • return = t_yreturn.

                                                                                                                                                  *

                                                                                                                                                  • APPEND t_yreturn.

                                                                                                                                                  • CLEAR t_yreturn.

                                                                                                                                                  • l_wa_zerrors-OBJECT = 'PURCHASE_ORDER'.

                                                                                                                                                  • l_wa_zerrors-COMP_CODE = t_poheader-comp_code.

                                                                                                                                                  • l_wa_zerrors-BEACON_DOC_NO = t_poheader-po_number.

                                                                                                                                                  • l_wa_zerrors-SRC_DOC_NO = t_poheader-po_number.

                                                                                                                                                  • l_wa_zerrors-ZDATE = sy-datum.

                                                                                                                                                  • l_wa_zerrors-ERR_MSG = c_msgnr_613.

                                                                                                                                                • read table t_yreturn index 1.

                                                                                                                                                • l_wa_zerrors-ERR_MSG = t_yreturn-message.

                                                                                                                                                • insert into zerrors values l_wa_zerrors.

                                                                                                                                                • clear: l_wa_zerrors.

                                                                                                                                                • *

                                                                                                                                                  • ENDIF.

                                                                                                                                                  • endif.

                                                                                                                                                  clear: l_prart, l_belkz.

                                                                                                                                                  If t_poaccount-zacct_type = C_W1. "'W'.

                                                                                                                                                  *********************************************

                                                                                                                                                  • Case 1 Expense WBS

                                                                                                                                                  *********************************************

                                                                                                                                                  CLEAR: L_ACCT_ASSMNT.

                                                                                                                                                  SELECT SINGLE ACCT_ASSGMNT

                                                                                                                                                  INTO L_ACCT_ASSMNT

                                                                                                                                                  FROM ZP2P_ACCTASSCATG

                                                                                                                                                  WHERE ZACCT_TYPE = T_POACCOUNT-ZACCT_TYPE.

                                                                                                                                                  IF L_ACCT_ASSMNT = C_P1.

                                                                                                                                                  • IF t_poitem-acctasscat = C_P1. "'P'.

                                                                                                                                                  IF NOT t_poaccount-gl_account IS INITIAL.

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  EXPORTING

                                                                                                                                                  INPUT = t_poaccount-gl_account

                                                                                                                                                  IMPORTING

                                                                                                                                                  OUTPUT = l_glacc.

                                                                                                                                                  MOVE: L_GLACC TO T_POACCOUNT-GL_ACCOUNT.

                                                                                                                                                  clear: l_flag.

                                                                                                                                                  *mod-004

                                                                                                                                                  • perform validate_gl_account using t_poaccount-gl_account

                                                                                                                                                  • t_compcode

                                                                                                                                                  • changing l_flag.

                                                                                                                                                  *mod-004

                                                                                                                                                  perform validate_gl_account using l_glacc

                                                                                                                                                  t_compcode

                                                                                                                                                  changing l_flag.

                                                                                                                                                  IF L_FLAG NE 'X'.

                                                                                                                                                  PERFORM ERROR_HANDLING_GL USING T_POHEADER

                                                                                                                                                  T_COMPCODE

                                                                                                                                                  L_WA_ZERRORS.

                                                                                                                                                  ENDIF.

                                                                                                                                                  PERFORM GET_CONSTANT_ZXA USING t_poheader

                                                                                                                                                  t_compcode

                                                                                                                                                  l_wa_zerrors

                                                                                                                                                  changing l_glaccount.

                                                                                                                                                  IF sy-subrc <> 0.

                                                                                                                                                  EXIT.

                                                                                                                                                  ELSE.

                                                                                                                                                  if not t_poaccount-wbs_element is initial.

                                                                                                                                                  perform check_project_type

                                                                                                                                                  using t_poaccount-wbs_element

                                                                                                                                                  t_poheader

                                                                                                                                                  t_compcode.

                                                                                                                                                  endif.

                                                                                                                                                  endif.

                                                                                                                                                  endif.

                                                                                                                                                  endif.

                                                                                                                                                  IF L_ACCT_ASSMNT = C_K1.

                                                                                                                                                  • IF t_poitem-acctasscat = C_K1. "'K'.

                                                                                                                                                  IF NOT t_poaccount-gl_account IS INITIAL.

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  EXPORTING

                                                                                                                                                  INPUT = t_poaccount-gl_account

                                                                                                                                                  IMPORTING

                                                                                                                                                  OUTPUT = l_glacc.

                                                                                                                                                  MOVE: L_GLACC TO T_POACCOUNT-GL_ACCOUNT.

                                                                                                                                                  *mod-004

                                                                                                                                                  • perform validate_gl_account using t_poaccount-gl_account

                                                                                                                                                  • t_compcode

                                                                                                                                                  • changing l_flag.

                                                                                                                                                  *MOD-004

                                                                                                                                                  perform validate_gl_account using l_glacc

                                                                                                                                                  t_compcode

                                                                                                                                                  changing l_flag.

                                                                                                                                                  IF L_FLAG NE C_X. "'X'.

                                                                                                                                                  PERFORM ERROR_HANDLING_GL USING T_POHEADER

                                                                                                                                                  T_COMPCODE

                                                                                                                                                  L_WA_ZERRORS.

                                                                                                                                                  ENDIF.

                                                                                                                                                  PERFORM GET_CONSTANT_ZXA USING t_poheader

                                                                                                                                                  t_compcode

                                                                                                                                                  l_wa_zerrors

                                                                                                                                                  changing l_glaccount.

                                                                                                                                                  IF sy-subrc <> 0.

                                                                                                                                                  EXIT.

                                                                                                                                                  ELSE.

                                                                                                                                                  IF NOT T_POACCOUNT-WBS_ELEMENT IS INITIAL.

                                                                                                                                                  perform check_project_type

                                                                                                                                                  using t_poaccount-wbs_element

                                                                                                                                                  t_poheader

                                                                                                                                                  t_compcode.

                                                                                                                                                  ENDIF.

                                                                                                                                                  endif.

                                                                                                                                                  endif.

                                                                                                                                                  ENDIF.

                                                                                                                                                  IF NOT t_poaccount-costcenter IS INITIAL AND

                                                                                                                                                  t_poaccount-costcenter NE '0000000000'.

                                                                                                                                                  *MOD-004

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  EXPORTING

                                                                                                                                                  INPUT = t_poaccount-costcenter

                                                                                                                                                  IMPORTING

                                                                                                                                                  OUTPUT = l_cost.

                                                                                                                                                  MOVE: L_COST TO T_POACCOUNT-COSTCENTER.

                                                                                                                                                  • perform validate_costcenter using t_poaccount-costcenter

                                                                                                                                                  • changing l_flag.

                                                                                                                                                  *MOD-004

                                                                                                                                                  perform validate_costcenter using l_cost

                                                                                                                                                  changing l_flag.

                                                                                                                                                  IF L_FLAG NE C_X. "'X'.

                                                                                                                                                  PERFORM ERROR_HANDLING_COST USING T_POHEADER

                                                                                                                                                  T_COMPCODE

                                                                                                                                                  L_WA_ZERRORS.

                                                                                                                                                  ENDIF.

                                                                                                                                                  l_cc_present = c_x. "X

                                                                                                                                                  ENDIF.

                                                                                                                                                  ENDIF.

                                                                                                                                                  *Case 1

                                                                                                                                                  **********************************************************************

                                                                                                                                                  **********************************************************************

                                                                                                                                                  *Case 2 : Capital WBS- New Asset

                                                                                                                                                  If t_poaccount-zacct_type = C_N1. "'N'.

                                                                                                                                                  • Case 1 Expense WBS

                                                                                                                                                  CLEAR: L_ACCT_ASSMNT.

                                                                                                                                                  SELECT SINGLE ACCT_ASSGMNT

                                                                                                                                                  INTO L_ACCT_ASSMNT

                                                                                                                                                  FROM ZP2P_ACCTASSCATG

                                                                                                                                                  WHERE ZACCT_TYPE = T_POACCOUNT-ZACCT_TYPE.

                                                                                                                                                  IF L_ACCT_ASSMNT = C_P1.

                                                                                                                                                  • IF t_poitem-acctasscat = C_P1. "'P'.

                                                                                                                                                  IF NOT t_poaccount-gl_account IS INITIAL.

                                                                                                                                                  *MOD-004

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  EXPORTING

                                                                                                                                                  INPUT = t_poaccount-gl_account

                                                                                                                                                  IMPORTING

                                                                                                                                                  OUTPUT = l_glacc.

                                                                                                                                                  MOVE: L_GLACC TO T_POACCOUNT-GL_ACCOUNT.

                                                                                                                                                  • perform validate_gl_account_exp_wbs

                                                                                                                                                  • using t_poaccount-gl_account

                                                                                                                                                  • t_compcode

                                                                                                                                                  • changing l_flag.

                                                                                                                                                  *MOD-004

                                                                                                                                                  perform validate_gl_account_exp_wbs

                                                                                                                                                  using l_glacc

                                                                                                                                                  t_compcode

                                                                                                                                                  changing l_flag.

                                                                                                                                                  IF L_FLAG NE C_X. "'X'.

                                                                                                                                                  PERFORM ERROR_HANDLING_GL USING T_POHEADER

                                                                                                                                                  T_COMPCODE

                                                                                                                                                  L_WA_ZERRORS.

                                                                                                                                                  ENDIF.

                                                                                                                                                  PERFORM GET_CONSTANT_ZXA USING t_poheader

                                                                                                                                                  t_compcode

                                                                                                                                                  l_wa_zerrors

                                                                                                                                                  changing l_glaccount.

                                                                                                                                                  IF sy-subrc <> 0.

                                                                                                                                                  PERFORM ERROR_HANDLING_GL USING T_POHEADER

                                                                                                                                                  T_COMPCODE

                                                                                                                                                  L_WA_ZERRORS.

                                                                                                                                                  EXIT.

                                                                                                                                                  ELSE.

                                                                                                                                                  if not t_poaccount-wbs_element is initial.

                                                                                                                                                  perform check_project_type

                                                                                                                                                  using t_poaccount-wbs_element

                                                                                                                                                  t_poheader

                                                                                                                                                  t_compcode.

                                                                                                                                                  if sy-subrc NE 0.

                                                                                                                                                  EXIT.

                                                                                                                                                  ENDIF.

                                                                                                                                                  endif.

                                                                                                                                                  endif.

                                                                                                                                                  endif.

                                                                                                                                                  • endif.

                                                                                                                                                  if not t_poitem-plant is initial.

                                                                                                                                                  clear: l_werks.

                                                                                                                                                  select single werks

                                                                                                                                                  into l_werks

                                                                                                                                                  from t499s

                                                                                                                                                  where werks = t_poitem-plant.

                                                                                                                                                  if sy-subrc ne 0.

                                                                                                                                                  PERFORM ERROR_HANDLING_PLANT USING T_POHEADER

                                                                                                                                                  T_COMPCODE

                                                                                                                                                  L_WA_ZERRORS.

                                                                                                                                                  EXIT.

                                                                                                                                                  endif.

                                                                                                                                                  • select single werks

                                                                                                                                                  • into l_werks

                                                                                                                                                  • from t001w

                                                                                                                                                  • where werks = t_poitem-plant.

                                                                                                                                                  • if sy-subrc ne 0.

                                                                                                                                                  • PERFORM ERROR_HANDLING_PLANT USING T_POHEADER

                                                                                                                                                  • T_COMPCODE

                                                                                                                                                  • L_WA_ZERRORS.

                                                                                                                                                  • EXIT.

                                                                                                                                                  • endif.

                                                                                                                                                  Clear: l_werks.

                                                                                                                                                  select single werks

                                                                                                                                                  into l_werks

                                                                                                                                                  from ANLZ

                                                                                                                                                  where bukrs = t_compcode and

                                                                                                                                                  werks = t_poitem-plant.

                                                                                                                                                  if sy-subrc ne 0.

                                                                                                                                                  PERFORM ERROR_HANDLING_ANLZ USING T_POHEADER

                                                                                                                                                  T_COMPCODE

                                                                                                                                                  L_WA_ZERRORS.

                                                                                                                                                  EXIT.

                                                                                                                                                  endif.

                                                                                                                                                  • clear: l_werks.

                                                                                                                                                  • select single werks

                                                                                                                                                  • into l_werks

                                                                                                                                                  • from t499s

                                                                                                                                                  • where werks = t_poitem-plant.

                                                                                                                                                  • if sy-subrc ne 0.

                                                                                                                                                  • PERFORM ERROR_HANDLING_PLANT USING T_POHEADER

                                                                                                                                                  • T_COMPCODE

                                                                                                                                                  • L_WA_ZERRORS.

                                                                                                                                                  • EXIT.

                                                                                                                                                  • endif.

                                                                                                                                                  endif.

                                                                                                                                                  • If not t_poitem-plant is initial.

                                                                                                                                                  If not t_poaccount-zplant is initial.

                                                                                                                                                  select single werks stand

                                                                                                                                                  into (l_werks, l_location )

                                                                                                                                                  from t499s

                                                                                                                                                  where werks = t_POACCOUNT-ZPLANT AND

                                                                                                                                                  • poitem-plant and

                                                                                                                                                  stand = t_poaccount-zlocation.

                                                                                                                                                  if sy-subrc ne 0.

                                                                                                                                                  PERFORM ERROR_HANDLING_location USING T_POHEADER

                                                                                                                                                  T_COMPCODE

                                                                                                                                                  L_WA_ZERRORS.

                                                                                                                                                  EXIT.

                                                                                                                                                  endif.

                                                                                                                                                  endif.

                                                                                                                                                  endif.

                                                                                                                                                  • IF t_poitem-acctasscat = C_K1. "'K'.

                                                                                                                                                  IF L_ACCT_ASSMNT = C_K1.

                                                                                                                                                  CLEAR: L_ACCT_ASSMNT.

                                                                                                                                                  SELECT SINGLE ACCT_ASSGMNT

                                                                                                                                                  INTO L_ACCT_ASSMNT

                                                                                                                                                  FROM ZP2P_ACCTASSCATG

                                                                                                                                                  • FROM ZPOACCTASGMNTCAT

                                                                                                                                                  WHERE ZACCT_TYPE = T_POACCOUNT-ZACCT_TYPE.

                                                                                                                                                  IF NOT t_poaccount-gl_account IS INITIAL.

                                                                                                                                                  • CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  • EXPORTING "@SDR

                                                                                                                                                  • INPUT = t_poaccount-gl_account

                                                                                                                                                  • IMPORTING "@SDR

                                                                                                                                                  • OUTPUT = t_poaccount-gl_account.

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  INPUT = t_poaccount-gl_account

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  OUTPUT = l_glacc.

                                                                                                                                                  MOVE: L_GLACC TO T_POACCOUNT-GL_ACCOUNT.

                                                                                                                                                  • perform validate_gl_account using t_poaccount-gl_account

                                                                                                                                                  • t_compcode

                                                                                                                                                  • changing l_flag.

                                                                                                                                                  perform validate_gl_account using l_glacc

                                                                                                                                                  t_compcode

                                                                                                                                                  changing l_flag.

                                                                                                                                                  IF L_FLAG NE C_X. "'X'.

                                                                                                                                                  PERFORM ERROR_HANDLING_GL USING T_POHEADER

                                                                                                                                                  T_COMPCODE

                                                                                                                                                  L_WA_ZERRORS.

                                                                                                                                                  ENDIF.

                                                                                                                                                  PERFORM GET_CONSTANT_ZXA USING t_poheader

                                                                                                                                                  t_compcode

                                                                                                                                                  l_wa_zerrors

                                                                                                                                                  changing l_glaccount.

                                                                                                                                                  IF sy-subrc <> 0.

                                                                                                                                                  EXIT.

                                                                                                                                                  ELSE.

                                                                                                                                                  IF NOT T_POACCOUNT-WBS_ELEMENT IS INITIAL.

                                                                                                                                                  perform check_project_type

                                                                                                                                                  using t_poaccount-wbs_element

                                                                                                                                                  t_poheader

                                                                                                                                                  t_compcode.

                                                                                                                                                  ENDIF.

                                                                                                                                                  endif.

                                                                                                                                                  endif.

                                                                                                                                                  ENDIF.

                                                                                                                                                  *MOD-004

                                                                                                                                                  IF NOT t_poaccount-costcenter IS INITIAL AND

                                                                                                                                                  t_poaccount-costcenter NE '0000000000'.

                                                                                                                                                  • CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  • EXPORTING

                                                                                                                                                  • INPUT = t_poaccount-costcenter

                                                                                                                                                  • IMPORTING

                                                                                                                                                  • OUTPUT = t_poaccount-costcenter.

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  EXPORTING

                                                                                                                                                  INPUT = t_poaccount-costcenter

                                                                                                                                                  IMPORTING

                                                                                                                                                  OUTPUT = l_cost.

                                                                                                                                                  IF t_poaccount-costcenter NE '0000000000'.

                                                                                                                                                  MOVE: L_COST TO T_POACCOUNT-COSTCENTER.

                                                                                                                                                  ENDIF.

                                                                                                                                                  *MOD-004

                                                                                                                                                  • perform validate_costcenter using t_poaccount-costcenter

                                                                                                                                                  • changing l_flag.

                                                                                                                                                  *MOD-004

                                                                                                                                                  perform validate_costcenter using l_cost

                                                                                                                                                  changing l_flag.

                                                                                                                                                  IF L_FLAG NE C_X. "'X'.

                                                                                                                                                  PERFORM ERROR_HANDLING_COST USING T_POHEADER

                                                                                                                                                  T_COMPCODE

                                                                                                                                                  L_WA_ZERRORS.

                                                                                                                                                  ENDIF.

                                                                                                                                                  l_cc_present = c_x. "X

                                                                                                                                                  ENDIF.

                                                                                                                                                  l_cc_present = c_x. "X

                                                                                                                                                  endif.

                                                                                                                                                  • Case 2

                                                                                                                                                  ***********************************************************************

                                                                                                                                                  *case 3 Capital WBS Existing Asset

                                                                                                                                                  ***********************************************************************

                                                                                                                                                  If t_poaccount-zacct_type = C_A1. "'A'.

                                                                                                                                                  • Case 1 Expense WBS

                                                                                                                                                  CLEAR: L_ACCT_ASSMNT.

                                                                                                                                                  SELECT SINGLE ACCT_ASSGMNT

                                                                                                                                                  INTO L_ACCT_ASSMNT

                                                                                                                                                  FROM ZP2P_ACCTASSCATG

                                                                                                                                                  • FROM ZPOACCTASGMNTCAT

                                                                                                                                                  WHERE ZACCT_TYPE = T_POACCOUNT-ZACCT_TYPE.

                                                                                                                                                  IF L_ACCT_ASSMNT = C_P1.

                                                                                                                                                  IF NOT t_poaccount-gl_account IS INITIAL.

                                                                                                                                                  *MOD-004

                                                                                                                                                  • CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  • EXPORTING "@SDR

                                                                                                                                                  • INPUT = t_poaccount-gl_account

                                                                                                                                                  • IMPORTING "@SDR

                                                                                                                                                  • OUTPUT = t_poaccount-gl_account.

                                                                                                                                                  *

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  INPUT = t_poaccount-gl_account

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  OUTPUT = l_glacc.

                                                                                                                                                  MOVE: L_GLACC TO T_POACCOUNT-GL_ACCOUNT.

                                                                                                                                                  • perform validate_gl_account_exp_wbs

                                                                                                                                                  • using t_poaccount-gl_account

                                                                                                                                                  • t_compcode

                                                                                                                                                  • changing l_flag.

                                                                                                                                                  *MOD-004

                                                                                                                                                  perform validate_gl_account_exp_wbs

                                                                                                                                                  using l_glacc

                                                                                                                                                  t_compcode

                                                                                                                                                  changing l_flag.

                                                                                                                                                  IF L_FLAG NE 'X'.

                                                                                                                                                  PERFORM ERROR_HANDLING_GL USING T_POHEADER

                                                                                                                                                  T_COMPCODE

                                                                                                                                                  L_WA_ZERRORS.

                                                                                                                                                  EXIT.

                                                                                                                                                  ENDIF.

                                                                                                                                                  PERFORM GET_CONSTANT_ZXA USING t_poheader

                                                                                                                                                  t_compcode

                                                                                                                                                  l_wa_zerrors

                                                                                                                                                  changing l_glaccount.

                                                                                                                                                  IF sy-subrc <> 0.

                                                                                                                                                  EXIT.

                                                                                                                                                  ELSE.

                                                                                                                                                  if not t_poaccount-wbs_element is initial.

                                                                                                                                                  perform check_project_type

                                                                                                                                                  using t_poaccount-wbs_element

                                                                                                                                                  t_poheader

                                                                                                                                                  t_compcode.

                                                                                                                                                  if sy-subrc NE 0.

                                                                                                                                                  EXIT.

                                                                                                                                                  ENDIF.

                                                                                                                                                  endif.

                                                                                                                                                  endif.

                                                                                                                                                  if not t_poaccount-asset_no is initial.

                                                                                                                                                  PERFORM GET_ASSET_DATA USING T_COMPCODE

                                                                                                                                                  T_POACCOUNT

                                                                                                                                                  T_POHEADER

                                                                                                                                                  CHANGING P_XSPEB.

                                                                                                                                                  if sy-subrc ne 0.

                                                                                                                                                  EXIT.

                                                                                                                                                  ELSE.

                                                                                                                                                  IF P_XSPEB eq C_X. "'X'.

                                                                                                                                                  PERFORM ERROR_HANDLING_XSPEBG USING T_POHEADER

                                                                                                                                                  T_COMPCODE

                                                                                                                                                  L_WA_ZERRORS.

                                                                                                                                                  EXIT.

                                                                                                                                                  ENDIF.

                                                                                                                                                  endif.

                                                                                                                                                  endif.

                                                                                                                                                  • if not t_poitem-plant is initial.

                                                                                                                                                  • select single werks

                                                                                                                                                  • into l_werks

                                                                                                                                                  • from t001w

                                                                                                                                                  • where werks = t_poitem-plant.

                                                                                                                                                  • if sy-subrc ne 0.

                                                                                                                                                  • PERFORM ERROR_HANDLING_PLANT USING T_POHEADER

                                                                                                                                                  • T_COMPCODE

                                                                                                                                                  • L_WA_ZERRORS.

                                                                                                                                                  • EXIT.

                                                                                                                                                  • endif.

                                                                                                                                                  • Clear: l_werks.

                                                                                                                                                  • IF NOT T_POITEM-PLANT IS INITIAL.

                                                                                                                                                  • select single werks

                                                                                                                                                  • into l_werks

                                                                                                                                                  • from ANLZ

                                                                                                                                                  • where bukrs = t_compcode and

                                                                                                                                                  • werks = t_poitem-plant.

                                                                                                                                                  • if sy-subrc ne 0.

                                                                                                                                                  • PERFORM ERROR_HANDLING_ANLZ USING T_POHEADER

                                                                                                                                                  • T_COMPCODE

                                                                                                                                                  • L_WA_ZERRORS.

                                                                                                                                                  • EXIT.

                                                                                                                                                  • endif.

                                                                                                                                                  • ENDIF.

                                                                                                                                                  • clear: l_werks.

                                                                                                                                                  • IF NOT T_POITEM-PLANT IS INITIAL.

                                                                                                                                                  • select single werks

                                                                                                                                                  • into l_werks

                                                                                                                                                  • from t499s

                                                                                                                                                  • where werks = t_poitem-plant.

                                                                                                                                                  • if sy-subrc ne 0.

                                                                                                                                                  • PERFORM ERROR_HANDLING_PLANT USING T_POHEADER

                                                                                                                                                  • T_COMPCODE

                                                                                                                                                  • L_WA_ZERRORS.

                                                                                                                                                  • EXIT.

                                                                                                                                                  • endif.

                                                                                                                                                  • ENDIF.

                                                                                                                                                  • endif.

                                                                                                                                                  • If not t_poitem-plant is initial.

                                                                                                                                                  • select single werks stand

                                                                                                                                                  • into (l_werks, l_location )

                                                                                                                                                  • from t499s

                                                                                                                                                  • where werks = t_POACCOUNT-ZPLANT AND

                                                                                                                                                  • stand = t_poaccount-Zlocation.

                                                                                                                                                  • if sy-subrc ne 0.

                                                                                                                                                  • PERFORM ERROR_HANDLING_location USING T_POHEADER

                                                                                                                                                  • T_COMPCODE

                                                                                                                                                  • L_WA_ZERRORS.

                                                                                                                                                  • EXIT.

                                                                                                                                                  • endif.

                                                                                                                                                  • endif.

                                                                                                                                                  endif.

                                                                                                                                                  endif.

                                                                                                                                                  • IF t_poitem-acctasscat = C_K1. "'K'.

                                                                                                                                                  IF L_ACCT_ASSMNT = C_K1.

                                                                                                                                                  IF NOT t_poaccount-gl_account IS INITIAL.

                                                                                                                                                  *MOD-004

                                                                                                                                                  • CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  • EXPORTING "@SDR

                                                                                                                                                  • INPUT = t_poaccount-gl_account

                                                                                                                                                  • IMPORTING "@SDR

                                                                                                                                                  • OUTPUT = t_poaccount-gl_account.

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  EXPORTING "@SDR

                                                                                                                                                  INPUT = t_poaccount-gl_account

                                                                                                                                                  IMPORTING "@SDR

                                                                                                                                                  OUTPUT = l_glacc.

                                                                                                                                                  MOVE: L_GLACC TO T_POACCOUNT-GL_ACCOUNT.

                                                                                                                                                  • perform validate_gl_account using t_poaccount-gl_account

                                                                                                                                                  • t_compcode

                                                                                                                                                  • changing l_flag.

                                                                                                                                                  *MOD-004

                                                                                                                                                  perform validate_gl_account using l_glacc

                                                                                                                                                  t_compcode

                                                                                                                                                  changing l_flag.

                                                                                                                                                  IF L_FLAG NE C_X. "'X'.

                                                                                                                                                  PERFORM ERROR_HANDLING_GL USING T_POHEADER

                                                                                                                                                  T_COMPCODE

                                                                                                                                                  L_WA_ZERRORS.

                                                                                                                                                  ENDIF.

                                                                                                                                                  PERFORM GET_CONSTANT_ZXA USING t_poheader

                                                                                                                                                  t_compcode

                                                                                                                                                  l_wa_zerrors

                                                                                                                                                  changing l_glaccount.

                                                                                                                                                  IF sy-subrc <> 0.

                                                                                                                                                  EXIT.

                                                                                                                                                  ELSE.

                                                                                                                                                  IF NOT T_POACCOUNT-WBS_ELEMENT IS INITIAL.

                                                                                                                                                  perform check_project_type

                                                                                                                                                  using t_poaccount-wbs_element

                                                                                                                                                  t_poheader

                                                                                                                                                  t_compcode.

                                                                                                                                                  ENDIF.

                                                                                                                                                  endif.

                                                                                                                                                  endif.

                                                                                                                                                  ENDIF.

                                                                                                                                                  IF NOT t_poaccount-costcenter IS INITIAL AND

                                                                                                                                                  t_poaccount-costcenter NE '0000000000'.

                                                                                                                                                  *mod-004

                                                                                                                                                  • CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  • EXPORTING

                                                                                                                                                  • INPUT = t_poaccount-costcenter

                                                                                                                                                  • IMPORTING

                                                                                                                                                  • OUTPUT = t_poaccount-costcenter.

                                                                                                                                                  *MOD-004

                                                                                                                                                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                                                                                                                                                  EXPORTING

                                                                                                                                                  INPUT = t_poaccount-costcenter

                                                                                                                                                  IMPORTING

                                                                                                                                                  OUTPUT = l_cost.

                                                                                                                                                  IF T_POACCOUNT-COSTCENTER NE '0000000000'.

                                                                                                                                                  MOVE: L_COST TO T_POACCOUNT-COSTCENTER.

                                                                                                                                                  ENDIF.

                                                                                                                                                  *MOD-004

                                                                                                                                                  • perform validate_costcenter using t_poaccount-costcenter

                                                                                                                                                  *

                                                                                                                                                Add comment
                                                                                                                                                10|10000 characters needed characters exceeded