Ansicht
Dokumentation

OFTV_MOD_BADI_10 - BAdI: Changes to Objects After Trip Settlement

OFTV_MOD_BADI_10 - BAdI: Changes to Objects After Trip Settlement

SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up  
This documentation is copyright by SAP AG.
SAP E-Book

This Business Add-In enables you to change the data of a settled trip before the data is written to the database.

Internal table IT_ROT_NOT_COLLECTED contains the entries of the results table ROT in non-aggregated form. Table IT_ROT_NOT_COLLECTED therefore enables you to determine the origin of each row (for example, that a row contains the result of receipt 007).

This is particularly important when individual aspects of the ROT results table need to be corrected. In this case, the procedure would be as follows: First correct the relevant aspect in table IT_ROT_NOT_COLLECTED. Then delete results table ROT and rebuild it from table IT_ROT_NOT_COLLECTED. See the following examples for more information.

In Great Britain, the share of an entertainment receipt used by domestic employees and business partners is fully deductible as regards input tax, while for the remaining (foreign) guests this share is not deductible. When you post to accounting, therefore, you must split the entertainment receipts entered in travel expenses into two parts, each with different input tax codes. One part is based on the number of domestic employees and business partners, and the other part on the number of other (foreign) guests.

Suppose a domestic employee, a domestic business partner, and two other guests participated in a dinner costing GBP 117.50. Here you would need to split the receipt for posting to accounting into two parts: one for the domestic employee and the domestic business partner (117.50 * factor (1+ 1) / 4)), and one for the other two guests:

117.50 * ((1+ 1) / 4 ) = 58.75 with original input tax code V1

117.50 - 58.75 = 58.75 with input tax code V2 for non-deductible input tax

Note 607880 explains how you can enter the required numbers of participants separately as additional receipt information. To ensure that payroll and posting are performed correctly for the travel expenses, implement method CHANGE_TRV_OBJECTS as follows:

method if_ex_after_trip_settlement~change_trv_objects .

  types: begin of wtype_for_entertainment,

            lgart type t706b4-lgarl,

            n_stf type i,

            n_ptn type i,

            n_gst type i,

            number type ptk03-belnr,

            betrg type ptk03-betrg,

         end of wtype_for_entertainment.

  data: rot_line type ptk30-line,

        wa_rot type ptk30,

        wa_rot_not_collected type fitv2_rot_not_collected,

        wa_rot_not_collected_help type fitv2_rot_not_collected,

        it_rot_not_collected_help type fitv2_t_rot_not_collected,

        wa_exbel   type ptk33,

        wa_beleg   type ptk03,

,, spkzl_3    TYPE Char3 value 'FAK',

        total      type p,

        wa_t706d   type t706d,

        wa_rot_betrg type ptk03-betrg,

        it_wtype_for_entertainment type

                      table of wtype_for_entertainment,

        wa_wtype_for_entertainment type wtype_for_entertainment.

* identify receipts with numbers of staff, partners or guests

  loop at it_exbel into wa_exbel where not n_stf is initial or

                                       not n_ptn is initial or

                                       not n_gst is initial.

* store these numbers

    wa_wtype_for_entertainment-n_stf = wa_exbel-n_stf.

    wa_wtype_for_entertainment-n_ptn = wa_exbel-n_ptn.

    wa_wtype_for_entertainment-n_gst = wa_exbel-n_gst.

* store receipt amount ( and number from 4.7 on)

    read table it_beleg into wa_beleg with key belnr = wa_exbel-belnr.

    if sy-subrc is initial.

      check wa_beleg-betrg is not initial.

      wa_wtype_for_entertainment-number = wa_beleg-belnr.

      wa_wtype_for_entertainment-betrg = wa_beleg-betrg.

* store wage type of this receipt

      select single lgarl into wa_wtype_for_entertainment-lgart

                          from t706b4

                         where morei = is_ptrv_head-morei

                           and spkzl eq wa_beleg-spkzl

                           and endda >= wa_beleg-bldat

                           and begda <= wa_beleg-bldat.

      if sy-subrc is initial.

     collect wa_wtype_for_entertainment into it_wtype_for_entertainment.

      endif.

    endif.

  endloop.

