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 to remove the leading spaces

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: how to remove the leading spaces
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: 1452
Location: Chicago, IL

PostPosted: Wed Dec 21, 2005 4:23 pm    Post subject: Re: how to remove the leading spaces
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    Post subject: Re: how to remove the leading spaces
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: 1452
Location: Chicago, IL

PostPosted: Thu Dec 22, 2005 3:33 pm    Post subject: Re: how to remove the leading spaces
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    Post subject:
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    Post subject: Re: how to remove the leading spaces
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    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 Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm
No new posts Remove junk values in a file and rite... KP1125 DFSORT/ICETOOL 2 Wed Jan 25, 2017 9:58 pm
No new posts Sort Card to Remove Duplicate records... raj4neo SYNCSORT 2 Wed Jan 25, 2017 4:44 am
No new posts To trim spaces in a pipe delimited da... Nish84 COBOL Programming 16 Mon Oct 10, 2016 1:54 pm
No new posts Removing Extra Spaces in a comma sepa... Puspojit DFSORT/ICETOOL 3 Tue Sep 13, 2016 7:46 am


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