View previous topic :: View next topic
|
Author |
Message |
nil_mf
New User
Joined: 06 Jun 2005 Posts: 29
|
|
|
|
Hi,
I have the following requirement.
There is a field of
NAME PIC X(60)
Now there any no of leading space may come in the field. I have to take only the value not the spaces. How to solve this.
Thanks
Nil |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
Quote: |
Now there any no of leading space may come in the field |
How ???????
Is that problem imaginary or you find it practical while working.
It could happen only If NAME field is receiving values with RIGHT Justification. So if you want to avoid problem, dont JUSTIFY RIGHT.
Regards,
Priyesh. |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
Priyesh,
I have run across this type of problem where there has been client input through a GUI. They insert leading spaces prior to data.
Nil maybe asking how to left justify this in the field by removing the leading spaces. The only way I know of doing this is through a simple code
Code: |
WORKING-STORAGE SECTION.
01 WS.
05 WS-X PIC X(30).
01 SUB PIC S9(5).
PROCEDURE DIVISION.
MOVE ' DAVIDATK' TO WS-X.
DISPLAY '>' WS-X.
PERFORM
VARYING SUB FROM 1 BY 1
UNTIL SUB > 30
OR WS-X(SUB:1) NOT = ' '
END-PERFORM.
IF SUB NOT > 30
THEN
MOVE WS-X(SUB:30 - SUB)
TO WS-X.
DISPLAY '>' WS-X.
GOBACK. |
results of the two displays
Code: |
> DAVIDATK
>DAVIDATK |
|
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
Quote: |
I have run across this type of problem where there has been client input through a GUI. They insert leading spaces prior to data. |
...agree man....I guess I wont be filling my name like " Priyesh" If asked for....Well, arguing requirements is not our job.....
Quote: |
The only way I know of doing this is through a simple code |
There is another....By a single UNSTRING statement....
Code: |
UNSTRING FULLNAME DELIMITED BY ALL SPACES
INTO WS-SPACE, FIRSTNAME, SURNAME
END-UNSTRING.
DISPLAY 'FULL NAME' FULLNAME.
DISPLAY 'FIRST NAME' FIRSTNAME.
DISPLAY 'SUR NAME' SURNAME. |
Also I think it can be done by INSPECT verb.... That I'll have to check ..c u later on this...
I hope if mmwife could have come till now....& we would have been reading some excellent suggestion with nice punch line "Late again to the party"....Well, we are waiting for mmwife to join the party...
Regards,
Priyesh. |
|
Back to top |
|
|
ksreddy
New User
Joined: 30 Mar 2005 Posts: 12 Location: Hyderabad
|
|
|
|
Hi Nil,
below code may help you
01 WS-STRING-WITH-SPACES PIC X(60).
01 WS-ACTUAL-STRING PIC X(60).
01 WS-SPACE-COUNT PIC S9(4) COMP VALUE ZERO.
01 WS-TOT-LEN PIC S9(4) COMP VALUE ZERO.
01 WS-ACTUAL-LEN PIC S9(4) COMP VALUE ZERO.
PROCEDURE DIVISION.
INSPECT WS-STRING-WITH-SPACES TALLYING WS-SPACE-COUNT
FOR LEADING SPACES.
MOVE LENGTH OF WS-STRING-WITH-SPACES TO WS-TOT-LEN
COMPUTE WS-ACTUAL-LEN = WS-TOT-LEN - WS-SPACE-COUNT
ADD +1 TO WS-SPACE-COUNT
MOVE WS-STRING-WITH-SPACES(WS-SPACE-COUNT:WS-ACTUAL-LEN) TO WS-ACTUAL-STRING. |
|
Back to top |
|
|
mijanurit Currently Banned New User
Joined: 26 Aug 2005 Posts: 33 Location: bangalore
|
|
|
|
hi all
it can be done using INSPECT verb and reference modification.
INSPECT name TALLYING tally-count LEADING " ".
from tally-count u can get number of leading space.
then use reference modification.
move name(tally-count:) to name1.
if i am wrong plz correct me.
regards
mijanurit |
|
Back to top |
|
|
|