* read zero VAT sign

  select single * into wa_t706d

                  from t706d

                  where morei = is_ptrv_head-morei.

  if sy-subrc ne 0.

    wa_t706d-mwaus = 'V0'.

  endif.

  loop at it_wtype_for_entertainment into wa_wtype_for_entertainment.

    loop at it_rot_not_collected into wa_rot_not_collected

                  where lgart  = wa_wtype_for_entertainment-lgart

                    and number = wa_wtype_for_entertainment-number.

check wa_rot_not_collected-spkzl(3) ne spkzl_3.

* only if number of other participants not zero

      if wa_wtype_for_entertainment-n_gst gt 0.

* and only if VAT is not zero

        if wa_rot_not_collected-mwskz ne wa_t706d-mwaus.

* calculate total participants for actual ROT line

          total = wa_wtype_for_entertainment-n_stf +

                  wa_wtype_for_entertainment-n_ptn +

                  wa_wtype_for_entertainment-n_gst.

* remove original ROT line

          delete it_rot_not_collected index sy-tabix.

* fill help structure for calculation

          move-corresponding wa_rot_not_collected to

                             wa_rot_not_collected_help.

* calculate amount for VAT participants

          wa_rot_not_collected_help-betrg =

            wa_rot_not_collected-betrg *

             ( wa_wtype_for_entertainment-n_stf +

               wa_wtype_for_entertainment-n_ptn ) / total.

          if wa_rot_not_collected_help-betrg gt 0.

* append new ROT line for VAT participants (with original VAT sign)

            append wa_rot_not_collected_help to

                   it_rot_not_collected_help.

          endif.

* calculate amount for non VAT participants (difference)

          wa_rot_not_collected_help-betrg =

             wa_rot_not_collected-betrg -

             wa_rot_not_collected_help-betrg.

* new VAT sign for non VAT participants (must be non-deductible)

          wa_rot_not_collected_help-mwskz = 'V2'.

* append new ROT line for non VAT participants (with changed VAT sign)

          append wa_rot_not_collected_help to it_rot_not_collected_help.

        endif.

      endif.

    endloop.

* append help structure with newly created ROT lines to ROT.

    append lines of it_rot_not_collected_help to it_rot_not_collected.

* clear help structure

    refresh it_rot_not_collected_help.

  endloop.

* collect table

  refresh it_rot.

  loop at it_rot_not_collected into wa_rot_not_collected.

    clear wa_rot.

    move-corresponding wa_rot_not_collected to wa_rot.

    collect wa_rot into it_rot.

  endloop.

* re-number lines of table ROT

  rot_line = 1.

  loop at it_rot into wa_rot.

    wa_rot-line = rot_line.

    modify it_rot from wa_rot.

    rot_line = rot_line + 1.

  endloop.

endmethod.

In the Implementation Guide for Travel Management, you can define travel flat rates that are billed to a particular customer. You can store such flat rates as "third" flat rates in each entry of view V_T706F. However, it is the user's responsibility to evaluate, process, and post these flat rates. For example, suppose that the user has defined the following per diem amounts in view V_T706F:

Tax-free amount:,,GBP 0.12

Amount subject to tax:,,GBP 0.12

Amount for customer:,,GBP 0.40

In this case the user should post another GBP 0.28 (0.28 = 0.40 - 0.12) to the assigned sales order in addition to the GBP 0.12 to be posted in the standard system.

You therefore need to add a line to the internal ROT table of the TE cluster by implementing method CHANGE_TRV_OBJECTS as follows:

method if_ex_after_trip_settlement~change_trv_objects.

  types: begin of wtype_for_mileage,

            lgart type t706b4-lgarl,

            number type ptk30-belnr,

            betfz type ptk21-betfz,

            betfa type ptk21-betfa,

            betku type ptk21-betku,

         end of wtype_for_mileage.

  data: rot_line type ptk30-line,

        wa_rot type ptk30,

        wa_rot_not_collected type fitv2_rot_not_collected,

        wa_rot_not_collected_help type fitv2_rot_not_collected,

        it_rot_not_collected_help type fitv2_t_rot_not_collected,

        wa_paufa type ptk21,

        wa_kostv type fitv2_typ_kostv,

        spkzl type ptk03-spkzl,

        it_wtype_for_mileage type table of wtype_for_mileage,

        wa_wtype_for_mileage type wtype_for_mileage.

