ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Reg : Length of the string

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

  • Reg : Length of the string

    Hi

    I need to know, how to find out the length of the string in clp.

    Thanx in advance
    magesh

  • #2
    Re: Reg : Length of the string

    Numerous times over the years, I’ve seen this question: How can I find the length of the value in a CL variable? That is, how many characters are in a variable, ignoring trailing blanks? I needed the answer often enough myself that I created my own “clever” way to handle it years ago by creating


    Just yesterday, I was trying to determine the length of the value of a CL variable, so your tip today using the MSGDTA trick was helpful. I was thinking that IBM had added %TRIM and %LEN to the list of CL built-in functions (BIFs) that exist in recent releases, but I guess I was imagining

    Comment


    • #3
      Re: Reg : Length of the string

      Hi,

      May be you will find info here

      http://www.itjungle.com/fhg/fhg120705-story01.html

      PHP Code:
      /* Command: RTVVARLEN                     */
      /* CPP: RTVVARLENC                        */
      /* Retrieve the length of a CL variable   */
      /* without trailing blanks                */
       
      CMD     PROMPT('Return the length of a CL var')
       
      PARM    KWD(STRING) TYPE(*CHARLEN(2000MIN(1) +
                 
      EXPR(*YESVARY(*YESCHOICE('String +
                 variable'
      PROMPT('String variable to check')
       
      PARM    KWD(LENTYPE(*DECLEN(4RTNVAL(*YES) +
                 
      MIN(1PROMPT('Return variable (4,0)'
      I used the name RTVVARLEN (Retrieve Variable Length). Here's the command to create the command.
      PHP Code:
      CRTCMD CMD(xxx/RTVVARLEN)
             
      PGM(*LIBL/RTVVARLENC)
             
      SRCFILE(xxx/QCMDSRC)
             
      ALLOW(*BPGM *IPGM *BREXX *IREXX
      The command-processing program is short and simple.

      /* Retrieve the length of a CL variable */
      /* with trailing blanks removed */
      Code:
      PGM        PARM(&STRING &LEN)
      DCL        VAR(&STRING) TYPE(*CHAR) LEN(2000)
      DCL        VAR(&LEN) TYPE(*DEC) LEN(4 0)
      CHGVAR     VAR(&LEN) VALUE(%BIN(&STRING 1 2))
      I called the program RTVVARLENC and implemented it as an ILE program compiled to run in the calling program's activation group.
      PHP Code:
      CRTBNDCL PGM(xxx/RTVVARLENC)
               
      SRCFILE(xxx/QCLSRC)
               
      SRCMBR(RTVVARLENC)
               
      DFTACTGRP(*NO)
               
      ACTGRP(*CALLER
      Last, here's the program I used to test the command. I called it RTVVARLENT.
      PHP Code:
      PGM        PARM(&P1)
      DCL        VAR(&P1TYPE(*CHARLEN(32)
      DCL        VAR(&LENTYPE(*DECLEN(4)
      RTVVARLEN  STRING(&P1LEN(&LEN)
      DMPCLPGM 

      Comment


      • #4
        Re: Reg : Length of the string

        Originally posted by susan View Post
        Hi,

        May be you will find info here

        http://www.itjungle.com/fhg/fhg120705-story01.html

        PHP Code:
        /* Command: RTVVARLEN                     */
        /* CPP: RTVVARLENC                        */
        /* Retrieve the length of a CL variable   */
        /* without trailing blanks                */
         
        CMD     PROMPT('Return the length of a CL var')
         
        PARM    KWD(STRING) TYPE(*CHARLEN(2000MIN(1) +
                   
        EXPR(*YESVARY(*YESCHOICE('String +
                   variable'
        PROMPT('String variable to check')
         
        PARM    KWD(LENTYPE(*DECLEN(4RTNVAL(*YES) +
                   
        MIN(1PROMPT('Return variable (4,0)'
        I used the name RTVVARLEN (Retrieve Variable Length). Here's the command to create the command.
        PHP Code:
        CRTCMD CMD(xxx/RTVVARLEN)
               
        PGM(*LIBL/RTVVARLENC)
               
        SRCFILE(xxx/QCMDSRC)
               
        ALLOW(*BPGM *IPGM *BREXX *IREXX)
                 
        ACTGRP(*CALLER
        Last, here's the program I used to test the command. I called it RTVVARLENT.
        The perfect coder Ctrl + C, Ctrl + V
        Last edited by sai400; October 3, 2008, 06:40 AM.
        To every equation there is a solution....
        Regards
        Sai.

        Comment


        • #5
          Re: Reg : Length of the string

          sai ...in defense of susan ... I inserted the code there...cause I can...
          on a side note nice dancing r u break dancing in those pictures?
          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


          • #6
            Re: Reg : Length of the string

            Originally posted by jamief View Post
            sai ...in defense of susan ... I inserted the code there...cause I can...
            on a side note nice dancing r u break dancing in those pictures?

            Yep, iam performing a break(tension break) dancing.
            Thanks..
            To every equation there is a solution....
            Regards
            Sai.

            Comment

            Working...
            X