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

Concatenation of fields without trailing spaces


IBM Mainframe Forums -> COBOL Programming
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
SankarV

New User


Joined: 07 Sep 2007
Posts: 2
Location: Singapore

PostPosted: Mon Jun 01, 2009 8:52 am
Reply with quote

Hi,

Could you pls provide me a simple solution for concatenation of 6 fields without trailing spaces. The target varriable length is 60 and the total length of 6 fields is more than 60. After concatenation the first 60 non space charecters should be lying in my target varriable. I used "Perform Unitil" and subscript which seems to be risky. Pls let me know a simple solution for the same. Thanks a lot in advance.

Regards,
Sankar.
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: Mon Jun 01, 2009 9:12 am
Reply with quote

Hello Sankar and welcome to the forum,

You need to better describe what you want to do.

How are the 6 fields defined? What should happen if there are more than 60 non-blank characters in the 6 fields?

Suggest you show some representative sample input and the output you want from that input.

Quote:
I used "Perform Unitil" and subscript which seems to be risky.
What is the risk?

If the first 60 non-blanks are to be put in the output "field" simply place all 6 input fields into a group field and parse the group field using reference modification until the first 60 have been found or the end of the input is reached. Make sure to move spaces to the output area at the start of each new set of input.
Back to top
View user's profile Send private message
SankarV

New User


Joined: 07 Sep 2007
Posts: 2
Location: Singapore

PostPosted: Mon Jun 01, 2009 9:30 pm
Reply with quote

Hi D.sch,

Thanks a lot for your valuable comments. My requirement is as below.

Input:
---------
Variable 1 -> 80 bytes
Variable 2 -> 20 bytes
Variable 3 -> 20 bytes
Variable 4 -> 12 bytes
Variable 5 -> 20 bytes
Variable 6 -> 20 bytes

Output
--------
Output Varriable -> 60 bytes.

Below is my requirement.

1. I want to concatenate all the 6 fields above only if it has some values. Also i need to concatenate first 60 non space charecters in to my target output varriable.

2. If only varriable 1 is having values and rest all having spaces then i shd take the entire sixty bytes from varriable 1. If any other varriable other than varriable 1 is having values, it shd take first 30 bytes from varriable 1 and rest 30 from other varriables which is having non space charecters.

I have user "Perform Unitil" and subscript to find the first occurance of non space charecter by scanning the varriable from last. The i calculated the lengths of the six fields and then concatenating which i feel risky because i use subscripts which may lead to "107" or "104" error. So could you please suggest me a simple solution with sample logic.

Again thanks a lot for your guidance.

Regards,
Sankar
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Jun 01, 2009 10:42 pm
Reply with quote

Quote:
So could you please suggest me a simple solution with sample logic.
Based on what you're describing as the logic required, I don't think there are any "simple" solutions.

Things you don't mention in your "requirements:"
What if all six variables are spaces?
What if variable 1 is spaces and variables 3, 4, and 5 are not spaces?
What if variable 1 and variable 4 are the only ones that are not spaces -- you get 30 bytes from variable 1 but you can only get 12 bytes from variable 4 -- what are the other 18 bytes supposed to be?
Are you talking only about leading or trailing spaces? What if variable 1 has 3 spaces in the first 10 bytes (positions 2, 6, 9 for example)?

I suspect the "risk" you think is there is due to poorly worded and incomplete requirements, not any inherent characteristics of the data or the language.
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Jun 02, 2009 1:49 am
Reply with quote

SankarV, The following assumptions are made while coding.
Quote:
I want to concatenate all the 6 fields above only if it has some values. Also i need to concatenate first 60 non space charecters in to my target output varriable.
If all the 6 variable have spaces, the target value will have spaces.
Quote:
If only varriable 1 is having values and rest all having spaces then i shd take the entire sixty bytes from varriable 1. If any other varriable other than varriable 1 is having values, it shd take first 30 bytes from varriable 1 and rest 30 from other varriables which is having non space charecters.
A. If only variable 1 has value and rest have spaces then varaibale 1 moves to output varibale.
B.If any other variable has value,first 30 bytes for variable1 and rest from other varibales(with no spaces)goes to the output variable in order 2,3,4 &5.
C.This code will only remove the trailing spaces.
Code:

INSPECT FUNCTION REVERSE(VAR1)           
TALLYING VAR1-LEN FOR LEADING SPACE     
SUBTRACT VAR1-LEN FROM 80 GIVING VAR1-LEN