* identify mileages with customer amount and store their wage types

* into table IT_WTYPE_FOR_MILEAGE

  loop at it_paufa into wa_paufa where not betku is initial.

* store all amounts

    wa_wtype_for_mileage-betfz = wa_paufa-betfz.

    wa_wtype_for_mileage-betfa = wa_paufa-betfa.

    wa_wtype_for_mileage-betku = wa_paufa-betku.

* store mileage number key

    wa_wtype_for_mileage-number = wa_paufa-kmkey.

* determine 'receipt' type of this mileage for finding wage types

    spkzl(3)   = 'FAK'.

    spkzl+3(1) = wa_paufa-kzpmf.

* store wage type of this mileage

    select single lgarl into wa_wtype_for_mileage-lgart

                        from t706b4

                       where morei = is_ptrv_head-morei

                         and spkzl eq spkzl

                         and endda >= wa_paufa-datum

                         and begda <= wa_paufa-datum.

    if sy-subrc is initial.

      collect wa_wtype_for_mileage into it_wtype_for_mileage.

    endif.

  endloop.

  loop at it_wtype_for_mileage into wa_wtype_for_mileage.

    loop at it_rot_not_collected into wa_rot_not_collected

                  where lgart  = wa_wtype_for_mileage-lgart

                    and spkzl  = spkzl

                    and number = wa_wtype_for_mileage-number.

* remove original line from table

      delete it_rot_not_collected index sy-tabix.

* append original line to help table (sorting reasons!)

      append wa_rot_not_collected to it_rot_not_collected_help.

* fill help structure for calculation

      move-corresponding wa_rot_not_collected to

      wa_rot_not_collected_help.

* calculate customer amount

      wa_rot_not_collected_help-betrg = wa_rot_not_collected-betrg *

       ( wa_wtype_for_mileage-betku - wa_wtype_for_mileage-betfa ) /

                          wa_wtype_for_mileage-betfa.

