• Aucun résultat trouvé

READ FILE(SORTOUT) INTO (CHARS);

Dans le document It System/360 (Page 193-200)

REGIO:NrAL Data Sets

Chapter 14: Other Facilities of the Operating System

L: READ FILE(SORTOUT) INTO (CHARS);

AAAAAA

ZZZZZZ 444444 CCCCCC XXXXXX CCCCCC CCCCCC CCCCCC CCCCCC CCCCCC 333333

VVVVVV

EEEEEE 333333 //STEP3 EXEC PL1LFCL

AAAAAA

ZZZZZZ 444444 ZZZZZZ 999999 ZZZZZP 888888

AAAAAA

ZZZZZZ ZZZZZA ZZZZZZ

AAAAAA AAAAAA

ZZZZZZ //PL1L.,DUMB DD DSNAME=ggGOSET(GO) ,DISP= (OLD, DELETE)

/ /PL1L., SYSIN DD

*

/* PI~I ROUTINE TO PRINT OUTPUT FROM SORT PROGRAM EXAMPLES */

P: PROC OPI'IONS(MAIN) 1

/*

DCL SORTOUT FILE INPUT RECORD, CHARS CHAR (80) VAR,

ON ENDFILE(SORTOUT) GOTO ENDP;

L: READ FILE(SORTOUT) INTO (CHARS);

PUT SKIP EDIT (CHARS) (A);

GOTO L;

ENDP: END P,

/ /STEPL!~ EXEC PGM=

*.

STEP3 • LKED. SYSLMOD //SYSPJITNT DD SYSOUT=A

//SORTOUT DD DSNAME=ggTEM,DISP=(OLD,DELETE),UNIT=2314 Figure 14-5. PL/I Pregram Inveking IHESRTB

ENTRY l'OI NT IHESRTC

Entry point IHESRTC is used fer serting records frem a data set and then passing them ene-by-one te a PL/I precedure. The fermat .of the CALL statement is:

CALL IIIESRTC(argument:l,.,argument2,argument3 , argument~,argument6);

where:

argullllents:l,. - ...

argull(\ent 6

as for IHESRTA

= entry name .of the PL/I procedure te which the sorted records are to be passed.

when IHESRTC is used, each record that appearfJ in the sorted .output is passed te user elcit E35. The PL/I procedure

associated with this user exit is invoked fer each record that i t receives as a paramet:er ..

The records passed by the sert pregram must bE~ in a character-string form. If this form is net the .one required by the PL/I pl:ogram, then the PL/I record must be defined en a character string. The same

difficulties can be expected here as for IHESRTB.

Return Codes frem PL/I te Sert

A return cede may be passed by the PL/I precedure te the sort pregram, using the CALL IHESARC(n) or CALL IHETSAC(n)

statement. The return cede'values are:

4 the record passed has been accepted, pass the next record

8 stop passing recerds, even if there are still mere te ceme.

IHESARC and IHETSAC must be declared as an entry of precision (31,0).

If ne return code is passed the sert pre gram continues te pass records until all have been passed.

An example .of a PL/I pregram that uses IHESRTC is given in Figure 14-6. This program sorts recerds similar te these in the previous examples. The PL/I procedure E35A is inveked from the sert program user Chapter 14: Other Facilities .of the Operating System 193

//R20C JOB

//STEP1 EXEC PL1LFCL //PL1L.SYSIN DD *

/*

/* PL/I PROGRAMMING EXAMPLE USING IH:ESRTC */

SORTC: PROC OPTIONS (MAIN);

/* DECLARE SORT PROGRAM ENTRY AND EXIT POINTS */

DeL lHESRTC ENTRY(CHAR(35),CHAR(27),FIXED BIN(31,0), FIXED BIN(31,0),ENTRY),

