Mister3
Mister3

Reputation: 11

Progress Openedge : Defining Delimiter as variable?

I have been trying to figure out how to use delimiter as a variable. However no go. Anyone got any suggestions?

This is what i have tried, however it does not work:

    iLine = getLastHeaderLine().
    cDelimiter = getDelimiter().
    REPEAT:
        IF iLine <= 1
        THEN DO:
            IMPORT UNFORMATTED csvRaLine.
        END.
        ELSE DO:
            IMPORT UNFORMATTED csvLine.
            
            IMPORT DELIMITER cDelimiter. 
            CREATE ttImportReport.
            ttImportReport.Amount = ParseAmount(csvLine).
            ttImportReport.Category = ParseCategory(csvLine).
                ttImportReport.dDate = ParseDate(csvLine).
            ttImportReport.cDescription = ParseDescription(csvLine).
            ttImportReport.cState = ParseState(csvLine).


        END.
        iLine = iLine + 1.

    END.

Upvotes: 1

Views: 212

Answers (2)

nwahmaet
nwahmaet

Reputation: 3909

I think your approach of using IMPORT UNFORMATTED can work, if you really need a variable delimiter. So your Parse<field>() methods could take a second parameter, the delimiter, along with the input line.

What you lose is the IMPORT statement's ability to deal with nested delimiters (eg when you have a comma in quotes, and are using a comma as delimiter).

Upvotes: 0

Tom Bascom
Tom Bascom

Reputation: 14020

Unfortunately the delimiter must be a literal.

The best you can do is to create an IF ... THEN ... ELSE or CASE statement to support multiple possible delimiters. Something like this:

CASE myDelimiter:

  WHEN ',' THEN
    IMPORT DELIMITER ',' inputData.

  WHEN '.' THEN
    IMPORT DELIMITER '.' inputData.

  WHEN '|' THEN
    IMPORT DELIMITER '|' inputData.

END.

Upvotes: 4

Related Questions