Smokus
Smokus

Reputation: 149

How to use IF ELSE IF in put unformatted in Progress?

I am having issues with a programm where I need to output different strings if a certain Database Field has a specific value.

Let's say I have a Database called TestDB with following Fields Name, Age, Currency

I am outputting the data into a .csv File so my company uses for that a lot of put unformatted statements.

The "output" part would look something like this:

put unformatted

TestDB.Name ';'
TestDB.Age ';'
if TestDB.Currency = 1 then 'Euro' else ? ';'
if TestDB.Currency = 2 then 'Dollar' else ? ';'
if TestDB.Currency = 3 then 'Kuna' else ? ';'
if TestDB.Currency = 4 then 'Pound' else ?
skip.

The problem with these if's is that if Currency is 1, it will output Euro, but for other if's still output ? in .csv File. I want these if's to be structured like: if... else if... else if... else So if the 1st if is correct, then all other if's would be skipped.

I tried in multiple ways, but failed every time. Could someone help me out please?

Upvotes: 0

Views: 1315

Answers (2)

Stefan Drissen
Stefan Drissen

Reputation: 3379

Since I doubt that anyone wants to see 1, 2, 3, 4 as currency you probably already have a function or method that performs this conversion.

class env.currency:

   method static character getName (
      i_icurrency as integer
   ):

      case i_icurrency:
         when 1 then return 'Euro'.
         when 2 then return 'Dollar'.
         when 3 then return 'Kuna'.
         when 4 then return 'Pound'.
      end case.

      return 'unknown'.

   end method.

end class.

And in use:

put unformatted
   TestDB.Name ';'
   TestDB.Age ';'
   env.currency:getName( TestDB.Currency ) ';'

   skip
   .

Upvotes: 1

nwahmaet
nwahmaet

Reputation: 3909

I think you're looking for something like this

if TestDB.Currency = 1 then 'Euro' 
else if TestDB.Currency = 2 then 'Dollar' 
else if TestDB.Currency = 3 then 'Kuna'
else if TestDB.Currency = 4 then 'Pound' 
else ?

But a CASE statement might work better here

case TestDB.Currency:
  when 1 then curName = 'Euro'.
  when 2 then curName = 'Dollar'.
  when 3 then curName = 'Kona'.
  when 4 then curName = 'Pound'.
  otherwise curName = 'unknown'.
end case.
put unformatted curName skip.

Upvotes: 2

Related Questions