sponsored links

Collapse

Announcement

Collapse
No announcement yet.

Variable Charater in CL

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

  • Variable Charater in CL

    Hi

    Can anyone tell me how to use the VARCHAR in the CL program variable declartion ?

    Requirement with example:

    My CL variable declared size : 50 *char
    My data to the variable is : 'Example' (7 characters length)

    So, my CL variable should take only the 7 characters out of 50 characters declared.

    Suppose my variable data changed to: 'SAMPLE' (6 characters len)

    CL Variable should be of 6 characters.

    Thanks in Advance.

  • #2
    Re: Variable Charater in CL

    Any replies on this.....

    time being i have used *TCAT to concatenate the CL variable with the variable having the blank value, then i'm getting the acutal datapath (Used for download of the CSV files).


    Anyother ideas are welcome.

    Thanks in Advance again..

    Comment


    • #3
      Re: Variable Charater in CL

      There is no VARCHAR data type in CL. CL handles VARCHAR (or VARYING) character data types from other programs as *CHAR and you have to use %BIN to extract the 2-character or 4-character binary length from the beginning of that string variable's content. Thus, the CL would have to know in advance the actual length of the binary prefix in the string.

      You can build such a string in CL as follows:
      PHP Code:
      CHGVAR VAR(&VARSTRVALUE('##' *CAT &SUBSTR)
      CHGVAR VAR(%BIN(&VARSTR 1 2)) VALUE(&SUBLEN
      And you can extract the string data from such a string as follows:

      PHP Code:
      CHGVAR VAR(&SUBLENVALUE(%BIN(&VARSTR 1 2))
      CHGVAR VAR(&SUBSTRVALUE(%SST(&VARSTR 3 &SUBLEN)) 
      Last edited by jamief; December 13th, 2018, 10:14 AM.

      Comment


      • #4
        Re: Variable Charater in CL

        The latest CL/LE enhancements have provided a method of easily handling VARCHAR variables in CL. You do this by redefining a *CHAR variable with subfields creating what is analogous to an RPG/ILE data structure. The following are a couple of examples:

        DCL VAR(&AD_MAIL) TYPE(*CHAR) LEN(66)
        DCL VAR(&AD_MADDL) TYPE(*UINT) LEN(2) STG(*DEFINED) DEFVAR(&AD_MAIL 1)
        DCL VAR(&AD_MADDR) TYPE(*CHAR) LEN(64) STG(*DEFINED) DEFVAR(&AD_MAIL 3)

        DCL VAR(&MSGINFO) TYPE(*CHAR) LEN(30390) /* array with 10 elements */
        DCL VAR(&MSGINFP) TYPE(*PTR) ADDRESS(&MSGINFO)
        DCL VAR(&MSGINFE) TYPE(*CHAR) STG(*BASED) LEN(3039) BASPTR(&MSGINFP)
        DCL VAR(&MSG_INFID) TYPE(*CHAR) LEN(7) STG(*DEFINED) DEFVAR(&MSGINFE 1)
        DCL VAR(&MSG_INFTPE) TYPE(*CHAR) LEN(10) STG(*DEFINED) DEFVAR(&MSGINFE 8)
        DCL VAR(&MSG_INFFLE) TYPE(*CHAR) LEN(10) STG(*DEFINED) DEFVAR(&MSGINFE 18)
        DCL VAR(&MSG_INFFLB) TYPE(*CHAR) LEN(10) STG(*DEFINED) DEFVAR(&MSGINFE 28)
        DCL VAR(&MSG_INFDLN) TYPE(*UINT) LEN(2) STG(*DEFINED) DEFVAR(&MSGINFE 38)
        DCL VAR(&MSG_INFDTA) TYPE(*CHAR) LEN(3000) STG(*DEFINED) DEFVAR(&MSGINFE 40)

        Comment

        sponsored links

        Collapse

        Working...
        X