In order for this site to work correctly, and for us to improve the site, we need to store a small file (called a cookie) on your computer.
By continuing to use this website, you agree to our cookies and privacy policy.
Home page Home page Home page Home page
Pixel Header R1 C1 Pixel
Pixel Header R2 C1 Pixel
Pixel Header R3 C1 Pixel

User Defined Conversions

One of the most common forms of user defined conversion is that which takes a code and using it extracts a description from a code table for display.

For example:

0002    BEGIN CASE
0003      CASE TYPE = "ICONV"
0004       *   Assuming codes are MVs in field 5 and descs in 6
0005       CODES = XLATE("CODES", BRANCH[-1,"B*"],5,"X")
0007         STATUS() = 0
0008       END ELSE
0009         STATUS() = 1 ; PASSED = ""
0010       END
0011       RETURNED = PASSED
0012      CASE TYPE = "OCONV"
0013       CODES = XLATE("CODES", BRANCH[-1,"B*"],"","X")
0015         RETURNED = CODES<6,POS>
0016       END ELSE
0017         RETURNED = PASSED
0018       END
0019    END CASE
0020  RETURN

Note that in this example the DATA logic is kept separate from the APPLICATION logic (the ICONV itself does not suggest replacements, it flags that an error has occurred and lets the application logic suggest alternatives. This leads to more portable code (see future articles on system design)).

However when the user presses Ctrl-F10 and then F2 the uncoded version shows up. If the user then chooses the uncoded version, the OCONV logic is invoked and it redisplays as the coded version. If the user then selects this version and F9s it, the system attempts to re-ICONV the OCONVed value - even though the internal form is available - fails to ICONV it and thus finds no hits. To fix this problem amend the code as follows :-

0001    CODES = XLATE("CODES", BRANCH[-1,"B*"], "", "X")
0004    END ELSE
0006        RETURNED = CODES<5,POS>
0007      END ELSE
0008        STATUS() = 1 ; RETURNED = ""
0009      END
0010    END

(Volume 3, Issue 1, Page 7)
Pixel Footer R1 C1 Pixel