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

How to strip the spaces in COBOL program.


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

New User


Joined: 14 Sep 2005
Posts: 16

PostPosted: Wed Oct 26, 2005 7:43 pm
Reply with quote

Hi,
I have to strip the values and should cancatenate them.
The Problem is :

I have the two fields

ws-fullname pic x(32)
ws-lastname pic x(32)

Resultant field:
ws-name pix x(64).

Here the Values in the fileds are
ws-fullname = 'A FULLNAME'
ws-lastname = 'LASTNAME'

here the resulatnat value should be 'A FULLNAME LASTNAME'

Here i need to strip the values and then concatenate like what we will do in feching the fields from db2 tru strip function, but in COBOL i couldnt able to use this.
So any one can suggest me how to strip the fileds and concatenate.
It would be grate if you provide some piece of code.
Thanks in Advance.

Regards,
Kiran.
Back to top
View user's profile Send private message
tdsvamsidhar

New User


Joined: 03 Oct 2005
Posts: 7

PostPosted: Thu Oct 27, 2005 9:21 am
Reply with quote

Try doing the following.

Iniitalize your variables with some character which you think does not come in the ws-firstname or secondname.

WS-FIRSTNAME pic X(32) value '////////////////////////'
WS-SECONDNAME pic X(32) value '////////////////////////'


move 'A FIRSTNAME' to WS-FIRSTNAME
move 'SECONDNAME' to WS-SECONDNAME

INSPECT WS-FIRSTNAME TALLYING WS-COUNT FOR CHARACTERS AFTER
INITIAL '/'.

COMPUTE WS-COUNT1 = 32 - WS-COUNT

MOVE ws-firstname(1:WS-COUNT1) to NEWVAR(1:WS-COUNT1)

Do the same for the second variable..

Hope this helps..Please somebdoy correct me if I am wrong.
Back to top
View user's profile Send private message
k_kirru
Currently Banned

New User


Joined: 14 Sep 2005
Posts: 16

PostPosted: Thu Oct 27, 2005 10:58 am
Reply with quote

Hi, Thanks....
What you have told is correct, but the filed names are coming from file, so when we move from the file to initialzed variables (/), here in the file itselef there might be some spaces so it over writes the initialized variables, hence its not working in my case. can you suggest me in any way..
Back to top
View user's profile Send private message
tdsvamsidhar

New User


Joined: 03 Oct 2005
Posts: 7

PostPosted: Thu Oct 27, 2005 11:08 am
Reply with quote

You can declare two other temp variables which receives the values from file variables and you can inspect the temp variables like I said earlier. Is that OK. Let me know.
Back to top
View user's profile Send private message
ikumar

New User


Joined: 02 Aug 2005
Posts: 81

PostPosted: Thu Oct 27, 2005 8:58 pm
Reply with quote

Hi,

check the below solution, you can implement it if you like the same...

1) using inspect fill all the SPACES in your first field to some delimiter that you would not face in your data, for example, '~'
2) Reverse the string using FUNCTION
for ex, MOVE FUNCTION REVERSE(WS-STRING) TO WS-STRING
3) using inspect fill all the leading delimiter '~' with spaces.
4) Do the reverse of the string again and
5) STRING WS-FIRSTNAME DELIMITED By ws-space and one space and WS-LASTNAME.


INSPECT WS-FIRSTNAME REPLACING ALL " " BY "~"
MOVE FUNCTION REVERSE(WS-FIRSTNAME) TO WS-FIRSTNAME
INSPECT WS-FIRSTNAME REPLACING ALL LEADING "~" BY " "
MOVE FUNCTION REVERSE(WS-FIRSTNAME) TO WS-FIRSTNAME
STRING WS-FIRSTNAME DELIMITED By ws-space
SPACE
WS-LASTNAME

just correct yourself if any syntax errors are there in the above code...and please let me know whether it has worked or not...

Hope this helps...

Cheers,
Kumar.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Oct 30, 2005 7:39 am
Reply with quote

Hi Kiran,

You can try something like this (untested):
Code:

MOVE ZERO TO L
INSPECT FUNCTION REVERSE(ws-fullname) TALLYING L FOR LEADING SPACES
COMPUTE L1 = LENGTH OF ws-fullname - L

MOVE ZERO TO L
INSPECT FUNCTION REVERSE(ws-lastname) TALLYING L FOR LEADING SPACES
COMPUTE L2 = LENGTH OF ws-lastname - L

STRING ws-fullname(1:L1) ' ' ws-lastname(1:L2) DELIMITED BY SIZE
  INTO ws-name
END-STRING
Back to top
View user's profile Send private message
ss.vijaysb1984

New User


Joined: 25 Jul 2008
Posts: 2
Location: India-Chennai

PostPosted: Wed Nov 12, 2008 3:29 pm
Reply with quote

Thisi is Very usefull for me...
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Nov 13, 2008 2:09 am
Reply with quote

Now that's the adventure of Forums..you find something very handy. And thanks for letting us know that yeah..some one is using the "Search" facility of this site.

-Ad
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Nov 13, 2008 2:10 am
Reply with quote

Mcmillian,

Can't we get a count of "how many times the search button was hit" for a given day.. icon_razz.gif
Back to top
View user's profile Send private message
mcmillan

Site Admin


Joined: 18 May 2003
Posts: 1210
Location: India

PostPosted: Thu Nov 13, 2008 2:39 am
Reply with quote

Quote:
Can't we get a count of "how many times the search button was hit" for a given day..


Yes, we can get it from the server access_log, if needed icon_smile.gif
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts Using API Gateway from CICS program CICS 0
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top