View previous topic :: View next topic
|
Author |
Message |
tosaurabh20
New User
Joined: 08 Jun 2007 Posts: 26 Location: Noida
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
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 |
|
|
tosaurabh20
New User
Joined: 08 Jun 2007 Posts: 26 Location: Noida
|
|
|
|
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 |
|
|
ParagChouguley
Active User
Joined: 03 Feb 2007 Posts: 175 Location: PUNE(INDIA)
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
wicked1925
New User
Joined: 12 Mar 2007 Posts: 15 Location: Philippines
|
|
|
|
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
If a better requirement definition is posted, we will be better able to offer suggestions. |
|
Back to top |
|
|
eHorizon.Andrew
New User
Joined: 18 Jan 2007 Posts: 28 Location: Bank of communications
|
|
|
|
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! |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
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 |
|
|
SHAILESH OZA
New User
Joined: 10 Jun 2005 Posts: 21 Location: Mumbai
|
|
|
|
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
William, doesn't the XML GENERATE automagically remove trailing spaces for you? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Usually, but not always, and sometimes those "small boxen" people choose tags that exceed the COBOL max length....grumble..... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Also, it has now been around 10 days since TS posted any follow-up. |
|
Back to top |
|
|
chintan
New User
Joined: 01 Jun 2007 Posts: 2 Location: banglore
|
|
|
|
u try for justify right it is synax.......i m not sure but it will solve your problem...... |
|
Back to top |
|
|
tosaurabh20
New User
Joined: 08 Jun 2007 Posts: 26 Location: Noida
|
|
|
|
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 |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello Saurabh,
Welcome back and thank you for posting your solution |
|
Back to top |
|
|
feellikeneo
New User
Joined: 19 Mar 2007 Posts: 73 Location: Chennai
|
|
|
|
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 |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
|