Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

append a string to another
Hi,

I am a Cobol newby, trying to write a first program which reads in a
textfile, line by line and concatenates the lines to one big string. I
do the following:

------------
string thelongstring delimited by size
In-Data       delimited by size
into thelongstring
---------------

thelongstring is 32000 bytes long, In-Data is 80 bytes long. It seems
that cobol appends In-Data at the very end of thelongstring, that is
after the last space at position 32000.

Please tell me how it is possible to solve my problem.

Thanks and Kind Regards,
Tobias Neubert

Report this thread to moderator Post Follow-up to this message
Old Post
Tobias Neubert
12-22-04 01:55 PM


Re: append a string to another
In article <ea2fae75.0412200727.c44265f@posting.google.com>,
t1@s-neubert.net (Tobias Neubert) wrote:

> Hi,
>
> I am a Cobol newby, trying to write a first program which reads in a
> textfile, line by line and concatenates the lines to one big string. I
> do the following:
>
> ------------
> string thelongstring delimited by size
>        In-Data       delimited by size
>   into thelongstring
> ---------------
>
> thelongstring is 32000 bytes long, In-Data is 80 bytes long. It seems
> that cobol appends In-Data at the very end of thelongstring, that is
> after the last space at position 32000.
>
> Please tell me how it is possible to solve my problem.
>
> Thanks and Kind Regards,
> Tobias Neubert

You could try the "pointer" option.  It will remember the last position
used in theLongString:


move 1 to I
String
in-data delimited by size
into thelongstring
pointer in I
End-String


Report this thread to moderator Post Follow-up to this message
Old Post
Joe Zitzelberger
12-23-04 08:55 AM


Re: append a string to another
For example
thelongstring has now the value "Warum ist es so schoen am Rhein"
In-Data has now the value "?"
you write string thelongstring delimited by "  "
In-Data        delimited by size
into thelongstring
and after thelongstring contains "Warum ist es so schoen am Rhein?"

the another way is

move 32000 to i1
perform  32000 times
if thelongstring (i1:01) > space
add 1      to  i1
move In-Data to thelongstring (i1:  )
exit perform
end-if
subtract 1      from i1
end-perform.


Tobias Neubert wrote:

> Hi,
>
> I am a Cobol newby, trying to write a first program which reads in a
> textfile, line by line and concatenates the lines to one big string. I
> do the following:
>
> ------------
> string thelongstring delimited by size
>        In-Data       delimited by size
>   into thelongstring
> ---------------
>
> thelongstring is 32000 bytes long, In-Data is 80 bytes long. It seems
> that cobol appends In-Data at the very end of thelongstring, that is
> after the last space at position 32000.
>
> Please tell me how it is possible to solve my problem.
>
> Thanks and Kind Regards,
> Tobias Neubert

--
Vaclav Snajdr 08141-70310

Report this thread to moderator Post Follow-up to this message
Old Post
Vaclav Snajdr
12-23-04 01:55 PM


Re: append a string to another
On 20/12/2004 10:27 AM, Tobias Neubert wrote:

> I am a Cobol newby, trying to write a first program which reads in a
> textfile, line by line and concatenates the lines to one big string. I
> do the following:
>
> ------------
> string thelongstring delimited by size
>        In-Data       delimited by size
>   into thelongstring
> ---------------
>
> thelongstring is 32000 bytes long, In-Data is 80 bytes long. It seems
> that cobol appends In-Data at the very end of thelongstring, that is
> after the last space at position 32000.
>
> Please tell me how it is possible to solve my problem.

I'm a raw novice, as well, but if I understand your question right, you
are trying to concatenate the _contents_ of the two strings.  If you
delimit by size, you are concatenating the entire allocated chunks,
including any trailing spaces at the end of each.  The resulting string
will be the entire contents of thelongstring + the entire contents of
In-data (including all trailing whitespace), even if both these strings
do not take up the entire length of their respective variables.

You probably want to "delimit by spaces" so you only get the non-space
contents of the strings.  If your strings contains embedded spaces, you
may have to come up with a better algorithm, or have the strings have an
official delimiter you look for.  Since I familiar with strings in C, I
used trailing nulls in some strings I passed around in my last project.
Either that, or use "counted strings", and have any string like this
have two value components: the string value, and another var holding
it's size.

I'm guessing there are typical COBOL ways to do this, or environment
specific string handling routines that may be more correct for you.
Others may be able to comment, as I'm ignorant of these details.

Furthermore, I'm not sure if you can concatenate a string back into
itself in this manner.  You may have to (or should) use a third value to
hold the result, and then copy that back into your buffer string.  Is
this in any COBOL standard, or is it an environment- or
compiler-dependent thing?  If something goes wrong during this
operation, what gets left in the target variable?

--
clvrmnky <mailto:clvrmnky@COLDmail.com.INVALID>

Heat up and unmunge email to reply.

Report this thread to moderator Post Follow-up to this message
Old Post
clvrmnky
12-23-04 01:55 PM


Re: append a string to another
On 20-Dec-2004, t1@s-neubert.net (Tobias Neubert) wrote:

> I am a Cobol newby, trying to write a first program which reads in a
> textfile, line by line and concatenates the lines to one big string. I
> do the following:

Are you wanting to learn the STRING command?    Depending on your programmin
g
experience, you might find reference modification more to your liking in thi
s
case.

MOVE WORK-IN (IN-NDX:1)
TO WORK-OUT (OUT-NDX:1)

Report this thread to moderator Post Follow-up to this message
Old Post
Howard Brazee
12-23-04 01:55 PM


Re: append a string to another
Something like

string function trim (thelongstring, right), function trim (in-data,
right) ...

is being proposed as part of the Any-Length Elementary Item proposal for the
2008 standard.  The second argument may also be "left", in which case it's
*leading* spaces that don't figure into the result, and in the absence of a
second argument, both leading and trailing spaces are omitted.

In 2002 COBOL, writing one or more user-defined functions to accomplish
these tasks should be straightforward.

-Chuck Stevens

"JJ" <jj@nospam.com> wrote in message
news:87GdnTmvY7WSGVrcRVn-3Q@comcast.com...
> As others have said, find the last non-space of the strings, then use the
> STRING verb with reference modifiers denoting the content length of each
> variable.
>
> This is a case where it sure would be nice to have a DELIMITED BY TRAILING
> SPACES clause, such as:
>
>    string thelongstring, in-data delimited by trailing spaces .....
>
> (don't try this - it doesn't exist - I'm just suggesting that it would be
> nice to have)
>
>
>
> "Tobias Neubert" <t1@s-neubert.net> wrote in message
> news:ea2fae75.0412200727.c44265f@posting.google.com... 
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Chuck Stevens
12-23-04 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Cobol archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:04 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.