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
Pixel Header R1 C1 Pixel
Pixel Header R2 C1 Pixel
Pixel Header R3 C1 Pixel
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:


0001  SUBROUTINE CODE_LOOKUP(TYPE, PASSED, BRANCH, RETURNED)
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")
0006       LOCATE PASSED IN CODES USING @VM SETTING POS THEN
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")
0014       LOCATE PASSED IN CODES<5> USING @VM SETTING POS THEN
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")
0002    LOCATE PASSED IN CODES<5> USING @VM SETTING POS THEN
0003      RETURNED = PASSED
0004    END ELSE
0005      LOCATE PASSED IN CODES<6> USING @VM SETTING POS THEN
0006        RETURNED = CODES<5,POS>
0007      END ELSE
0008        STATUS() = 1 ; RETURNED = ""
0009      END
0010    END

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