View previous topic :: View next topic
|
Author |
Message |
kumar_jalluri
New User
Joined: 02 Jun 2005 Posts: 24 Location: PUNE
|
|
|
|
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 |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
You are not clear with your request. An example showing what do you want to do 'exactly' will be appriciated.. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Code: |
A PIC X(100) OCCURS 100 TIMES.
B REDEFINES A
PIC X(80) OCCURS 125 TIMES.
|
|
|
Back to top |
|
|
ksk
Active User
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
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 |
|
|
hariibm
New User
Joined: 05 Feb 2007 Posts: 61 Location: Chennai
|
|
|
|
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 |
|
|
kumar_jalluri
New User
Joined: 02 Jun 2005 Posts: 24 Location: PUNE
|
|
|
|
Brenholtz,
Thanks for your solution.
what will happen if elements in A have spaces in it |
|
Back to top |
|
|
hariibm
New User
Joined: 05 Feb 2007 Posts: 61 Location: Chennai
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
kumar_jalluri
New User
Joined: 02 Jun 2005 Posts: 24 Location: PUNE
|
|
|
|
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 |
|
|
kumar_jalluri
New User
Joined: 02 Jun 2005 Posts: 24 Location: PUNE
|
|
|
|
I don't need the spcaes |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
With Dick's solution if A has spaces, B will have spaces in the place where A did. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
hariibm
New User
Joined: 05 Feb 2007 Posts: 61 Location: Chennai
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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
Maybe TS will also post the requested info and we can offer suggestions from there as well. . . . |
|
Back to top |
|
|
|