commented code in adjustment

39
D01K913456 – print D01K913462 V_T095_MASTER * * DATA LV_CHAR TYPE CHAR30. * * DATA: LV_NUM1 TYPE I VALUE 1, * LV_NUM2 TYPE I VALUE 7, * LV_LINES TYPE I, * LV_REM TYPE I, * LW_FINAL3 LIKE LW_FINAL. * * * FIELD-SYMBOLS: <FS_LEASE> TYPE ZFI_LEASE. * * SORT IT_ANLA BY BUKRS ANLN1 ANLN2 ORD41 DESCENDING. * * SORT IT_ANLA BY ORD41 DESCENDING. * SORT IT_LEASE BY ANLN1 DATE1 DESCENDING. * * DELETE ADJACENT DUPLICATES FROM IT_LEASE * COMPARING ANLN1. * * * LT_ANLA_TEMP = IT_ANLA. * * DELETE ADJACENT DUPLICATES FROM LT_ANLA_TEMP * COMPARING ORD41. * * LOOP AT LT_ANLA_TEMP INTO LW_ANLA_TEMP. * * READ TABLE IT_ANLA TRANSPORTING NO FIELDS * WITH KEY ORD41 = LW_ANLA_TEMP-ORD41. * IF SY-SUBRC = 0. * LV_INDEX = SY-TABIX. * * IF LW_ANLA_TEMP-ORD41 = ''. * CONTINUE. * ENDIF. * * LOOP AT IT_ANLA INTO LW_ANLA FROM LV_INDEX. *

Upload: gopi-gundeti

Post on 04-Jan-2016

33 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Commented Code in Adjustment

D01K913456 – print

D01K913462

V_T095_MASTER

**  DATA  LV_CHAR TYPE CHAR30.**  DATA: LV_NUM1 TYPE I VALUE 1,*        LV_NUM2 TYPE I VALUE 7,*        LV_LINES TYPE I,*        LV_REM TYPE I,*        LW_FINAL3 LIKE LW_FINAL.***  FIELD-SYMBOLS: <FS_LEASE> TYPE ZFI_LEASE.**  SORT IT_ANLA BY BUKRS ANLN1 ANLN2 ORD41 DESCENDING.**  SORT IT_ANLA BY ORD41 DESCENDING.*  SORT IT_LEASE BY ANLN1 DATE1 DESCENDING.**  DELETE ADJACENT DUPLICATES FROM IT_LEASE*  COMPARING ANLN1.***  LT_ANLA_TEMP = IT_ANLA.**  DELETE ADJACENT DUPLICATES FROM LT_ANLA_TEMP*  COMPARING ORD41.**  LOOP AT LT_ANLA_TEMP INTO LW_ANLA_TEMP.**    READ TABLE IT_ANLA TRANSPORTING NO FIELDS*    WITH KEY ORD41 = LW_ANLA_TEMP-ORD41.*    IF SY-SUBRC = 0.*      LV_INDEX = SY-TABIX.**      IF LW_ANLA_TEMP-ORD41 = ''.*        CONTINUE.*      ENDIF.**      LOOP AT IT_ANLA INTO LW_ANLA FROM LV_INDEX.**        IF LW_ANLA_TEMP-ORD41 <> LW_ANLA-ORD41.*          EXIT.*        ENDIF.**        READ TABLE IT_LEASE INTO LW_LEASE_TEMP*        WITH KEY ANLN1 = LW_ANLA-ANLN1*        BINARY SEARCH.*        IF SY-SUBRC = 0.*

Page 2: Commented Code in Adjustment

*          IF LW_LEASE_TEMP-STATUS = '0'.**            LV_LEASE_DOM = LV_LEASE_DOM + 1.*            LV_TEU_L_DOM = LV_TEU_L_DOM + LW_ANLA-ORD42.**          ELSEIF LW_LEASE_TEMP-STATUS = '1'.**            IF LW_LEASE_TEMP-MOVEM = 'LI'.**              LV_STOCK_DOM = LV_STOCK_DOM + 1.*              LV_TEU_S_DOM = LV_TEU_S_DOM + LW_ANLA-ORD42.**            ELSEIF LW_LEASE_TEMP-MOVEM = 'LO'.**              LV_LEASE_DOM = LV_LEASE_DOM + 1.*              LV_TEU_L_DOM = LV_TEU_L_DOM + LW_ANLA-ORD42.*            ENDIF.*          ENDIF.*        ELSE. " IF THE ASSET NOT IN ZFI_LEASE MEANS IT IS IN STOCK**          LV_STOCK_DOM = LV_STOCK_DOM + 1.*          LV_TEU_S_DOM = LV_TEU_S_DOM + LW_ANLA-ORD42.**        ENDIF.***      ENDLOOP.**      READ TABLE IT_T087T INTO LW_T087T*      WITH KEY SPRAS = SY-LANGU*               ORDNR = '1'*               ORD4X = LW_ANLA_TEMP-ORD41.**      CONCATENATE LW_T087T-ORDTX '( Nos. )'*      INTO LV_CHAR SEPARATED BY ' '.*      LW_FINAL-CTYPE = LV_CHAR.**      LW_FINAL-LEASE = LV_LEASE_DOM.*      LW_FINAL-STOCK = LV_STOCK_DOM.*      LW_FINAL-FLEET = LV_LEASE_DOM +*                       LV_STOCK_DOM.*      LW_FINAL-UF    = ( LV_LEASE_DOM * 100 ) /*                        LW_FINAL-FLEET.*      APPEND LW_FINAL TO IT_FINAL.*      CLEAR: LW_FINAL,*             LV_CHAR.**      CONCATENATE LW_T087T-ORDTX '( TEUs. )'*      INTO LV_CHAR SEPARATED BY ' '.**      LW_FINAL-CTYPE = LV_CHAR.*      LW_FINAL-LEASE = LV_TEU_L_DOM.*      LW_FINAL-STOCK = LV_TEU_S_DOM.

Page 3: Commented Code in Adjustment

