zxcv

— Define the function GetDataFrom1861Dict
CREATE FUNCTION GetDataFrom1861Dict(dictionaryValue CHARACTER) RETURNS CHARACTER
BEGIN
    — Declare local variables for splitting and processing the input field
    DECLARE questionParts REFERENCE TO NULL;
    DECLARE delimiter CHARACTER ‘@’;
    SET questionParts = LIST{};

    — Split the dictionaryValue string using ‘@’ as the delimiter
    SET questionParts = SPLIT(dictionaryValue, delimiter);

    — The first part (questionParts[1]) will be empty because of the leading ‘@’, so skip it.

    — Create the <Question> element inside <QuestionList> and map the fields
    CREATE LASTCHILD OF OutputRoot.XMLNSC.QuestionList.Question
        NAME ‘QuestionKey’ VALUE questionParts[2];         — Map to QuestionKey
    CREATE LASTCHILD OF OutputRoot.XMLNSC.QuestionList.Question
        NAME ‘Question’ VALUE questionParts[3];            — Map to Question
    CREATE LASTCHILD OF OutputRoot.XMLNSC.QuestionList.Question
        NAME ‘TypeOfSurvey’ VALUE questionParts[4];        — Map to TypeOfSurvey
    CREATE LASTCHILD OF OutputRoot.XMLNSC.QuestionList.Question
        NAME ‘ClientType’ VALUE questionParts[5];          — Map to ClientType
    CREATE LASTCHILD OF OutputRoot.XMLNSC.QuestionList.Question
        NAME ‘AnswerType’ VALUE questionParts[6];          — Map to AnswerType
    CREATE LASTCHILD OF OutputRoot.XMLNSC.QuestionList.Question
        NAME ‘AnswerDictionary’ VALUE questionParts[7];    — Map to AnswerDictionary
    CREATE LASTCHILD OF OutputRoot.XMLNSC.QuestionList.Question
        NAME ‘SpecialAnswerKey’ VALUE questionParts[8];    — Map to SpecialAnswerKey
    CREATE LASTCHILD OF OutputRoot.XMLNSC.QuestionList.Question
        NAME ‘Source’ VALUE questionParts[9];              — Map to Source

    RETURN ‘Processed’;  — Optionally return a status or processed value
END;

— Main processing logic
DECLARE i INTEGER 1;
DECLARE totalQuestions INTEGER;

— Get the total number of <Question> elements in the <Questions> array
SET totalQuestions = CARDINALITY(InputRoot.XMLNSC.Questions.Question[]);

— Loop through each <Question> entry
FOR i = 1 TO totalQuestions DO
    — Retrieve the current Question element
    DECLARE questionText CHARACTER InputRoot.XMLNSC.Questions.Question[i];
    
    — Call the GetDataFrom1861Dict function for each Question
    CALL GetDataFrom1861Dict(questionText);

END FOR;

Paste text,images,html and share with anyone
Scroll to Top