Determine Tax Jurisdictions for Customers During Conversion Step

Jimbo's picture

Pre-validating source data during the conversion step in LSMW is a great way to provide meaningful reports to the resources who are extracting and transforming data from legacy systems. Finding errors in the source data and correcting them before attempting to load ensures a smoother ETL process.

In some countries like the US the customers get a Tax Jurisdiction and SAP determines the tax jurisdiction by the customer's country code, region (state), city and postal code. If the configuration makes the tax jurisdiction mandatory for customers then customers whose tax jurisdiction cannot be determined cannot be loaded. Subsequently, sales orders and accounts receivables cannot be loaded and the project has major issues.

With a little effort and some ingenuity the customers with incorrect addresses can be identified and corrected. Most issues with tax jurisdiction determination are caused by typographical errors in the postal code. Sometimes the country code is incorrect and replacing the incorrect country code with the correct one enables SAP to determine the tax jurisdiction.

Once the poorly formed addresses are identified in the conversion report, the next step is to contact the customer and ask for the correct mailing or billing address. An easy way to find this information without having to contact the customer is to look on the customer's website or search on google.com for the customer's correct address. If the street address and state are known-good then the correct postal code may be determined by using the Find Postal Code feature at USPS.gov.

The tax jurisdiction field is TXJCD in the standard transaction (XD01) or TAXJURCODE in a normal recording. Calling SAP's function saves us a lot of time. In the field mapping for the tax jurisdiction field add this snippet of code. Be sure to replace the name of the source structure and the field names with your source structure and field names.

perform FindTaxJurisdiction using ZXD011-COUNTRY ZXD011-REGION
 ZXD011-CITY1 ZXD011-POST_CODE1
 changing ZXD011-TAXJURCODE.
if sy-subrc ne 0.
  WRITE: / ZZXD011-KUNNR COLOR COL_NEGATIVE,
   'Tax jurisdiction cannot be determined.  Bad address data.'.
  skip_transaction.
endif.

Redundant customer tax jurisdictions in SAPIn the User-defined Routines section or in FORM_ROUTINES section add this snippet of code. It has a work-around added that still determines the tax jurisdiction when redundant tax jurisdictions cause the function to throw a Non-unique error. Vertex, when used as an interface for tax jurisdiction determination, can cause this error; realistically it's a non-issue because the redundant tax jurisdictions are the same, but pre-determining the tax jurisdiction prevents loaders from having to decide between "Tax Jurisdiction A" and "Tax Jurisdiction A" during the load.

 
form FindTaxJurisdiction using lvLAND1 lvREGIO lvORT01 lvPSTLZ
 changing lvJurisdiction.
  data: begin of jurtab occurs 0.
          include structure com_jur.
  data: end of jurtab.
  data: lvCOM_JUR like COM_JUR, lvCOM_JURO like COM_JUR.
  data: error_msg like com_err,
        tax_msg like tax_message,
        ext_tax_id like ttxd-xextn,
        procedure like ttxd-kalsm.
  data: lTTXD like TTXD, lv_LAND1 like T005-LAND1.
  data: com_err type com_err,
        com_err_doc type com_err_doc,
        rfc_error_code type tax_rfc_error_code.

  lvCOM_JUR-COUNTRY = lvLAND1.
  lvCOM_JUR-STATE = lvREGIO.
*  lvCOM_JUR-CITY = lvORT01.
  lvCOM_JUR-ZIPCODE = lvPSTLZ.

  call function 'JURISDICTION_DETERMINE'
    EXPORTING
      address_in    = lvCOM_JUR
      no_dialog_flag = 'X'
    IMPORTING
      address_out      = lvCOM_JURO
    EXCEPTIONS
       TAXJURCODE_NOT_FOUND = 1
       Others = 99.
  if sy-subrc eq 0.
    lvJurisdiction = lvCOM_JURO-TXJCD.
  elseif sy-subrc eq 99. "Can still find if problem is duplicates
    select single LAND1 from T005 into lv_LAND1 where LAND1 eq lvLAND1.
    if sy-subrc eq 0.
      call function 'DETERMINE_EXTERNAL_TAX_SYST_ID'
         exporting
              country                = lv_LAND1
         importing
              ext_tax_id             = ext_tax_id
              taxprocedure           = procedure
         exceptions
              input_incomplete       = 1
              no_tax_procedure       = 2
              no_taxjurcode_required = 3
              others                 = 4.
     if sy-subrc eq 0 and ext_tax_id ne ''.
        select single * from ttxd into lTTXD
         where kalsm = procedure.
        if sy-subrc eq 0.
          lvCOM_JUR-TXJCD_L1 = lTTXD-LENG1.
          lvCOM_JUR-TXJCD_L2 = lTTXD-LENG2.
          lvCOM_JUR-TXJCD_L3 = lTTXD-LENG3.
          lvCOM_JUR-TXJCD_L4 = lTTXD-LENG4.
        call function 'RFC_DETERMINE_JURISDICTION'
          destination           lTTXD-rfcdest
          exporting
            location_data         = lvCOM_JUR
          importing
            o_com_err             = com_err
          tables
            location_results    = jurtab
          exceptions
            communication_failure   = 01
            system_error            = 02.
          if sy-subrc eq 0.
            loop at jurtab into lvCOM_JUR.
              lvJurisdiction = lvCOM_JUR-TXJCD.
            endloop.
            "Loop through again with additional filter for accuracy.
            lvCOM_JUR-CITY = lvORT01. "Now we use the city.
            translate lvCOM_JUR-CITY to UPPER CASE.
            loop at jurtab into lvCOM_JUR 
             where CITY eq lvCOM_JUR-CITY.
              lvJurisdiction = lvCOM_JUR-TXJCD.
            endloop.
          endif.
        endif.
      endif.
    endif.
  endif.
endform.
Programming Language: 
ABAP