2

I've been trying to create a simple function that would accumulate some strings and then I would call it an it would return it, but for some reason I'm getting:

Could not understand line 1 (198)

Which is too vague, I've been looking in forums for examples to compare mine to, but it seems all right, May someone provide me an explanation of what I might be doing wrong?

Code:

put unformatted fcustomer(). /*line one*/

function fcustomer returns char():

    define variable vgatherer as character.
    define variable i as integer no-undo.

    do i = 1 to 10:
        assign vgatherer = vgatherer + "thing(s)".
    end.

    return vgatherer.

end function.
Kyle
  • 1,568
  • 2
  • 20
  • 46

2 Answers2

4

Functions need to be declared prior to use or be forward declared.

You might also want to have an input parameter.

function fcustomer returns character ( input p1 as character ) forward.

put unformatted fcustomer( "some text" ). /*line one*/

function fcustomer returns character ( input p1 as character ):

    define variable vgatherer as character.
    define variable i as integer no-undo.

    do i = 1 to 10:
        assign vgatherer = vgatherer + p1.
    end.

    return vgatherer.

end function.
Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
3

The ABL uses a single-pass compiler, so functions have to be declared before they're used. If you change the code like so, it'll work:

function fcustomer returns char():

    define variable vgatherer as character.
    define variable i as integer no-undo.

    do i = 1 to 10:
        assign vgatherer = vgatherer + "thing(s)".
    end.

    return vgatherer.

end function.

put unformatted fcustomer(). /*line one*/

You can also forward-define your functions with the FORWARD phrase. Check your ABL docs for details.

Tim Kuehn
  • 3,201
  • 1
  • 17
  • 23
  • Thank you so much once again Tim. I've still got a question, why do procedures work even if you declare them after you ran them? – Kyle Feb 22 '16 at 18:38
  • 1
    I can't really answer that - I think the difference is that functions return data and have strict type checking on their parameters so their call interface needs to be known before they're called. Procedures don't have those restrictions. – Tim Kuehn Feb 22 '16 at 19:02