
Here’s the program code to solve the problem in PReS
The country written out as the last line of a foreign address in capital letters is now mandatory. But the customer delivers only country code according to ISO 3166 standard (codes for the representation of names of countries) in its data. It is important to allocate the complete country written out to these abbreviated forms of the countries.
Delivered:
AF $ AFG$ 004 %Afghanistan
AX $ ALA$ 248 %Åland Islands
AL $ ALB$ 008 %Albania
DZ $ DZA$ 012 %Algeria
AS $ ASM$ 016 %American Samoa
AD $ AND$ 020 %Andorra
AO $ AGO$ 024 %Angola
AI $ AIA$ 660 %Anguilla
AQ $ ATA$ 010 %Antarctica
AG $ ATG$ 028 %Antigua and Barbuda
AR $ ARG$ 032 %Argentina
AM $ ARM$ 051 %Armenia
AW $ ABW$ 533 %Aruba
AU $ AUS$ 036 %Australia
AT $ AUT$ 040 %Austria
AZ $ AZE$ 031 %Azerbaijan
BS $ BHS$ 044 %Bahamas (the)
BH $ BHR$ 048 %Bahrain
BD $ BGD$ 050 %Bangladesh
BB $ BRB$ 052 %Barbados
BY $ BLR$ 112 %Belarus
BE $ BEL$ 056 %Belgium
BZ $ BLZ$ 084 %Belize
BJ $ BEN$ 204 %Benin
BM $ BMU$ 060 %Bermuda
BT $ BTN$ 064 %Bhutan
BO $ BOL$ 068 %Bolivia (Plurinational State of)
…
CA $ CAN$ 404 %CANADA
…
Needed:
First we convert the field with the country code (D_LAND) left-aligned and capitalized into our work variable LKZ. Then we replace any hyphens with a space and put a “$” at position 4:
CONVERT LKZ, D_LAND, ‘LU’
REPLACE LKZ, “-“, “\x20” ! LKZ[3] L1= “$”
Then we go to the subroutine to lookup the country code:
GOSUB CatAuswerten(LKZ, FilRec)
…
START
TempSub=””
ProjOK=1
fMODUL=””
LOCATE fMODUL0, CATSub, Pointer
IF (Pointer>-1) fMODUL=fModul0
…
TempSub=fMODUL[Pointer] L85
RETURN
TempSub now contains the relevant line with the ISO countries and the country written out after the “%” character.
….
Now we need two more positions in the string: Where is the percent sign after which the written country begins and where is the end of the line (\x0A):
LOCATE FilRec, “%”, Pointer
LOCATE Filrec, “\x0A”, ePOS
…
We calculate the length and convert the country to the “BRIEFLAND” variable uppercase:
Length=ePOS-Pointer-2
IF (Length GT 0) {
CONVERT BRIEFLAND, FilRec[Pointer+1] L=Length, ‘U’
}
voilà