How to convert date format from one format to another in RPG/400?

470 pts.
Tags:
AS/400
AS/400 date format
RPG/400
V5R3
how to convert date format from one format to another i think in CL/400 its CVTDAT,Please tell in RPG/400 sir not in RPGILE

Software/Hardware used:
v5r3

Answer Wiki

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

If you want to validate a date in RPG/400, you write your own routine to do it. You parse the value and decide if each segment is valid according to the format that your program expects.

There is no special handling of dates in RPG/400. The coding is completely up to you.

Alternatively, you can go outside of RPG and call the <a href=”http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/qwccvtdt.htm”>Convert Date and Time Format (QWCCVTDT) API</a> to attempt a conversion of a temporary variable. If you don’t receive an error, then the date is valid.

Overall, it’s easier to use RPG IV.

Tom

Discuss This Question: 20  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
  • Kaly
    when a date format is entered by user how to Check whether it is a valid date type or not,please give the coding for this in RPG/400 and CL/400 i'm new to AS/400 please help
    470 pointsBadges:
    report
  • Kaly
    how to convert date format from one format to another i think in CL/400 its CVTDAT,Please tell in RPG/400 sir not in RPGILE
    470 pointsBadges:
    report
  • WoodEngineer
    Try the TEST op code. IBM RPG manual sayd, "The TEST operation code allows users to test the validity of date, time, or timestamp fields prior to using them." It has been around a long time. In fact, it works just fine in fixed format.
    6,530 pointsBadges:
    report
  • TomLiotta
    Try the TEST op code. IBM RPG manual says... Which RPG manual? My RPG/400 manual doesn't list a TEST op-code. SEU marks it as an error at V5R4. Keep in mind that this is RPG/400, not RPG IV. Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    Tom's answer - API sounds great In the not so long ago days, we would create two data structures with I specs. Each with subfields for the date parts, month, year, day, century Then move the input month field to the output .. same for day, year, and then populate the century ( if you need it) Test the fields in the data structure -- month between 1 and 12, day >= 1 and less than .. well that depends on the month and year. And in the older days we would multiply the date by 10000.01 to change MDY to YMD! And remember none of these are required for RPGIV or RPGLE just for RPG/400 Phil
    49,850 pointsBadges:
    report
  • slateken
    Sounds like you need to validate AND convert a date? As far as the conversion part goes, you might want to look into data structures for manipulating the date into the format(s) you desire.
    230 pointsBadges:
    report
  • Kaly
    thanks everyone for answering for converting date format we can use data structure only in RPG400 ah OK,for testing a date validating purpose is there any opcode like TEST or TESTD in ILE
    470 pointsBadges:
    report
  • TomLiotta
    ...is there any opcode like TEST or TESTD in ILE Yes, and it can be found in the ILE RPG Reference manual, just like everything else. The TEST (Test Date/Time/Timestamp) op-code can be used. Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    You can use the data structures in RPG/400 or RPGLE but RPGLE has much better ways to validate (test) and convert the dates. Phil
    49,850 pointsBadges:
    report
  • WoodEngineer
    Regarding the question of which RPG manual details the Test op code. I am referning to ILE RPG Language Reference, Version 5 (SC09-2508-06), Seventh Edition (Feb 2006), page 781 where it documents the TEST op code in both fixed and free formats. This is quoted from one of the first pages of that manual: "This edition applies to Version 5, Release 4, Modification Level 0, of IBM® WebSphere® Development Studio for iSeries (5722-WDS), ILE RPG compiler, and to all subsequent releases and modifications until otherwise indicated in new editions. This edition applies only to reduced instruction set computer (RISC) systems." We are running V5R4M0. SEU allows the TEST op code plus shows it when we press F1 on the op code field when prompting a C spec. TEST has been around for a long time. My first recollection of using it was on a V3R1 box.
    6,530 pointsBadges:
    report
  • WoodEngineer
    Tom, your reply got me wondering about RPG/400. I finally found an old manual. As you wrote, the TEST op code is not listed in that manual. Now I was really wondering if my memory had gone south. After searching old source code on our machine I found this example. Notice the dates on the lines of code:
    C     *MDY          TEST(D)                 $MDY_LEG               99                               990825
                                                                                                        990805
     * If a valid date was entered then *IN99 will be off.                                              990805
                                                                                                        990805
    C                   IF        NOT *IN99                                                             990805
                                                                                                        990805
    
    I think our compadre should be able to use TEST.
    6,530 pointsBadges:
    report
  • TomLiotta
    @WoodEngineer: It sounded plenty familiar and reasonable when I read your first post, so I looked to see what the exact syntax was -- I haven't used RPG/400 this century. I was a bit surprised when I didn't find it, and I really wanted to know where you found the documentation. I'd like to see it referenced in answers for later use. Then again, ILE RPG (RPG IV) has been around for so long that maybe it just seemed familiar from memories of going on a couple decades back. Very strange that it's seemed to disappear from the manuals -- and that no one seems to have complained before! That might be a useful example to keep in mind about whether IBM has any intention of paying attention to RPG/400. If any argument can be made to get away from RPG/400 ASAP, that's gotta be the one. Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    @WoodEngineer: BTW, did you try prompting the TEST(D) line in SEU? The lines that you posted aren't in RPG/400 format -- they're RPG IV (ILE RPG). Tom
    125,585 pointsBadges:
    report
  • WoodEngineer
    Good point about testing SEU. A few minutes ago I tested this line of code in SEU:
     C     *YMD          TEST(D)                 Ary60P(X)              70           
    
    No errors when I prompted the line of code. While still in prompt mode I changed *YMD to *YMDX for force an error. SUE displayed an error regarding *YMDX. I removed the X, returning the value to *YMD and the error cleared. Next I placed the cursor in the op code field and pressed help. Results were:
                         Operation and Extender - Help                       
                                                                             
        SUBST {(P | E)} (Substring)                                          
        TAG (Tag)                                                            
        TEST {(D | T | Z | E)} (Test Date/Time/Timestamp)                    
        TESTB (Test Bit)                                                     
        TESTN (Test Numeric)                                                 
        TESTZ (Test Zone)                                                    
        TIME (Time of Day)                                                   
        UNLOCK {(E)} (Unlock a Data Area or Release a Record)                
                                                                     More... 
    F2=Extended help   F3=Exit help   F10=Move to top   F11=Search Index     
    F12=Cancel   F13=Information Assistant   F14=Print help   F20=Enlarge
    
    As a final test I compiled the program. No errors. Maybe it was just an oversight when IBM did not list TEST in the prior manual.
    6,530 pointsBadges:
    report
  • philpl1jb
    RPG/400 - member type is RPG - TEST(D) could not have been an RPG/400 command because the op-code area was limited to 5 characters. Older format but so am I. RPG/IV - member type is RPGLE or SQLRPGLE can include fixed format and free format and TEST is a valid operation in RPG/IV. Everyone but Bob Kozzi calls this RPGLE. Phil
    49,850 pointsBadges:
    report
  • TomLiotta
    Good point about testing SEU. And the member type is "RPG" rather than "RPGLE"? If it is "RPG", what parameters are you using for the STRSERU command? A "RPG" source member should cause an error in SEU if you use the TEST op-code. But if you override the TYPE() parameter on the STRSEU command, you can get SEU to accept it. But then you'd also need to override the compiler to invoke the ILE RPG compiler. Regardless, the resulting program object won't be RPG/400. Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    RPG/400 uses the RPG III compiler. As Phil rightly notes, the op-code column only allowed 5 spaces. It also did not allow extenders in the op-code columns -- they were in a separate column, position 53, and only include H, N and P (no "D"). ILE RPG uses the RPG IV compiler. An expanded set of op-codes along with a 10-character area (in fixed-format) that allowed for extenders in the op-code field were characteristics of RPG IV. So far, the example code is ILE RPG rather than RPG/400. Tom
    125,585 pointsBadges:
    report
  • WoodEngineer
    As suspected, the example I sent was RPGLE. As soon as I flipped the member type to RPG, SEU did not like the code nor did it offer TEST as an op code. Wow! It really has been a long time since I worked in RPG/400! ;-)
    6,530 pointsBadges:
    report
  • TomLiotta
    ...a long time since I worked in RPG/400! Me, too. I can't grasp why anyone still uses it. I would convert to RPG IV immediately if confronted with RPG/400, and I'd spend the time that I saved by cleaning up the old code. Tom
    125,585 pointsBadges:
    report
  • Kaly
    [...] How to convert date format from one format to another in RPG/400? [...]
    0 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