View previous topic :: View next topic |
Author |
Message |
DaPlaze Beginner
Joined: 29 Mar 2007 Posts: 9 Topics: 2
|
Posted: Thu May 22, 2008 1:36 am Post subject: PL/1 Question regarding SELECT |
|
|
Hi everyone,
I have this Select statement and I would believe that it would work, however it doesn't.. Can anyone answer me why?
The program doesn't find the '#' in the FUNKTION field even though
I through Intertest have seen its there.
SELECT(AKT_SERVICE.SERVICE_FUNKTION);
WHEN(SUBSTR(AKT_SERVICE.SERVICE_FUNKTION,9,1) = '#')
AU72791_INPUT.FUNKTION = 'CHK TILM';
OTHERWISE
AU72791_INPUT.FUNKTION = AKT_SERVICE.SERVICE_FUNKTION;
END; |
|
Back to top |
|
 |
DaPlaze Beginner
Joined: 29 Mar 2007 Posts: 9 Topics: 2
|
Posted: Thu May 22, 2008 1:54 am Post subject: |
|
|
I forgot to tell that the field AKT_SERVICE.SERVICE_FUNKTION is a CHAR(10) field. |
|
Back to top |
|
 |
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Thu May 22, 2008 3:37 am Post subject: |
|
|
Are you sure that '#' is in column 9? You didn't post the data so we cannot be sure.
As a BTW, if that is your complete SELECT then IF-THEN-ELSE would be a simpler alternative (SELCET is best when you have several alternatives) and also the SELECT statement should be SELECT; with no variable because the only WHEN has its own specific variable name specified. _________________ Utility and Program control cards are NOT, repeat NOT, JCL. |
|
Back to top |
|
 |
DaPlaze Beginner
Joined: 29 Mar 2007 Posts: 9 Topics: 2
|
Posted: Thu May 22, 2008 4:31 am Post subject: |
|
|
I understand that you can't be sure if it is in position 9, but what the field contains is: 'CHK TILM#1' or 'CHK TILM#2' and I know that for sure as
I have seen it intertest.
I understand that an if-then-else could be better, but we know that there will come more of these, therefore the SELECT |
|
Back to top |
|
 |
prino Banned
Joined: 01 Feb 2007 Posts: 45 Topics: 5 Location: Oostende
|
Posted: Thu May 22, 2008 4:53 am Post subject: |
|
|
Use either:
Code: |
select;
when (substr(whatever, a, b) = 'x')
do;
end;
other ....
end;
|
or
Code: |
select (substr(whatever, a, b));
when ('A')
do;
end;
other ...
end;
|
but don't mix the two.
Robert |
|
Back to top |
|
 |
DaPlaze Beginner
Joined: 29 Mar 2007 Posts: 9 Topics: 2
|
Posted: Thu May 22, 2008 6:10 am Post subject: |
|
|
Ok, thanks, can you explain why and what the difference is?
Is it because of the compiler or?
prino wrote: | Use either:
Code: |
select;
when (substr(whatever, a, b) = 'x')
do;
end;
other ....
end;
|
or
Code: |
select (substr(whatever, a, b));
when ('A')
do;
end;
other ...
end;
|
but don't mix the two.
Robert |
|
|
Back to top |
|
 |
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Thu May 22, 2008 6:43 am Post subject: |
|
|
The style is somewhat arbitrary. You could mix the two if e.g. you had 4 WHENs using Prino's second style but need a WHEN that does not fall into that category. However, for the single WHEN you are doing extra processing because the value is being calculated on the SELECT and then again on the WHEN.
Back to your problem: do a PUT SKIP of
SUBSTR(AKT_SERVICE.SERVICE_FUNKTION,9,1)
before the SELECT to see what is being returned. In fact, just to be sure, also PUT SKIP the entire variable. _________________ Utility and Program control cards are NOT, repeat NOT, JCL. |
|
Back to top |
|
 |
Grant Beginner
Joined: 02 Dec 2002 Posts: 45 Topics: 1 Location: Sydney, NSW, Australia
|
Posted: Thu May 22, 2008 6:52 pm Post subject: |
|
|
When you specify Code: | SELECT(AKT_SERVICE.SERVICE_FUNKTION);
WHEN(SUBSTR(AKT_SERVICE.SERVICE_FUNKTION,9,1) = '#')
AU72791_INPUT.FUNKTION = 'CHK TILM';
OTHERWISE
AU72791_INPUT.FUNKTION = AKT_SERVICE.SERVICE_FUNKTION;
END; | you are asking the compiler to SELECT a 10 byte field, and then compare 1 byte in the WHEN to the entire 10 bytes - this is why you are not getting a match. As Prino suggested, this is when you would use the null SELECT |
|
Back to top |
|
 |
DaPlaze Beginner
Joined: 29 Mar 2007 Posts: 9 Topics: 2
|
Posted: Fri May 23, 2008 12:29 am Post subject: |
|
|
Aha ok.. Now I understand... Thanks guys.. all of you |
|
Back to top |
|
 |
|
|