Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How do i use the switch indicators for the below senario

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
raghava manda

New User


Joined: 06 Jan 2016
Posts: 1
Location: USA

PostPosted: Wed Jan 06, 2016 11:42 pm    Post subject: How do i use the switch indicators for the below senario
Reply with quote

i have a table which has 12 entries and i want to process only those valid records if an invalid record is found i want to throw an error. how can i check for spaces here?

Thank You for your Help.

example:

first entry always numeric. abcd 02 is key

Code:
abcd 02  1 2 3 4 5 6 7 8 9 10  this is valid record 
abcd 02  1 2 " 3 to 10 all spaces "   this is valid  record 
abcd 02  1 2 3 4 5  space 6 7 8 space 10 ---this is invalid scenario. 


Currently i have written this code i want to check for the above situation in the else part (i.e for prov-index 2 to 12)
Code:
IF PROV-INDX = 1                                 
   IF PROV-TYPE(PROV-INDX) NUMERIC               
   AND PROV-TYPE(PROV-INDX) > ZEROES             
       NEXT SENTENCE                             
   ELSE                                           
       MOVE WS-ASTERISKS TO L-RPT-PROV-TYP       
       MOVE E-PROV-TYP-NOT-VALID-MSG TO W-ERR-MSG
       ADD 1 TO L-ERROR-COUNT                     
       PERFORM 8900-ADD-ERROR-MSG                 
   END-IF                                         
ELSE                                             
   IF PROV-TYPE(PROV-INDX) NUMERIC               
     AND PROV-TYPE(PROV-INDX) = SPACES           
     AND PROV-TYPE(PROV-INDX) > ZEROES           
       NEXT SENTENCE                             
   ELSE                                           
       MOVE WS-ASTERISKS TO L-RPT-PROV-TYP       
       MOVE E-PROV-TYP-NOT-VALID-MSG TO W-ERR-MSG
       ADD 1 TO L-ERROR-COUNT                     
       PERFORM 8900-ADD-ERROR-MSG                 
END-IF
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7908
Location: Bellevue, IA

PostPosted: Thu Jan 07, 2016 12:03 am    Post subject: Reply to: How do i use the switch indicators for the below senario
Reply with quote

1. COBOL does NOT "throw errors". You are wrong to use this phrase for a COBOL program.

2. You do not show your DATA DIVISION variable definitions so how do we know if you're coding them right?

3. If the data is NUMERIC, it won't be equal to SPACES. If it is equal to SPACES, it won't be NUMERIC. So why do you use both conditions in your IF test?
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7226

PostPosted: Thu Jan 07, 2016 12:35 am    Post subject: Reply to: How do i use the switch indicators for the below senario
Reply with quote

And don't use NEXT SENTENCE within an IF/END-IF. Use CONTINUE instead.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7908
Location: Bellevue, IA

PostPosted: Thu Jan 07, 2016 5:32 am    Post subject:
Reply with quote

Looking more at what you posted, it is NOT at all clear what you are attempting to do. Is the second data record you posted supposed to contain the text value "3 to 10 all spaces " as you posted? If not, you need to post a fresh set of data records showing EXACTLY what is coming in; putting comments in the data to say what it is generally doesn't allow us to help you much since we want to see the precise and exact data records, not your comments about the data records.

You did NOT explain the difference between a valid and an invalid record. You did NOT indicate whether the 1 through 10 are in fixed columns or can vary location in the record. You did NOT indicate why your post text mentions 12 elements in the array yet the data you posted only contains 10 (1 through 10). Assuming that you are saying that the data is in fixed columns and that once a space is found in a data column all the rest of the data values must also be spaces, you'll need a flag variable. Clear the flag variable before each record is processed. When you find a data column that has a space, set the flag variable to whatever value you're using to indicate this. Your logic will be
Code:
IF  PROV-TYPE (PROV-INDX) = SPACE
    SET FLAG-VARIABLE TO 'S'
ELSE
    IF  PROV-TYPE (PROV-INDX) NUMERIC
    AND FLAG-VARIABLE = 'S'
       <handle the error condition>
    ELSE
        CONTINUE
    END-IF
END-IF
I did not include the PERFORM loop on PROV-INDX in this code, but the clear flag variable should occur before the PERFORM. Note that you do not have to check PROV-TYPE (PROV-INDX) to be > zero since if it is numeric it automatically is >= zero. Unless, of course, you didn't mention that zero is not an allowed value in which case you'd need to change my IF code logic to include that condition.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Switch between environments Khadhar Basha CLIST & REXX 9 Sat Jan 17, 2015 2:43 pm
No new posts ISPF panel scrollable field indicator... Ron Masters TSO/ISPF 14 Wed Jan 25, 2012 11:44 pm
No new posts Update columns without using NULL ind... dbzTHEdinosauer DB2 12 Tue Sep 20, 2011 1:17 pm
No new posts usage of null indicators abdulrafi DB2 2 Wed Nov 17, 2010 7:23 pm
No new posts How to switch plans within a batch co... gjdeluca DB2 1 Wed Dec 09, 2009 5:20 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us