Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DECODE for variables? 1

Status
Not open for further replies.

kaeserea

Programmer
Feb 26, 2003
164
DE
Hello!

Can I use the DECODE function (or some similar function) for variables?

My basic problem is that I want to say:

if any of the variables &MONTH1, &MONTH2, &MONTH3, &MONTH4, &MONTH5, &MONTH6 equal '01' then set &SMONTH1, &SMONTH2, &SMONTH3, &SMONTH4, &SMONTH5, &SMONTH6 to 'January'

if the first variables equal '02' then set &SMONTH1, &SMONTH2, &SMONTH3, &SMONTH4, &SMONTH5, &SMONTH6 to 'February'

etc.

Of course &MONTH1, &MONTH2, &MONTH3, &MONTH4, &MONTH5, &MONTH6 are all different.

So my idea was to use something like DECODE. But I guess DECODE con only be used for data rows and not for variables?

Does anybody know how to do this?
Thanx a lot
Eva
 
Hello!

I finally solved this problem. Here's the solution for anyone interested:

[tt]
-SET &X = '0';
-REPEAT W1 FOR &X FROM 0 TO 5
-SET &SMONTH.&X = IF &MONAT.&X EQ '01' THEN 'January'
- ELSE IF &MONTH.&X EQ '02' THEN 'February'
- ELSE IF &MONTH.&X EQ '03' THEN 'March'
- ELSE IF &MONTH.&X EQ '04' THEN 'April'
- ELSE IF &MONTH.&X EQ '05' THEN 'May'
- ELSE IF &MONTH.&X EQ '06' THEN 'June'
- ELSE IF &MONTH.&X EQ '07' THEN 'July'
- ELSE IF &MONTH.&X EQ '08' THEN 'August'
- ELSE IF &MONTH.&X EQ '09' THEN 'September'
- ELSE IF &MONTH.&X EQ '10' THEN 'October'
- ELSE IF &MONTH.&X EQ '11' THEN 'November'
- ELSE 'December';
-W1
[/tt]

Eva
 
Eva,

You could use DECODE. Here's an example, based on what you did:

-REPEAT W1 FOR &X FROM 0 TO 5
-SET &SMONTH.&X = DECODE &MONTH.&X ('01' 'January'
- '02' 'February'
- '03' 'March'
- '04' 'April'
- '05' 'May'
- '06' 'June'
- '07' 'July'
- '08' 'August'
- '09' 'September'
- '10' 'October'
- '11' 'November'
- ELSE 'December');
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top