%SUBST Built-In Functions in rpgle

%SUBST function partially extracts the string from any position.

Format of this function is %SUBST(Source string:start:length to extract).

Here 1st parameter is the source string from which we want to extract some part of string.

2nd parameter is the starting position from where we will start the extraction of string.

3rd parameter is the length to extract.


Example -%SUBST Built-In Functions in rpgle


Below example extract year, month, day etc. from the timestamp.




 Columns . . . :    6  80                                              AMIT/QRPGSRC
 SEU==>                                                                     TESTRPG
 FMT *   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
        *************** Beginning of data *****************************************
0001.00 D times           s               Z
0002.00 D timesChar       S             30A
0003.00 D CurrDate        S              8A
0004.00 D CurrYear        S              4A
0005.00 D CurrMonth       S              2A
0006.00 D CurrDay         S              2A
0007.00
0008.00 C                   EVAL      times     = %TIMESTAMP()
0009.00 C                   EVAL      timesChar = %char(times:*iso0)
0010.00 C     timesChar     DSPLY
0011.00 C
0012.00 C                   EVAL      CurrDate = %subst (timesChar:1:8)
0013.00 C     CurrDate      DSPLY
0014.00 C
0015.00 C                   EVAL      CurrYear = %subst (CurrDate:1:4)
0016.00 C     CurrYear      DSPLY
0017.00 C
0018.00 C                   EVAL      CurrMonth = %subst (CurrDate:5:2)
0019.00 C     CurrMonth     DSPLY
0020.00 C
0021.00 C                   EVAL      CurrDay = %subst (CurrDate:7:2)
0022.00 C     CurrDay       DSPLY
0023.00
0024.00
0025.00 C                   Seton                                        LR


Output

DSPLY  20171120164843104000       
DSPLY  20171120                   
DSPLY  2017                       
DSPLY  11                         
DSPLY  20  











User Comments:



Subscribe

.  


Copyright © www.go4as400.com, 2013-2023. Copyright notice   Terms of services   Privacy policy