How to replace invalid, malformed postal codes with valid dummy values
Many legacy systems have little or no validation on the postal code and SAP has very strict, country-specific validation that cannot be circumvented. Validating the postal codes in LSMW as part of the Convert Data phase is always a good idea and is a great way to identify defects in the data and provide feedback to the client. Early in the implementation it is better to transport the master data with dummy postal codes to allow the processing of downstream transactional data.
This snippet of code checks the validity of postal codes passed in and then replaces the failed postal codes with easily-identifiable dummy values. This allows the master data to be transported without causing an error during the processing. This is simply a work-around for master data so that downstream cut-over testing can proceed. The code has been tested in ECC6, but will most likely work for older and newer versions. To more easily identify malformed postal codes for defect reporting use this snippet instead.
form fix_pstlz using lland1 changing lpstlz. tables: t005. CALL FUNCTION 'POSTAL_CODE_CHECK' EXPORTING country = lland1 one_time_account = space postal_code = lpstlz EXCEPTIONS not_valid = 4 error_message = 5. if sy-subrc ne 0. select single * from t005 where land1 eq lland1. if t005-xplzs ne 'X'. "Not required. lpstlz = ''. else. if t005-prplz ca '1235679'. "country specific. case t005-landk. when 'CDN'. lpstlz = 'Z9Z 9Z9'. "Canada when 'CZ ' or 'S ' or 'SK '. lpstlz = '999 99'. "CZ,SE,SK when 'ROK'. lpstlz = '999-999'. "South Korea when 'PL '. lpstlz = '99-999'. "Poland when 'RCH'. lpstlz = '999-9999'. "Chile when 'USA'. lpstlz = '99999-9999'. "USA when 'AUS'. lpstlz = '9999'. "Australia. when 'BRA'. lpstlz = '99999-999'. "Brazil when 'J '. lpstlz = '999-9999'. "Japan when 'NL '. lpstlz = '9999 ZZ'. "Holland when 'RC '. lpstlz = '99999'. "Taiwan when 'GB '. lpstlz = 'Z99 9ZZ'. "Great Brittian when 'P '. lpstlz = '9999'. "Portugal endcase. else. lpstlz = ''. do t005-lnplz times. concatenate lpsltz '9' into lpstlz. enddo. endif. endif. endif. endform.