Page 1 of 1

PL1 subroutine help

PostPosted: Sat Jul 24, 2021 10:24 pm
by grasshopper
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.

Re: PL1 subroutine help

PostPosted: Sat Jul 24, 2021 11:13 pm
by prino
Q: What have you tried yourself?

A: Nothing, I'm waiting for someone to do my work for me!

Re: PL1 subroutine help

PostPosted: Sat Jul 24, 2021 11:22 pm
by grasshopper
am a python guy, hv no mf editor to try. learning slowly and then to understand using python. takes more time

Re: PL1 subroutine help

PostPosted: Sun Jul 25, 2021 3:02 am
by sergeyken
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.

Re: PL1 subroutine help

PostPosted: Sun Jul 25, 2021 10:10 pm
by grasshopper
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/

Re: PL1 subroutine help

PostPosted: Sun Jul 25, 2021 11:01 pm
by sergeyken
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……..

Re: PL1 subroutine help

PostPosted: Sun Jul 25, 2021 11:12 pm
by sergeyken
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!!!

Re: PL1 subroutine help

PostPosted: Sun Jul 25, 2021 11:49 pm
by grasshopper
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

Re: PL1 subroutine help

PostPosted: Mon Jul 26, 2021 5:57 am
by sergeyken
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!

Re: PL1 subroutine help

PostPosted: Mon Jul 26, 2021 6:16 am
by sergeyken
. . . . .
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 */
 . . . . .