IHESARC ENTRY(FIXED BIN(31..,0», E35A ENTRY,

RETURN_CODE FIXED BIN(31,O);

/* INVOKE THE SORT PROGRAM */

CALL IHESRTC (' SORT FIELDS=(75,6,CH,A,16,6,CH,A) "

, RECORD TYPE=F,LENGTH=(SO) "

25000, /* MAIN STORAGE FOR SORT PROGRAM */

RETURN_CODE, E35A)i /* TEST RETURN CODE */

IF RETURN CODE = 16 THEN PUT SKIP EDIT ('SORT FAILED')(A);

ELSE IF RETURN_CODE = 0 THEN PUT SKIP EDIT ('SORT COMPLETE') ( A)i ESLE PUT SKIP EDIT ('INVALID SORT RETURN CODE.CODE=',

RETURN_CODE) (A) ;

E35A: /* THIS PROCEDURE OBTAINS SORTED RECORDS FROM THE */

/* SORT PROGRAM AND LISTS THEM. DUPLICATE RECORDS */

/* ARE IGNORED.

PROC (INREC)i

/* PRINT HEADING FOR SORTED OUTPUT ON SYSPRINT */

DCL I STATIC INIT(O)i IF I = 0 THEN DO;

PUT SKIP EDIT (' OUTPUT FROM E35 SUBROUTINE') (A) ; 1=1;

END~

/* PROCESS SORTED RECORDS */

DCL INREC CHAR(SO),

PREVREC CHAR(SO) STATIC INIT(' I ) ;

IF INREC=PREVREC THEN GOTO NEXT; /* IGNORE THIS RECORD */

ELSE DO;

PREVREC=INRECi /* STORE CURRENT RECORD */

PUT SKIP EDIT (INREC) (A);

END;

NEXT: CALL IHESARC(4); /* REQUEST NEXT RECORD FROM SORT */

END E35A;

END SORTCi

//STEP2 EXEC PGM=*.STEP1.LKED.SYSLMOD //SYSOUT DD SYSOUT=A

//SYSPRINT DD SYSOUT=A

//SORTLIB DD DISP=SHR,DSN=SYS1.S0RTLIB

//SORTWK01 DD UNIT=2314fSPACE=(TRK,(60,20)"CONTIG) //SORTWK02 DD UNIT=2314,SPACE=(TRK,(60,20)"CONTIG) //SORTWK03 DD UNIT=2314fSPACE=(TRK,(60,20)"CONTIG) //SORTWK04 DD UNIT=2314,SPACE=(TRK,(60,20)"CONTIG)

//SORT1WKOS DD UNIT=2314,SPACE=(TRIS, (60,20) "CONTIG) //SORT1NK06 DD UNIT=2314, SPACE= (TRK, (60,20) "CONTIG) //SORTIN DD =Ie

AAAAAA ZZZZZZ 444444 CCCCCC XXXXXX CCCCCC CCCCCC CCCCCC CCCCCC CCCCCC 333333 VVVVVV EEEEEE 333333

Figure 14-6. PL/I Program Invoking IHESRTC

exit E3S. This procedure receives a charact,er-string representing -a sorted record from the sort program. The input to the sort program is in the input stream.

ENTRY POINT IHESRTD

Entry point IHESRTD is used for sorting records constructed or updated by a PL/I function and then passing them one-by-one to anot~her procedure. The format 'of the CALL st~atement is:

CALL IHESRTD(argument1 ,argument2,argument3 , argument~,arguments,argument6);

where:

arguments1-~ = as for IHESRTA

AAAAAA ZZZZZZ 444444 ZZZZZZ 999999 ZZZZZZ AAAAAA AAAAAA ZZZZZP ZZZZZZ ZZZZZZ AAAAAA AAAAAA ZZZZZZ

arguments = entry name of the PL/I procedure supplying the

:r:,~cords to the sort program

arguments = entry name of the PLII procedure to which the sorted records are to be passed

An example of a PL/I program that uses IHESRTD is given in Figure 14-7. This program sorts records similar to those in the previous examples. The PL/I procedure ElSA is invoked from the sort program user exit E1S. This procedure return a

character string that is inserted by the sort program into the sort. At the end of the sort, the sorted' records are associated with a character string parameter in the PL/I procedure E3SA, which is invoked from the sort user exit E3S for each record emerging from the sort.

Chapter 14: other Facilities of the operating System 195

//R20D JOB

//STEPl EXEC PL1LFCL //PL1L.SYSIN DD

*

/* PL/I PROGRAMMING EXAMPLE USING IHESRTD */

SORTD: PROC OPTIONS (MAIN);

/* DECLARE SORT PROGRAM ENTRY AND EXIT POINTS */

DCL IHESRTD ENTRY(CHAR(35),CHAR(27),FIXED BIN(31,0), FIXED BIN(3l,0),ENTRY,ENTRY),

IHESARC ENTRY(FIXED BIN(3l,0», E15 ENTRY RETURNS(CHAR(SO», E35 ENTRY,

RETURN_CODE FIXED BIN(3l,0);

/* INVOKE THE SORT PROGRAM */

CALL IHESRTD C' SORT FIELD=(75,6,CH,A,16,6,CH,A) 0' , RECORD TYPE=F,LENGTH=(SO) "

25000, /* MAIN STORAGE FOR SORT PROGRAM */

RETURN_CODE, E15A,E35A);

/* TEST RETURN CODE */

IF RETURN CODE = 16 THEN PUT SKIP EDIT ('SORT FAILED') (A);

ELSE IF RETURN CODE = 0 THEN PUT SKIP EDIT ('SORT COMPLETE') (A);

ELSE PUT SKIP EDIT C' INVA:LID SORT RETURN CODE. CODE=' , RETURN_CODE)CA);

E15A: /* THIS PROCEDURE OBTAINS RECORDS FROM THE INPUT STREAM */

/* AND CHECKS FOR NUMERIC OR AI,PHABETIC CODES BEFORE */

/* PASSING ONLY THOSE WITH ALPHABETIC CODES TO THE SORT */

/* PROGRAM. RECORDS WITH NUMERIC CODES ARE LISTED. */

PROC RETURNSCCHARCSO»;

DCL SYSIN FILE RECORD INPUT;

ON ENDFILE(SYSIN) BEGIN;

PUT SKIP(3) EDIT (':END OF SORT PROGRAM INPUT.', 'SORTED OUTPUT SHOULD FOLLOW')CA);

CALL IHESARC(S); /* SIGNAL END OF SORT INPUT */

GOTO ENDE15;

END;

DCL INFIELD CHAR(SO), FIELDl CHAR(6) DEF INFIELD POS(75);

NEXT: READ FILE (SYSIN) INTO (INE'IELD);

IF FIELDl > 'ZZZZZZ' THEN DO;

PUT SKIP EDIT (INFIELD) (A);

GOTO NEXT;

END;

CALL IHESARC(12); /* INPUT TO SORT CONTINUES */

RETURN (INFIELD); . ENDE15: END E15A;

E35A: /* THIS PROCEDURE OBTAINS SORTED RECORDS FROM THE */

/* SORT PROGRAM AND LISTS THEM. DUPLICATE RECORDS */

/* ARE IGNORED. */

PROC ( INREC) ;

/* PRINT HEADING FOR SORTED OUTPUT ON SYSPRINT */

DCL I STATIC INI'!' (0) ; IF I = 0 THEN DO;

PUT SKIP EDIT ('OUTPUT FROM E35 SUBROUTINE') (A);

1=1;

END;

/* PROCESS SORTED RECORDS */

DCL INREC CHAR(80),

PREVREC CHAR(80) STATIC INIT(~ .);

IF INREC=PREVREC THEN GOTO NEXT; /* IGNORE THIS RECORD */

ELSE DO~

PREVREC=INRECi /* STORE CURRENT RECORD */

PUT SKIP EDIT (INREC) (A);

END;

NEXT: CALL IHESARC(4); /* REQUEST NEXT RECORD FROM SORT */

RETURN;

END E35A;

END SORTD;

/*

//STEP2 EXEC PGM=*.STEP1.LKED.SYSLMOD

//SYSot~ DD SYSOUT=A //SYSPHINT DD SYSOUT=A

/ /SORT][JIB DO DISP=SHR, DSN=SYS1. SORTLIB

/ /SORTWK01 DO UNIT=2314, SPACE= (TRK, (60,20) "CONTIG) / /SORTl~02 DO UNIT=2314, SPACE= (TRK, (60,20) , ,CONTIG) //SORTlil1K03 DD UNIT=2314,SPACE=(TRK, (60,20) "CONTIG)

//SORTl~04 DD UNIT=2314,SPACE=(TRK,(60,20)"CONTIG)

//SORTl~05 DD UNIT=2314,SPACE=(TRK,(60,20)"CONTIG)

//SORTl~06 DO UNIT=2314,SPACE=(TRK,(60,20)"CONTIG) //SYSIN DD

*

/*

zzzzzz

ZZZZZZ 444444 CCCCCC XXXXXX CCCCCC CCCCCC CCCCCC CCCCCC 333333 VVVVVV EEEEEE 333333

Figure 14-7. PL/I Program Invoking IHESRTD

SORTING VARIABLE-LENGTH RECORDS

When you wish to use the PL/I sorting facili 1:ies to sort variable-length records, you should note the following points:

1. The portion of a variable-length

rE~cord that contains the control field 01: fields on which the sort is to be

pE~rf ormed must be present and of the SClme length for every record to be sorted. A sort cannot be performed on control fields whose length or

position within a record is liable to alter. Thus the control fields would

bE~ expected wi thin the minimum length given for the records in the RECORD control statement.

2. The length of each record is recorded in the first four bytes of the record.

P1:ovision for this length field should

bE~ made when you specify the sort control fields in the SORT control s1:atement.

AAAAAA ZZZZZZ 444444 ZZZZZZ 999999 ZZZZZZ 888888 AAAAAA ZZZZZP ZZZZZZ AAAAAA AAAAAA ZZZZZZ

3. Varying-length strings passed from a PL/I user exit E15 procedure will have the length field added to the record automatically; the length will be the current length of the character string plus four bytes for the field itself.

The same applies if 'fixed-length strings of different lengths are returned from the E15 procedure.

4. The four-byte length field is removed from variable-length records passed to a PL/I user exit E35 routine.

An example of a PL/I program that uses IHESRTA to sqrt variable-length records is given in Figure 14-8. This example

includes a PL/I program to create a data set of variable-length records from data items obtained from the input stream. The sort is performed on alphanumeric data in the first six bytes following the length field in each record. A third PL/I program retrieves the sorted variable-length

records from a temporary data set and lists them. Note that the maximum record length includes four bytes for the length field,

Chapter 14: Other Facilities of the Operating System 197

and corresponds to the maximum length given in the LRECL subparameter.

OSE OF PL/I SORT IN A MULTITASKING ENVIRONMENT

When the sort program is invoked from different PL/I tasks, so that two Ol~ more sorting operations are to be performed asynchronously by separate subtasks, the following should be noted if -the sort program diagnostic messages are to be printed on the line printer:

If the DD statement for the SYSOUT data set contains SYSOUT=A in the operand field, some sort program messages may be

overwritten in the data management buffers and therefore not printed. FUrther, the program in some cases will terminate

abnormally or go into a wait state. These problems are caused by the inability to modify the ddname for the SYSOUT data set in the additional tasks that use the sort program: they give rise to synchronization conflicts within data management.

This problem does not apply if, when thE!

system is generated, the sort program

messages are specified to be printed on the console.

/ /R20V ,JOB

//STEPl EXEC PL1LFCLG //PL1L.SYSIN DO *

/*

VAR2:: PROC OPTIONS (MAIN) ;

ON ENDFILE(SYSIN) GOTO END;

DCL OUT FILE RECORD OUTPUT, OUTREC CHAR (80) VAR;

NEXT: GET LIST (OUTREC);

PUT SKIP EDIT (OUTREC) (A);

WRITE FILE (OUT) FROM (OUTREC);

GOTO NEXT;

END: END VAR2;

//GO.otn~ DD DSNAME=&&TEMP,DISP=(NEW,PASS),SPACE=(TRK,(l,l», //DCB=(,RECFM=V,LRECL=84),UNIT=2314

//GO.DIDIlB DO DSNAME=&&GOSET(GO) ,DISP=(OLD,DELETE) //GO.SYSIN DO

*

'003329HOOKER S.W. RIVERDALE, SATCHWELL LANE, BACONSFIELD' '002886ElOOKER R.R. ROTORUA, MILKEDGE LANE, TOBLEY'

'003077HOKKER & SON, LITTLETON NURSERIES, SHOLTSPAR'

'059334HOOK E.H. 109 ELMTREE ROAD, GANNET PARK, NORTHAMPTON' '73872HOME TAVERN, WESTLEIGH'

'000931:E'OREST, IVER, BUCKS' /*

//STEP2 EXEC PL1LFCL //PL1L.SYSIN DD *

/*

VARY1.: PROC OPTIONS(MAIN);

DCL IHESRTA ENTRY (CHAR(24),CHAR(3S),

FIXED BIN(31,0),FIXED BIN(31,0», RETURN CODE FIXED BIN(31,O);

CALL lHESRTA(' SORT FIELDS=(5,6,CH,A) ,

, RECORD TYPE=V,LENGTH=(84",20,40) "

25000, /* MAIN STORAGE FOR THE SORT PROGRAM */

RETURN CODE);

IF RETURN CODE=O THEN PUT SKIP EDIT ('SORT-COMPLETE') (A);

END VARY1;

ELSE IF RETURN CODE=16 THEN PUT SKIP EDIT ('SORT FAILED') (A);

ELSE PUT SKIP EDIT

('INVALID SORT RETURN CODE') (A);

//STEP3 EXEC PGM=*.STEP2.LKED.SYSLMOD / /SYSOU'I' DD SYSOUT=A

//SYSPRINT DO SYSOUT=A

//SORTLIB DO DISP=SHR,DSN=SYS1.S0RTLIB

//SORTWl<:Ol DO UNIT=2314, SPACE= (TRK, (60,20) "CONTIG) //SORTWK02 DO UNIT=2314, SPACE= (TRK, (60,20) "CONTIG) //SORTWl<:03 DD UNIT=2314,SPACE=(TRK, (60,20) "CONTIG) / /SORTWK04 DO UNIT=2314, SPACE= (TRK, (60,20) "CONTIG) //SORTWR05 DD UNIT=2314,SPACE=(TRK, (60,20) "CONTIG) / /SORTWK06 DD UNIT=2314, SPACE= (TRK, (60,20) "CONTIG) //SORTINI DO DSNAME=&&TEMP,DISP=(OLD,DELETE),

/ / DCB=: (BLKSI ZE= 8 8, LRECL= 84, RECFM=V) //SORTOUT DO DSNAME=&&TEM,DISP=(NEW,PASS),

/ / SPACE:= (TRK, (1,1) ) , UNIT=2314, DCB= (RECFM=V, LRECL=84, BLKSI ZE=88) //STEP4 EXEC PL1LFCL

//PL1L.DUMB DO DSNAME=&&GOSET(GO),DISP=(OLD,DELETE) //PL1L.SYSIN DO *

/* PL/t ROUTINE TO PRINT OUTPUT FROM SORT PROGRAM EXAMPLES */

P: PR:OC OPTIONS (MAIN) ;

DeL SORTOUT FILE INPUT RECORD, CHARS CHAR (80) VAR;

ON ENDFILE(SORTOUT) GOTO ENDP;

L: READ FILE(SORTOUT) INTO (CHARS);

PUT SKIP EDIT (CHARS) (A);

GOTO L;

Chapter 14: Other Facilities of the operating System 199

ENDP: END Pi /*

//STEP5 EXEC PGM=*.STEP4.LKED.SYSLMOD //SYSPRINT DD SYSOUT=A

//SORTOUT DD DSNAME=&&TEM,DISP=(OLD,DELETE),UNIT=2314

Figure 14-8. Using IHESRTA to Sort Variable~length Records

Dans le document It System/360 (Page 193-200)