Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to eliminate unwanted spaces?

Status
Not open for further replies.

RNTH

Programmer
Jul 27, 2005
19
IN
Hi,

I am pulling a file from MQ(using MQGET) which has the following structure.

Header - Rec length 100
Details - Rec length 250

As per our MVS provision, we are using a dataset with LRECL=254, RECFM=VB

But in the output DSN, the header record is getting padded with spaces to match the length of details.

Is there any way in which I can eliminate the right padded spaces?

Please advise.

Thanks
 
COBOL needs to understand that you have different lengths for different records. One way to do that would be to set up two different 01 levels under the FD.

FD OUTPUT-FILE.
01 HEADER-RECORD PIC X(100).
01 DETAIL-RECORD PIC X(250).


If you have a WRITE HEADER-RECORD you will create a 100 byte record (plus 4 for the length).

IF you have a WRITE DETAIL-RECORD you will create a 250 byte record (plus 4 for the length).

Another method would be to have an OCCURS DEPENDING ON variable in your output 01 level definition. The DEPENDING ON variable would have to be set to the proper value before each WRITE so that you would write the correct number of bytes.

FD OUTPUT-FILE.
01 OUTPUT-RECORD.
03 OUTPUT-BYTE
OCCURS 100 TO 250 TIMES
DEPENDING ON REC-LENGTH
PIC X(01).

To write a header record,
MOVE 100 TO REC-LENGTH
WRITE OUTPUT-RECORD

To write a detail record,
MOVE 250 TO REC-LENGTH
WRITE OUTPUT-RECORD


 
It's been a while since I used VB records, but I seem to recall defining records as VBA which allows the first 4 chars (binary) to be set manually in the program to the length of the reocrd required.

Is this an option?

Marc
 
Kenny is right. You cannot tell COBOL directly how many bytes to write; you have to write a record that is defined to be the length you want. The first method he suggests is easier for a small number of record sizes, and better documentation.
 
Nope. The methods suggested by Kenny won't work here. It is padding spaces at the right side, to match the record length specified in the JCL which runs the program.
 
It sounds to me like you're writing fixed length records every time. Or else your write statement is always referring to the detail record rather than the header record so every 'variable length' record you write is 250 bytes.
 
No. As you said I am having 2 records, HEADER PIC X(100) and DETAILS PIC X(250).

But the output file is having the HEADER + 150 spaces = 250
 
Do you have 2 separate WRITE statements - one for the header record and one for the detail record?
 
Yes I had. I tested using the following.

FD OUTFILE.
01 HEADER PIC X(10).
01 DETAILS PIC X(20).

01 WS-OUTFILE-REC.
05 WS-OUTFILE-LEN PIC S9(4) COMP VALUE 0.
05 WS-OUTFILE-RECORD PIC X(100) VALUE SPACES.


PROCEDURE DIVISION.
OPEN OUTPUT OUTFILE.
MOVE 'TEST HEADER RECORD WRITTEN' TO WS-OUTFILE-RECORD.
MOVE 10 TO WS-OUTFILE-LEN.
WRITE HEADER FROM WS-OUTFILE-REC.
MOVE 'TEST DETAIL RECORD WRITTEN' TO WS-OUTFILE-RECORD.
MOVE 20 TO WS-OUTFILE-LEN.
WRITE DETAILS FROM WS-OUTFILE-REC.
CLOSE OUTFILE.
STOP RUN


My output file OUTFILE in HEX ON mode is like,

------------------------------------
000001 TEST HEA
00ECEE4CCC4444444444
0A352308510000000000
------------------------------------
000002 TEST DETAIL RECORD
01ECEE4CCECCD4DCCDDC
04352304531930953694
------------------------------------
 
You're writing a fixed length record.

Let's look at a couple of things. The length code of a variable length record is defined to use 4 bytes. Your COMP PIC S9(04) only takes two bytes. The IBM manual that I have says the length fields are not available to you for reference. You're trying to put in a length code for the system to understand how long your record is but it is using that as a piece of data.

I don't use a RECORDING MODE clause in my code but the IBM manual says that if there is more than one 01 level defined and they are a different length, it is assumed to be RECORDING MODE V. This may be an IBM extension since that phrase is coded in blue in my manual.

You might need to use the RECORD IS VARYING clause.
Try this....


FD OUTFILE
RECORD IS VARYING.
01 HEADER PIC X(10).
01 DETAILS PIC X(20).


PROCEDURE DIVISION.
OPEN OUTPUT OUTFILE.
MOVE 'TEST HEADER RECORD WRITTEN' TO HEADER.
WRITE HEADER.
MOVE 'TEST DETAIL RECORD WRITTEN' TO DETAILS.
WRITE DETAILS.
CLOSE OUTFILE.
STOP RUN.

See how that works.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top