INSPECT FUNCTION REVERSE(VAR2)           
TALLYING VAR2-LEN FOR LEADING SPACE     
SUBTRACT VAR2-LEN FROM 20 GIVING VAR2-LEN

INSPECT FUNCTION REVERSE(VAR3)           
TALLYING VAR3-LEN FOR LEADING SPACE       
SUBTRACT VAR3-LEN FROM 20 GIVING VAR3-LEN

INSPECT FUNCTION REVERSE(VAR4)           
TALLYING VAR4-LEN FOR LEADING SPACE     
SUBTRACT VAR4-LEN FROM 12 GIVING VAR4-LEN

INSPECT FUNCTION REVERSE(VAR5)             
TALLYING VAR5-LEN FOR LEADING SPACE       
SUBTRACT VAR5-LEN FROM 20 GIVING VAR5-LEN 

 INSPECT FUNCTION REVERSE(VAR6)           
 TALLYING VAR6-LEN FOR LEADING SPACE       
 SUBTRACT VAR6-LEN FROM 20 GIVING VAR6-LEN

IF VAR2 = SPACES  AND                               
     VAR3 = SPACES  AND                               
     VAR4 = SPACES  AND                               
     VAR5 = SPACES  AND                               
     VAR6 = SPACES  AND                               
     VAR1 NOT EQUAL SPACES                             
                                                       
     MOVE VAR1(1:VAR1-LEN) TO VARF                     
     DISPLAY 'FINAL VALUE OF OUTPUT VARIABLE :' VARF
ELSE   
   IF  VAR2 NOT EQUAL TO SPACES OR   
     VAR3 NOT EQUAL TO SPACES OR   
     VAR4 NOT EQUAL TO SPACES OR   
     VAR5 NOT EQUAL TO SPACES OR   
     VAR6 NOT EQUAL TO SPACES AND   
     VAR1 = SPACES (You can decide on this AND)                 
     MOVE VAR1(1:VARIN) TO VARF                       
     COMPUTE VARIN = VARIN + 1                       
     IF VAR2 NOT EQUAL SPACES                         
         MOVE VAR2(1:VAR2-LEN) TO VARF(VARIN:VAR2-LEN)
         COMPUTE VARIN = VARIN + VAR2-LEN             
     END-IF                                           
                                                 
     IF VAR3 NOT EQUAL SPACES                         
     MOVE VAR3(1:VAR3-LEN) TO VARF(VARIN:VAR3-LEN)
     COMPUTE VARIN = VARIN + VAR3-LEN             
     END-IF   

     IF VAR4 NOT EQUAL SPACES                       
     MOVE VAR4(1:VAR4-LEN) TO VARF(VARIN:VAR4-LEN)
     COMPUTE VARIN = VARIN + VAR4-LEN             
     END-IF   

     IF VAR5 NOT EQUAL SPACES                       
    MOVE VAR5(1:VAR5-LEN) TO VARF(VARIN:VAR5-LEN)
    COMPUTE VARIN = VARIN + VAR5-LEN 
    END-IF         
   
    IF VAR6 NOT EQUAL SPACES                       
   MOVE VAR6(1:VAR6-LEN) TO VARF(VARIN:VAR6-LEN)
   COMPUTE VARIN = VARIN + VAR6-LEN             
   END-IF   

  END-IF                                     
END-IF                                         
DISPLAY 'FINAL VALUE OF OUTPUT VARIABLE :' VARF 

Tweak it as per your requirement.

WTH.
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Jun 02, 2009 1:54 am
Reply with quote

Forgot to include the Variable definitions.
Code:
Working Storage.
01 VAR1 PIC X(80) VALUE SPACES.       
01 VAR2 PIC X(20) VALUE SPACES.       
01 VAR3 PIC X(20) VALUE SPACES.       
01 VAR4 PIC X(12) VALUE SPACES.       
01 VAR5 PIC X(20) VALUE SPACES.       
01 VAR6 PIC X(20) VALUE SPACES.       
01 VARF PIC X(60) VALUE SPACES.       
01 VAR1-LEN PIC 9(02) VALUE ZEROES.   
01 VAR2-LEN PIC 9(02) VALUE ZEROES.   
01 VAR3-LEN PIC 9(02) VALUE ZEROES.   
01 VAR4-LEN PIC 9(02) VALUE ZEROES.   
01 VAR5-LEN PIC 9(02) VALUE ZEROES.   
01 VAR6-LEN PIC 9(02) VALUE ZEROES.   
01 VARF-LEN PIC 9(02) VALUE ZEROES.   
01 VARIN    PIC 9(02) VALUE 30.       

 PROCEDURE DIVISION.   
  0001-MAIN.  (I used Accept to feed the variables)         
        ACCEPT VAR1   
        ACCEPT VAR2   
        ACCEPT VAR3   
        ACCEPT VAR4   
        ACCEPT VAR5   
        ACCEPT VAR6   
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 Jun 02, 2009 2:47 am
Reply with quote

