Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== User Defined Conversions===== ^Published By^Date^Version^Knowledge Level^Keywords^ |Sprezzatura Ltd|01 MAY 1991|2.03+|EXPERT|CONVERSION, OCONV, ICONV| 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 <code> SUBROUTINE CODE_LOOKUP(TYPE, PASSED, BRANCH, RETURNED) BEGIN CASE CASE TYPE = "ICONV" * Assuming codes are MVs in field 5 and descs in 6 CODES = XLATE("CODES", BRANCH[-1,"B*"],5,"X") LOCATE PASSED IN CODES USING @VM SETTING POS THEN STATUS() = 0 END ELSE STATUS() = 1 ; PASSED = "" END RETURNED = PASSED CASE TYPE = "OCONV" CODES = XLATE("CODES", BRANCH[-1,"B*"],"","X") LOCATE PASSED IN CODES<5> USING @VM SETTING POS THEN RETURNED = CODES<6,POS> END ELSE RETURNED = PASSED END END CASE RETURN </code> 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 :- <code> CODES = XLATE("CODES", BRANCH[-1,"B*"], "", "X") LOCATE PASSED IN CODES<5> USING @VM SETTING POS THEN RETURNED = PASSED END ELSE LOCATE PASSED IN CODES<6> USING @VM SETTING POS THEN RETURNED = CODES<5,POS> END ELSE STATUS() = 1 ; RETURNED = "" END END </code> (Volume 3, Issue 1, Page 7) tips/revmedia/v3i1a2.txt Last modified: 2024/06/19 20:20by 127.0.0.1