I wrote a copybook (/COPY) procedure that has this interface:
DCL-PI *N VARCHAR(5000);
FILE_NAME CHAR(10) CONST;
DS_OLD VARCHAR(5000) CONST;
DS_NEW VARCHAR(5000) CONST;
END-PI;
This procedure is called by this sample program. FILE_DS_* are external DS with PFFILE definition.
EXEC SQL SELECT * INTO :FILE_DS_OLD FROM PFFILE FETCH FIRST 1 ROW ONLY;
FILE_DS_NEW = FILE_DS_OLD;
FILE_DS_NEW.MYFIELD = 'MODIFIED';
RESULT = MYPROC('PFFILE':FILE_DS_OLD:FILE_DS_NEW);
The field I'm modifying is defined as VARCHAR and its original value is, for example:
'PEN IS ON THE TABLE'
Strange thing is that at the entry point of the procedure I've got this value on the FILE_DS_NEW DS:
'MODIFIEDN THE TABLE'
I went mad but couldn't find why! Any idea?
How DS are defined:
D FILE_DS_OLD E DS EXTNAME(PFFILE) QUALIFIED INZ
D FILE_DS_NEW E DS EXTNAME(PFFILE) QUALIFIED INZ
FILE_DS_NEW = FILE_DS_OLD; (1)
FILE_DS_NEW.MYFIELD = 'MODIFIED'; (2)
I'm guessing you're confused about the varchar. Varchar data type is just a way to save data just to the limit of the field. This means if you have a varchar(10) and just 'DATA' this field is using only 6 bytes. If you change it to varchar(1000) the field will be still using just 6 bytes.
I hope this helps.