简体   繁体   中英

RPG - passing DS as arguments to procedure

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)
  1. You're moving all ds-data from old to new ds.
  2. You're setting a subfield of the new ds. I bet you myfield is char(8), so you're just changing the first 8 bytes of the new ds.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM