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

String Handling problem.


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

New User


Joined: 08 Jun 2007
Posts: 26
Location: Noida

PostPosted: Fri Jul 13, 2007 10:47 am
Reply with quote

Hi,

I have a program in which i am accepting input from the file.
Now there is a field in file record which gets a value of client ID from the file. It is usually of 5 characters. But if sometimes it is less than 5 characters then there exists trailing spaces.

Now My doubt is how to remove such trailing spaces ?
Is this can be done through any string handling commands?

I will provide you an example.

Client ID- A -------50768
Client ID- B -------123

Now for A there is no need of touching the record fields but for client B i have to remove two trailing spaces.


Thanks
Saurabh Gupta
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Jul 13, 2007 11:27 am
Reply with quote

tosaurabh20 wrote:
Now My doubt is how to remove such trailing spaces ?
Is this can be done through any string handling commands?

I will provide you an example.

Client ID- A -------50768
Client ID- B -------123

Now for A there is no need of touching the record fields but for client B i have to remove two trailing spaces.
What are you going to replace the trailing spaces with?
What size is the field you want to move client B into?
Or do you want the trailing spaces with leading spaces?
Like:
Code:

Client ID- B -------123
Client ID- B -------  123
Back to top
View user's profile Send private message
tosaurabh20

New User


Joined: 08 Jun 2007
Posts: 26
Location: Noida

PostPosted: Fri Jul 13, 2007 11:33 am
Reply with quote

William Thompson wrote:
tosaurabh20 wrote:
Now My doubt is how to remove such trailing spaces ?
Is this can be done through any string handling commands?

I will provide you an example.

Client ID- A -------50768
Client ID- B -------123

Now for A there is no need of touching the record fields but for client B i have to remove two trailing spaces.
What are you going to replace the trailing spaces with?
What size is the field you want to move client B into?
Or do you want the trailing spaces with leading spaces?
Like:
Code:

Client ID- B -------123
Client ID- B -------  123


Hi William,

I just wish to remove the spaces.
There is nothing through which i can replace them, actually this program does some reformatting of the string and prpare reformatted output file.this is the requirement from the client side.

let me know in case of any issues.

Thanks
Saurabh Gupta
Back to top
View user's profile Send private message
ParagChouguley

Active User


Joined: 03 Feb 2007
Posts: 175
Location: PUNE(INDIA)

PostPosted: Fri Jul 13, 2007 11:50 am
Reply with quote

Quote:
Hi William,

I just wish to remove the spaces.
There is nothing through which i can replace them,


Hi tosaurabh20,

William asked right question. You have to clearly tell what the spaces are to be replaced with. There is no concept of "Removing spaces from variables" in COBOL. You can count leading/ trailing spaces and shift your value to right or left accordingly.

--Parag
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Jul 13, 2007 11:51 am
Reply with quote

What size is the field you want to move client B into?

If the value is going to be reformatted to an output, that is when the trailing spaces will best be ignored is that string command by delimiting by those spaces.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jul 13, 2007 11:48 pm
Reply with quote

Hello,

What process do you need to implement that requires their "removal"?

As has been mentioned, the bytes are there and they will contain something.
Back to top
View user's profile Send private message
wicked1925

New User


Joined: 12 Mar 2007
Posts: 15
Location: Philippines

PostPosted: Sat Jul 14, 2007 12:18 pm
Reply with quote

Hi tosaurabh20,

You can validate each character in your Client ID field until you reach the last byte (5th char) and store each character in a variable. Now if in any instance you encountered a space you must immediately terminate the validation process. The only problem is you must know the minimum size that the Client ID field can have for you to eliminate the space when you store the validated characters in your variable.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Sat Jul 14, 2007 7:54 pm
Reply with quote

You could define

10 WS-STRING-LEN pic 9(1).
10 WS-STRING OCCURS DEPENDING ON WS-STRING-LEN
15 STRING-CHAR PIC X(1).

Unstring using SPACE into the ws-string field and put the length in the proper place..... You have a variable lenght string then (well sort of)
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Jul 14, 2007 10:53 pm
Reply with quote

Hello,

If a better requirement definition is posted, we will be better able to offer suggestions.
Back to top
View user's profile Send private message
eHorizon.Andrew

New User


Joined: 18 Jan 2007
Posts: 28
Location: Bank of communications

PostPosted: Wed Jul 18, 2007 2:39 pm
Reply with quote

stodolas wrote:
You could define

10 WS-STRING-LEN pic 9(1).
10 WS-STRING OCCURS DEPENDING ON WS-STRING-LEN
15 STRING-CHAR PIC X(1).

Unstring using SPACE into the ws-string field and put the length in the proper place..... You have a variable lenght string then (well sort of)


hi stodolas,

could you pls explain more exactly? Sorry for bothering you! I am green hand on COBOL! icon_sad.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jul 18, 2007 9:05 pm
Reply with quote

Hello,

As was mentioned earlier, if you describe how you will use the "output" field, we will be better able to help.

Keep in mind that your meaning is quite clear to you, but not to everyone else.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Wed Jul 18, 2007 9:17 pm
Reply with quote

I gave a possible thing to do, but as Dick infers variable length strings just don't make sense in COBOL.

Variable length strings are a hack and could cause many problems with copybooks and file layouts.
Back to top
View user's profile Send private message
SHAILESH OZA

New User


Joined: 10 Jun 2005
Posts: 21
Location: Mumbai

PostPosted: Mon Jul 23, 2007 10:16 pm
Reply with quote

Hi

i am suggesting one code which will not use string or unstring but what you want will get solve ?

declare variables

01 WS-CLIENTID1 PIC X(10).
01 WS-CLIENTID2 PIC X(10).
01 J PIC 9(1) VALUE 1.

PERFORM PARA1 VARYING I FROM 1 BY 1 UNTIL I>= 10.

PARA1.

IF WS-CLIENTID1(I) IS ALPHANUMERIC
MOVE WS-CLIENTID(I) TO WS-CLIENTID2(J)
COMPUTE J = J + 1
ELSE
NEXT SENTENCE
END-IF.

After completion of this upto the lengh , i hope the space or any other special charecters are removed IN WS-CLIENTID2.

I am writing this code on trial and error basis. you can please check it.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Mon Jul 23, 2007 10:31 pm
Reply with quote

SHAILESH OZA:

You aren't going to be trimming spaces from the end of the WS-CLIENTID1 when you move it to WS-CLIENTID2, you are preserving the string as is. The original requirement from what we can gather is a variable length string without the trailing spaces.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Mon Jul 23, 2007 11:54 pm
Reply with quote

Hi Saurabh,

I think the confusion stems from our not knowing how the receiving data will look after you move 123 there without the spaces.

Will it be a report line that shows the ID, name and address of a worker, for example:

123 John Doe 10 Last Place, New York, National League (or some such).

Or will it be in a 50 byte field with similar info.

Give us an example of what it will look like afer it's "moved".
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Jul 24, 2007 1:25 am
Reply with quote

After my last project, I can see it could be something a simple as building a XML output, eliminating the trailing spaces before plugging in the closing tag.....

But Saurabh Gupta has been in&out at least once without bothering to clear up the general confusion about his/her request/requirement....

As a systems person, is "software engineer" a synonym for programmer?
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Jul 24, 2007 1:49 am
Reply with quote

William, doesn't the XML GENERATE automagically remove trailing spaces for you?
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Jul 24, 2007 1:55 am
Reply with quote

Usually, but not always, and sometimes those "small boxen" people choose tags that exceed the COBOL max length....grumble.....
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jul 24, 2007 2:19 am
Reply with quote

Also, it has now been around 10 days since TS posted any follow-up.
Back to top
View user's profile Send private message
chintan

New User


Joined: 01 Jun 2007
Posts: 2
Location: banglore

PostPosted: Wed Jul 25, 2007 10:38 am
Reply with quote

u try for justify right it is synax.......i m not sure but it will solve your problem......
Back to top
View user's profile Send private message
tosaurabh20

New User


Joined: 08 Jun 2007
Posts: 26
Location: Noida

PostPosted: Thu Jul 26, 2007 5:24 pm
Reply with quote

chintan wrote:
u try for justify right it is synax.......i m not sure but it will solve your problem......


Hi all,

First of all very sorry for not responding, got occupied with project which required this string handling functionality. I will explain the whole scenario and as well as the solution which i implemented.

there is a parm file which is used in program, the contents of which are as follows:

ISELIGIBILITY FAI03U
CD RDS
PUT 'QCPPNP.ADJ.RDSU.ELGP357.A#####.OAUDTRPT' +
RDSUAUDT.XXXXX.A#####.CLIENT_NAME.CCYYMMDDHHMMSS
QUIT

Now my requirement was to replace "XXXXX" with client id from database, now that client can be of any length upto 5 characters.

Also client_name can also be of variable length upto 30 characters, what i need to implement that the whole string should remain in each and every scenario without the extra spaces or special characters.

