An external function PRUEF receives a CHAR VAR string as parameter and shall check whether this string complies with the following rules:
- the length of the string may be max. 18 bytes
- the first character must be an asterisk (*) or a sign (+ or -)
- the rest may only consist of digits and a maximum of one dot
return value of the function is one BIT. If the above rules are followed, the function returns '1'B to the calling program, otherwise '0'B is returned.
Example of a possible call to PRUEF:
DCL ZK CHAR (15) VAR;
DCL PRUEF ENTRY RETURNS (BIT);
...
IF PRUEF (ZK) THEN CALL SUB2;
ELSE CALL ERROR;
Code the complete function!
/code
EXTSUB2: PROC(ZK, ) RETURNS(BIT) ;
DCL ZK CHAR(15) VAR;
DCL XYZ BIT;
IF MAXLENGTH(ZK) <= 18 THEN CALL VERB;
ELSE CALL FEHLER;
VERB: PROC;
IF (SUBSTR(ZK,1,1) = ‘+’) or (SUBSTR(ZK,1,1) = ‘-’) THEN CALL VERC;
ELSE CALL FEHLER;
END VERB;
VERC: PROC;
ZK1 = SUBSTR(ZK, 2, LENGTH(ZK)-1)
IF VERIFY(ZK1, ‘0123456789’) = 0 THEN CALL GUT;
ELSE CALL VERD;
END VERC;
VERD: PROC;
DCL CNT1 FIXED BIN(15);
DO
i = 1 by 1 TO LENGTH(ZK1);
IF SUBSTR(ZK1, I, 1) = ‘.’ THEN CNT1 = CNT1+1;
END;
IF CNT1 = 1 THEN CALL GUT;
ELSE CALL FEHLER;
END VERD;
GUT: PROC;
XYZ = ‘1’B;
END GUT;
CALL EXIT;
FEHLER: PROC;
XYZ = ‘0’B;
END FEHLER;
EXIT: PROC;
END EXIT;
END EXTSUB1;
DCL ZK CHAR(15) VAR;
DCL XYZ BIT;
IF MAXLENGTH(ZK) <= 18 THEN CALL VERB;
ELSE CALL FEHLER;
VERB: PROC;
IF (SUBSTR(ZK,1,1) = ‘+’) or (SUBSTR(ZK,1,1) = ‘-’) THEN CALL VERC;
ELSE CALL FEHLER;
END VERB;
VERC: PROC;
ZK1 = SUBSTR(ZK, 2, LENGTH(ZK)-1)
IF VERIFY(ZK1, ‘0123456789’) = 0 THEN CALL GUT;
ELSE CALL VERD;
END VERC;
VERD: PROC;
DCL CNT1 FIXED BIN(15);
DO
i = 1 by 1 TO LENGTH(ZK1);
IF SUBSTR(ZK1, I, 1) = ‘.’ THEN CNT1 = CNT1+1;
END;
IF CNT1 = 1 THEN CALL GUT;
ELSE CALL FEHLER;
END VERD;
GUT: PROC;
XYZ = ‘1’B;
END GUT;
CALL EXIT;
FEHLER: PROC;
XYZ = ‘0’B;
END FEHLER;
EXIT: PROC;
END EXIT;
END EXTSUB1;
code/