3

I'm a progress noob, actually having problem with basic blocks.

Below the issue is in my if else statement. It works fine when its just if, then, else then, but when I want to put in more than one statement into the if portion, I have to put it in a block, so I'm using if, then do: else, then do: but these aren't working for me. Any obvious errors you can see? My error message is **Colon followed by white space terminates a statement. (199)

INPUT FROM "r:\_content\stephen\4gl apps\dpl\output.csv".
REPEAT:
  ASSIGN i_cntr = (i_cntr + 1).
  myRow = "".
  IMPORT DELIMITER ',' myRow.

  IF myRow[5] <> "" THEN DO:
      /*change this to assign 2 rows - 2 creates - 2 sets of four*/
      c_fname = myRow[1].

      MESSAGE 
      c_fname SKIP
      myRow[2] SKIP
      myRow[3] skip
      myRow[4] skip
      myRow[5] SKIP
      i_cntr
      VIEW-AS ALERT-BOX INFO BUTTONS OK.
   END./*end of if, then do:*/
   ELSE IF myRow[5] = "" THEN DO:
   MESSAGE 
   myRow[1] SKIP
   myRow[2] skip
   myRow[3] skip
   myRow[4] skip
   i_cntr
   VIEW-AS ALERT-BOX INFO BUTTONS OK.
END./*end of else if, then do:*/   
END./*end of repeat*/
Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
Stephen Kennedy
  • 529
  • 5
  • 18
  • asking questions is how we learn :) A good thing to do is to do a syntax check is it should already highlight for you that there is an issue - Would say something like Unable to understand after - "END" – AquaAlex Jun 18 '14 at 15:04
  • also you do not need the ( IF myRow[5] = "" THEN) between the ELSE and DO: as there is only 2 options <> and = :-) – AquaAlex Jun 18 '14 at 15:07

3 Answers3

3

Rather than using nested IF/ELSE, you'd be better off using a CASE statement like so:

CASE varname:
WHEN ""      THEN DO: /*something */ END.
WHEN "value" THEN DO: /*something */ END.
OTHERWISE         DO: /*something */ END.
END CASE.

Check the docs on this statement for more details.

Tim Kuehn
  • 3,201
  • 1
  • 17
  • 23
3

A very simple syntax error: you need at least one space after the END-statement.

END. /*end of if, then do:*/
/*  ^ Make sure there's space above here! */

And if you don't want to follow the excellent advice in Tims answer (use CASE). This is the "complete" syntax of the IF statement.

IF expression1 THEN DO:
  /* Code goes here */
END.
ELSE IF expression2 THEN DO:
  /* Code goes here */
END.
ELSE DO:
  /* Code goes here */
END.

expressions:

A constant, field name, variable name, or expression whose value is logical (TRUE or FALSE). The expression can include comparisons, logical operators, and parentheses.

You can also leave out the DO: END. When the IF code to be executed only consists of a single statement:

IF TRUE THEN DISPLAY "TRUE".
ELSE DISPLAY "NOT TRUE".

You could also use other block-statements (such as FOR or REPEAT) but that will most likely only create code that is hard to read.

Jensd
  • 7,886
  • 2
  • 28
  • 37
1

I figured out the issue. This wasn't caused by a coding error. Apparently Progress doesn't like comments too close to the code, which caused it to throw an error.

END. /*end of if, then do:*/ => This is ok.
END./*end of if, then do:*/ => This caused the issue comments too close to statement.

Thanks To Tim Kuehn for his response.

Stephen Kennedy
  • 529
  • 5
  • 18