* new wagetype for customer amount (let's assume it is MJ32!)

      wa_rot_not_collected_help-lgart = 'MJ32'.

* append new line for customer amount to help table

      append wa_rot_not_collected_help to it_rot_not_collected_help.

    endloop.

* append help table with original and newly created lines to table

* (but only if amount is not zero)

    if wa_rot_not_collected_help-betrg is not initial.

      append lines of it_rot_not_collected_help to it_rot_not_collected.

    endif.

* clear help table

    refresh it_rot_not_collected_help.

  endloop.

* collect table

  refresh it_rot.

  loop at it_rot_not_collected into wa_rot_not_collected.

    clear wa_rot.

    move-corresponding wa_rot_not_collected to wa_rot.

    collect wa_rot into it_rot.

  endloop.

* re-number lines of table ROT

  rot_line = 1.

  loop at it_rot into wa_rot.

    wa_rot-line = rot_line.

    modify it_rot from wa_rot.

    rot_line = rot_line + 1.

  endloop.

endmethod.

If you want to implement both examples simultaneously, implement method CHANGE_TRV_OBJECTS as follows:

method if_ex_after_trip_settlement~change_trv_objects.

  TYPES: BEGIN OF wtype_for_entertainment,

            lgart TYPE t706b4-lgarl,

            n_stf TYPE i,

            n_ptn TYPE i,

            n_gst TYPE i,

            number TYPE ptk03-belnr,

            betrg TYPE ptk03-betrg,

         END OF wtype_for_entertainment.

   TYPES: BEGIN OF wtype_for_mileage,

             lgart TYPE t706b4-lgarl,

             number TYPE ptk30-belnr,

             betfz TYPE ptk21-betfz,

             betfa TYPE ptk21-betfa,

             betku TYPE ptk21-betku,

          END OF wtype_for_mileage.

  DATA: rot_line TYPE ptk30-line,

        wa_rot TYPE ptk30,

        wa_rot_not_collected TYPE fitv2_rot_not_collected,

        wa_rot_not_collected_help TYPE fitv2_rot_not_collected,

        it_rot_not_collected_help TYPE fitv2_t_rot_not_collected.

  Data: wa_exbel   TYPE ptk33,

        wa_beleg   TYPE ptk03,

        total      TYPE p,

        wa_t706d   TYPE t706d,

        wa_rot_betrg TYPE ptk03-betrg,

        it_wtype_for_entertainment TYPE

                      TABLE OF wtype_for_entertainment,

        wa_wtype_for_entertainment TYPE wtype_for_entertainment.

  Data: wa_paufa TYPE ptk21,

        wa_kostv TYPE fitv2_typ_kostv,

        spkzl    TYPE ptk03-spkzl,

        spkzl_3  TYPE Char3 value 'FAK',

        it_wtype_for_mileage TYPE TABLE OF wtype_for_mileage,

        wa_wtype_for_mileage TYPE wtype_for_mileage.

* Business Mileage adjustment....

* identify mileages with customer amount and store their wage types

* into table IT_WTYPE_FOR_MILEAGE

  LOOP AT it_paufa INTO wa_paufa WHERE NOT betku IS INITIAL.

* store all amounts

    wa_wtype_for_mileage-betfz = wa_paufa-betfz.

    wa_wtype_for_mileage-betfa = wa_paufa-betfa.

    wa_wtype_for_mileage-betku = wa_paufa-betku.

* store mileage number key

    wa_wtype_for_mileage-number = wa_paufa-kmkey.

* determine 'receipt' type of this mileage for finding wage types

    spkzl(3)   = 'FAK'.

    spkzl+3(1) = wa_paufa-kzpmf.

* store wage type of this mileage

    SELECT SINGLE lgarl INTO wa_wtype_for_mileage-lgart

                        FROM t706b4

                       WHERE morei = is_ptrv_head-morei

                         AND spkzl EQ spkzl

                         AND endda >= wa_paufa-datum

                         AND begda <= wa_paufa-datum.

    IF sy-subrc IS INITIAL.

      COLLECT wa_wtype_for_mileage INTO it_wtype_for_mileage.

    ENDIF.

  ENDLOOP.

  LOOP AT it_wtype_for_mileage INTO wa_wtype_for_mileage.

    LOOP AT it_rot_not_collected INTO wa_rot_not_collected

                  WHERE lgart  = wa_wtype_for_mileage-lgart

                    and spkzl  = spkzl

                    AND number = wa_wtype_for_mileage-number.

* remove original line from table

      DELETE it_rot_not_collected INDEX sy-tabix.

* append original line to help table (sorting reasons!)

      APPEND wa_rot_not_collected TO it_rot_not_collected_help.

* fill help structure for calculation

      MOVE-CORRESPONDING wa_rot_not_collected TO

      wa_rot_not_collected_help.

* calculate customer amount

      wa_rot_not_collected_help-betrg = wa_rot_not_collected-betrg *

       ( wa_wtype_for_mileage-betku - wa_wtype_for_mileage-betfa ) /

                          wa_wtype_for_mileage-betfa.

* new wagetype for customer amount (let's assume it is MJ32!)

      wa_rot_not_collected_help-lgart = 'MJ32'.

* append new line for customer amount to help table

* (but only if amount is not zero)

      if wa_rot_not_collected_help-betrg is not initial.

        APPEND wa_rot_not_collected_help TO it_rot_not_collected_help.

      endif.

    ENDLOOP.

* append help table with original and newly created lines to table

    APPEND LINES OF it_rot_not_collected_help TO it_rot_not_collected.

* clear help table

    REFRESH it_rot_not_collected_help.

  ENDLOOP.

* Split entertainment expense types according to attendees....

* identify receipts with numbers of staff, partners or guests

  LOOP AT it_exbel INTO wa_exbel WHERE NOT n_stf IS INITIAL or

                                       NOT n_ptn IS INITIAL OR

                                       NOT n_gst IS INITIAL.

* store these numbers

    wa_wtype_for_entertainment-n_stf = wa_exbel-n_stf.

    wa_wtype_for_entertainment-n_ptn = wa_exbel-n_ptn.

    wa_wtype_for_entertainment-n_gst = wa_exbel-n_gst.

* store receipt amount ( and number from 4.7 on)

    READ TABLE it_beleg INTO wa_beleg WITH KEY belnr = wa_exbel-belnr.

    IF sy-subrc IS INITIAL.

      CHECK wa_beleg-betrg IS NOT INITIAL.

      wa_wtype_for_entertainment-number = wa_beleg-belnr.

      wa_wtype_for_entertainment-betrg = wa_beleg-betrg.

* store wage type of this receipt

      SELECT SINGLE lgarl INTO wa_wtype_for_entertainment-lgart

                          FROM t706b4

                         WHERE morei = is_ptrv_head-morei

                           AND spkzl EQ wa_beleg-spkzl

                           AND endda >= wa_beleg-bldat

                           AND begda <= wa_beleg-bldat.

      IF sy-subrc IS INITIAL.

     COLLECT wa_wtype_for_entertainment INTO it_wtype_for_entertainment.

      ENDIF.

    ENDIF.

  ENDLOOP.

* read zero VAT sign

  SELECT SINGLE * INTO wa_t706d

                  FROM t706d

                  WHERE morei = is_ptrv_head-morei.

  IF sy-subrc NE 0.

    wa_t706d-mwaus = 'V0'.

  ENDIF.

  LOOP AT it_wtype_for_entertainment INTO wa_wtype_for_entertainment.

    LOOP AT it_rot_not_collected INTO wa_rot_not_collected

                  WHERE lgart  =  wa_wtype_for_entertainment-lgart

                    AND number =  wa_wtype_for_entertainment-number.

      check wa_rot_not_collected-spkzl(3) ne spkzl_3.

* only if number of other participants not zero

      IF wa_wtype_for_entertainment-n_gst GT 0.

* and only if VAT is not zero

        IF wa_rot_not_collected-mwskz NE wa_t706d-mwaus.

* calculate total participants for actual ROT line

          total = wa_wtype_for_entertainment-n_stf +

                  wa_wtype_for_entertainment-n_ptn +

                  wa_wtype_for_entertainment-n_gst.

* remove original ROT line

          DELETE it_rot_not_collected INDEX sy-tabix.

* fill help structure for calculation

          MOVE-CORRESPONDING wa_rot_not_collected TO

                             wa_rot_not_collected_help.

* calculate amount for VAT participants

          wa_rot_not_collected_help-betrg =

            wa_rot_not_collected-betrg *

             ( wa_wtype_for_entertainment-n_stf +

               wa_wtype_for_entertainment-n_ptn ) / total.

          IF wa_rot_not_collected_help-betrg GT 0.

* append new ROT line for VAT participants (with original VAT sign)

            APPEND wa_rot_not_collected_help TO

                   it_rot_not_collected_help.

          ENDIF.

* calculate amount for non VAT participants (difference)

          wa_rot_not_collected_help-betrg =

             wa_rot_not_collected-betrg -

             wa_rot_not_collected_help-betrg.

* new VAT sign for non VAT participants (must be non-deductible), let's say 'V2'

          wa_rot_not_collected_help-mwskz = 'V2'.

* append new ROT line for non VAT participants (with changed VAT sign)

          APPEND wa_rot_not_collected_help TO it_rot_not_collected_help.

        ENDIF.

      ENDIF.

    ENDLOOP.

* append help structure with newly created ROT lines to ROT.

    APPEND LINES OF it_rot_not_collected_help TO it_rot_not_collected.

* clear help structure

    REFRESH it_rot_not_collected_help.

  ENDLOOP.

* rebuild table ROT...

* collect table

  REFRESH it_rot.

  LOOP AT it_rot_not_collected INTO wa_rot_not_collected.

    CLEAR wa_rot.

    MOVE-CORRESPONDING wa_rot_not_collected TO wa_rot.

    COLLECT wa_rot INTO it_rot.

  ENDLOOP.

* re-number lines of table ROT

  rot_line = 1.

  LOOP AT it_rot INTO wa_rot.

    wa_rot-line = rot_line.

    MODIFY it_rot FROM wa_rot.

    rot_line = rot_line + 1.

  ENDLOOP.

endmethod.






TXBHW - Original Tax Base Amount in Local Currency   General Material Data  
This documentation is copyright by SAP AG.

Length: 41284 Date: 20240523 Time: 190452     sap01-206 ( 242 ms )