Hello,

Does this code deal with embedded spaces? It does not appear to do so.

Quote:
Tweak it as per your requirement.
Suspect there will be more than "tweaking" to get to the not yet clearly defined requirement. . .

I believe Sankar needs to provide additonal "specs" before code is implemented.
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Jun 02, 2009 3:07 am
Reply with quote

Quote:
Does this code deal with embedded spaces? It does not appear to do so.

Dick can you elaborate on the term "embedded 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: Tue Jun 02, 2009 3:18 am
Reply with quote

Hi Succor,

If field1 contains
Code:
AAA BBCCFFRR GGHHJJ  TTRREEWW     
it contains embedded spaces, not just trailing spaces (which i believe is all the posted code will detect). If i read the original request correctly, there should be no spaces in the output data.

As Robert and i have both mentioned, the requirement needs better definition.
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Jun 02, 2009 3:26 am
Reply with quote

As the OP had specified
Quote:
Could you pls provide me a simple solution for concatenation of 6 fields without trailing spaces.

And based on my identified Assumptions:
Quote:
C.This code will only remove the trailing spaces.
I had suggested the code.
Quote:
Dick can you elaborate on the term "embedded spaces".

Just wanted to confirm on my understanding,which is the same as explained by you.
Quote:
As Robert and i have both mentioned, the requirement needs better definition.

Probably this is required ,we need to wait for the detailed and clear requirements.

WTH.
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 Jun 02, 2009 3:32 am
Reply with quote

Hi Succor,

Quote:
Could you pls provide me a simple solution for concatenation of 6 fields without trailing spaces.
You focused on this. . .

Quote:
After concatenation the first 60 non space charecters should be lying in my target varriable.
This was one sentence later in the same paragraph you quoted. . .
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Jun 02, 2009 4:56 am
Reply with quote

Quote:
Quote:
After concatenation the first 60 non space charecters should be lying in my target varriable.
This was one sentence later in the same paragraph you quoted. . .

Dick,do you really think it is possible if all the variables have spaces and he dosen't want to pad them with something else.
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 Jun 02, 2009 5:21 am
Reply with quote

Quote:
Dick,do you really think it is possible if all the variables have spaces and he dosen't want to pad them with something else.
I believe all of this it is just wasted effort unless/until a better definition is posted. . . icon_confused.gif

The only reason i've continued this dialog is that one lesson might be taken from this topic: When one or more of the senior contributors post that more/better info is needed, the TS should provide the info before we start offering technical alternatives that are primarily guess-based.

d
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Jun 02, 2009 5:43 am
Reply with quote

Quote:
I believe all of this it is just wasted effort unless/until a better definition is posted. . .
No, its is not a waste of effort as many people get to learn and understand...by actually helping others..and i certainly do.
Quote:
The only reason i've continued this dialog is that one lesson might be taken from this topic: When one or more of the senior contributors post that more/better info is needed, the TS should provide the info before we start offering technical alternatives that are primarily guess-based.

I am a beginner and my knowledge is in no comaprion with you
Quote:
senior contributors
and i should say thanks to you for continuing in this discussion.

WTH.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Jun 02, 2009 5:51 am
Reply with quote

Quote:
technical alternatives that are primarily guess-based.


and then we have to go thru 100 posts by someone defending his post (READ: guess).

