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 

label not being called properly in PLI

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


Joined: 09 May 2006
Posts: 9
Topics: 3

PostPosted: Thu May 11, 2006 9:19 am    Post subject: label not being called properly in PLI Reply with quote

Hai Members,

I have a very basic question in PLI and my code looks like below:
The value of A > B , the label executes and displays HAI.
Code:

 PROG1:PROCEDURE OPTIONS(MAIN);         
       DCL A         FIXED DEC INIT (0);
       DCL B         FIXED DEC INIT (0);
       A = 50;                         
       B = 10;                         
       CALL PROCA;                     
                                       
       PROCA: PROC;                     
       IF A > B THEN                   
          GO TO WORK;                   
                                       
       WORK:                           
             PUT SKIP LIST('HAI');     
       END PROCA;                       
 END PROG1;                             

OUTPUT
Code:

HAI


Now i change the value of A by making less than B .If the value of A less than B ,the label still executes and display HAI.The condition is not met and why is the label called.Can anybody help me out as i am quite new to PLI ? In PLI a label is called irrespective of the condition : So in my case the label will be called always whenever the PROCA is called ? Please correct me in my understanding and correct me if i am wrong .
Code:

 PROG1:PROCEDURE OPTIONS(MAIN);         
       DCL A         FIXED DEC INIT (0);
       DCL B         FIXED DEC INIT (0);
       A = 5;                           
       B = 10;                           
       CALL PROCA;                       
                                         
       PROCA: PROC;                     
       IF A > B THEN                     
          GO TO WORK;                   
                                         
       WORK:                             
             PUT SKIP LIST('HAI');       
       END PROCA;                       
 END PROG1;

OUTPUT
Code:

HAI
Back to top
View user's profile Send private message
Cogito-Ergo-Sum
Advanced


Joined: 15 Dec 2002
Posts: 637
Topics: 43
Location: Bengaluru, INDIA

PostPosted: Thu May 11, 2006 11:28 am    Post subject: Reply with quote

A label by itself does not ensure conditional execution. You would have to 'escape' it. Something as follows:
Code:

       PROCA: PROC;                     
       IF A > B THEN                     
          GO TO WORK                   
       ELSE
          GO TO NOWORK;

       WORK:                             
             PUT SKIP LIST('HAI');     
       NOWORK:                             
          END PROCA;                       

_________________
ALL opinions are welcome.

Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes.
Back to top
View user's profile Send private message
hemamfuser
Beginner


Joined: 09 May 2006
Posts: 9
Topics: 3

PostPosted: Thu May 11, 2006 1:11 pm    Post subject: Reply with quote

Thanks for your reply.But why in the example label WORK is being executed , as per the condition A is less than B ,so the label should not execute and PUT SKIP LIST statement shoud not execute at all and there will be no output for the program.Can i have some information on this please ?
Back to top
View user's profile Send private message
Mervyn
Moderator


Joined: 02 Dec 2002
Posts: 415
Topics: 6
Location: Hove, England

PostPosted: Thu May 11, 2006 2:13 pm    Post subject: Reply with quote

Cogito is absolutely correct.

WORK is executed because you have done nothing to cause it NOT to be executed. Your code simply "drops" into the "PUT" code.

Have you actually tried Cogito's code?

This would work, too:
Code:

PROCA:
    PROC;                     
    IF A <= B THEN                     
        PUT SKIP LIST('HAI');
  END PROCA;

_________________
The day you stop learning the dinosaur becomes extinct
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