Link to home
Create AccountLog in
Avatar of SaravananM
SaravananM

asked on

Issue With - Externally described Data structure in RPGLE

Hi,
I have a PF  (FILE1) with the following fields
PFFLD1   10S 0  (Zoned)
PFFLD2    5S  0 (Zoned)

And I have my RPGLE program using this file.
FFILE1 IF E   DISK

In my D Secification I am decalaring a variable using LIKE class as follows

D PGMFLD1   S            LIKE(PFFLD1)
D PGMFlD2    S            LIKE(PFFLD2)

If I compile this program, the PGMFLD* attributes should be ZONED, but they are created as PACKED. and If I add the followin Externally Described data Structure declaration as below to my program,  and compile the it, these PGMFLD* fields are defined as ZONED.

D DS_PFILE      E DS         EXTNAME(FILE1)

Can you tell me why? and how can I get rid of this? Meaning, in both the cases, I need the fields as ZONED not PACKED.

Thanks in advance.
Saravanan M
ASKER CERTIFIED SOLUTION
Avatar of daveslater
daveslater
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of mlaman
mlaman

The trick is in the OS...

OS 400 ALWAYS packs programmed defined fields.  The *like defining you are using will define the length of the field, but since it is a programmed defined field, the underpinnings will be Packed.  A zoned field in a database is always converted to packed, processed and then returned back to zone for database storage.  For those reasons, the best practice is always to pack your database fields.  If you do not need them packed (like phone numbers, zip codes, etc) then you should store the data as character.  Just a recommendation, though you can always do what fits your needs of course!

If you are wanting to zone the fields because of certain op codes you are wanting to use, I would recommend researching some of the slick bifs that will do the same a moves, etc.  Not sure why you need them zoned, just trying to speculate to complete the answer.
Avatar of SaravananM

ASKER

Hi,
Daveslater, thanks for the comment.
But Mlaman, my expectation is that, I need to declare a program variable as that of the one in my physical file. One way of achieving this is, using LIKE keyword.

Here my problem is that, I have a  ZONED field in my file. But if I use that field in LIKE statement, it defines the program varible as PACKED. And if I am going to declare the file as DATASTRUCTURE, then all the file fields and their attributes are copied to the datastructure as it is.

So, this is my problem.
Does it make sense?

Saravanan M
Hi Saravanan
simply declare the file as as DS

D DS_PFILE      E DS         EXTNAME(FILE1) Prefix(x)

then use this as the basis of the definition

D PGMFLD1   S            LIKE(xPFFLD1)
D PGMFlD2    S            LIKE(xPFFLD2)

Dave
Dave,

Thats what I have done.

But, this DS_PFILE declaration is unnecessary when I am using the file in my program. Right? I just wanted check is there any compilation parameters available to acheive this or alternate way of doing this.

Anyway thanks Dave and malman.

Saravanan M