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

Logic to divide/concate the string/array


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

New User


Joined: 02 Jun 2005
Posts: 24
Location: PUNE

PostPosted: Wed Aug 08, 2007 4:00 pm
Reply with quote

I have following requirement
A PIC X(100) OCCURS 100 TIMES

This array can have any number of occurrences from 1 to 100
and array element can have any number of characters

I have to concatenate all the elements in a string. And then that string
needs to be divided into parts of size 80

If you get any idea let me know.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Wed Aug 08, 2007 4:37 pm
Reply with quote

You are not clear with your request. An example showing what do you want to do 'exactly' will be appriciated..
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 08, 2007 4:41 pm
Reply with quote

Code:

A PIC X(100) OCCURS 100 TIMES.
B REDEFINES A
  PIC X(80)  OCCURS 125 TIMES.
Back to top
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Wed Aug 08, 2007 4:52 pm
Reply with quote

My understanding is as follows.

Your array can have any number of elements b\w 1 to 100 and variable can have any number of characters b\w 1 to 100 again as size of the array is 100. If my understandis is right, following might solve your problem.

Increment a counter when something will be loaded into array. After completion of the loading take those many elements (e.g., you will have 52 elements, so use this counter as subscript) and using STRING you can concatenate all the array elements.

E.g., your counter is having value 3 and 3 elements of array information is ABC, BDEF and EFHGI.

Then you can concatenate using STRING as

STRING A(1) A(2) A(3) delimited by size to variable-name.

I don't have exact idea about deviding.

Please correct me if I am wrong anywhere.
Back to top
View user's profile Send private message
hariibm

New User


Joined: 05 Feb 2007
Posts: 61
Location: Chennai

PostPosted: Wed Aug 08, 2007 5:19 pm
Reply with quote

Hi Kumar,

Hope the below sample code help you.
Code:

01   A PIC X(100) OCCURS 100 TIMES.
01   B      pic   x(10000)
01   c      redefines B   pic   x(80)   occurs    125 times.
01   ws-i      pic   9(3) value 0.
01   ws-len      pic   9(3)
01   ws-last-pos   pic   9(4)

procedure division.
   move   1   to   ws-last-pos.
   perform 1000-collect-string varying ws-i from 1 by 1 until ws-i>100.

   1000-collect-string.
   move length of A(ws-i) to ws-len.
   move   A(ws-i)   to   B(ws-last-pos:ws-len).
   add   ws-len   to   ws-last-pos.

I am not sure if an alphanumeric datatype can hold the value of length 10000. If so, at the end of the execution of this code, C will have the content what you have asked for.

Please let me know if I am wrong.
Back to top
View user's profile Send private message
kumar_jalluri

New User


Joined: 02 Jun 2005
Posts: 24
Location: PUNE

PostPosted: Wed Aug 08, 2007 6:04 pm
Reply with quote

Brenholtz,

Thanks for your solution.

what will happen if elements in A have spaces in it
Back to top
View user's profile Send private message
hariibm

New User


Joined: 05 Feb 2007
Posts: 61
Location: Chennai

PostPosted: Wed Aug 08, 2007 6:21 pm
Reply with quote

Yes, Length of won't be enough.
you could get the length of the string without spaces using INSPECT verb instead of "LENGTH OF" and can proceed with the above code.
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 08, 2007 6:32 pm
Reply with quote

kumar_jalluri wrote:
what will happen if elements in A have spaces in it


They will still be there. you never did answer the question posed by agkshirsagar. I answered your question based on your requirements. If you want something else, then define your requirements.

what do you want to do? Remove all spaces? remove 2 to n contiguous spaces?
Back to top
View user's profile Send private message
kumar_jalluri

New User


Joined: 02 Jun 2005
Posts: 24
Location: PUNE

PostPosted: Wed Aug 08, 2007 6:55 pm
Reply with quote

Example -

Array have the following data

ABCD
SDF
SDFGHJI....... 73 characters
FGHJKMNHI ...... 80 characters


Each element can have a maximum of 100 characters.

I want the o/p as follows -

ABCDSDFSDFGHJI.......
FGHJKMNHI..............

Each string will have 80 chanracters....
Back to top
View user's profile Send private message
kumar_jalluri

New User


