Regarding Extract Function

Hi,

I have  a local variable that holds data like this.

local!data:[id:122,month:12,numberofdays:2]; [id:123,month:1,numberofdays:4]; [id:124,month:12,numberofdays:6]; 

while extracting the "numberofdays"  from the above format  by using extract function like this

local!january:extract(local!data,"month:1,numberofdays:","]") 

I am getting this error.please check this image.

 

Your suggestions are valuable

 

Thanks and Regards,

Divya

  Discussion posts and replies are publicly visible

Parents
  • What type is local!data? Your code works well if it's a text variable. For instance, this returns 4:

    extract("[id:122,month:12,numberofdays:2]; [id:123,month:1,numberofdays:4]; [id:124,month:12,numberofdays:6];","month:1,numberofdays:","]")

    My guess is that local!data isn't a string but an array of either dictionaries or CDTs, in which case you'd be better off using something other than extract. Either a combination of index and wherecontains, or just using find would be better in that case.

    If you want to stick to using extract for whatever reason, just convert it to string before passing it to extract.
  • Hi carlos
    I converted to string.But agian got the same error when using the extract function.Basically we are extract data dynamically thats why we are not using the where contains with index combination and find function.

    TIA
  • load(
      local!data: tostring(
        {
          {
            id: 122,
            month: 12,
            numberofdays: 2
          },
          {
            id: 123,
            month: 1,
            numberofdays: 4
          },
          {
            id: 124,
            month: 12,
            numberofdays: 6
          }
        }
      ),
      local!january: extract(
        local!data,
        "month:1,numberofdays:",
        "]"
      ),
      local!january
    )

    Hi Divya,

    In case you are using the extract function, you have to convert the local variable into the string before extracting to get the desired result as mentioned by Carlos.  

    Please find the code for the same. Its working for me as well.

    Thanks

    Aditya

Reply
  • load(
      local!data: tostring(
        {
          {
            id: 122,
            month: 12,
            numberofdays: 2
          },
          {
            id: 123,
            month: 1,
            numberofdays: 4
          },
          {
            id: 124,
            month: 12,
            numberofdays: 6
          }
        }
      ),
      local!january: extract(
        local!data,
        "month:1,numberofdays:",
        "]"
      ),
      local!january
    )

    Hi Divya,

    In case you are using the extract function, you have to convert the local variable into the string before extracting to get the desired result as mentioned by Carlos.  

    Please find the code for the same. Its working for me as well.

    Thanks

    Aditya

Children
No Data