Contents of Article


LRECL Considerations

The MINLEN profile option

The TR and PL line commands


Introduction


SPFLite gives you the control over the lengths of lines of text files. This is done primarily by the command MINLEN - Set Minimum Record Length.


Why would this issue be important to you?  Here are some likely reasons:


    • You are using Picture strings in conjunction with primary commands like FIND, CHANGE, EXCLUDE, SPLIT and JOIN, and sometimes run into issues with "blank" lines that are zero-length. If you could avoid creating zero-length lines, some types of editing tasks can be done more simply.


    • You may be creating a conventional text file with standard FORMAT End-of-Line delimiters, but for some reason you need all lines to be of the same length. This requirement may stem from usage of the file by an external system such as a mainframe, or perhaps by an embedded system.


LRECL Considerations


When setting LRECL to a value greater than 0, you need to be mindful of what this value means and how it is processed by SPFLite.


When a file is opened that is defined with Record-length N (where N is > 0) and the file has Record-Format F and End-of-Line NONE, SPFLite uses the N value to 'divide up' the file data into 'pieces' that are exactly N characters each.  Here, the N value is needed because otherwise there would be no way to know how long each "piece" is.  On IBM mainframes, they use the LRECL value for exactly the same reason.


However, once your data is in the editor, SPFLite performs its normal function as a text editor, where "text" lines can vary to any arbitrary size.  SPFLite does NOT prevent any of your text lines from exceeding a length of N characters.


Why doesn't it do that?  First, it would be difficult to implement, since it would mean SPFLite would have to operate in two different 'modes' - where one only allowed fixed-length records and the other allowed line sizes to vary. Second, you might want to place information 'outside' of the LRECL size, perhaps as "notes" or as temporary information, which you intended to truncate or discard later.  You are allowed the flexibility to do such things.


What happens if your edit session has created lines longer than N characters? While you are editing, nothing happens.  But when you go to SAVE the file, or

END the edit when AUTOSAVE is in effect, SPFLite will issue a warning message like this:


File contains lines longer than Record-Length of nnn

Click YES to continue and truncate lines, or

Click NO to abandon the file save and return to Edit


If you didn't intend to create "long" lines but you are done with your editing work, click on YES.  If you click on NO, you will not lose any data, but you will not have saved it, either.  If you want to truncate all of your data to a fixed length, you can use the TL/TLL (Truncate to Length) line command.


Other ways to truncate your data to a given length are:




The MINLEN profile option


To define a "garden variety" standard, variable-length Windows text file, the associated PROFILE settings are FORMAT U CRLF 0. In SPFLite, this term really means the maximum logical record length. For files of type Record-format is F, the Record-Length must be a positive number defining the fixed line size. For Record-Format U, Record-Length 0 really means that there is no (arbitrary) maximum length, because the end of the line is determined from the End-of-Line setting rather than a fixed value.


In addition to the Record-Length option, you can now define the minimum logical record length using MINLEN.


In prior versions of SPFLite, the minimum logical record length is treated as 0; that is, there is no minimum, so text lines can be of any length, including length zero.


The MINLEN option defaults to 0 unless you set it otherwise.


When the MINLEN option is set, SPFLite does the following:


    • If the MINLEN value is greater than zero, the file currently being edited is scanned, any any lines shorter than the newly-specified MINLEN are padded with blanks to the minimum length.


    • Any lines changed manually by typing into them, lines changed from primary or line commands, and lines added from COPY and PASTE commands, will have their minimum line length enforced by the MINLEN value in effect at the time.


NOTE: MINLEN affects the contents of the file "while you are editing", it does NOT necessarily affect the file when it is written. See the next section and the Profile option PRESERVE for details.


The MINLEN option, being a PROFILE setting, is unique to a given file type. If you want a certain minimum length enforce (like 1 for example), you would have to update all of your existing profiles, and then update the DEFAULT profile so that any newly-created profiles would also have the MINLEN set to what you wanted.


Note: Be aware that any primary command such as SPLIT and JOIN, and line commands such as TS, TB/TBB, TR, PL and TL may be documented as implicitly producing lines of a certain length, but the MINLEN value in effect at the time for a file will override this, so that no matter what you attempt to do, you will not create lines shorter than the minimum length.


PRESERVE handling


PRESERVE specifies how trailing blanks on a line are to be handled, so it does interact with MINLEN.


The extra blanks that may be added by MINLEN processing are not treated specially. So if you specify PRESERVE ON, these extra added blanks will be written to the file. So don't specify an uneccessarily large value for MINLEN if you use PRESERVE ON, you could add considerably to your file size.   


The TR and PL line commands


If you need to truncate or pad lines to manually enforce a line length, the Trim command TR/TRR and the Pad to Length command PL/PLL can be used. 


The Pad to Length line command PL will accept a special modifier of / or \. When used in this way, a command of PL/ will pad all following lines to a minimum length of 1; PL\ will do the same to preceding lines. Placing PL/ on line 1 of a file can be used to ensure that all lines in the file have a minimum line length of 1; that is, it is a quick way to ensure there are no zero-length lines in the file. If you need to pad to a longer length (such as 4 for example), you can use the block mode version with PLL4 on line 1 and PLL on the last line.


The Truncate line command TL/TLL can also be used, but be aware that since truncation is involved, this command can cause data loss.


See TR / TRR - Trim Trailing Blanks, PL / PLL - Pad Lines, and TL / TLL - Truncate Lines to a Length for more information.


Created with the Personal Edition of HelpNDoc: Make Your PDFs More Secure with Encryption and Password Protection