Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PF format with data stamp

Status
Not open for further replies.

George221

MIS
Dec 2, 2005
50
US
I'm trying to create a Physical file through DDS (not SQL) that would stamp a field with the current date in the format YYYYMMDD and store it this way. I'm able to get the format with the dashes in between year, month and day with the DATFMT keyword but do not want it this way. Would like a field length of 8, not 10.
Does anyone know if this is possible?
Thanks.
 
George221 said:
Would like a field length of 8, not 10.
Does anyone know if this is possible?
Only if you store them as numeric, not as dates. But it does not matter. i5/OS stores dates internally as 4-byte binary. It just displays them as 10-character dates (with separators). In reality, you can, in your programs, display them any way you want.

When defining a date field, you must have a date separator:

DATSEP (Date Separator) keyword for physical and logical files

IBM DDS Manual said:
For physical files, if you do not specify the DATSEP keyword, the default is the job attribute.

Solum potestis prohibere ignes silvarum.

 
Only if you store them as numeric"

Can you show an example of how the physical file would automatically generate a date stamp with a field like this?
 
It's the weekend and I don't have access to a machine right now, but you code it in DDS as a type L (date). If you don't specify a format with the DATFMT keyword, it will default to *ISO (2007-12-22).

Now, in RPG, if you want to display the date without the separators, you can do this:

displaydate = %char(ddsdate:*iso0);

The zero means "don't use a separator".

But as I said, you cannot store a native date without a separator. But that should not concern you. Under the covers, it's a 4-byte binary integer.

What, exactly, are you trying to accomplish?

Solum potestis prohibere ignes silvarum.

 
George221,

Making a field as a date data type does not "stamp" the record with the current date like SQL does with the timestamp data type. If you don't move the date into the date field, it will default to 0001-01-01, the date's low value.


 
Tcsbiz,
If I insert a record using SQL, it will automatically stamp that date field with the current date (without specifying a value or function for that field on the insert statment), now if I write that record using RPG, you are right, it defaults to 0001-01-01.
How should I define the DDS then to get this date field automatically populated when I write records through RPG?
Thanks.
 
Why not just do that in RPG?

TimeStampField = %timestamp();

Solum potestis prohibere ignes silvarum.

 
George221 said:
How should I define the DDS then to get this date field automatically populated when I write records through RPG?
You cant do it straight. To do so, you can utilize one of the options below :
- use SQL to create the date field as DATE NOT NULL WITH DEFAULT current date.
- populate the date field using the default %date() or %timestamp() function value in the RPG program.
- create the date field MyDate thru DDS (type L or Z) then give it the current date or current timestamp default value thru ALTER statement, that is
Code:
ALTER TABLE ... ALTER COLUMN [i]MyDate[/i] SET DATA TYPE 
DATE NOT NULL WITH DEFAULT [b]current date[/b]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top