View previous topic :: View next topic
|
Author |
Message |
kiran1
New User
Joined: 30 Mar 2007 Posts: 1 Location: kolkata
|
|
|
|
I need to validate a value in a field. If the value contains spaces in the middle, then it should check for the rest of the characters until 15 positons and if all are spaces, then continue else if a character found after 1st space then error message should be displayed.
ex: UDAY KIRAN , so after UDAY it should capture this space and then check the next character. As it is K, it should display an error message. |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Check if this solves your requirement
Code: |
*WS
01 ORIGVAR PIC X(30) VALUE 'UDAY KIRAN'
01 TRUNCVAR PIC X(15).
01 DESTVAR1 PIC X(15).
01 DESTVAR2 PIC X(15).
*PD
MOVE ORIGVAR(1:15) TO TRUNCVAR.
UNSTRING TRUNCVAR DELIMITED BY SPACES
INTO DESTVAR1 DESTVAR2.
IF DESTVAR2(1:1) NOT = ' ' THEN
DISPLAY "YOUR ERROR MESSAGE".
|
|
|
Back to top |
|
|
Cristopher
New User
Joined: 31 Jul 2008 Posts: 53 Location: NY
|
|
|
|
kiran1 if i have understood your requirement correctly thn : There should be an error mssg displayed if there is a character found in 1st 15 bytes of the string after the 1st space found.
You can try this aswell :
Code: |
01 A PIC X(25).
01 B PIC X(15) VALUE SPACES.
01 Y PIC 9(01) VALUE ZEROES.
01 SPACE-STATUS PIC X(1) VALUE 'N'.
88 NO-SPACE VALUE 'N'.
88 SPACES-FOUND VALUE 'Y'.
PERFORM UNTIL Y = LENGTH OF A OR SPACES-FOUND
Increment Y by 1
IF A (Y:1) EQUAL TO SPACES
Increment Y by 1
MOVE A (Y: ) to b
if b not equal to spaces
display "error found"
end-if
SET SPACES-FOUND TO TRUE
END-IF
END-PERFORM
|
Cris |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
Sambhaji,
Quote: |
IF DESTVAR2(1:1) NOT = ' ' THEN
DISPLAY "YOUR ERROR MESSAGE". |
What if the first byte after the first space is also spaces and next few bytes with characters? In that case i think your code would not display the error message.
The above code should be put in a loop with the check for the spaces. |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
lil correction to code
Code: |
*WS
01 ORIGVAR PIC X(30) VALUE 'UDAY KIRAN'
01 TRUNCVAR PIC X(15).
01 DESTVAR1 PIC X(15).
01 DESTVAR2 PIC X(15).
*PD
MOVE ORIGVAR(1:15) TO TRUNCVAR.
UNSTRING TRUNCVAR DELIMITED BY ALL SPACES
INTO DESTVAR1 DESTVAR2.
IF DESTVAR2(1:1) NOT = ' ' THEN
DISPLAY "YOUR ERROR MESSAGE".
|
It sould be ALL SPACES |
|
Back to top |
|
|
|