Timestamp Data Type

pts.
Tags:
RPG
Hi I am writing an RPG400 program which is populating a file, this file has one field in it defined as a TIMESTAMP field of 26 long. How do i populate this field with RPG400, everything i have tried so far has failed. Thanks in advance for any help

Answer Wiki

Thanks. We'll let you know when a new response is added.

As far as I know RPG400 doesn’t handle date, time and timestamp data types, you would have to use RPG IV. Is there any reason why you can’t create an RPG IV program to populate the file?

If not, you can create the following RPG IV program to do the move for you:

D iCharStamp s 26a
D oTimeStamp s z

D TimeStamp ds
D wTimeStamp z

C *Entry PList
C Parm iCharStamp
C Parm oTimeStamp

C Eval TimeStamp = iCharStamp
C Eval oTimeStamp = wTimeStamp
C Return

Create the program with a source type of RPGLE and compile using option 14 (CRTBNDRPG) in PDM. Call the program passing a character version of the timestamp you want to use in the format “YYYY-MM-DD-hh.mm.ss.nnnnnn” and the database field you want updated as the second parameter.

Hope it helps

Jonathan
www.astradyne-uk.com

Discuss This Question: 10  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Gilly400
    Hi, It should also be possible to use embedded SQL to do a 'SET' of your timestamp field. Assuming you have a date field called NUMDAT which is numeric 8,0 in the form of CCYYMMDD (Century/Year/Month/Date) and a time field called NUMTIM which is also numeric 6,0 in the form of HHMMSS. Where DATTIM is your 26 long timestamp field. SET :DATTIM = ( SUBSTRING(DIGITS(:NUMDAT), 1, 4) || '-' || SUBSTRING(DIGITS(:NUMDAT), 5, 2) || '-' || SUBSTRING(DIGITS(:NUMDAT), 7, 2) || '-' || SUBSTRING(DIGITS(:NUMTIM), 1, 2) || '.' || SUBSTRING(DIGITS(:NUMTIM), 3, 2) || '.' || SUBSTRING(DIGITS(:NUMTIM), 5, 2) || '.' || '000000') If NUMDAT is today 20060922 and NUMTIM is 142559 then you should get :- 2006-09-22-14.25.59.000000 Year-Month-Date-Hours.Minutes.Seconds.000000 I'm not sure whether the separators '-' and '.' are always the same. What you can try is UPDDTA on your file - in entry mode the default format should be shown. Of course you can simplify this if your program variables are character, then you can remove the digits functions. Hope this helps. Gilly.
    23,730 pointsBadges:
    report
  • Kkings
    The way we handle this in RPG/400 is by using a Program Status Data Structure. By default, this DS holds a lot of the "machine info" about a program. The date of when the program started running is in positions 276-281; the time is in positions 282-287. Here's how we access it: I SDS I 254 263 USER C TIME TIMETP 60 If you have access to the RPG/400 Reference book, this is described in section 2.5 or you might can find it in the IBM Redbooks online. Hope this help, Kenya
    0 pointsBadges:
    report
  • WickedWoman
    If the file field is defined as a timestamp (Z) and RPG400 does not recognize a timestamp I don't see how you can update the field. Seems that the file would complain if you tried to put an alpha field into a field that the system knows is not alpha. Why don't you live dangerously and convert your program to RPG IV? Create a source file QRPGLESRC, give it a longer record length (I use 127) and use the convert RPG source (CVTRPGSRC command. This will provide you with a duplicate of your program to which you can easily add timestamp processing -- and it will give you a quick lesson in modernizing your code.
    0 pointsBadges:
    report
  • SteveCCNJ
    Why not just use straight SQL? Make the pgm SQLRPGLE. In addition to whatever else you are updating, on update(or insert) you could do: C/EXEC SQL C+ UPDATE TheFile C+ set TSFld = CURRENT TIMESTAMP C+ WHERE KeyFld = :KeyFld C/END-EXEC Retrieval is also simple, and can use BIF's not otherwise available, as in: C/EXEC SQL C+ SELECT DATE(TSFld) INTO :DtFld C+ FROM TheFile C+ WHERE KeyFld = :KeyFld C/END-EXEC Or this: C/EXEC SQL C+ SELECT DAYOFWEEK(TSFld) INTO :WkDay C+ FROM TheFile C+ WHERE KeyFld = :KeyFld C/END-EXEC
    0 pointsBadges:
    report
  • astradyne
    The trouble with all of these answers (including my own earlier) is that you end up using RPG IV, with or without embedded SQL. If the original poster, Hazermark, has to resort to creating an SQLRPGLE program then he may as well just stick to using straight forward RPGLE. I accept that embedded SQL has its place and use it myself when necessary, but I don't think that this situation would be the right place to use it. Just my two cents worth. Jonathan
    370 pointsBadges:
    report
  • SteveCCNJ
    "I accept that embedded SQL has its place and use it myself when necessary, but I don't think that this situation would be the right place to use it." Well, the difference for me is that I do everything in embedded SQL and only resort to RPG file I/O operations when forced to at gun point. Just 2 more cents..... /grin/
    0 pointsBadges:
    report
  • Gilly400
    Hi, Embedded SQL can also be used in an OPM RPG program (SQLRPG), it's not absolutely necesary to use ILE (SQLRPGLE). Cheers, Gilly400.
    23,730 pointsBadges:
    report
  • astradyne
    Gilly400, I never knew that, I always thought it was only available through RPG IV/ILE. Just shows, you're never too old to learn. Thanks JOnathan
    370 pointsBadges:
    report
  • BobbyS40
    I never had problems with timestamp - just treat as an alphanumeric field. Easiest way to get timestamp would be to make an RPGLE program with one parm and use the %timestamp bif
    10 pointsBadges:
    report
  • TomLiotta
    I can't imagine why anyone would be trying to use RPG/400 when ILE RPG is available. However, you might review the CRTRPGPGM CVTOPT(*DATETIME) parameter value when compiling. The help text gives a basic explanation. See the Chapter 10 subtopic in the RPG/400 User Guide titled 'Date, Time, and Timestamp Fields'. Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following