Joined: 02 Jun 2005
Posts: 24
Location: PUNE

PostPosted: Wed Aug 08, 2007 6:56 pm
Reply with quote

I don't need the spcaes
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 08, 2007 7:29 pm
Reply with quote

kumar_jalluri,
so, you just want to shift all non-spaces to the left throughout the complete array?

Code:

A PIC X(100) OCCURS 100 TIMES.
B REDEFINES A
  PIC X(80)  OCCURS 125 TIMES INDEXED BY B-IDX.
   88 DONT-USE-THIS-LINE  VALUE SPACES.
C REDEFINES A
   PIC X(1) OCCURS 10000 TIMES INDEXED BY C1-IDX, C2-IDX.
   88  IS-A-SPACE               VALUE SPACE.


Code:

PERFORM VARYING C1-IDX FROM 1 TO 10000
    SET C2-IDX TO C1-IDX
    SET C2-IDX UP BY 1
    IF IS-A-SPACE(C2-IDX)
    THEN
           CONTINUE
    ELSE
           MOVE C(C2-IDX) TO C(C1-IDX)
           SET IS-A-SPACE(C2-IDX) TO TRUE
    END-IF
END-PERFORM
PERFROM VARYING B-IDX FROM 1 TO 125
                   OR DONT-USE-THIS-LINE(B-IDX)
    DISPLAY B(B-IDX)
END-PERFORM
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: Thu Aug 09, 2007 12:47 am
Reply with quote

Hello,

When you are "reading" the 100-byte entries and "constructing" the 80-byte result entries, how should the process determine where a 100-byte entry ends? With these
Code:
ABCD
SDF
SDFGHJI....... 73 characters
FGHJKMNHI ...... 80 characters
how would the code know to stop after ABCD and/or SDF? Given that you've defined 100-byte "input", what should happen with data in pos 81-100? What should happen if the data in any one of the 100-byte entries is longer than 80 bytes?

What does the "real" data look like?

Please change your requirement definition to 20-byte input and 15-byte output, show some realistic "input" and what the resulting "output" would be. Include at least one example of 18 bytes of input data. Once the method is established, changing back to 100/80 will be trivial. Using the shorter lengths will make posting test input/output much easier.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Aug 09, 2007 7:47 am
Reply with quote

With Dick's solution if A has spaces, B will have spaces in the place where A did.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Aug 09, 2007 1:44 pm
Reply with quote

syntax was wrong:
Code:

PERFROM VARYING B-IDX FROM 1 TO 125
                   OR DONT-USE-THIS-LINE(B-IDX)
    DISPLAY B(B-IDX)
END-PERFORM


should be:
Code:

PERFROM VARYING B-IDX FROM 1 TO 125
              UNTIL DONT-USE-THIS-LINE(B-IDX)
    DISPLAY B(B-IDX)
END-PERFORM
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Aug 09, 2007 2:07 pm
Reply with quote

stodolas wrote:
With Dick's solution if A has spaces, B will have spaces in the place where A did.


Since B redefines A, what you said is true.

kumar_jalluri,

you need to provide more explanation if your desired output is not having every space 'removed' through the tablespace. My second solution was the same as doing the (( line command. Every non-space char is shifted to the left throughout the 10000 char area.

Unless this is a student project, shifting everything to the left makes no business sense. The examples that you gave are ambiguous at best.
Back to top
View user's profile Send private message
hariibm

New User


Joined: 05 Feb 2007
Posts: 61
Location: Chennai

PostPosted: Fri Aug 10, 2007 12:32 pm
Reply with quote

sorry to interrupt you guys... but I am eager to know whether my solution provided above will solve the problem if LENGTH OF is replaced by INSPECT VERB to know the actual string length (ie. to exclude the spaces on the right hand side). Please explain.
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 Aug 10, 2007 8:31 pm
Reply with quote

Hello,

Quote:
but I am eager to know whether my solution provided above will solve the problem
an easy way to find out is to try the code on your system. You could then post your findings here and others could learn what you learned icon_smile.gif

Maybe TS will also post the requested info and we can offer suggestions from there as well. . . .
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 file manager is doing string conversion IBM Tools 3
No new posts Search string in job at regular Spool... CLIST & REXX 0
Search our Forums:

Back to Top