Test for date in *DMY format in RPGLE

2505 pts.
Tags:
AS/400
I have a file field(InpDate) which is of length 6A. It is assumed to have value in ddmmyy format. I am extracting the day month and year part of it using Day = %Dec(%Subst(InpDate:1:2):2:0) Month = %Dec(%Subst(InpDate:3:2):2:0) Year = %Dec(%Subst(InpDate:4:2):2:0) Since am doing a %Dec, I want to test whether the InpDate field has valid value. But I am not able to use Test(DE) opcode on a DMY format(ie ddmmyy). Can anyone help me to reach my goal.?

Answer Wiki

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

Hi,

I try to test using the TEST opcode, but even for valid date value Indicator and %error sets on. please assist.

D datevalid       S              8A   inz('20131225')    
D dateINVAlid     S              8A   inz('99999999')    
 *                                                                      
 /free                                                                  
  test(DE) *ymd0  datevalid;                                            
  if %error() ;                                                         
     dsply 'Error!' ;                                                   
  endif ;                                                               
 /end-free                                                              
 *                                                                      
C     *YMD          TEST(D)                 datevalid              44   
C  N44'valid'       dsply                                               
C     *YMD          TEST(D)                 dateINVAlid            55    
C 55'INVALID' dsply

Discuss This Question: 5  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
  • philpl1jb
    This might be something
    Monitor;
      Mydate =  %date(string:*MDY0);
      Month  = %subdt(Mydate:*Month);
      Year   = %subdt(Mydate:*Year);
      Day    = %subdt(Mydate:*Days);
    On-Error;
      do stuff
    EndMon;
    
    
    
    
    49,730 pointsBadges:
    report
  • philpl1jb
    revise you have a character string in DMY order then use: Mydate =  %date(string:*DMY0);<BR>
    49,730 pointsBadges:
    report
  • TomLiotta
    If there is only a need to do the test, it can be tested fairly directly. No need to extract the parts:
    test(DE) *dmy0  @charD ;
    if %error() ;
       dsply 'Error!' ;
    endif ;
    Tom
    125,585 pointsBadges:
    report
  • TomLiotta

    I try to test using the TEST opcode, but even for valid date value Indicator and %error sets on. please assist.

    D datevalid       S              8A   inz('20131225')    
    D dateINVAlid     S              8A   inz('99999999')    
     *                                                                      
     /free                                                                  
      test(DE) *ymd0  datevalid;                                            
      if %error() ;                                                         
         dsply 'Error!' ;                                                   
      endif ;                                                               
     /end-free                                                              
     *                                                                      
    C     *YMD          TEST(D)                 datevalid              44   
    C  N44'valid'       dsply                                               
    C     *YMD          TEST(D)                 dateINVAlid            55    
    C 55'INVALID' dsply

    According to your date format (*YMD), you don't have any valid dates to test. The *YMD format expects 2-digit years.

    Tom

    125,585 pointsBadges:
    report
  • BigKat
    you should use *iso0 for a value like '20131225'
    8,060 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