ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

I know this is old but.......

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • I know this is old but.......

    I found this on "some" site and I actually didnt know a couple of
    these - for example the %dec and the %trim replacement characters...
    so I thought Id share with you..


    The following list describes the enhancements made to ILE RPG in V5R3:

    * New builtin function %SUBARR:

    New builtin function %SUBARR allows assignment to a sub-array or returning a
    sub-array as a value.

    Along with the existing %LOOKUP builtin function, this enhancements enables
    the implementation of dynamically sized arrays with a varying number of elements.

    %SUBARR(array : start) specifies array elements array(start) to the end of the array

    %SUBARR(array : start : num) specifies array elements array(start) to
    array(start + num - 1)

    Example:
    PHP Code:

              
    // Copy part of an array to another array: 
              
    resultArr = %subarr(array1:start:num);  

              
    // Copy part of an array to part of another array: 
              
    %subarr(Array1:x:y) = %subarr(Array2:m:n);  

              
    // Sort part of an array 
              
    sorta %subarr(Array3:x:y);  

              
    // Sum part of an array 
              
    sum = %xfoot(%subarr(Array4:x:y)); 
    * The SORTA operation code is enhanced to allow sorting of partial arrays.

    When %SUBARR is specified in factor 2, the sort only affects the partial array
    indicated by the %SUBARR builtin function.
    * Direct conversion of date/time/timestamp to numeric, using %DEC:

    %DEC is enhanced to allow the first parameter to be a date, time or timestamp,
    and the optional second parameter to specify the format of the resulting numeric value.

    Example:
    PHP Code:
              D numDdMmYy       s              6p 0 
              D date            s               d    datfmt
    (*jul)    
                  
    date D'2003-08-21'
                  
    numDdMmYy = %dec(date : *dmy); 
                  
    // now numDdMmYy = 210803 
    * Control specification CCSID(*CHAR : *JOBRUN) for correct conversion of
    character data at runtime:

    The Control specification CCSID keyword is enhanced to allow a first parameter
    of *CHAR. When the first parameter is *CHAR, the second parameter must be *JOBRUN.
    CCSID(*CHAR : *JOBRUN) controls the way character data is converted to UCS-2 at
    runtime. When CCSID(*CHAR:*JOBRUN) is specified, character data will be assumed
    to be in the job CCSID; when CCSID(*CHAR : *JOBRUN) is not specified, character
    data will be assumed to be in the mixed-byte CCSID related to the job CCSID.

    * Second parameter for %TRIM, %TRIMR and %TRIML indicating what characters to trim:

    %TRIM is enhanced to allow an optional second parameter giving the list of
    characters to be trimmed.

    Example:
    PHP Code:
              trimchars '*-.'
              
    data '***a-b-c-.' 
              
    result = %trim(data trimchars); 
              
    // now result = 'a-b-c'.  All * - and . were trimmed from the ends of the data 
    * New prototype option OPTIONS(*TRIM) to pass a trimmed parameter:

    When OPTIONS(*TRIM) is specified on a prototyped parameter, the data that
    is passed be trimmed of leading and trailing blanks. OPTIONS(*TRIM) is valid
    for character, UCS-2 and graphic parameters defined with CONST or VALUE. It
    is also valid for pointer parameters defined with OPTIONS(*STRING). With
    OPTIONS(*STRING : *TRIM), the passed data will be trimmed even if a
    pointer is passed on the call.

    Example:

    PHP Code:
          D proc            pr 
          D   parm1                        5a    
    const options(*trim
          
    D   parm2                        5a    const options(*trim : *rightadj
          
    D   parm3                        5a    const varying options(*trim
          
    D   parm4                         *    value options(*string : *trim
          
    D   parm5                         *    value options(*string : *trim)  
          
    D ptr             s               
          
    D data            s             10a 
          D fld1            s              5a   

              
    /free         
                      data 
    ' rst ' x'00';        
                      
    ptr = %addr(data);         

                      
    proc (' xyz ' ' @#$ ' ' 123 ' ' abc ' ptr);        
                      
    // the called procedure receives the following parameters        
                      //    parm1 = 'xyz  '        
                      //    parm2 = '  @#$'        
                      //    parm3 = '123'        
                      //    parm4 = a pointer to 'abc.' (where . is x'00')        
                      //    parm5 = a pointer to 'rst.' (where . is x'00') 
    * Support for 63 digit packed and zoned decimal values

    Packed and zoned data can be defined with up to 63 digits and 63 decimal positions.
    The previous limit was 31 digits.
    * Relaxation of the rules for using a result data structure for I/O to
    externally-described files and record formats

    o The result data structure for I/O to a record format may be an
    externally-described data structure.
    o A data structure may be specified in the result field for I/O
    to an externally-described file name for operation codes
    CHAIN, READ, READE, READP and READPE.

    Examples:
    1. The following program writes to a record format using from an externally-described data structure.
    PHP Code:

                Foutfile    o    e           k disk                                
                D outrecDs      e ds                  extname
    (outfileprefix(O_)   
                /
    free     
                        O_FLD1 
    'ABCDE';     
                        
    O_FLD2 7;            
                        
    write outrec outrecDs;                                                    
                        *
    inlr = *on;    
                /
    end-free         

             2. The following program reads from a multi
    -format logical file into 
                 data structure INPUT which contains two overlapping subfields 
                 holding the fields of the respective record formats
    .

                
    Flog       if   e           k disk    infds(infds)                 
                
    D infds           ds                                               
                D   recname             261    270                                         
                D input           ds                  qualified                    
                D   rec1                              likerec
    (rec1overlay(input
                
    D   rec2                              likerec(rec2overlay(input)  
                    /
    free                                                                 
                        read log input
    ;                                                    
                        
    dow not %eof(log);                                                    
                            
    dsply recname;                                                     
                            if 
    recname 'REC1';                                                  
                                
    // handle rec1                                                  
                            
    elseif recname 'REC2';                                              
                                
    // handle rec2                                                  
                            
    endif;                                                             
                            
    read log input;                                                 
                        
    enddo;             
                        *
    inlr = *on;    
                    /
    end-free 
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

  • #2
    Re: I know this is old but.......

    Many thanks this helped me to convert my ISO dates in my input file to numeric dates for screen display using edtcde(y). Are there any better alternatives to displaying ISO dates in a subfile list. Usually we want our dates to appear as 01/12/07 (DD/MM/YY)

    What is your best method of displaying dates on screen or do you do something different altogether?

    Comment


    • #3
      Re: I know this is old but.......

      this works date is an DATE type

      defined in d specs with a D instead of length
      PHP Code:
      d ISOdate         S               D 

      PHP Code:
      V5R2
           
      /free
             numDate 
      = %int(%char(date : *eur0);  //  ddmmyyyy
             
      numTS = %dec(%char(timestamp : *iso0) : 20 0);   //yyyymmddhhmmssuuuuuu
           
      /End Free
           
      --------------------------------------------------------------------------------
           
           
      V5R1
          
            H bnddir
      ('QC2LE')   
            
      D atoll           pr            20i 0 extproc('atoll')   
            
      D  string                         *   value options(*string)
            
           /
      free 
            numDate 
      atoll(%char(date : *eur0));
           /
      End Free 
      All my answers were extracted from the "Big Dummy's Guide to the As400"
      and I take no responsibility for any of them.

      www.code400.com

      Comment


      • #4
        Re: I know this is old but.......

        Thats cool I do not understand the following code ie the atoll procedure ...

        Code:
             V5R1
            
              H bnddir('QC2LE')   
              D atoll           pr            20i 0 extproc('atoll')   
              D  string                         *   value options(*string)
              
             /free 
              numDate = atoll(%char(date : *eur0));
             /End Free
        I am trying to display a db field defined as type L so the date data looks like 0001-01-01 when not set ie null. I'd like to reformat the date to xx/yy/zzz for the screen output. So I am now using ...

        Code:
        c                   if        c2tfdt <> *loval          
        c                   eval      s#tfdt = %dec(c2tfdt:*dmy)
        c                   else                                
        c                   eval      s#tfdt = 0                
        c                   endif                               
        c                   if        c2ldat <> *loval          
        c                   eval      s#ldat = %dec(c2ldat:*dmy)
        c                   else                                
        c                   eval      s#ldat = 0                
        c                   endif
        So I get dates displaying as 0/00/00 on screen when *loval date data is processed. I would like to have the screen display blank when null or formatted so the leading zero is not dropped. Maybe a char field in my subfile and use %editw?

        Thanks Jamie

        Comment


        • #5
          Re: I know this is old but.......

          Instead of EVAL S#ldat = 0, shouldn't you use EVAL s#ldate = 00010101. Actually better yet, I would define the DDS field as a char field, and do the editing in the RPG code.

          What release are you on ?

          Also, remember that *loval in *iso format is 0001-01-01, but in *dmy its 31/12/40

          Comment


          • #6
            Re: I know this is old but.......

            I think doing the date edit in the rpg is good solution then i can output blank string for the zero dates thanks very much

            Comment

            Working...
            X