View previous topic :: View next topic
|
Author |
Message |
raghava manda
New User
Joined: 06 Jan 2016 Posts: 1 Location: USA
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
And don't use NEXT SENTENCE within an IF/END-IF. Use CONTINUE instead. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
|