PDA

View Full Version : Variable Length fields



Guest.Visitor
01-01-1995, 02:00 AM
We are beginning to use the AS400 as our data source for Intranet Applications. I have a need to use variable length fields for a text field. The text can be as small in size as 100 characters or as large as 30,000 characters. If I define the field as fixed length of 30,000 then I waste much disk space! On the as400 does creating a variable length field allocate the space required for the actual number of characters in the field? Is there a formula in calculating disk space for a variable length field? Are there problems in using a variable length fields? Thanks, Bob

Guest.Visitor
07-05-2000, 04:37 PM
Hello Bob, I am not sure about COBOL, but if you are going to use RPG, you can use variable length fields. You will define your field with a length of 30000 since that is the maximum you will need, but you will use the VARYING keyword and optionally the INZ keyword to tell define the field as variable length and initialize it to something. The following is a code example. D VarField s 30000 Varying D Inz('Test') This code will define VarField as a variable length field and initialize it to 'Test'. The field is now only 4 bytes in length. You can use the Inz keyword in the D specs to set the length as well as the following operation codes: Eval, Dsply, Clear (which sets the length to 0), and Parm. The following will not change the length: Move, Movel, Cat, Subst,and Xlate. You can also read data from a file into a variable field to change the length, use the "blank after" function in an O spec to change the length to 0 and use the %LEN built-in function to change the length. Hope this helps a little, let me know if you have any other questions. Kevin Vandever kvandever@nexsource.com

D.Handy
07-05-2000, 04:46 PM
Bob, <font color=blue>On the as400 does creating a variable length field allocate the space required for the actual number of characters in the field?</font> The allocated length depends on how you define the field. In DDS, you specify the maximum length (eg 30K in your case) in the length column, then add the keyword <font color=blue>VARLEN( allocated length )</font> to specify how much should be allocated for each record. <font color=blue>Are there problems in using a variable length fields? </font> The AS/400 implementation reserves the allocated length within each PF record. Records with data longer than this (and up to the maximum defined length) get the excess stored in an overflow area. Writing to, and reading from, this overflow area is inherently less efficient than records which do not need the overflow area. As a rule of thumb, I've heard you should strive for around 90% of the records to fit within the allocated length. In other words, specify a VARLEN() value such that most records will have the data stored with the rest of the PF record. Then let the overflow area handle the extreme cases. If using RPG prior to V4Rx (4?), you will want to specify the CVTOPT(*VARCHAR) option on the compile. This makes the field visible to RPG as a fixed length field of the maximum DDS size, plus a 2-byte binary prefix with the current length. With RPG IV starting in V4Rx (4?), if you do not specify CVTOPT(*VARCHAR) then the field will be a varying length field in the RPG program. Doug