Progress if statement

Stephen Kennedy picture Stephen Kennedy · Jun 18, 2014 · Viewed 7.2k times · Source

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*/

Answer

Tim Kuehn picture Tim Kuehn · Jun 18, 2014

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.