the solution which i implemented is


UNSTRING INPUT-DATA-CURR
DELIMITED BY '.'
INTO WS-SUBSTRING1 COUNT IN WS-RDSCNT
, WS-SUBSTRING2
, WS-SUBSTRING3
, WS-SUBSTRING4
, WS-SUBSTRING5
END-UNSTRING.


PERFORM VARYING WS-SUB4 FROM +30 BY -1
UNTIL CLT-NM(WS-SUB4:1) NOT = SPACE
END-PERFORM

this will give me a length of the client name.

PERFORM VARYING WS-SUB2 FROM +5 BY -1
UNTIL CLT-CD(WS-SUB2:1) NOT = SPACE
END-PERFORM

this will provide me length of client code.

after that i again concantenated the everything using reference modification.

hope i have made myself clear.

sorry for delay once again.

Thanks for all your suggestions and feedbacks.

Saurabh
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Thu Jul 26, 2007 5:29 pm
Reply with quote

A little hint at the beginning, like you needed to insert the 1 to 5 character string into a 5 character hole and squeeze out the extra spaces would have helped your question along greatly.....
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jul 27, 2007 3:32 am
Reply with quote

Hello Saurabh,

Welcome back and thank you for posting your solution icon_smile.gif
Back to top
View user's profile Send private message
feellikeneo

New User


Joined: 19 Mar 2007
Posts: 73
Location: Chennai

PostPosted: Tue Jul 31, 2007 6:57 pm
Reply with quote

Hi Saurabh,

I too have a similar kind of requirement.

Can you pls, explain what this piece of code will do.

UNSTRING INPUT-DATA-CURR
DELIMITED BY '.'
INTO WS-SUBSTRING1 COUNT IN WS-RDSCNT
, WS-SUBSTRING2
, WS-SUBSTRING3
, WS-SUBSTRING4
, WS-SUBSTRING5
END-UNSTRING.


I too need to remove the trailing spaces and I have to plug the trimmed variable in a JCL. (ie) I will write a JCL from COBOL. I have to plug this trimmed variable.

pls help

Cheers,
Neo icon_smile.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 01, 2007 5:13 pm
Reply with quote

given the following input:
Code:

<<<<<<input lines 1 thru 3:>>>>>>>>>
ISELIGIBILITY FAI03U
CD RDS
PUT 'QCPPNP.ADJ.RDSU.ELGP357.A#####.OAUDTRPT' +
<<<<<<input line 4:>>>>>>>>>
RDSUAUDT.XXXXX.A#####.CLIENT_NAME.CCYYMMDDHHMMSS
<<<<<<input line 5:>>>>>>>>>
QUIT

each, 80 chars in length and following these requirements:
Quote:

Now my requirement was to replace "XXXXX" with client id from database, now that client can be of any length upto 5 characters.

Also client_name can also be of variable length upto 30 characters, what i need to implement that the whole string should remain in each and every scenario without the extra spaces or special characters.

in the fourth input line you need to replace
  • XXXXX with :CLIENT_ID from database, length 5, spaces on the right to be trimmed
  • CLIENT_NAME in input with :CLIENT_NAME from database, length 30, spaces on the right to be trimmed


Code:

01  WORK-AREAS.
    05  FIRST-PART        PIC X(80).
    05  SECOND-PART       PIC X(80).
    05  THIRD-PART        PIC X(80).
    05  GARBAGE           PIC X(80).
    05  NUM-FIELDS        PIC S9(3).
        88  GOOD-SPLIT     VALUE +3.
    05  RECEIVING-FLD     PIC X(80).

INITIALIZE WORK-AREAS

UNSTRING <input line 4>
               DELIMITED BY 'XXXXX' OR 'CLIENT_NAME'
    INTO FIRST-PART
         SECOND-PART
         THIRD-PART
         GARBAGE
    TALLYING IN NUM-FIELDS
END-UNSTRING

IF GOOD-SPLIT
THEN
    STRING FIRST-PART
                       DELIMITED BY SPACES
           :CLIENT_ID
                      DELIMITED BY SPACES
           SECOND-PART
                      DELIMITED BY SPACES
           :CLIENT_NAME
                      DELIMITED BY SPACES
           THIRD-PART
                      DELIMITED BY SPACES
      INTO RECEIVING-FIELD
   END-STRING

   MOVE RECEIVING-FIELD TO <input-line-4>
ELSE
   DISPLAY 'ERROR'
END-IF
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 PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts file manager is doing string conversion IBM Tools 3
Search our Forums:

Back to Top