IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

how to remove the leading spaces


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
nil_mf

New User


Joined: 06 Jun 2005
Posts: 29

PostPosted: Wed Dec 21, 2005 2:53 pm
Reply with quote

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
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Wed Dec 21, 2005 4:23 pm
Reply with quote

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
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Thu Dec 22, 2005 4:25 am
Reply with quote

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
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Thu Dec 22, 2005 3:33 pm
Reply with quote

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.


icon_biggrin.gif ...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
View user's profile Send private message
ksreddy

New User


Joined: 30 Mar 2005
Posts: 12
Location: Hyderabad

PostPosted: Fri Dec 23, 2005 7:54 pm
Reply with quote

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
View user's profile Send private message
mijanurit
Currently Banned

New User


Joined: 26 Aug 2005
Posts: 33
Location: bangalore

PostPosted: Sun Jan 08, 2006 10:46 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Remove leading zeroes SYNCSORT 4
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Cobol program with sequence number ra... COBOL Programming 5
Search our Forums:

Back to Top