*      LW_FINAL-FLEET = LV_TEU_L_DOM +*                       LV_TEU_S_DOM.*      LW_FINAL-UF    = ( LV_TEU_L_DOM * 100 ) /*                        LW_FINAL-FLEET.*      APPEND LW_FINAL TO IT_FINAL.*      CLEAR LW_FINAL.**      APPEND LW_FINAL TO IT_FINAL.**      CLEAR: LV_LEASE_DOM,*             LV_STOCK_DOM,*             LW_FINAL,*             LW_T087T,*             LV_INDEX,*             LV_CHAR,*             LV_TEU_L_DOM,*             LV_TEU_S_DOM.*    ENDIF.*  ENDLOOP.*  CLEAR LW_T087T.**  DESCRIBE TABLE IT_FINAL LINES LV_LINES.**  SORT IT_T087T BY ORDTX DESCENDING.**  CLEAR LV_INDEX.*  LOOP AT IT_T087T INTO LW_T087T.*    LV_INDEX = SY-TABIX.*    IF LW_T087T-ORDTX+0(13) = 'International'.**      CONCATENATE LW_T087T-ORDTX+13(7) 'Total ( Nos. )'*      INTO LW_FINAL-CTYPE SEPARATED BY ' '.**      APPEND LW_FINAL TO IT_FINAL.*      CLEAR LW_FINAL.**      CONCATENATE LW_T087T-ORDTX+13(7) 'Total ( TEUs. )'*      INTO LW_FINAL-CTYPE SEPARATED BY ' '.*      APPEND LW_FINAL TO IT_FINAL.*      CLEAR LW_FINAL.**      APPEND LW_FINAL TO IT_FINAL.*    ENDIF.**    READ TABLE IT_FINAL INTO LW_FINAL1*    INDEX LV_NUM1.**    READ TABLE IT_FINAL INTO LW_FINAL2*    INDEX LV_NUM2.*    LW_FINAL-LEASE = LW_FINAL1-LEASE +*                     LW_FINAL2-LEASE.*    LW_FINAL-STOCK = LW_FINAL1-STOCK +*                     LW_FINAL2-STOCK.

Page 4: Commented Code in Adjustment

*    LW_FINAL-FLEET = LW_FINAL-LEASE +*                     LW_FINAL-STOCK.*    LW_FINAL-UF    = ( LW_FINAL-LEASE * 100 ) / LW_FINAL-FLEET.**    LV_LINES = LV_LINES + 1.*    READ TABLE IT_FINAL INTO LW_FINAL3*    INDEX LV_LINES.**    MODIFY IT_FINAL FROM LW_FINAL*    TRANSPORTING LEASE STOCK FLEET UF*    WHERE CTYPE = LW_FINAL3-CTYPE.**    CLEAR: LW_FINAL,*           LW_FINAL1,*           LW_FINAL2,*           LW_FINAL3.*    LV_NUM1 = LV_NUM1 + 1.*    LV_NUM2 = LV_NUM2 + 1.**    LV_REM = LV_INDEX MOD 2.*    IF LV_REM = 0.*      LV_NUM1 = LV_NUM1 + 1.*      LV_NUM2 = LV_NUM2 + 1.*      LV_LINES = LV_LINES + 1.*    ENDIF.*  ENDLOOP.

FU BAPI_GOODSMVT_CREATE

____________________________________________________

Short Text

Post goods movements with MB_CREATE_GOODS_MOVEMENT

Functionality

You can use this method to create a material document for a goods movement.

You can only create one material document each time you call up the method.

You can use a simulation function before posting the goods movement to check how the data is updated in the database. The standard system is configured so that the goods movement is posted immediately, without prior simulation.

Ensure that you transfer the data in the same way as it is managed in the database. For example:

Material number 18-character with leading zeros

Batches with uppercase letters

Page 5: Commented Code in Adjustment

Ensure that the header data of the material document includes the posting date for all transactions/events listed below. Populate the PSTNG_DATE field (import structure GOODSMVT_HEADER) in the interface BAPI2017_GM_HEAD_01 for this purpose.

Notes

From Release ERP2005 onwards, it is possible to populate customers' own fields in database tables using the BAPI, without carrying out a modification.

The enhancements are passed on to the BAPI in a container and can be processed within the BAPI function module.

Technically, this is realized via an extension parameter (ExtensionIn) (see below or tab page 'Tables -> Long Text') .

Authorization check

In the MM Inventory Management component, the method does not perform any authorization checks.

Note that the system can also check authorization objects of other applications during the posting of a goods movement, depending on the business transaction.

Transfer

The following information about the material document that is to be created is passed on to the method:

A structure with the header data

A structure with the code for the movement

A table with the item data

A table with the serial numbers

The posting is made by the function module MB_CREATE_GOODS_MOVEMENT.

Confirmations

Messages are returned in the Return parameter. The parameter documentation shows the return codes and their meanings.

Further information

The method can only perform your function if no error messages were generated in the Return table. This is the case if the header data and all the items were processed successfully.

Transaction control is not implemented. The calling program therefore has to execute the Commit Work itself after this method has been successfully invoked (in other words, if no errors were reported in the Return parameter).

Which fields must be populated during the various transactions/events?

The following example scenarios illustrate which fields have to be populated for which business transactions/events (code).

There are the following types of transactions/events:

Page 6: Commented Code in Adjustment

1. GM_Code 01: Goods receipt for purchase order2. GM_Code 02: Goods receipt for production order3. GM_Code 03: Goods issue4. GM_Code 04: Transfer posting5. GM_Code 05: Other goods receipt6. GM_Code 06: Reversal of goods movements7. GM_Code 07: Subsequent adjustment with regard to a subcontract order

Entering the movement indicator

Depending on the transaction, you must enter the following in the movement indicator field:

GM_Code 01 (Goods receipt for purchase order): B

GM_Code 02 (Goods receipt for production order): F

For all other transactions, leave the field blank.

For 1: GM_Code 01: Goods receipt for purchase order

Purchase order known

The following fields must be populated:

o Purchase order

o Purchase order item

o Movement type

o Movement indicator

o Quantity in unit of entry

o ISO code unit of measurement for unit of entry orquantity proposal

The following fields may have to be populated (this is not a complete list):

o Minimum shelf life expiration date (if set up in the system)

o Reason for movement (if set up in the system)

o Batch (if the material is handled in batches and no automatic batch assignment has been set up)

o Storage location (if no storage location us specified in the purchase order item)

The following fields can be populated (this is not a complete list):

o Stock type

o Item text

o Unloading point

Page 7: Commented Code in Adjustment

o Delivery completed indicator

The following fields must not be populated (this is not a complete list):

o Account assignment fields (the account assignment is adopted from the purchase order)

o Reservation

o Receiving/issuing material

o Receiving/issuing plant

o Receiving/issuing storage location

In the case of a purchase order item with the item category "subcontracting", only the GR item is to be passed on in the interface. The GI items are determined automatically in the system.

Purchase order unknown: Shipping notification known

The following fields must be populated:

o Delivery

o Delivery item

o Movement type

Other fields as under "Purchase order known". The system determines the relevant purchase order item via the delivery/delivery item.

Purchase order unknown: Purchase order is to be created automatically

The following fields must be populated:

o Material number

o Plant

o Storage location

o Vendor

o Movement type

o Movement indicator

o Quantity in unit of entry

o ISO code unit of measurement for unit of entry

The following fields may have to be populated (this is not a complete list):

o Minimum shelf life expiration date (if set up in the system)

Page 8: Commented Code in Adjustment

o Reason for movement (if set up in the system)

o Batch (if the material is handled in batches and batches are not assigned automatically)

The following fields can be populated (this is not a complete list):

o Stock type

o Item text

o Unloading point

You cannot populate the following fields (this is not a complete list):

o Account assignment fields (automatic creation of purchase order items with account assignment is not supported)

o Reservation

o Receiving/issuing material

o Receiving/issuing plant

o Receiving/issuing storage location

Purchase order unknown: A purchase order is not to be created

The following fields must be populated:

o Material number

o Plant

o Storage location

o Vendor

o Movement type

o Movement indicator

o Quantity in unit of entry

o ISO code unit of measurement for unit of entry

The following fields may have to be populated in some cases (this is not a complete list)

o Minimum shelf life expiration date (if set up in the system)

o Reason for movement (if set up in the system)

o Batch (if the material is handled in batches and automatic assignment of batch numbers is not set)

Page 9: Commented Code in Adjustment

The following fields can be populated (this is not a complete list)

o Special stock indicator

o Item text

o Unloading point

o Goods recipient

The following fields cannot be populated (this is not a complete list)

o Account assignment fields (automatic creation of purchase order items with account assignment is not supported)

o Reservation

o Receiving/issuing material

o Receiving/issuing plant

o Receiving/issuing storage location

o Receiving/issuing batch

The input combinations listed above for the GM_CODE 01 can be combined within an input table so that they can be posted in a material document. Items can also be posted for different purchase orders, provided that all the purchase orders relate to the same vendor.

Transfer of subcontracting components

When the end product (ordered material of a subcontract order) is posted using movement type 101, the populated unique identification of the document line (LINE_ID) is additionally needed for the transfer of the subcontracting components.More information on LINE_ID and PARENT_IDThe following fields must be populated for the components:

o Unique identification of the document line

o Identification of the immediately superordinate line

o Material number

o Plant

o Storage location

o Quantity in unit of entry

The following fields can be filled for the components:

o All other fields in the method that are included in this list.

The following fields cannot be populated for the components:

Page 10: Commented Code in Adjustment

o All fields that are not included in the list above. The movement indicator must be initial.

Additional fields in goods-receipt-based invoice verification

When you post a goods receipt to purchase order with movement type 102, an issue with reference to a previously posted goods issue, the following fields must also be transferred:

o REF_DOC_IT (LFPOS): Item of a reference document

o REF_DOC (LFBNR): Document number of a reference document

o REF_DOC_YR (LFBJA): Fiscal year of a reference document

Only if you transfer these fields can you be sure that the link to the original goods movement is retained.

For 2 GM_Code 02: Goods receipt for production order

The following fields have to be populated:

o Order

o Movement type

o Movement indicator

o Quantity in unit of entry

o ISO code unit of measurement for unit of entry orquantity proposal

The following fields may have to be populated in some cases (this is not a complete list):

o Minimum shelf life expiration date (if set up in the system)

o Reason for movement (if set up in the system)

o Batch (if the material is handled in batches and automatic batch number assignment is not set)

o Storage location (if storage location has not been specified in the order)

The following fields can be populated (this is not a complete list):

o Order item (co-product)

o Stock type

o Item text

o Unloading point

o "Delivery completed" indicator

The following fields cannot be populated (this is not a complete list):

Page 11: Commented Code in Adjustment

o Account assignment fields (the account assignments are adopted from the purchase order)

o Reservation

o Receiving/issuing material

o Receiving/issuing plant

o Receiving/issuing storage location

o Receiving/issuing batch

For 3 GM_Code 03: Goods issue

Goods issue without reference to a reservation

The following fields must be populated:

o Material number

o Plant

o Storage location

o Movement type

o Movement indicator

o Quantity in unit of entry

o ISO code unit of measurement for unit of entry

The following fields may have to be populated in some cases (this is not a complete list):

o Special stock (e.g. sales order, project, vendor etc.)

o Minimum shelf life expiration date (if set up in the system)

o Reason for movement (if set up in the system)

o Batch (if the material is handled in batches and automatic batch number assignment is not set)

o Account assignment fields

The following fields can be populated (this is not a complete list):

o Special stock indicator

o Item text

o Unloading point

Page 12: Commented Code in Adjustment

o Goods recipient

The following fields cannot be populated (this is not a complete list):

o Reservation

o Receiving/issuing material

o Receiving/issuing plant

o Receiving/issuing storage location

o Receiving/issuing batch

Goods issue with reference to a reservation

The following fields must to be populated:

o Reservation number

o Reservation item

o Record type of the reservation

o Movement indicator

o Quantity in unit of entry

o ISO code unit of measurement for unit of entry

The following fields may have to be populated in some cases (this is not a complete list):

o Minimum shelf life expiration date (if set up in the system)

o Reason for movement (if set up in the system)

o Batch (if the material is handled in batches and automatic batch number assignment is not set)

o Storage location (if not planned in the reservation)

The following fields can be populated (this is not a complete list):

o Special stock indicator

o Item text

o Unloading point

o Goods recipient

The following fields cannot be populated (this is not a complete list):

o Movement type

Page 13: Commented Code in Adjustment

o Material

o Plant

o Account assignment fields

For 4 GM_Code 04: Transfer posting

Transfer posting without reference to a reservation

The following fields must be populated:

o Material number

o Plant

o Storage location

o Movement type

o Movement indicator

o Quantity in unit of entry

o ISO code unit of measurement for unit of entry

The following fields may have to be populated in some cases (this is not a complete list):

o Receiving material

o Receiving plant

o Receiving storage location

o Receiving batch (if material is handled in batches and you want to change batches)

o Receiving/issuing special stock (e.g. sales order, project, vendor etc.)

o Minimum shelf life expiration date (if set up in the system)

o Reason for movement (if set up in the system)

o Batch (if the material is handled in batches and automatic batch number assignment is not set)

The following fields can be populated (this is not a complete list):

o Special stock indicator

o Item text

o Account assignment fields (for automatic posting lines: expense/income from stock transfer)

Page 14: Commented Code in Adjustment

The following fields cannot be populated (this is not a complete list):

o Reservation

Transfer posting with reference to a reservation

See goods issue with reference to a reservation

For 5 GM_Code 05: Other goods receipts

Other goods receipt without reference to a reservation

See goods issue without reference to a reservation

Other goods receipt with reference to a reservation

See goods issue with reference to a reservation

For 6 GM_Code 06: Reversal of goods movements

You can use the Cancel method to reverse goods movements. But you may also want to cancel a goods movement without referring to a material document (see the Cancel method).If you want to work without referring to the document, you have to populate the BAPI_GM_ITEM_CREATE-XSTOB field in the interface (import table GOODSMVT_ITEM). In this case, the system converts the movement type assigned in the interface to the reversal movement type. Alternatively, you can set the reversal movement type in the interface. In this case, the BAPI_GM_ITEM_CREATE_XSTOB field must be transferred blank.If you want to cancel a goods movement with reference to a reservation (without using the Cancel method) you can only transfer the BAPI_GM_ITEM_CREATE_XSTOB field if it is populated. Movement types are not transferred when you post with reference to a reservation, as the movement type is contained in the reservation item.

For 7. GM_Code 07: Subsequent adjustment with regard to a subcontract order

Ordered material of subcontract order

The following fields must be populated:

o Unique identification of document line (can be freely assigned)

o Posting date in document header

o Document number of purchasing document

o Item number of purchasing document

o Material number

o Plant

o Movement type (select movement type 121)

o Movement indicator (must be O)

Further entries are not allowed. The entry quantity for the ordered material of a subcontract order must be zero.

Page 15: Commented Code in Adjustment

Components

The following fields must be populated:

o Unique identification of document line (can be freely assigned)

o Identification of the immediately superordinate line

o Plant

o Material number

o Quantity in unit of entry; can also be negative

The following fields can be populated:

o Storage location

o All other fields in the method that are included in this list.

The following fields may not be populated:

o All fields that are not in the list above. The movement indicator must be blank.

More information on LINE_ID and PARENT_ID

Additional fields in goods-receipt-based invoice verification

When you post a subsequent adjustment, the following fields must also be transferred:

o REF_DOC_IT (LFPOS): Item of a reference document

o REF_DOC (LFBNR): Document number of a reference document

o REF_DOC_YR (LFBJA): Fiscal year of a reference document

Only if you transfer these fields can you be sure that the link to the original goods movement is retained.

Parameters

GOODSMVT_HEADERGOODSMVT_CODETESTRUNGOODSMVT_REF_EWMGOODSMVT_HEADRETMATERIALDOCUMENTMATDOCUMENTYEARGOODSMVT_ITEMGOODSMVT_SERIALNUMBERRETURNGOODSMVT_SERV_PART_DATAEXTENSIONIN

Exceptions

Page 16: Commented Code in Adjustment

Function Group

MB_BUS2017

*****    WRITE P_LCAMT TO LV_AMOUNT.**    READ TABLE IT_MSEG INTO WA_MSEG**    INDEX 1.****    perform bdc_dynpro      using 'SAPMM07M' '0400'.**    perform bdc_field       using 'BDC_CURSOR'**                                  'MKPF-BUDAT'.**    perform bdc_field       using 'BDC_OKCODE'**                                  '/00'.**    perform bdc_field       using 'MKPF-BLDAT'**                                  lv_docdat."'17.06.2012'.**    perform bdc_field       using 'MKPF-BUDAT'**                                  lv_postdat."'17.06.2012'.**    perform bdc_field       using 'RM07M-BWARTWA'**                                  'Z02'.**    perform bdc_field       using 'RM07M-WERKS'**                                   wa_mseg-werks."'DE01'.**    clear wa_mseg.****    perform bdc_field       using 'XFULL'**                                  'X'.**    perform bdc_field       using 'RM07M-WVERS2'**                                  'X'.**    perform bdc_dynpro      using 'SAPMM07M' '0421'.**    perform bdc_field       using 'BDC_OKCODE'**                                  '/00'.**    perform bdc_field       using 'MSEGK-KONTO'**                                  '58190000'.**  loop at it_mseg into wa_mseg.**    perform bdc_field       using 'MSEG-MATNR(01)'**                                  '3000000012'.**    perform bdc_field       using 'MSEG-ERFMG(01)'**                                  '1'.**    perform bdc_field       using 'MSEG-LGORT(01)'**                                  'manf'.**    perform bdc_field       using 'BDC_CURSOR'**                                  'DKACB-FMORE'.**    perform bdc_field       using 'DKACB-FMORE'**                                  ''.**    perform bdc_dynpro      using 'SAPLKACB' '0002'.**    perform bdc_field       using 'BDC_CURSOR'**                                  'COBL-KOSTL'.**    perform bdc_field       using 'BDC_OKCODE'**                                  '=ENTE'.**    perform bdc_field       using 'COBL-KOSTL'**                                  '1000_DEL'.

Page 17: Commented Code in Adjustment

**    perform bdc_field       using 'COBL-PRCTR'**                                  'CC_DEL'.**    perform bdc_dynpro      using 'SAPMM07M' '0421'.**    perform bdc_field       using 'BDC_OKCODE'**                                  '/00'.**    perform bdc_field       using 'MSEG-MATNR(02)'**                                  '3000000013'.**    perform bdc_field       using 'MSEG-ERFMG(02)'**                                  '2'.**    perform bdc_field       using 'MSEG-LGORT(02)'**                                  'manf'.**    perform bdc_field       using 'MSEG-WERKS(02)'**                                  'mu01'.**    perform bdc_field       using 'BDC_CURSOR'**                                  'DKACB-FMORE'.**    perform bdc_field       using 'DKACB-FMORE'**                                  ''.**    perform bdc_dynpro      using 'SAPLKACB' '0002'.**    perform bdc_field       using 'BDC_CURSOR'**                                  'COBL-KOSTL'.**    perform bdc_field       using 'BDC_OKCODE'**                                  '=ENTE'.**    perform bdc_field       using 'COBL-KOSTL'**                                  '1000_DEL'.**    perform bdc_field       using 'COBL-PRCTR'**                                  'ICL_DEL'.**    perform bdc_dynpro      using 'SAPMM07M' '0421'.**    perform bdc_field       using 'BDC_OKCODE'**                                  '/00'.**    perform bdc_field       using 'MSEG-MATNR(03)'**                                  '3000000014'.**    perform bdc_field       using 'MSEG-ERFMG(03)'**                                  '3'.**    perform bdc_field       using 'MSEG-LGORT(03)'**                                  'manf'.**    perform bdc_field       using 'MSEG-WERKS(03)'**                                  'KO01'.**    perform bdc_field       using 'BDC_CURSOR'**                                  'DKACB-FMORE'.**    perform bdc_field       using 'DKACB-FMORE'**                                  ''.******    perform bdc_dynpro      using 'SAPLKACB' '0002'.**    perform bdc_field       using 'BDC_CURSOR'**                                  'COBL-KOSTL'.**    perform bdc_field       using 'BDC_OKCODE'**                                  '=ENTE'.**    perform bdc_field       using 'COBL-KOSTL'**                                  '1000_DEL'.**    perform bdc_field       using 'COBL-PRCTR'**                                  'ICL_DEL'.

Page 18: Commented Code in Adjustment

******    perform bdc_dynpro      using 'SAPMM07M' '0421'.**    perform bdc_field       using 'BDC_CURSOR'**                                  'MSEG-MATNR(01)'.**    perform bdc_field       using 'BDC_OKCODE'**                                  '=PF02'.**    perform bdc_field       using 'DKACB-FMORE'**                                  'X'.**    perform bdc_dynpro      using 'SAPLKACB' '0002'.**    perform bdc_field       using 'BDC_CURSOR'**                                  'COBL-KOSTL'.**    perform bdc_field       using 'BDC_OKCODE'**                                  '=ENTE'.**** endloop.****    perform bdc_dynpro      using 'SAPMM07M' '0410'.**    perform bdc_field       using 'BDC_CURSOR'**                                  'MSEG-EXBWR'.**    perform bdc_field       using 'BDC_OKCODE'**                                  '=KPN'.**    perform bdc_field       using 'MSEG-ERFMG'**                                  '1'.**    perform bdc_field       using 'DM07M-KONTO'**                                  '58190000'.**    perform bdc_field       using 'MSEG-EXBWR'**                                  '200'.**    perform bdc_field       using 'DKACB-FMORE'**                                  'X'.**    perform bdc_dynpro      using 'SAPLKACB' '0002'.**    perform bdc_field       using 'BDC_CURSOR'**                                  'COBL-KOSTL'.**    perform bdc_field       using 'BDC_OKCODE'**                                  '=ENTE'.**    perform bdc_field       using 'COBL-KOSTL'**                                  '1000_DEL'.**    perform bdc_field       using 'COBL-PRCTR'**                                  'ICL_DEL'.**    perform bdc_dynpro      using 'SAPMM07M' '0410'.**    perform bdc_field       using 'BDC_CURSOR'**                                  'MSEG-EXBWR'.**    perform bdc_field       using 'BDC_OKCODE'**                                  '=KPN'.**    perform bdc_field       using 'MSEG-ERFMG'**                                  '2'.**    perform bdc_field       using 'DM07M-KONTO'**                                  '58190000'.**    perform bdc_field       using 'MSEG-EXBWR'**                                  '200'.**    perform bdc_field       using 'DKACB-FMORE'**                                  'X'.

Page 19: Commented Code in Adjustment

**    perform bdc_dynpro      using 'SAPLKACB' '0002'.**    perform bdc_field       using 'BDC_CURSOR'**                                  'COBL-KOSTL'.**    perform bdc_field       using 'BDC_OKCODE'**                                  '=ENTE'.**    perform bdc_field       using 'COBL-KOSTL'**                                  '1000_DEL'.**    perform bdc_field       using 'COBL-PRCTR'**                                  'ICL_DEL'.**    perform bdc_dynpro      using 'SAPMM07M' '0410'.**    perform bdc_field       using 'BDC_OKCODE'**                                  '=BU'.**    perform bdc_field       using 'MSEG-ERFMG'**                                  '3'.**    perform bdc_field       using 'DM07M-KONTO'**                                  '58190000'.**    perform bdc_field       using 'MSEG-EXBWR'**                                  '200'.**    perform bdc_field       using 'BDC_CURSOR'**                                  'DKACB-FMORE'.**    perform bdc_field       using 'DKACB-FMORE'**                                  ''.********    perform bdc_dynpro      using 'SAPMM07M' '0400'.***    perform bdc_field       using 'BDC_CURSOR'***                                  'MKPF-BUDAT'.***    perform bdc_field       using 'BDC_OKCODE'***                                  '/00'.***    perform bdc_field       using 'MKPF-BLDAT'***                                  LV_DOCDAT.***    perform bdc_field       using 'MKPF-BUDAT'***                                  LV_POSTDAT.***    perform bdc_field       using 'RM07M-BWARTWA'***                                  'Z02'.***    perform bdc_field       using 'RM07M-WERKS'***                                  WA_MSEG-WERKS.***    CLEAR WA_MSEG.***    perform bdc_field       using 'XFULL'***                                  'X'.***    perform bdc_field       using 'RM07M-WVERS2'***                                  'X'.***    perform bdc_dynpro      using 'SAPMM07M' '0421'.***    perform bdc_field       using 'BDC_OKCODE'***                                  '/00'.***    perform bdc_field       using 'MSEGK-KONTO'***                                  '58190000'.****    TABLE CONTROL START***  LOOP AT IT_MSEG INTO WA_MSEG.******    WRITE: WA_MSEG-MATNR TO LV_MATNR,***           WA_MSEG-ERFMG TO LV_ERFMG,

Page 20: Commented Code in Adjustment

***           WA_MSEG-EXBWR TO LV_EXBWR.***    LV_NUM = LV_NUM + 1.******    CONCATENATE 'MSEG-MATNR('***                LV_NUM***                ')'***           INTO LV_CHAR   .***    perform bdc_field       using LV_CHAR"'MSEG-MATNR(01)'***                                  LV_MATNR."'3000000013'.****    perform bdc_field       using 'MSEG-MATNR(02)'****                                  '3000000012'.******    CLEAR LV_CHAR.***    CONCATENATE 'MSEG-ERFMG('***                LV_NUM***                ')'***           INTO LV_CHAR   .***    perform bdc_field       using LV_CHAR   "'MSEG-ERFMG(01)'***                                  LV_ERFMG. "'1'****    perform bdc_field       using 'MSEG-ERFMG(02)'****                                  '2'.******    CLEAR LV_CHAR.***    CONCATENATE 'MSEG-LGORT('***                LV_NUM***                ')'***           INTO LV_CHAR   .***    perform bdc_field       using LV_CHAR  "'MSEG-LGORT(01)'***                                  WA_MSEG-LGORT. "'manf'.****    perform bdc_field       using 'MSEG-LGORT(02)'****                                  'manf'.******    CLEAR LV_CHAR.***    CONCATENATE 'MSEG-WERKS('***                LV_NUM***                ')'***           INTO LV_CHAR   .***    perform bdc_field       using LV_CHAR   "'MSEG-WERKS(02)'***                                  WA_MSEG-WERKS. "'MU01'.***    perform bdc_field       using 'BDC_CURSOR'***                                  'DKACB-FMORE'.***    perform bdc_field       using 'DKACB-FMORE'***                                  ''.******    perform bdc_dynpro      using 'SAPLKACB' '0002'.***    perform bdc_field       using 'BDC_CURSOR'***                                  'COBL-KOSTL'.***    perform bdc_field       using 'BDC_OKCODE'***                                  '=ENTE'.***    perform bdc_field       using 'COBL-KOSTL'***                                  WA_MSEG-KOSTL."'1000_DEL'.****    perform bdc_field       using 'COBL-PRCTR'"NOT REQUIRED

Page 21: Commented Code in Adjustment

****                                  'CC_DEL'.*******    perform bdc_dynpro      using 'SAPLKACB' '0002'.****    perform bdc_field       using 'BDC_CURSOR'****                                  'COBL-KOSTL'.****    perform bdc_field       using 'BDC_OKCODE'****                                  '=ENTE'.****    perform bdc_field       using 'COBL-KOSTL'****                                  '1000_MUM'.****    perform bdc_field       using 'COBL-PRCTR'"NOT REQUIRED****                                  'CC_MUM'.***  ENDLOOP.*****    TABLE CONTROL END***    perform bdc_dynpro      using 'SAPMM07M' '0421'.***    perform bdc_field       using 'BDC_CURSOR'***                                  'MSEG-MATNR(01)'.***    perform bdc_field       using 'BDC_OKCODE'***                                  '=PF02'.***    perform bdc_field       using 'DKACB-FMORE'***                                  ''.***    perform bdc_dynpro      using 'SAPMM07M' '0410'.***    perform bdc_field       using 'BDC_CURSOR'***                                  'MSEG-EXBWR'.***    perform bdc_field       using 'BDC_OKCODE'***                                  '=KPN'.****    TABLE CONTROL STARTS***    LV_NUMBER = LV_NUMBER + 1.******  LOOP AT IT_MSEG INTO WA_MSEG.*********    perform bdc_field       using 'MSEG-ERFMG'***                                  LV_NUMBER." '1' SY-TABIX****    perform bdc_field       using 'DM07M-KONTO'"NOT REQUIRED****                                  '58190000'.***    perform bdc_field       using 'MSEG-EXBWR'***                                  WA_MSEG-EXBWR.***    perform bdc_field       using 'DKACB-FMORE'***                                  ''.***    LV_NUMBER = LV_NUMBER + 1.***    READ TABLE IT_MSEG TRANSPORTING NO FIELDS***    INDEX LV_NUMBER.***    IF SY-SUBRC = 0.***      perform bdc_dynpro      using 'SAPMM07M' '0410'.***      perform bdc_field       using 'BDC_OKCODE'***                                    '=BU'.***    ENDIF.****    perform bdc_field       using 'MSEG-ERFMG'****                                  '2'.  "SY-TABIX*****    perform bdc_field       using 'DM07M-KONTO'"NOT REQUIRED*****                                  '58190000'. "GL****    perform bdc_field       using 'MSEG-EXBWR'

Page 22: Commented Code in Adjustment

****                                  '200'.  "AMOUNT***  ENDLOOP.****    END TABLE CONTROL***    perform bdc_field       using 'BDC_CURSOR'***                                  'DKACB-FMORE'.***    perform bdc_field       using 'DKACB-FMORE'***                                  ''.**    CALL TRANSACTION 'MB1C' USING IT_BDCDATA**    MODE LV_MODE UPDATE 'S' MESSAGES INTO IT_MSGCOLL.**    IF SY-SUBRC = 0.**         READ TABLE IT_MSGCOLL INTO LW_MSGCOLL**         WITH KEY DYNAME = 'SAPMF05A'**                  DYNUMB = '0700'**                  MSGTYP = 'S'**                  MSGNR  = '312'.**         IF SY-SUBRC = 0.**            V_MATER_DOC = LW_MSGCOLL-MSGV1.**         ENDIF.****    ELSE.**        CLEAR LV_MSG.**        CALL FUNCTION 'FORMAT_MESSAGE'**         EXPORTING**           ID              = SY-MSGID**           LANG            = SY-LANGU**           NO              = SY-MSGNO**           V1              = SY-MSGV1**           V2              = SY-MSGV2**           V3              = SY-MSGV3**           V4              = SY-MSGV4**         IMPORTING**           MSG             = LV_MSG**         EXCEPTIONS**           NOT_FOUND       = 1**           OTHERS          = 2**                  .**        IF SY-SUBRC <> 0.*** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO***         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.**        ENDIF.****        MESSAGE LV_MSG TYPE 'I'.**        LEAVE PROGRAM.****    ENDIF.

Page 23: Commented Code in Adjustment

*  INSERTING CODE FOR FETCHING AMOUNT FROM CONTRACT REVISION TABLE****           READ TABLE IT_CONTRACT_REV INTO LW_CONTRACT_REV**           WITH KEY VBELN = LW_LEASE-VBELN**                    POSNR = LW_LEASE-POSNR**           BINARY SEARCH.**           IF SY-SUBRC = 0.***** ADJUSTMENT MONTH EQUAL TO CONTRACT CHANGE DATE MONTH**              IF P_BUDAT+0(6) EQ LW_CONTRACT_REV-CHANGE_DATE+0(6).*** LEASE IN DATE MONTH EQUAL TO CHANGE DATE MONTH**                  IF LW_LEASE-DATE1+0(6) EQ**                     LW_CONTRACT_REV-CHANGE_DATE+0(6).****                      IF LW_CONTRACT_REV-CHANGE_DATE GT**                         LW_ADV_BILL-CPUDT.****                         LW_AMOUNT-LAMOUNT = LV_NUM_DAYS ***                                             LW_CONTRACT_REV-OLDRATE. "OLDRate******                      ELSE.****                         IF LW_LEASE_REF-DATE1+0(6) EQ**                            LW_CONTRACT_REV-CHANGE_DATE+0(6) .****                           LW_AMOUNT-LAMOUNT = LV_NUM_DAYS ***                                             LW_CONTRACT_REV-NEWRATE. "old rate**                         ELSE.****                         LW_AMOUNT-LAMOUNT = LV_NUM_DAYS ***                                             LW_CONTRACT_REV-NEWRATE.**                         ENDIF.****                      ENDIF.****                  ELSE.    "LEASE IN DATE MONTH NOT EQUAL TO**                           "CHANGE DATE MONTH****                      IF LW_CONTRACT_REV-CHANGE_DATE GT**                         LW_ADV_BILL-CPUDT.****                         LW_AMOUNT-LAMOUNT = LV_NUM_DAYS ***                                             LW_CONTRACT_REV-OLDRATE.******                      ELSE.****                         IF LW_LEASE_REF-DATE1+0(6) NE**                            LW_CONTRACT_REV-CHANGE_DATE+0(6) .

Page 24: Commented Code in Adjustment

****                           LW_AMOUNT-LAMOUNT = LV_NUM_DAYS ***                                             LW_CONTRACT_REV-NEWRATE. "OLD RATE**                         ELSE.****                         LW_AMOUNT-LAMOUNT = LV_NUM_DAYS ***                                             LW_CONTRACT_REV-NEWRATE.**                         ENDIF.******                      ENDIF.****                  ENDIF.****              ELSE."ADJUSTMENT MONTH NOT EQUAL TO CONTRACT CHANGE MONTH****                IF LW_LEASE-DATE1+0(6) EQ**                     LW_CONTRACT_REV-CHANGE_DATE+0(6).****                      IF LW_CONTRACT_REV-CHANGE_DATE GT**                         LW_ADV_BILL-CPUDT.****                         LW_AMOUNT-LAMOUNT = LV_NUM_DAYS ***                                             LW_CONTRACT_REV-NEWRATE. "OLD RATE******                      ELSE.****                         IF LW_LEASE_REF-DATE1+0(6) NE**                            LW_CONTRACT_REV-CHANGE_DATE+0(6) .****                           LW_AMOUNT-LAMOUNT = LV_NUM_DAYS ***                                             LW_CONTRACT_REV-OLDRATE.**                         ELSE.****                         LW_AMOUNT-LAMOUNT = LV_NUM_DAYS ***                                             LW_CONTRACT_REV-NEWRATE.**                         ENDIF.******                      ENDIF.****                  ELSE.    "LEASE IN DATE MONTH NOT EQUAL TO**                           "CHANGE DATE MONTH****                      IF LW_CONTRACT_REV-CHANGE_DATE GT**                         LW_ADV_BILL-CPUDT.****                         LW_AMOUNT-LAMOUNT = LV_NUM_DAYS ***                                             LW_CONTRACT_REV-OLDRATE.**

Page 25: Commented Code in Adjustment

****                      ELSE.****                         IF LW_LEASE_REF-DATE1+0(6) NE**                            LW_CONTRACT_REV-CHANGE_DATE+0(6) .****                           LW_AMOUNT-LAMOUNT = LV_NUM_DAYS ***                                             LW_CONTRACT_REV-NEWRATE. "OLD RATE**                         ELSE.****                         LW_AMOUNT-LAMOUNT = LV_NUM_DAYS ***                                             LW_CONTRACT_REV-NEWRATE.**                         ENDIF.******                      ENDIF.****                  ENDIF.******              ENDIF.****           ELSE.****             LW_AMOUNT-LAMOUNT = LV_NUM_DAYS ***                              LW_tax_amount-amount.****           ENDIF.*  END OF CODE  INSERTION  31.07.2012

Copied from BAPI form

*           READ TABLE IT_CONTRACT_REV INTO LW_CONTRACT_REV*           WITH KEY VBELN = LW_LEASE-VBELN*                    POSNR = LW_LEASE-POSNR*           BINARY SEARCH.*           IF SY-SUBRC = 0.*** ADJUSTMENT MONTH EQUAL TO CONTRACT CHANGE DATE MONTH*              IF P_BUDAT+0(6) EQ LW_CONTRACT_REV-CHANGE_DATE+0(6).** LEASE IN DATE MONTH EQUAL TO CHANGE DATE MONTH*                  IF LW_LEASE-DATE1+0(6) EQ*                     LW_CONTRACT_REV-CHANGE_DATE+0(6).

Page 26: Commented Code in Adjustment

**                      IF LW_CONTRACT_REV-CHANGE_DATE GT*                         LW_ADV_BILL-CPUDT.**                        LW_BILL_UPDATE-KBETR = LW_CONTRACT_REV-OLDRATE.***                      ELSE.**                       IF LW_LEASE_REF-DATE1+0(6) EQ*                            LW_CONTRACT_REV-CHANGE_DATE+0(6) .**                          LW_BILL_UPDATE-KBETR = LW_CONTRACT_REV-NEWRATE. "OLD*                       ELSE.**                          LW_BILL_UPDATE-KBETR = LW_CONTRACT_REV-NEWRATE.*                       ENDIF.**                      ENDIF.***                  ELSE.    "LEASE IN DATE MONTH NOT EQUAL TO*                           "CHANGE DATE MONTH**                     IF LW_CONTRACT_REV-CHANGE_DATE GT*                         LW_ADV_BILL-CPUDT.**                        LW_BILL_UPDATE-KBETR = LW_CONTRACT_REV-OLDRATE.***                      ELSE.**                        IF LW_LEASE_REF-DATE1+0(6) NE*                            LW_CONTRACT_REV-CHANGE_DATE+0(6) .**                          LW_BILL_UPDATE-KBETR = LW_CONTRACT_REV-NEWRATE. "OLD RATE*                       ELSE.**                          LW_BILL_UPDATE-KBETR = LW_CONTRACT_REV-NEWRATE.*                       ENDIF.***                      ENDIF.***                  ENDIF.**              ELSE."ADJUSTMENT MONTH NOT EQUAL TO CONTRACT CHANGE MONTH**                IF LW_LEASE-DATE1+0(6) EQ*                     LW_CONTRACT_REV-CHANGE_DATE+0(6).

Page 27: Commented Code in Adjustment

**                   IF LW_CONTRACT_REV-CHANGE_DATE GT*                         LW_ADV_BILL-CPUDT.**                        LW_BILL_UPDATE-KBETR = LW_CONTRACT_REV-NEWRATE. "OLD***                      ELSE.**                        IF LW_LEASE_REF-DATE1+0(6) NE*                            LW_CONTRACT_REV-CHANGE_DATE+0(6) .**                          LW_BILL_UPDATE-KBETR = LW_CONTRACT_REV-OLDRATE.*                       ELSE.**                          LW_BILL_UPDATE-KBETR = LW_CONTRACT_REV-NEWRATE.*                       ENDIF.***                      ENDIF.***                ELSE.    "LEASE IN DATE MONTH NOT EQUAL TO*                           "CHANGE DATE MONTH**                    IF LW_CONTRACT_REV-CHANGE_DATE GT*                       LW_ADV_BILL-CPUDT.**                       LW_BILL_UPDATE-KBETR = LW_CONTRACT_REV-OLDRATE.**                    ELSE.**                       IF LW_LEASE_REF-DATE1+0(6) NE*                            LW_CONTRACT_REV-CHANGE_DATE+0(6) .**                          LW_BILL_UPDATE-KBETR = LW_CONTRACT_REV-NEWRATE."OLDRATE*                       ELSE.**                          LW_BILL_UPDATE-KBETR = LW_CONTRACT_REV-NEWRATE.**                       ENDIF.***                    ENDIF.**                  ENDIF.***              ENDIF.**           ELSE.

Page 28: Commented Code in Adjustment

**             LW_BILL_UPDATE-KBETR =  LW_tax_amount-amount.**           ENDIF.

Contract revision prongram

              CALL FUNCTION 'LAST_DAY_OF_MONTHS'                EXPORTING                  DAY_IN                  = LW_LEASE-DATE1                IMPORTING                  LAST_DAY_OF_MONTH       = LV_DATE                EXCEPTIONS                  DAY_IN_NO_DATE          = 1                  OTHERS                  = 2                        .              IF SY-SUBRC <> 0.*               MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO*                       WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.              ENDIF.

              CALL FUNCTION 'LAST_DAY_OF_MONTHS'                EXPORTING                  DAY_IN                  = LW_CONTRACT_NUM-CHANGE_DATE                IMPORTING                  LAST_DAY_OF_MONTH       = LV_DATE1                EXCEPTIONS                  DAY_IN_NO_DATE          = 1                  OTHERS                  = 2                        .              IF SY-SUBRC <> 0.*MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO*  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.              ENDIF.              LV_DATE3 = LV_DATE1 + 1.*  LAST DAY OF THE NEXT MONTH              CALL FUNCTION 'LAST_DAY_OF_MONTHS'                EXPORTING                  DAY_IN                  =  LV_DATE3                IMPORTING                  LAST_DAY_OF_MONTH       = LV_DATE2                EXCEPTIONS                  DAY_IN_NO_DATE          = 1                  OTHERS                  = 2                        .              IF SY-SUBRC <> 0.*MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO*  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.              ENDIF.              READ TABLE IT_ADV_BILL INTO LW_ADV_BILL

Page 29: Commented Code in Adjustment

              WITH KEY VBELN = LW_LEASE-VBELN                       CBDAT = LV_DATE2.              IF SY-SUBRC = 0. " ADVANCE BILL IS ALREADY DONE BEFORE                               " RATE CHANGE               IF LW_LEASE-STATUS = 0.

                   IF LW_LEASE-BSDAT+0(6) NE" Billing start date and change date                      LW_CONTRACT_NUM-CHANGE_DATE+0(6)." are in different month

                     IF LW_LEASE-BSDAT GT LV_DATE1.                         CONTINUE.                     ELSEIF LW_LEASE-BSDAT LE                            LW_CONTRACT_NUM-EFFECT_DATE AND                            LW_CONTRACT_NUM-CHANGE_DATE GT                            LW_ADV_BILL-CPUDT.

                       LV_NUM_DAYS = LV_DATE2 -                                     LW_CONTRACT_NUM-EFFECT_DATE + 1.

                     ELSEIF LW_LEASE-BSDAT GE                            LW_CONTRACT_NUM-EFFECT_DATE AND*                            LW_LEASE-BSDAT LE LV_DATE1 AND                            LW_CONTRACT_NUM-CHANGE_DATE GT                            LW_ADV_BILL-CPUDT..

                       LV_NUM_DAYS = LV_DATE2 - LW_LEASE-BSDAT + 1.

                     ELSEIF LW_LEASE-BSDAT LE                            LW_CONTRACT_NUM-EFFECT_DATE AND                            LW_CONTRACT_NUM-CHANGE_DATE LT                            LW_ADV_BILL-CPUDT.

                       LV_NUM_DAYS = LV_DATE1 -                                     LW_CONTRACT_NUM-EFFECT_DATE + 1.

                     ELSEIF LW_LEASE-BSDAT GE                            LW_CONTRACT_NUM-EFFECT_DATE AND*                            LW_LEASE-BSDAT LE LV_DATE1 AND                            LW_CONTRACT_NUM-CHANGE_DATE LT                            LW_ADV_BILL-CPUDT.

                       LV_NUM_DAYS = LV_DATE1 - LW_LEASE-BSDAT + 1.

                     ENDIF.

                   ELSE.  " Billing start date and change date                          " are in same month                     IF LW_LEASE-BSDAT GT LW_CONTRACT_NUM-EFFECT_DATE                        AND

Page 30: Commented Code in Adjustment

                        LW_CONTRACT_NUM-CHANGE_DATE LT LW_ADV_BILL-CPUDT.

                        CONTINUE.

                     ENDIF.                     IF LW_LEASE-BSDAT GE LW_CONTRACT_NUM-EFFECT_DATE                        AND*                        LW_LEASE-BSDAT LT LV_DATE1 AND                        LW_LEASE-BSDAT LT LW_ADV_BILL-CPUDT.

                          LV_NUM_DAYS = LV_DATE2 - LV_DATE3 + 1.

                     ELSEIF LW_LEASE-BSDAT GE LW_CONTRACT_NUM-EFFECT_DATE                        AND                        LW_LEASE-BSDAT GE LW_ADV_BILL-CPUDT.

                        CONTINUE.

                     ELSEIF LW_LEASE-BSDAT LT LW_CONTRACT_NUM-EFFECT_DATE                            AND                            LW_LEASE-BSDAT LE LW_ADV_BILL-CPUDT  AND                            LW_CONTRACT_NUM-CHANGE_DATE GT LW_ADV_BILL-CPUDT..

                        LV_NUM_DAYS = ( LW_CONTRACT_NUM-EFFECT_DATE -                                      LW_LEASE-BSDAT ) +                                      ( LV_DATE2 - LV_DATE3 ) + 2.

                     ELSEIF LW_LEASE-BSDAT LT LW_CONTRACT_NUM-EFFECT_DATE                            AND                            LW_LEASE-BSDAT LT LW_ADV_BILL-CPUDT AND                            LW_CONTRACT_NUM-CHANGE_DATE LT LW_ADV_BILL-CPUDT.

                       LV_NUM_DAYS = LW_CONTRACT_NUM-EFFECT_DATE -                                     LW_LEASE-BSDAT + 1.

                     ELSEIF LW_LEASE-BSDAT LT LW_CONTRACT_NUM-EFFECT_DATE                            AND                            LW_CONTRACT_NUM-EFFECT_DATE GT                            LW_ADV_BILL-CPUDT.

                      LV_NUM_DAYS = ( LW_CONTRACT_NUM-EFFECT_DATE -                                    LW_LEASE-BSDAT ) +                                    ( LV_DATE2 - LV_DATE3 ) + 2.                     ENDIF.

                   ENDIF.

              ELSEIF LW_LEASE-STATUS = 1.

                READ TABLE IT_LEASE INTO LW_LEASE1

Page 31: Commented Code in Adjustment

                WITH KEY RCIRN = LW_LEASE-DCREF.                IF SY-SUBRC = 0.

                  IF LW_CONTRACT_NUM-CHANGE_DATE+0(6) NE                     LW_CONTRACT_NUM-EFFECT_DATE+0(6).

                      IF LW_LEASE1-BSDAT  LT                         LW_CONTRACT_NUM-EFFECT_DATE AND                         LW_LEASE-DATE1 LT LW_CONTRACT_NUM-EFFECT_DATE.                          CONTINUE.                      ENDIF.

                      IF LW_LEASE1-BSDAT LE                         LW_CONTRACT_NUM-EFFECT_DATE AND                         LW_LEASE-DATE1 GE LV_DATE2.

                         LV_NUM_DAYS = LV_DATE2 -                                       LW_CONTRACT_NUM-EFFECT_DATE + 1.                      ELSEIF LW_LEASE1-BSDAT  LE                             LW_CONTRACT_NUM-EFFECT_DATE AND                             LW_LEASE-DATE1 LE LV_DATE2.

                        LV_NUM_DAYS = LW_LEASE-DATE1 -                                      LW_CONTRACT_NUM-EFFECT_DATE + 1.

                      ELSEIF LW_LEASE1-BSDAT GE                             LW_CONTRACT_NUM-EFFECT_DATE AND                             LW_LEASE-DATE1 GE LV_DATE2.

                        LV_NUM_DAYS = LV_DATE2 -                                      LW_LEASE1-BSDAT + 1.

                      ELSEIF LW_LEASE1-BSDAT GE                             LW_CONTRACT_NUM-EFFECT_DATE AND                             LW_LEASE-DATE1 LE LV_DATE2.

                        LV_NUM_DAYS = LW_LEASE-DATE1 -                                      LW_LEASE1-BSDAT + 1.

                      ENDIF.                ELSEIF LW_CONTRACT_NUM-CHANGE_DATE+0(6) EQ                       LW_CONTRACT_NUM-EFFECT_DATE+0(6).

                     IF LW_LEASE-DATE1 LT LW_CONTRACT_NUM-EFFECT_DATE                        AND                        LW_LEASE-DATE1 LT LW_ADV_BILL-CPUDT.

                        CONTINUE.

                     ELSEIF LW_LEASE-DATE1+0(6) EQ                            LW_CONTRACT_NUM-CHANGE_DATE+0(6) AND                            LW_CONTRACT_NUM-CHANGE_DATE LE                            LW_ADV_BILL-CPUDT.

Page 32: Commented Code in Adjustment

                          CONTINUE.*                     ELSEIF LW_LEASE-DATE1 GT*                            LW_CONTRACT_NUM-EFFECT_DATE AND*                            LW_LEASE-DATE1 LT LW_ADV_BILL-CPUDT.**                           LV_NUM_DAYS = LW_LEASE-DATE1 -*                                         LW_CONTRACT_NUM-EFFECT_DATE .                     ELSEIF LW_LEASE-DATE1 GE                            LW_CONTRACT_NUM-EFFECT_DATE AND                            LW_LEASE-DATE1 GT LW_ADV_BILL-CPUDT AND                            LW_LEASE1-DATE1 LT LW_CONTRACT_NUM-EFFECT_DATE.

                          LV_NUM_DAYS = ( LW_LEASE-DATE1 -                                        LW_CONTRACT_NUM-EFFECT_DATE ) +                                        ( LV_DATE2 - LV_DATE3 ) + 2.

                     ELSEIF LW_LEASE-DATE1 GE                            LW_CONTRACT_NUM-EFFECT_DATE AND                            LW_LEASE-DATE1 GT LW_ADV_BILL-CPUDT AND                            LW_LEASE1-BSDAT GT LW_CONTRACT_NUM-EFFECT_DATE.

                          LV_NUM_DAYS = ( LW_LEASE-DATE1 -                                          LW_LEASE1-BSDAT ) +                                        ( LV_DATE2 - LV_DATE3 ) + 2.

                     ENDIF.                ENDIF.                ENDIF.

               ENDIF.            ELSE.   "advance bill done after revision

               IF LW_LEASE-STATUS = 0.

                    IF LW_LEASE-BSDAT+0(6) NE" Billing start date and change date                      LW_CONTRACT_NUM-CHANGE_DATE+0(6)." are in different month

                   IF LW_LEASE-BSDAT LT                      LW_CONTRACT_NUM-EFFECT_DATE.

                      LV_NUM_DAYS = LV_DATE1 -                                    LW_CONTRACT_NUM-EFFECT_DATE + 1.

                   ELSEIF LW_LEASE-BSDAT GE                          LW_CONTRACT_NUM-EFFECT_DATE AND                          LW_LEASE-BSDAT LT                          LV_DATE1.

                     LV_NUM_DAYS = LV_DATE1 - LW_LEASE-DATE1.

Page 33: Commented Code in Adjustment

                   ENDIF.                   else.                     IF LW_LEASE-BSDAT GT                        LW_CONTRACT_NUM-EFFECT_DATE AND                        LW_CONTRACT_NUM-CHANGE_DATE LT                        LW_ADV_BILL-CPUDT.                       CONTINUE.                     ENDIF.                   endif.               ELSEIF LW_LEASE-STATUS = 1.

                READ TABLE IT_LEASE INTO LW_LEASE1                WITH KEY RCIRN = LW_LEASE-DCREF.                IF SY-SUBRC = 0.                  IF LW_CONTRACT_NUM-CHANGE_DATE+0(6) NE                     LW_CONTRACT_NUM-EFFECT_DATE+0(6) .

                      IF LW_LEASE1-BSDAT  LT                         LW_CONTRACT_NUM-EFFECT_DATE AND                         LW_LEASE-DATE1 LT LW_CONTRACT_NUM-EFFECT_DATE.                          CONTINUE.                      ENDIF.                      IF LW_LEASE1-BSDAT LT                         LW_CONTRACT_NUM-EFFECT_DATE AND                         LW_LEASE-DATE1 GT LV_DATE1.

                         LV_NUM_DAYS = LV_DATE1 -                                       LW_CONTRACT_NUM-EFFECT_DATE + 1.                      ELSEIF LW_LEASE1-BSDAT  LT                             LW_CONTRACT_NUM-EFFECT_DATE AND                             LW_LEASE-DATE1 LE LV_DATE1.

                        LV_NUM_DAYS = LW_LEASE-DATE1 -                                      LW_CONTRACT_NUM-EFFECT_DATE + 1.

                      ELSEIF LW_LEASE1-BSDAT GE                             LW_CONTRACT_NUM-EFFECT_DATE AND                             LW_LEASE-DATE1 GT LV_DATE1.

                        LV_NUM_DAYS = LV_DATE1 -                                      LW_LEASE1-BSDAT + 1.

                      ELSEIF LW_LEASE1-BSDAT GE                             LW_CONTRACT_NUM-EFFECT_DATE AND                             LW_LEASE-DATE1 LT LV_DATE1.

                        LV_NUM_DAYS = LW_LEASE-DATE1 -                                      LW_LEASE1-BSDAT + 1.

                      ENDIF.                  ELSEIF LW_CONTRACT_NUM-CHANGE_DATE+0(6) EQ                         LW_CONTRACT_NUM-EFFECT_DATE+0(6) .

Page 34: Commented Code in Adjustment

                      IF LW_LEASE-DATE1 LT LW_CONTRACT_NUM-EFFECT_DATE                        AND                        LW_LEASE-DATE1 LT LW_ADV_BILL-CPUDT.

                        CONTINUE.

                     ELSEIF LW_LEASE-DATE1 GE                            LW_CONTRACT_NUM-EFFECT_DATE AND                            LW_LEASE-DATE1 LT LV_DATE1.

                           LV_NUM_DAYS = LW_LEASE-DATE1 -                                         LW_CONTRACT_NUM-EFFECT_DATE .                      ELSEIF LW_LEASE-DATE1 LT                             LW_CONTRACT_NUM-EFFECT_DATE AND                             LW_LEASE-DATE1 LT LV_DATE1.

                        LV_DATE_TEMP = LV_DATE1 - LV_DATE1+6(2) + 1.                        LV_NUM_DAYS = LW_LEASE-DATE1 - LV_DATE_TEMP + 1.

                      ENDIF.                  ENDIF.                ENDIF.             ENDIF.          ENDIF.