PL1 FUNCTION - PLEASE VERIFY CODE



IBM's cross-platform compiler PL/I for MVS, VM & VSE, OS/390 and Enterprise PL/I for z/OS

PL1 FUNCTION - PLEASE VERIFY CODE

Postby grasshopper » Mon Jul 26, 2021 2:20 am

. Function with parameter transfer
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;
 

code/
grasshopper
 
Posts: 8
Joined: Sat Jul 24, 2021 10:04 pm
Has thanked: 0 time
Been thanked: 0 time

Re: PL1 FUNCTION - PLEASE VERIFY CODE

Postby sergeyken » Mon Jul 26, 2021 5:51 am

Please, use code tags when presenting any code or data to others.
Of course, you can ignore this advice if you want others to ignore your questions.
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 438
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 7 times
Been thanked: 40 times

Re: PL1 FUNCTION - PLEASE VERIFY CODE

Postby Robert Sample » Mon Jul 26, 2021 6:08 am

The presented code is one of the most ridiculous programs I've seen in more than 40 years of programming, teaching, and reviewing code. There is no reason to break up what you're doing into so many subprograms -- it just complicates figuring out what the code does.

This is a HELP forum -- we're not here to verify your code, or code your program for you, With that being said, I did briefly scan the code (since you did not use the CODE button, it is much more difficult to read -- I did this for you). Some comments:
- your program statement says the variable can be up to 18 characters, yet you define it as 15 characters.
- you check the first byte to be a + or - but where do you check if it is *?
- you accumulate into CNT1 yet where did you initialize it to zero?
- why did you check the first byte to be a . since your problem statement indicates the first byte is * or + or -?
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: PL1 FUNCTION - PLEASE VERIFY CODE

Postby sergeyken » Mon Jul 26, 2021 6:34 am

Only using the code tags does not help if the code itself is not aligned properly.

I personally ignore the code presented in this manner. From my point of view, such way of asking questions demonstrates only disrespect of TS to his potential assistants.
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 438
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 7 times
Been thanked: 40 times

Re: PL1 FUNCTION - PLEASE VERIFY CODE

Postby grasshopper » Mon Jul 26, 2021 9:17 am

THANK YOU VERY MUCH.
I have been using code/ as tags. So i need to use the code tag from the screen. This is realise now. Thanks. will do that next time.
grasshopper
 
Posts: 8
Joined: Sat Jul 24, 2021 10:04 pm
Has thanked: 0 time
Been thanked: 0 time


Return to PL/I

 


  • Related topics
    Replies
    Views
    Last post