this is why my post was ok...... (too bad we don't have bbcode to indicate whinning!)

(in the time that it took me to compose this post - I am slow, i know -
yet another post was made....man, talk about having to have the last word!)

sorry, it is late and I should not 'attack' contributors.
my apologies (and yes, my post stands)
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Jun 02, 2009 6:00 am
Reply with quote

Quote:
too bad we don't have bbcode to indicate whinning
OK, let's all get together and ask for wwcode! icon_smile.gif
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Jun 02, 2009 6:42 am
Reply with quote

Quote:
and then we have to go thru 100 posts by someone defending his post (READ: guess).
You are not a moderator to look what every one is posting...but you do..and that is how you increase your posts...try giving better answers then to meddle in whatever you find can help your cause.I hope someday you will understand you ARE HERE TO HELP.
Yes it is late , for all of us, and i think i am done with this.
Mr DBz..you have again done the trick...This is my last post and thanks for ridiculing people more then helping them....
Dick(not Dbz) , i understand and respect your perspective.You have been great in helping people and i admire that.

Moderators,please don't be biased...it certainly doesn't pose a good example.Though not a good note to leave a forum like this..I would like to say thanks to all the learned people.

WTF.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Jun 02, 2009 3:16 pm
Reply with quote

If you think I am going to let you have the last post in this thread, you are as crazy as you are insecure and naive.

If I was a moderator, I would have to be nice to those who do not deserve being dealt with in a civil manner.

3/4's of the time, the reason a thread is started is because the TS can not define the problem.

nearly 100% of my consultant work is due to my ability to define the problem.

nearly anybody can code, but few (it seems) can determine the reason for the problem.

this thread was a good example of an incomplete idea.
there are currently a couple of thread where instead of solving the problem,
they are covering up the symptom (wait step in a job, for example)

dick scherrer was attempting to force the TS to define his requirement.
After that, the TS could have probably solved his problem.

Quote:
Moderators,please don't be biased

Forcing posters to think is not being biased.

Post count increases by one for each thread, not how many times one "contributes" to a thread.
Post count seems to be your problem.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Jun 02, 2009 3:47 pm
Reply with quote

So here I put in my two cents too.

Why are some assume that there are others who have more than enough time to bother oneself about another ones complete and complex task description.

Most of all the thoughts and relevant hints, coming from others, should have been piece of the problem evaluation of the TS, as he got in touch with the mission. This is normal work.
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Jun 02, 2009 5:41 pm
Reply with quote

Quote:
vvmanyam,
you were correct. I apologize for my post.
_________________
Dick Brenholtz .

Quote:
I tried to take part in a discussion where I had no knowledge. Dick Brenholtz
Quote:

my answer did not make much sense. .Dick Brenholtz

Keep counting...this is just a sub set of those i have come across and this is the way you accomplish
Quote:
nearly 100% of my consultant work is due to my ability to define the problem.
..Hopefully someday you will learn how to define the problem.One more jewel in your self proclaimed crown.
DBZ's Sincere efforts
And better get this post deleted...the more people read all this...the more they will laugh on you....I never thought i would be posting again...but people like you....I hope we stop here until and unless you want to feed your self with more disgrace …that too with the hands of a rookie.
I know, you have said lot worse things in this forum,still moderators have always backed you....they will be on their way ...again.

Good Luck To Everyone.
Succor
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Jun 02, 2009 6:17 pm
Reply with quote

I realize that you have an issue with me Succor,

but please, quote me correctly.

Links to the above quoted threads:

ibmmainframes.com/viewtopic.php?p=192267&highlight=&sid=d45f8a06d68823cc0954e52f44f93261

ibmmainframes.com/viewtopic.php?t=40901&start=0&postdays=0&postorder=asc&highlight=&sid=d45f8a06d68823cc0954e52f44f93261

ibmmainframes.com/viewtopic.php?p=192810&highlight=&sid=d45f8a06d68823cc0954e52f44f93261
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Jun 02, 2009 6:48 pm
Reply with quote

Quote:
I realize that you have an issue with me Succor
Do you 'realize' the same way as your ability to 'define the problem'. I reckon so...i have better things in life to do then to develop issues with people like you....you don't worth it.
Quote:
but please, quote me correctly. Links to the above quoted threads:
They were correctly posted and people have brains to understand ..thanks.. don't try too hard Dick, you are ending up messing yourself too much..stop it here...and I am done.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Jun 02, 2009 7:14 pm
Reply with quote

bet you're not!
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Jun 02, 2009 7:16 pm
Reply with quote

An opportune moment to lock this thread I believe.

I am sure that if you really do want to, then offline would be a better arena to continue the combat.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
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
No new posts To Remove spaces (which is in hex for... JCL & VSAM 10
No new posts How to remove spaces in between. SYNCSORT 12
No new posts Concatenate 2 fields (usage national)... COBOL Programming 2
Search our Forums:

Back to Top