PUTDDREC: Writing a Character String as a Record in a Sequential File

How to:

The PUTDDREC function writes a character string as a record in a sequential file. The file must be identified with a FILEDEF (DYNAM on z/OS) command. If the file is defined as an existing file (with the APPEND option), the new record is appended. If the file is defined as NEW and it already exists, the new record overwrites the existing file.

PUTDDREC opens the file if it is not already open. Each call to PUTDDREC can use the same file or a new one. All of the files opened by PUTDDREC remain open until the end of a request or connection. At the end of the request or connection, all files opened by PUTDDREC are automatically closed.

If PUTDDREC is called in a Dialogue Manager -SET command, the files opened by PUTDDREC are not closed automatically until the end of a request or connection. In this case, you can close the files and free the memory used to store information about open file by calling the CLSDDREC function.

Syntax: How to Write a Character String as a Record in a Sequential File

PUTDDREC(ddname, dd_len, record_string, record_len, output) 

where:

ddname

Alphanumeric

Is the logical name assigned to the sequential file in a FILEDEF command.

dd_len

Numeric

Is the number of characters in the logical name.

record_string

Alphanumeric

Is the character string to be added as the new record in the sequential file.

record_len

Numeric

Is the number of characters to add as the new record.

It cannot be larger than the number of characters in record_string. To write all of record_string to the file, record_len should equal the number of characters in record_string and should not exceed the record length declared in the FILEDEF command. If record_len is shorter than the declared length declared, the resulting file may contain extraneous characters at the end of each record. If record_string is longer than the declared length, record_string may be truncated in the resulting file.

output

Integer

Is the return code, which can have one of the following values:

 0 - Record is added.

-1 - FILEDEF statement is not found.

-2 - Error while opening the file.

-3 - Error while adding the record to the file.

Example: Calling PUTDDREC in a TABLE Request

The following example defines a new file whose logical name is PUTDD1. The TABLE request then calls PUTDDREC for each employee in the EMPLOYEE data source and writes a record to the file composed of the employee's last name, first name, employee ID, current job code, and current salary (converted to alphanumeric using the EDIT function). The return code of zero (in OUT1) indicates that the calls to PUTDDREC were successful:

FILEDEF PUTDD1 DISK putdd1.datTABLE FILE EMPLOYEE
PRINT EMP_ID CURR_JOBCODE AS 'JOB' CURR_SAL
COMPUTE SALA/A12 = EDIT(CURR_SAL); NOPRINT
COMPUTE EMP1/A50= LAST_NAME|FIRST_NAME|EMP_ID|CURR_JOBCODE|SALA;
NOPRINT
COMPUTE OUT1/I1 = PUTDDREC('PUTDD1',6, EMP1, 50, OUT1);
BY LAST_NAME BY FIRST_NAME
END

The output is:

LAST_NAME        FIRST_NAME  EMP_ID     JOB         CURR_SAL  OUT1
---------        ----------  ---------  ---         --------  ----
BANNING          JOHN        119329144  A17       $29,700.00     0
BLACKWOOD        ROSEMARIE   326179357  B04       $21,780.00     0
CROSS            BARBARA     818692173  A17       $27,062.00     0
GREENSPAN        MARY        543729165  A07        $9,000.00     0
IRVING           JOAN        123764317  A15       $26,862.00     0
JONES            DIANE       117593129  B03       $18,480.00     0
MCCOY            JOHN        219984371  B02       $18,480.00     0
MCKNIGHT         ROGER       451123478  B02       $16,100.00     0
ROMANS           ANTHONY     126724188  B04       $21,120.00     0
SMITH            MARY        112847612  B14       $13,200.00     0
                 RICHARD     119265415  A01        $9,500.00     0
STEVENS          ALFRED      071382660  A07       $11,000.00     0

After running this request, the sequential file contains the following records:

BANNING        JOHN      119329144A17000000029700
BLACKWOOD      ROSEMARIE 326179357B04000000021780
CROSS          BARBARA   818692173A17000000027062
GREENSPAN      MARY      543729165A07000000009000
IRVING         JOAN      123764317A15000000026862
JONES          DIANE     117593129B03000000018480
MCCOY          JOHN      219984371B02000000018480
MCKNIGHT       ROGER     451123478B02000000016100
ROMANS         ANTHONY   126724188B04000000021120
SMITH          MARY      112847612B14000000013200
SMITH          RICHARD   119265415A01000000009500
STEVENS        ALFRED    071382660A07000000011000

Example: Calling PUTDDREC and CLSDDREC in Dialogue Manager -SET Commands

The following example defines a new file whose logical name is PUTDD1. The first -SET command creates a record to add to this file. The second -SET command calls PUTDDREC to add the record. The last -SET command calls CLSDDREC to close the file. The return codes are displayed to make sure operations were successful:

FILEDEF PUTDD1 DISK putdd1.dat -SET &EMP1 = 'SMITH'|'MARY'|'A07'|'27000';
-TYPE DATA = &EMP1
-SET &OUT1 = PUTDDREC('PUTDD1',6, &EMP1, 17, 'I1');
-TYPE PUT RESULT = &OUT1
-SET &OUT1 = CLSDDREC('I1');
-TYPE CLOSE RESULT = &OUT1

The output is:

DATA = SMITHMARYA0727000
PUT RESULT = 0
CLOSE RESULT = 0

After running this procedure, the sequential file contains the following record:

SMITHMARYA0727000

WebFOCUS

Feedback