Question: Any bright suggestions for handling platform dependent codes?
For example:
----------------
I see some sources using hex values (e.g. for carriage return).
This is great but there are (at least 2) distinguish differently coding schemes, namely:
ASCII
EBCDIC
(and of course there is UNICODE...but it uses 2 bytes,
I have no experience with unicode. anybody????)
This means that any program using hex values is tight to a specific scheme (or worse still a esotoric dialect of a scheme!).
I wonder if it was possible to make each source independent of the coding scheme environment.
On the top of my hat I came up with something like this:
NOTE:
Don't be surprised by the structure of the next source
program. I am used to method programming. Normally I would even use ENTRYs (non standard!) so I can use different linkage values in the same source program.
The called (sub)program looks more or less like this:
Notice that with the coding above that within the program it is not possible to accidently override the return value with some other value. This is because these values are private data protected by the contained programs.
Notice that the carriage return for ASCII is the same as for EBCDIC (and this is true!). And this carriage return value is coded and guarded in only one place (EcarriageReturn).
I am just fishing for similar codes and solutions...anybody?
For example:
----------------
I see some sources using hex values (e.g. for carriage return).
This is great but there are (at least 2) distinguish differently coding schemes, namely:
ASCII
EBCDIC
(and of course there is UNICODE...but it uses 2 bytes,
I have no experience with unicode. anybody????)
This means that any program using hex values is tight to a specific scheme (or worse still a esotoric dialect of a scheme!).
I wonder if it was possible to make each source independent of the coding scheme environment.
On the top of my hat I came up with something like this:
Code:
01 workingStorageFields.
05 getCode PIC X(08) VALUE 'getCode'.
05 LineFeedChar PIC X(01).
05 returnFlag.
88 returnOK VALUE '0'.
88 returnNOTok VALUE '0'.
05 forMethod PIC X(20).
88 .......... VALUE '........'.
88 lineFeed VALUE 'lineFeed'.
88 .......... VALUE '........'.
SET lineFeed IN forMethod TO TRUE
CALL getCode USING
, by reference returnFlag
, by content forMethod
, by reference lineFeedChar
END-CALL
IF returnOK
, MOVE lineFeedChar TO ......
, .... and the rest of the code ...
,
NOTE:
Don't be surprised by the structure of the next source
program. I am used to method programming. Normally I would even use ENTRYs (non standard!) so I can use different linkage values in the same source program.
The called (sub)program looks more or less like this:
Code:
PROGRAM-ID. getCode.
01 privateData.
05 theLetter-a PIC X(01) VALUE 'a'.
05 invokeGetHEXcode.
10 theEnvironment PIC X(01).
88 EBCDIC VALUE 'E'.
88 ASCII VALUE 'A'.
88 ELBONIAN VALUE 'Z'.
10 invokeMethod PIC X(20).
LINKAGE-SECTION.
01 returnFlag PIC X(01).
88 returnOK VALUE '0'.
88 returnNOTok VALUE '1'.
01 theMethod PIC X(20).
01 returnHEXcode PIC X(01).
PROCEDURE DIVISION USING returnFlag
theMethod
returnHEXcode
.
EVALUATE TRUE
, WHEN theLetter-a = x'81'
, SET EBCDIC TO TRUE
, PERFORM getHEXcode
,
, WHEN theLetter-a = x'61'
, SET ASCII TO TRUE
, PERFORM getHEXcode
,
*// from elbonia! see: Dilbert cartoons.
, WHEN theLetter-a = x'**'
, SET ELBONIAN TO TRUE
, PERFORM getHEXcode
,
, WHEN OTHER
, SET returnNOTok TO TRUE
,
END-EVALUATE
GOBACK
.
getHEXcode.
SET returnOK TO TRUE
MOVE theMethod TO invokeMethod
CALL invokeGetHEXcode USING
, by reference returnHEXcode
ON EXCEPTION
, SET returnNOTok TO TRUE
END-CALL
.
IDENTIFICATION DIVISION.
PROGRAM-ID. AlineFeed.
DATA DIVISION.
LINKAGE SECTION.
01 returnField PIC X(01).
88 lineFeed VALUE x'0A'.
PROCEDURE DIVISION USING returnField.
SET lineFeed TO TRUE
GOBACK
.
END PROGRAM AlineFeed.
IDENTIFICATION DIVISION.
PROGRAM-ID. ElineFeed.
DATA DIVISION.
LINKAGE SECTION.
01 returnField PIC X(01).
88 lineFeed VALUE x'15'.
PROCEDURE DIVISION USING returnField.
SET lineFeed TO TRUE
GOBACK
.
END PROGRAM ElineFeed.
IDENTIFICATION DIVISION.
PROGRAM-ID. ZlineFeed.
DATA DIVISION.
LINKAGE SECTION.
01 returnField PIC X(01).
88 lineFeed VALUE x'**'.
^^ works in Elbonia!
PROCEDURE DIVISION USING returnField.
SET lineFeed TO TRUE
GOBACK
.
END PROGRAM ZlineFeed.
IDENTIFICATION DIVISION.
PROGRAM-ID. AcarriageReturn.
DATA DIVISION.
LINKAGE SECTION.
01 returnField PIC X(01).
PROCEDURE DIVISION USING returnField.
CALL 'EcarriageReturn' USING returnField
GOBACK
.
END PROGRAM AcarriageReturn.
IDENTIFICATION DIVISION.
PROGRAM-ID. EcarriageReturn.
DATA DIVISION.
LINKAGE SECTION.
01 returnField PIC X(01).
88 carriageReturn VALUE x'0D'.
PROCEDURE DIVISION USING returnField.
SET carriageReturn TO TRUE
GOBACK
.
END PROGRAM EcarriageReturn.
END PROGRAM getCode.
Notice that with the coding above that within the program it is not possible to accidently override the return value with some other value. This is because these values are private data protected by the contained programs.
Notice that the carriage return for ASCII is the same as for EBCDIC (and this is true!). And this carriage return value is coded and guarded in only one place (EcarriageReturn).
I am just fishing for similar codes and solutions...anybody?