Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
RubenMagro Absent Member.
Absent Member.
1167 views

binary sequential file with record size depending on...

Hi,

I have the next definition in a file:

           SELECT SOMODFOV  ASSIGN TO FIL-SOMODFOV
                            ORGANIZATION BINARY SEQUENTIAL,
                            ACCESS SEQUENTIAL
                            STATUS W-ESTADO.

 

       FD  SOMODFOV    LABEL RECORDS ARE STANDARD
                       RECORD IS VARYING IN SIZE  FROM 1 TO 4000
                       DEPENDING ON W-TAMANO.
       01  REG-FICFOV    PIC X(4000).

 

The problem is by creating the file this way, I get 2 characters in the beginning of each record. Something like this:

,<TFOV020160A

I attach the file too because the first character is not shown in HTML (you can see it on Windows Notepad for example)BinarySequentialDependingOn.txt

 

I need to use this kind of file because I'm required to use a file without 'enters' and each record has a different size.

Has anyone any alternative approach?

Thanks!

 

 

0 Likes
4 Replies
Sebis Absent Member.
Absent Member.

RE: binary sequential file with record size depending on...

As per manual
"Variable-length binary sequential records occupy only as much disk space as necessary. If the maximum record size is equal to or less than 65,535 bytes, two bytes indicating record size (VLI) are placed in front of each variable-length record when it is written to disk. If the record size is larger than 65,535 bytes, four bytes are placed in front of each variable-length record. This two- or four-byte field is not specified in your COBOL program, and non-COBOL programs that access the records need to be aware of the extra bytes. "

You need someway of determining where a record ends. When you say without "enters" do you just mean Carriage Return (hex 0d) or the combination of Carriage Return + Line Feed (hex 0d0a). If it is just the Carriage Return then look at using line sequential.
0 Likes
redhat37 Absent Member.
Absent Member.

RE: binary sequential file with record size depending on...

We had a similar problem with a ASCII upload file where they only wanted CR at the end end of each line and not CR on the last record of the file.

Here is a code sample of how we achieved this with the binary file and writing one character at a time to have total control over what was used as record delimiters.

FILE-CONTROL.
SELECT OUTFILE ASSIGN TO DISK OUTNAME
ORGANIZATION IS BINARY SEQUENTIAL
FILE STATUS IS DSTAT.


FILE SECTION.
FD OUTFILE
LABEL RECORD IS STANDARD.
01 OUTREC.
02 O-LINE PIC X.

WORKING-STORAGE SECTION.
01 W-FILENAME PIC X(150).
01 W-STATUS PIC X(50).
01 SOURCE-FILE PIC X(200).
01 DEST-FILE PIC X(200).
01 COPY-STATUS PIC S9.

77 CR PIC X(01) Value X'0D'.
77 LF PIC X(01) Value X'0A'.
77 CRLF PIC X(02) Value X'0D0A'.
01 WS-OUTREC PIC X(500).
77 O-COUNT PIC S99999 BINARY VALUE 0.
01 STR-PTR PIC S9(5) BINARY VALUE 0.



When writing the file out use the following.

MOVE 1 TO STR-PTR
STRING "CSDHeader" DELIMITED BY SIZE
"|" DELIMITED BY SIZE
CMUN-CODE DELIMITED BY " "
"|" DELIMITED BY SIZE
CNAME DELIMITED BY " "
"|" DELIMITED BY SIZE
WS-RECORDS DELIMITED BY " "
"|" DELIMITED BY SIZE
CR DELIMITED BY SIZE
INTO WS-OUTREC
WITH POINTER STR-PTR.


MOVE STR-PTR TO O-COUNT.
SUBTRACT 1 FROM O-COUNT.

PERFORM VARYING CNT FROM 1 BY 1 UNTIL CNT > O-COUNT
WRITE OUTREC FROM WS-OUTREC(CNT:1)
END-PERFORM.
0 Likes
Sebis Absent Member.
Absent Member.

Re: binary sequential file with record size depending on...

Hi,

The following is extract from the ACUCobol manual

"Variable-length binary sequential records occupy only as much disk
space as necessary. If the maximum record size is equal to or less
than 65,535 bytes, two bytes indicating record size (VLI) are placed
in front of each variable-length record when it is written to disk.
If the record size is larger than 65,535 bytes, four bytes are placed
in front of each variable-length record. This two- or four-byte field
is not specified in your COBOL program, and non-COBOL programs that
access the records need to be aware of the extra bytes. "

So what ever is going to read the binary sequential file will have to
read the first 2 bytes to find out how many bytes are in the record.

When you say you cannot use "ENTER" do you mean the combination
Carriage-return (\r) + Line-feed or just Line-feed (\n) ?
0 Likes
RobertRedekop Trusted Contributor.
Trusted Contributor.

Re: binary sequential file with record size depending on...

Use format 3 of the write statement.  "WRITE xxx WITH NO CONTROL".  Make sure the record is varying in size based on a variable.   The file definition might need to be LINE SEQUENTIAL but I do not think so.

eg)

MOVE "<TFOV020160A0000><AUX>" TO MYFILE-RECORD.

MOVE 22 TO MYFILE-RECORD-SIZE-VAR.

WRITE MYFILE-RECORD WITH NO CONTROL.

 

would result in no carriage returns, no line feeds just the 22 bytes specified.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.