How can you add some fields to an existing PE group? The PE also exists in the "middle" of the file. After reading the utilities manual (version 5.2), it looks like ADACMP decompress with a format parameter may be useful, but you can't find any examples.
There may be a way to do this with without using the FORMAT parm.
If you answered "YES" to (1) and (3) there may be an easier way to do this. For example, if your PE looks like this:
ADACMP FNDEF='01,S6,PE' ADACMP FNDEF='02,S7,2,A,NU' ADACMP FNDEF='02,S8,30,A,NU' ADACMP FNDEF='02,S9,5,U,NU'
If you want to add a 20 byte alpha field then:
change the length of S7 to 22 using ADADBS/SYSAOS decompress file change your PE to look like this:
ADACMP FNDEF='01,S6,PE' ADACMP FNDEF='02,S7,2,A,NU' ADACMP FNDEF='02,NF,20,A,NU' ADACMP FNDEF='02,S8,30,A,NU' ADACMP FNDEF='02,S9,5,U,NU'
compress and load the file
If you want to add a 5 byte unpacked field then:
change the length of S9 to 10 using ADADBS/SYSAOS decompress file change your PE to look like this:
ADACMP FNDEF='01,S6,PE' ADACMP FNDEF='02,S7,2,A,NU' ADACMP FNDEF='02,S8,30,A,NU' ADACMP FNDEF='02,NF,5,U,NU' ADACMP FNDEF='02,S9,5,U,NU'
compress and load the file
If the numeric fields in your PE are Packed or you want to add Packed fields then the easiest thing to do is to use the FORMAT statement unless you use a technique similar to above *AND* then write a program to update the additional bytes in the decompressed record with valid packed values.
For example if you change a 5 byte packed field to a 10 byte packed field so you can add a new 5 byte packed field, the decompressed data will look like (assuming the value was 0)
To compress this as two 5 byte packed fields you would need to change the field to
Some companies use the ADACMP with the FORMAT parameter all the time to reformate their files. For a better performance (format translations = CPU time) sometimes it is better to add the fields to the middle or at the beginning of a record. Also, it is good to delete no longer used fields.
The ADABAS V6.1 Utilities Manual Volume I, it is on page 75. Look at examples 2 and 3.
Other companies do not like to use ADACMP with the format parameter, since Treehouse has an excellent solution. Their ADAREORG is the tool, allows you to do just about any reformatting of a file that you may want.
For the sake of completeness, and depending on your file sizes, another company had needed another method as a "work around".
A while back they had one file that was large and they could not afford the outage to add a field in the middle of the PE. Instead they added another PE with the single required field at the end of the record. It can be treated the same as the normal fields in the PE (except for group references). While it is not as easy for programmers to identify, it has served their purpose.
Another option is to write two Natural programs, one to read the file and write the records off to a sequential file and one to read the sequential file and use MOVE BY NAME to repopulate the data to the file. In between running the two programs you delete the file and rebuild it in the new format.
I personally prefer the ADACMP FORMAT method, especially if I am dealing with a lot of data, but sometimes the programatic method is easier, a DBA reported.
One disadvantage to using a program to do the 'unload' is that the file must be unlocked while the program is running. I like to lock the files for utility usage and ADACMP FORMAT allows me to unload while locked. That way no other updates can occur to the records that have been unloaded.
Similar to answer 2 but more detailed is the way Sheldon Gullason from CO-OP Canada reported.
ADACMP DECOMPRESS ADACMP FORMAT='DT,AB,CH,AC,AD,BB,BC,BD,BE,BF,BG,BH,BI,ZA,ZB,AQ,ZC' ADACMP FORMAT='AXC,AX1-N,TDC,TD1-N,TEC,TE1-N,CPC,CP1-N,EB,EC,ED.'
The counter bytes are needed preceding the PE/MU shortnames.
This next example is of a DECOMPRESS FORMAT where the new field is added to the PE:
ADACMP DECOMPRESS ADACMP FORMAT='AA,CC,AB,AC,AD,BK,AE,AF,AG,AH,AI,BI,AJ,AK,AL,AM,AN' ADACMP FORMAT='BE,BF,BG,BN,BO,BP,BQ,BR,BS,BL,CE,PAC,PA1-N,BX1,BY1' ADACMP FORMAT=',BZ1,CA1,CB1,BM,CD,BX2,BY2,BZ2,CA2,CB2,BM,CD,BX3,' ADACMP FORMAT='BY3,BZ3,CA3,CB3,BM,CD,BX4,BY4,BZ4,CA4,CB4,BM,CD.'
This is where knowing your data can really help. Both the fields BM and CD were new fields that were at the end of the file. In this example I will only build the new file with 4 occurrences of the PE, this also needs to be specified in your ADACMP COMPRESS cards. These new fields do not need to have an occurrence number associated with them, also the shortname and counter byte of the modified PE are not needed; they too will get added in the ADACMP COMPRESS cards.
ADACMP FNDEF='01,PB,PE(4)' ADACMP FNDEF='02,BX,8,U,NU' ADACMP FNDEF='02,BY,2,U,NU' ADACMP FNDEF='02,BZ,5,P,NU' ADACMP FNDEF='02,CA,2,U,NU' ADACMP FNDEF='02,CB,5,P,NU' ADACMP FNDEF='02,BM,5,P,NU' ADACMP FNDEF='02,CD,5,P,NU'
I always string out the PE's to the maximum, but it is not always necessary. If there is a MAXPE191 in the ADAWAN cards, then I take the PE down to 191 occurrences otherwise I just do 99. If you know there are only 4 occurrences of data in the PE though, you can only do it 4 times like in the example.
This also works great if your deleting fields too, you simply don't include them in the DECOMPRESS FORMAT layout. You can also move existing fields to anywhere you want them as well. So if your most used fields change, you can move them to the top as need be.
Sheldon Gullason wrote a utility in NATURAL that builds all the DECOMPRESS FORMAT data based on how they set it up in PREDICT, then just feed this file into the DECOMPRESS step. Drop him a line if you need more info E-mail