Hi Level 49 is the last sub level and is used to declare identifiers for which we are not sure that what length they can occupy. For exapmle we have a filed NAME in our file and its length is 50 and we want that if name of a person is of 20 chars only rest 30 chars positions could be reused than to leave the space unused.EX. Say our Rec is01 EMP-REC 05 EMPID PIC X(10). 05 DEPT PIC X(20). 49 NAME PIC X(50). 49 ADDRESS PIC X(50). And if NAME is 'PRADEEP' i.e. using only 7 chars out of allocated 50 then the next field ADDRESS will start right from where the NAME filed ends instead of leaving the 43 positions unused.All Please advise me if I am wrong.pradeep
Yes It is used for VARCHAR type in a Copybook for a DB2 table but the logic is to implement the efficient space utilization which is provided in DB2 by VARCHAR against CHAR.
You "need" 49 levels to define host variables for VARCHAR cols in DB2. The 1st 49 contains the length of the string; the 2nd the string itself. To move the string you can use refmod or the STRING stmt eg.:
PS It's the creator's responsibility to populate vf-len when vf-data is populated. When the data is written to the DB2 table it will only occupy as many bytes as the vf-len indicates even though the PIC of the host variable may be larger.
Also note that there is no "space" fill when the col is loaded into vf-data. If vf-data was 5 bytes and conained "AAAAA" then you loaded the col containing "BB" the result would be "BBAAA"