1.) write a pl/i program to call a external subroutine named EXTSUB with two arguments, NAME of char type,and AGE of fixed bin type ...
with two arguments, NAME of char type,and AGE of fixed bin type
and change the value of age in external subroutine and return the
AGE alone to the main subroutine named MAINSUB.
EXTSUB:PROC(NAM,AG) RETURNS(FIXED BIN(15,0));
DCL NAM CHAR(10);
DCL AG FIXED BIN(15,0);
PUT SKIP LIST('NAME:',NAM);
PUT SKIP LIST('AGE:',AG);
AG=25;
RETURN (AG);
END EXTSUB;
MAINSUB:PROC OPTIONS(MAIN) REORDER;
DCL EXTSUB RETURNS(FIXED BIN(15,0)) ENTRY;
DCL AGE2 PIC '(2)9';
DCL NAME1 CHAR(10) INIT('MOULEE');
DCL AGE1 FIXED BIN(15,0) INIT(23);
AGE2=EXTSUB(NAME1,AGE1);
PUT SKIP LIST('THE AGE IS:',AGE2);
END MAINSUB;
2.) write an internal subroutine to print the factorial of a given number.
let the subroutine name be FACT.The subroutine named FACT should return
the factorial of the given number.
MAINFACT:PROC OPTIONS(MAIN) REORDER;
FACT:PROC(NUM) RETURNS(FIXED BIN(15,0));
DCL FCT FIXED BIN(15,0) INIT(1);
DCL NUM FIXED BIN(15,0);
DO WHILE(NUM>0);
FCT=FCT*NUM;
NUM=NUM-1;
END;
RETURN (FCT);
END FACT;
FACT1:PROC(NUM1) RECURSIVE;
DCL NUM1 FIXED BIN(15,0);
IF NUM1 <=1 THEN
RETURN(1);
ELSE
RETURN(NUM1*FACT1(NUM1-1));
END FACT1;
DCL ANS FIXED BIN(15,0);
ANS=FACT(6);
PUT SKIP LIST(ANS);
ANS=FACT1(5);
PUT SKIP LIST(ANS);
END MAINFACT;
3.) write a program to show pseudo variable.(hint :use substr)
PSEUDO:PROC OPTIONS(MAIN) REORDER;
DCL SUBSTR BUILTIN;
IF SUBSTR('MOWLEESWAR',6,5)=SUBSTR('ESWARAN',1,5) THEN
PUT SKIP LIST('STRING''S ARE EQUAL.');
ELSE
PUT SKIP LIST('STRINGS ARE NOT EQUAL.');
END PSEUDO;
4.) write a program to print date in the following formats.
1.yymmdd
2.yyyymmdd
3.yy/mm/dd
4.dd/mm/yyyy
and also print the time in the following formats
hh:mm:ss
DTTIME:PROC OPTIONS(MAIN) REORDER;
DCL DATE BUILTIN;
DCL TIME BUILTIN;
DCL DATETIME BUILTIN;
DCL VDATE1 CHAR(6);
DCL VDATE2 CHAR(8);
VDATE1=DATE;
PUT SKIP LIST('DATE1:',VDATE1);
VDATE2=DATETIME;
PUT SKIP LIST('DATE2:',VDATE2);
PUT SKIP LIST(SUBSTR(VDATE1,1,2)||'/'||(SUBSTR(VDATE1,3,2)||
'/'||SUBSTR(VDATE1,5,2);
PUT SKIP LIST(SUBSTR(VDATE2,7,2)||'/'||(SUBSTR(VDATE2,5,2)||
'/'||SUBSTR(VDATE2,1,4);
DCL TM CHAR(6);
TM=TIME;
PUT SKIP LIST(SUBSTR(TM,1,2)||':'||SUBSTR(TM,3,2)||':'||
SUBSTR(TM,5,2);
END DTTIME;
5.) write a pli program ,write a internal subroutine named CHKDATE,the
arguments for the subroutine is a date string,the subroutine should
print the date is valid or not.
CHECKDT:PROC OPTIONS(MAIN) REORDER;
DCL CHKDATE RETURNS(BIT(1)) ENTRY;
DCL VERIFY BUILTIN;
DCL MOD BUILTIN;
DCL DT CHAR(10) INIT('31/13/2005');
DCL FLG BIT(1) INIT('1'B);
FLG=CHKDATE(DT);
CHKDATE:PROC(DT1) RETURNS(BIT(1));
PUT SKIP LIST('CHAND');
DCL DT1 CHAR(10);
IF VERIFY(DT1,'0123456789/') THEN
DO;
PUT SKIP LIST('ESWAR');
RETURN ('0'B);
END;
ELSE
DO;
DCL MM PIC'(2)9';
DCL DD PIC'(2)9';
DCL YY PIC'(4)9';
MM=SUBSTR(DT1,4,2);
DD=SUBSTR(DT1,1,2);
YY=SUBSTR(DT1,7,4);
IF MM=01|MM=03|MM=05|MM=07|MM=08|MM=10|MM=12 THEN
DO;
PUT SKIP LIST('MOULI');
IF DD>=32 THEN
DO;
PUT SKIP LIST('PARTHA');
RETURN('0'B);
END;
ELSE
RETURN ('1'B);
END;
ELSE
IF MM=04|MM=06|MM=09|MM=11 THEN
DO;
IF DD>=31 THEN
RETURN ('0'B);
ELSE
RETURN ('1'B);
END;
ELSE
IF MM=02 THEN
DO;
IF MOD(YY,400)=0 THEN
DO;
IF DD>=30 THEN
RETURN ('0'B);
ELSE
RETURN ('1'B);
END;
ELSE
IF DD>=29 THEN
RETURN ('0'B);
ELSE
RETURN ('1'B);
END;
END;
END CHKDATE;
IF FLG='0'B THEN
PUT SKIP LIST('FALSE');
ELSE
PUT SKIP LIST('TRUE');
END CHECKDT;
6.) write a pli program to return a RETURNCODE TO THE EXECUTION JCL
and also print the return code to the sysprint.
(try with 2 pli programs with condition codes)
RTCODE:PROC OPTIONS(MAIN) REORDER;
DCL PLIRETC BUILTIN;
DCL PLIRETV BUILTIN;
PUT SKIP LIST(PLIRETV);
CALL PLIRETC(4);
PUT SKIP LIST(PLIRETV);
END;
//TRGA13AA JOB NOTIFY=TRGA13
//STEP1 EXEC PGM=RTCODE
//STEPLIB DD DSN=TRGA13.MOULI.LOADLIB,DISP=SHR
//SYSPRINT DD SYSOUT=A
//STEP2 EXEC PGM=CHECKDT,COND=(04,EQ)
//STEPLIB DD DSN=TRGA13.MOULI.LOADLIB,DISP=SHR
//SYSPRINT DD SYSOUT=A
//
7.) write a pli program to submit a JCL from pli program.
8.) write a pli program to extract the string'GLOBAL' from the 'HTC
GLOBAL SERVICES' and also change the string 'services' to 'software'.
STRREP:PROC OPTIONS(MAIN) REORDER;
DCL SOURCE CHAR(25) INIT('HTC GLOBAL SERVICES');
PUT SKIP LIST('EXTRACT:',SUBSTR(SOURCE,INDEX(SOURCE,'GLOBAL'),
LENGTH('GLOBAL'));
SUBSTR(SOURCE,INDEX(SOURCE,'SERVICES'),LENGTH('SERVICES'))=
'SOFTWARE';
PUT SKIP LIST(SOURCE);
END;
9.) WRITE a pli program to print the number of occurance of a string
in a given string. main string: 'external subroutine is the main
subroutine.' search string:'subroutine'.
SRCH:PROC OPTIONS(MAIN) REORDER;
DCL SRC CHAR(50) INIT('EXT SUBROUTINE IS SUBROUTINE');
DCL SUBSTR BUILTIN;
DCL LENGTH BUILTIN;
DCL INDEX BUILTIN;
DCL TEMP FIXED BIN(15,0) INIT(0);
DCL LEN FIXED BIN(15,0) INIT(0);
PUT SKIP LIST(LENGTH(SRC));
DO WHILE(INDEX(SRC,'SUBROUTINE'));
TEMP=TEMP+1;
SRC=SUBSTR(SRC,INDEX(SRC,'SUBROUTINE')+1);
END;
PUT SKIP LIST(TEMP);
END SRCH;
No comments
Post a Comment