MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PL/1 Question regarding SELECT

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
DaPlaze
Beginner


Joined: 29 Mar 2007
Posts: 9
Topics: 2

PostPosted: Thu May 22, 2008 1:36 am    Post subject: PL/1 Question regarding SELECT Reply with quote

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
View user's profile Send private message
DaPlaze
Beginner


Joined: 29 Mar 2007
Posts: 9
Topics: 2

PostPosted: Thu May 22, 2008 1:54 am    Post subject: Reply with quote

I forgot to tell that the field AKT_SERVICE.SERVICE_FUNKTION is a CHAR(10) field.
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Thu May 22, 2008 3:37 am    Post subject: Reply with quote

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
View user's profile Send private message
DaPlaze
Beginner


Joined: 29 Mar 2007
Posts: 9
Topics: 2

PostPosted: Thu May 22, 2008 4:31 am    Post subject: Reply with quote

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
View user's profile Send private message
prino
Banned


Joined: 01 Feb 2007
Posts: 45
Topics: 5
Location: Oostende

PostPosted: Thu May 22, 2008 4:53 am    Post subject: Reply with quote

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
View user's profile Send private message
DaPlaze
Beginner


Joined: 29 Mar 2007
Posts: 9
Topics: 2

PostPosted: Thu May 22, 2008 6:10 am    Post subject: Reply with quote

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
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Thu May 22, 2008 6:43 am    Post subject: Reply with quote

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
View user's profile Send private message
Grant
Beginner


Joined: 02 Dec 2002
Posts: 45
Topics: 1
Location: Sydney, NSW, Australia

PostPosted: Thu May 22, 2008 6:52 pm    Post subject: Reply with quote

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
View user's profile Send private message
DaPlaze
Beginner


Joined: 29 Mar 2007
Posts: 9
Topics: 2

PostPosted: Fri May 23, 2008 12:29 am    Post subject: Reply with quote

Aha ok.. Smile Now I understand... Thanks guys.. all of you
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group