PL1 subroutine help



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

PL1 subroutine help

Postby grasshopper » Sat Jul 24, 2021 10:24 pm

please help me write this subroutine and sub-module:

1. An subprogram receives 5 parameters
- CHAR VAR String with max. 200 bytes length
- Table with unknown number of elements Index lower limit 1, elements CHAR (01)
- BIN FIXED (15) (for current table size)
- Table with unknown number of elements Index lower limit 1, elements PIC '9'.
- BIN FIXED (15) (for current table size)

Task of the subroutine:
- transfer all digits of the 1st parameter to table2 (4th parameter)
- ignore all blanks
- transfer remaining characters to table1 (2nd parameter)
- in parameters 3 and 5 the current number of table elements is to be stored in each case
how to Code the subprogram, am ok with cobol but pl1 confuses me and i have no time to sit and debug

2. 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!

3. Pointer arithmetic

DCL EVENT-NAME CHAR(50) VAR INIT('TOKYO-OLYMPICS-TOKYO');
DCL PTR POINTER;
DCL CHAR1 CHAR(1) BASED(PTR);

In a loop using pointer arithmetic, output each character of the variable EVENT NAME one at a time and count the number of 'O' characters.
grasshopper
 
Posts: 8
Joined: Sat Jul 24, 2021 10:04 pm
Has thanked: 0 time
Been thanked: 0 time

Re: PL1 subroutine help

Postby prino » Sat Jul 24, 2021 11:13 pm

Q: What have you tried yourself?

A: Nothing, I'm waiting for someone to do my work for me!
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 641
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 29 times

Re: PL1 subroutine help

Postby grasshopper » Sat Jul 24, 2021 11:22 pm

am a python guy, hv no mf editor to try. learning slowly and then to understand using python. takes more time
grasshopper
 
Posts: 8
Joined: Sat Jul 24, 2021 10:04 pm
Has thanked: 0 time
Been thanked: 0 time

Re: PL1 subroutine help

Postby sergeyken » Sun Jul 25, 2021 3:02 am

grasshopper wrote:am a python guy, hv no mf editor to try. learning slowly and then to understand using python. takes more time

It looks like your problem is not in transition from Python (or whatever else) to PL/I (or whatever else).
Your problem is in lack of logical thinking, and zero level of experience in algorithm design, as important parts of any IT education. If those two problems were not the case, the transition from ANY language to ANY OTHER one would be a piece of cake.
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 436
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 7 times
Been thanked: 40 times

Re: PL1 subroutine help

Postby grasshopper » Sun Jul 25, 2021 10:10 pm

for question #3.
3. Pointer arithmetic

DCL EVENT-NAME CHAR(50) VAR INIT('TOKYO-OLYMPICS-TOKYO');
DCL PTR POINTER;
DCL CHAR1 CHAR(1) BASED(PTR);

here is my code, but i cnnot execute, can someone verify this please????

/code/
DCL CHAR2 CHAR(1);
DCL CNT1 FIXED BIN(15);
PTR = addr(EVENT-NAME);
DO
PTR = PTR BY 1 TO LENGTH(EVENT-NAME)
IF CHAR1 = ‘A’ THEN CNT1 = CNT1 + 1;
PUT SKIP DATA(CHAR1, CNT1);
END;
/code/
grasshopper
 
Posts: 8
Joined: Sat Jul 24, 2021 10:04 pm
Has thanked: 0 time
Been thanked: 0 time

Re: PL1 subroutine help

Postby sergeyken » Sun Jul 25, 2021 11:01 pm

1) variable names CANNOT include minus sign (unlike COBOL)
2) Variables PTR and EVENT_NAME must be declared before usage
3) Pointer variables are physical addresses, they cannot be used as array indexes, or integer variables, or whatever else except the base address of a based variable
4) etc, etc, etc……..
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 436
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 7 times
Been thanked: 40 times

Re: PL1 subroutine help

Postby sergeyken » Sun Jul 25, 2021 11:12 pm

Hint:
To work with characters of a text string there is no need of based variables. Use string manipulation functions, like SUBSTR, and others.

RTFM, RTFM, and RTFM!!!
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 436
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 7 times
Been thanked: 40 times

Re: PL1 subroutine help

Postby grasshopper » Sun Jul 25, 2021 11:49 pm

my case study is to use pointers only for this.
will this work?

/code
DCL NAME CHAR(50) VAR INIT('TOKYO-OLYMPICS-TOKYO');
DCL PTR POINTER;
DCL CHAR1 CHAR(1) BASED(PTR);
DCL CNT1 FIXED BIN(15);
PTR = addr(NAME);
DO
I = 1 BY 1 TO LENGTH(NAME) ;
PTR = PTR+1;
IF CHAR1 = ‘O’ THEN CNT1 = CNT1 + 1;
PUT SKIP DATA(CHAR1, CNT1);
END;
/code
grasshopper
 
Posts: 8
Joined: Sat Jul 24, 2021 10:04 pm
Has thanked: 0 time
Been thanked: 0 time

Re: PL1 subroutine help

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

grasshopper wrote:my case study is to use pointers only for this.
will this work?

/code
DCL NAME CHAR(50) VAR INIT('TOKYO-OLYMPICS-TOKYO');
DCL PTR POINTER;
DCL CHAR1 CHAR(1) BASED(PTR);
DCL CNT1 FIXED BIN(15);
PTR = addr(NAME);
DO
I = 1 BY 1 TO LENGTH(NAME) ;
PTR = PTR+1;
IF CHAR1 = ‘O’ THEN CNT1 = CNT1 + 1;
PUT SKIP DATA(CHAR1, CNT1);
END;
/code

This cannot work at all!
Please, read carefully my notes to your previous posts, regarding the difference between pointers, and indexes!
Please, use code tags when presenting your code!
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 436
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 7 times
Been thanked: 40 times

Re: PL1 subroutine help

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

. . . . .
DCL NAME CHAR(50) VAR INIT('TOKYO-OLYMPICS-TOKYO');
DCL CHAR1 CHAR(1);
DCL CNT1 FIXED BIN(15);
DCL XCHAR BIN FIXED(15);

CNT1 = 0;    /* do not forget to initialize the counter before counting!!! */
DO XCHAR = 1 TO LENGTH(NAME) ;   /* scan index along the string NAME */
   CHAR1 = SUBSTR(NAME, XCHAR, 1);  /* extract single character, for clarity */
   IF CHAR1 = ‘O’ THEN DO;     /* check for super-character ‘O’ */
      CNT1 = CNT1 + 1;         /* count one more ‘O’ when found */
      PUT SKIP DATA(CHAR1, CNT1); /* debug print */
   END;
END;
   . . . . /* output of required results */
 . . . . .
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 436
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 7 times
Been thanked: 40 times


Return to PL/I

 


  • Related topics
    Replies
    Views
    Last post