CL date extraction in AS/400

635 pts.
Tags:
AS/400
AS/400 commands
CL Commands
CL Program
I want to take out date value from today to last 7 days in CL command. Kindly help
ASKED: January 6, 2011  11:02 AM
UPDATED: January 7, 2011  12:20 AM

Answer Wiki

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

There is not an IBM supplied CL command to do what you are asking.
If you have TAATOOLS library you can use the ADDDAT command.
There are other free tools available on the web you could download.
Here is a link to one site and at the bottom of the page for this list is a list of many more.

http://www.help400.de/Eng/Freeware.htm

Discuss This Question: 1  Reply

 
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
  • TomLiotta
    Here's a basic ILE CL proc that subtracts 7 days from current date and returns the result in MMDDYY format:
    pgm    ( +
             &RtnVal      +
           )
    
       dcl   &RtnVal        *char   10
    
    
       dcl   &FirstDate     *char    6
       dcl   &RtnVal1       *int
    
       dcl   &PicStr        *char   10   value( 'MMDDYY' )
    
    
       chgvar          &RtnVal            ( '*ERROR' )
    
       rtvsysval   QDATE  rtnvar( &FirstDate )
    
    
       callprc      CEEDAYS      ( +
                                   &FirstDate     +
                                   &PicStr        +
                                   &RtnVal1       +
                                   *omit          +
                                 )
    
       chgvar          &RtnVal1           ( &RtnVal1 - 7 )
    
       callprc      CEEDATE      ( +
                                   &RtnVal1       +
                                   &PicStr        +
                                   &RtnVal        +
                                   *omit          +
                                 )
    
       return
    
    endpgm
    Or this REXX proc subtracts 7 days from current date and stores the result in the *LDA in *ISO format:
     /* REXX to subtract 7 days for CL... */
    
     signal on error name command_error
     signal on failure name command_error
     signal on syntax name syntax_error
    
        PRVDATE = '0001-01-01'
    
        'execsql ',
             'SET OPTION DATFMT = *ISO   '
    
        sql_Stmt = ,
                'select CHAR(DATE(CURRENT_DATE -  7 DAYS))      ',
                '    from sysibm/sysdummy1                      '
    
        'execsql ',
             'PREPARE S1 FROM :sql_Stmt '
        'execsql ',
             'DECLARE C1 CURSOR FOR S1'
        'execsql ',
             'OPEN C1 '
    
        'execsql ',
               'FETCH C1 INTO :PRVDATE'
    
        'execsql ',
              'CLOSE C1'
    
     /* Send out value to CL... */
    
        address COMMAND ,
                'CHGDTAARA DTAARA(*LDA) VALUE('''PRVDATE''')      '
    
     exit
    
     /* ---------------------------------------------------------------- */
     command_error:
    
            trace off
    
            parse source system start srcmbr srcfile srclib
            say 'Unexpected error at line 'sigl' of REXX program ',
                srcmbr' in 'srclib'/'srcfile'. The exception ID is 'rc'.'
    
     exit(right(rc,4))
     /* ---------------------------------------------------------------- */
     syntax_error:
    
            trace off
    
            parse source system start srcmbr srcfile srclib
            say 'Syntax error at line 'sigl' of REXX program ',
                srcmbr' in 'srclib'/'srcfile'. The error code is 'rc'.',
                ' The description is :'
            say errortext(rc)
    
     exit(rc)
    Call that proc in CL with this command:
    STRREXPRC SRCMBR( sub7days ) SRCFILE( mylib/QREXSRC ) CMDENV(*EXECSQL)
    Retrieve the date with the RTVDTAARA command after calling the REXX proc. 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