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-20-04 08: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-20-04 08:55 PM


Re: append a string to another
Tobias Neubert schrieb:
>
> 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

Das will ich doch auch hoffen, wenn 'thelongstring' als x(32000)
definiert ist. Und Du willst es auch so mit der Anweisung '... delimited
by size'. Die Betonung liegt auf SIZE. Die Groesse ist also der
Begrenzer.
Wahrscheinlich willst Du hinter dem letzten Zeichen anhaengen. Das musst
Du dann - wenn nicht eindeutig im ganzen String - dann auch selber
ermitteln.

MfG
Manfred

Report this thread to moderator Post Follow-up to this message
Old Post
Manfred Niendiek
12-20-04 08:55 PM


Re: append a string to another
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

The delimiter needs to specify the end of the string.  If it is a null
terminated C style string, try DELIMITED BY x'00'.  If not, then try
delimited by '      ' where the quotes contain several spaces. Note that
the first instance of a string of blanks equal to the number of blanks
in the quotes will be considered the end of the long string.

Donald


Report this thread to moderator Post Follow-up to this message
Old Post
Donald Tees
12-20-04 08: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-20-04 08:55 PM


Re: append a string to another
..    On  20.12.04
wrote  t1@s-neubert.net (Tobias Neubert)
on  /COMP/LANG/COBOL
in  ea2fae75.0412200727.c44265f@posting.google.com
about  append a string to another


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

DELIMITED BY wurde schon angesprochen; außerdem sollte man die
aktuelle Position mit der Klausel "WITH POINTER integer-variable"
festhalten, damit das nächste STRING vom nächsten Satz genau dort
aufsetzen kann. Hier werden keine Strings konkateniert.

Außerdem kann man mit PERFORM VARYING den neuen String von hinten
her durchsuchen, um die Position des letzten Zeichens zu finden, das
nicht BLANK oder NULL ist.


English:
........

DELIMITED BY has already been discussed; also you should keep the
actual position in the receiving item by the clause "WITH POINTER
integer-variable", so that the next STRING for the next record can
start exactly at that position. This is not string-concatenation.


Yours,
Lüko Willms                                     http://www.willms-edv.de
/--------- L.WILLMS@jpberlin.de -- Alle Rechte vorbehalten --

Der Satz muß noch mit einem Bruch multipliziert werden. -G.C.Lichtenberg

Report this thread to moderator Post Follow-up to this message
Old Post
Lueko Willms
12-21-04 01:55 AM


Re: append a string to another
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.

You need to know the length of the data contained in string-1, either
implicitly or explicitly.

Implicitly, as others have said,
STRING string-1 DELIMITED BY "         " .....

For explicitly, you need to find the length. There are several ways:

Method 1:
PERFORM VARYING LEN FROM 32000 BY -1
UNTIL string-1(LEN:1) NOT = SPACE
CONTINUE
END-PERFORM

STRING string-1(1:LEN) DELIMITED SIZE....

Method 2 (If compiler permits):
COMPUTE LEN = FUNCTION STORED-CHAR-LENGTH(string-1)

Method 3 (many fans)
MOVE FUNCTION REVERSE(string-1) TO string-1
MOVE 0 TO LEN
INSPECT string-1 TALLYING LEN FOR LEADING SPACE
COMPUTE LEN = 32000 - LEN

Have fun.




Report this thread to moderator Post Follow-up to this message
Old Post
JerryMouse
12-21-04 01:55 AM


Re: append a string to another
I prefer INSPECT FUNCTION REVERSE for figuring out where the last non-blank
character is.

-Chuck Stevens

"JerryMouse" <nospam@bisusa.com> wrote in message
news:10sejuos7es0s1a@news.supernews.com...
> Tobias Neubert wrote: 
>
> You need to know the length of the data contained in string-1, either
> implicitly or explicitly.
>
> Implicitly, as others have said,
> STRING string-1 DELIMITED BY "         " .....
>
> For explicitly, you need to find the length. There are several ways:
>
> Method 1:
> PERFORM VARYING LEN FROM 32000 BY -1
>    UNTIL string-1(LEN:1) NOT = SPACE
>    CONTINUE
>    END-PERFORM
>
> STRING string-1(1:LEN) DELIMITED SIZE....
>
> Method 2 (If compiler permits):
> COMPUTE LEN = FUNCTION STORED-CHAR-LENGTH(string-1)
>
> Method 3 (many fans)
> MOVE FUNCTION REVERSE(string-1) TO string-1
> MOVE 0 TO LEN
> INSPECT string-1 TALLYING LEN FOR LEADING SPACE
> COMPUTE LEN = 32000 - LEN
>
> Have fun.
>
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Chuck Stevens
12-21-04 01:55 AM


Re: append a string to another
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...
> 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
JJ
12-21-04 08:55 AM


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-21-04 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
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 08:11 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.