Tuesday, 2 January 2018

%DECH Example

      * 
      * Description :·%DecH() Example
      *
      * Syntex      :
      *
      * %DecH(Numeric Expression : Precision : Decimal Places)
      *
      * Function    :·Return Packed decimal value for given numeric
      *               expression with half adjusted decimal value.
      *
      * Output      :·Packed Decimal Value of first parameter
      *
      * Note        :·No msg will be issued if unable to convert in
      *               desired precision
      *==========================================================
      *
     D ZonedDec        S              5S 3 Inz(10.123)
     D FloatDec        S              8F   Inz(123.45678)
     D PackedDec       S             15P 5

     C
      /Free

           PackedDec = %DecH(ZonedDec : 5 : 2) ;
           Dsply %Char(PackedDec) ;              // 10.12000

           PackedDec = %DecH(FloatDec : 5 : 2) ;
           Dsply %Char(PackedDec) ;              // 123.46000

      /End-Free
     C                   SetOn                                        LR

Monday, 1 January 2018

%Days Example

      * Program     :·DaysR
      * Description :·%Days() Example
      *
      * %Days(Input)
      *
      * Input       :·No. of Days
      *
      * Output      :·Days as a duration
      *==========================================================
      *
     D TodayDate       S               D   Datfmt(*USA)
     D TomorrowDate    S               D   Datfmt(*USA)

     C
      /Free
        // ------------------------------------------------------
        // Date from integer
        // ======================================================

           TodayDate = %Date() ;
           Dsply TodayDate ;

           TomorrowDate = TodayDate + %Days(1) ;
           Dsply TomorrowDate ;

      /End-Free
     C                   SetOn                                        LR

%Date Example

      * Program     :·DateR
      * Description :·%Date() Example
      *
      * %Date(Parm1 { : Parm2 })
      *
      * Input  Parm1:·Integer, Character
      *        Parm2:·Date format
      *
      * Output      :·Date for given value
      *
      * Note        :·%Date always returns date in *ISO format
      *               *ISO - YYYY-MM-DD
      *==========================================================
      *
     C
      /Free
           Dsply %Date() ;                // Today's Date

        // ------------------------------------------------------
        // Convert number to date
        // ======================================================
           Dsply %Date(20120405) ;        // 2012-04-05

           Dsply %Date(01022011 : *USA) ; // 2011-01-02

           Dsply %Date(1120311 : *CYMD) ; // 2012-03-11
        // ------------------------------------------------------
        // Convert char to date
        // ======================================================
           Dsply %Date('2012-04-05') ;        // 2012-04-05

           Dsply %Date('02032011' : *USA0) ;  // 2011-02-03

           Dsply %Date('01/04/2012' : *USA/) ; // 2012-01-04

           Dsply %Date('1120311' : *CYMD0) ;  // 2012-03-11
      /End-Free
     C                   SetOn                                        LR

%CHECKR Example

      * Program     :·CheckRR
      * Description :·%Checkr() Example
      *
      * %CheckR()
      * Input  Parm1:·String of characters to be checked (Comparator)
      *        Parm2:·String in which the characters to be scaned/searched
      *
      * Output      :·Last location of Parm2 string where char is not matched
      *               with Comparator's chars
      *
      * Note        :·0 will be returned if no exception found
      *==========================================================
      *

     D Digits          S             10    Inz('0123456789')
     D Vowals          S             10    Inz('AEIOU')

     C
      /Free
           Dsply %CheckR(Digits : '123AB56') ;  // '5'

           Dsply %CheckR(Vowals : 'AEIOU') ;    // '0'

           Dsply %CheckR(Vowals : 'AEIoU') ;    // '4' CASE SENSITIVE
      /End-Free
     C                   SetOn                                        LR

Sunday, 17 September 2017

%CHECK Example

      * Program     :·CheckR
      * Description :·%Check() Example
      *
      * %Check()
      * Input  Parm1:·String of characters to be checked (Comparator)
      *        Parm2:·String in which the characters to be scaned/searched
      *
      * Output      :·First location of Parm2 string where char is not matched
      *               with Comparator's chars
      *
      * Note        :·0 will be returned if no exception found
      *==========================================================
      *

     D Digits          S             10    Inz('0123456789')
     D Vowals          S             10    Inz('AEIOU')

     C
      /Free
           Dsply %Check(Digits : '123A456') ;  // '4'

           Dsply %Check(Vowals : 'AEIOU') ;    // '0'

           Dsply %Check(Vowals : 'AEiOU') ;    // '3' CASE SENSITIVE
      /End-Free
     C                   SetOn                                        LR

%CHAR Example

      * Program     :·CharR
      * Description :·%Char() Example
      *
      * %Char()
      * Input  Parm1:·Number, date, time, timeStamp
      *        Parm2:·date or time format (When Parm1 is date or time)
      *
      * Output      :·Character String for Input parameter
      *
      *==========================================================
      *

     C
      /Free
           Dsply %Char(5) ;                    // '5'

           Dsply %Char(55.55) ;                // '55.55'

           Dsply %Char(d'2012-11-11' : *ISO) ; // '2012-11-11'

           Dsply %Char(d'2012-11-11' : *ISO0) ; // '20121111'
      /End-Free
     C                   SetOn                                        LR

%ALLOC Example

      * Program     :·AllocR
      * Description :·%Alloc() Example
      *
      * %Alloc()
      * Input       :·Memory size(positive integer) to be allocated
      * Output      :·Pointer to Allocated memory
      *
      * Note        :·dynamically allocated memory should be set free
      *               when not required, else it will cause memory leak
      *
      *==========================================================
      *
     D Var1            S             20    Based(Ptr)

     D Ptr             S               *

     C
      /Free
           Ptr = %Alloc(5) ;
           Dealloc Ptr ;

           Ptr = %Alloc(2*2 + 1) ;

           Var1 = 'Allocated' ;
           Dsply Var1 ;

           Dealloc Ptr ;
      /End-Free
     C                   SetOn                                        LR