Stephen Kennedy
Stephen Kennedy

Reputation: 549

Progress if statement

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

Upvotes: 5

Views: 10085

Answers (3)

Tim Kuehn
Tim Kuehn

Reputation: 3251

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.

Upvotes: 3

Jensd
Jensd

Reputation: 8011

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.

Upvotes: 4

Stephen Kennedy
Stephen Kennedy

Reputation: 549

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.

Upvotes: 1

Related Questions