· Oct 16, 2017

Mapping comma delimited stringValues into a complex recordmap definition

Hello Community,

I need advice converting a comma delimited string container with multiple records into some type of recordmap that iterates through all the records.

My string container has several records and I would like to loop through the number of records in the string container and transform each record in the container individually. Number of records will vary but the number of fields per record is static (28 fields). Meaning after every 28 fields, a new record begins. The goal is to convert to individual delimited flat file records.

I am attaching sample data for clarification. Any pointer in the right direction will be hugely appreciated?



Example below is 3 records in the string container.


<StringContainer xmlns:xsi="" xmlns:s="">



Discussion (2)1
Log in or sign up to continue

Here is some code that will process your string container into lines of records that you want but you might want to change a few things to get this working with your records after converting your string container to a simple csv file you can then map it to your record mapper and process it any how.

Class TestEnvironment.Custom.GENERAL.ContainerString Extends (%Persistent, %Populate, %XML.Adaptor, %ZEN.DataModel.Adaptor)

Property Mystring As %String(MAXLEN = 32000, XMLPROJECTION = "CONTENT");

ClassMethod Import()
    // Create an instance of %XML.Reader
    Set reader = ##class(%XML.Reader).%New()

    // Begin processing of the file
    Set status = reader.OpenFile("C:\TEST\test.xml")
    If $$$ISERR(status) {do $System.Status.DisplayError(status)}

    // Associate a class name with the XML element name
    Do reader.Correlate("StringValue","TestEnvironment.Custom.GENERAL.ContainerString")
    // Read objects from xml file
    While (reader.Next(.object,.status)) {
        Write object.Mystring,!
//check the length of the string
         set lstr=$length(object.Mystring,",")
	    write "The length of incoming string is : "_lstr
	    if (lstr>28)
//divide by 28 for your processing
		    set div=lstr/28
		    if (div=2)
//assign your strings to something and write to file to map your records
			    set newstrObject=$piece(object.Mystring,",",1,28)
			    set secNewStrOJect=$piece(object.Mystring,",",29,56)
			 elseif (div=3)
			    set newstrObject=$piece(object.Mystring,",",1,28)
			    set secNewStrOJect=$piece(object.Mystring,",",29,56)
			     set thirdNewStrOJect=$piece(object.Mystring,",",57,84)
			     write "this is the string cut1 :"_newstrObject,!
			      write "this is the string cut2 :"_secNewStrOJect,!
			       write "this is the string cut3 :"_thirdNewStrOJect,!
    // If error found during processing, show it
    If $$$ISERR(status) {do $System.Status.DisplayError(status)}


hope this helps