View previous topic :: View next topic
|
Author |
Message |
PrabakarV
New User
Joined: 21 Dec 2007 Posts: 88 Location: My Desk
|
|
|
|
ARRAY 1
Code: |
05 CONV-LINE-DATA OCCURS 99.
10 CONV-LINE-NUMBER PIC 9(02). |
ARRAY2
Code: |
05 HOLD-LINE-DATA-H OCCURS 6 TIMES.
07 HOLD-LINE-DATA-HOSP OCCURS 18.
10 HOLD-LINE-NUMBER-H PIC 9(02). |
my requirement is to move those 99 oocurences into the second array. can u please suggest me how to do it.[/code] |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
There are a different number of entries in the two-dimensional table than in the other.
We can't have anything more than a guess about how the data maps from one table to the other.
Here's my guess.
Code: |
05 CONV-LINE-DATA.
07 FILLER OCCURS 99.
10 CONV-LINE-NUMBER PIC 9(02).
07 FILLER PIX X(18) VALUE ZERO. (so you end up with zeros in the final 9 entries).
05 HOLD-LINE-DATA-H.
06 FILLER OCCURS 6 TIMES.
07 HOLD-LINE-DATA-HOSP OCCURS 18.
10 HOLD-LINE-NUMBER-H PIC 9(02).
MOVE CONV-LINE-DATA TO HOLD-LINE-DATA-H |
I'm one of those who always puts OCCURS on FILLERs. I like solutions with data definitions.
May not be any use to you at all, as the mapping is totally crucial to success.
Why are they PIC 9(02)? Just because it has "NUMBER" in the name, or do you use it as a numeric item? |
|
Back to top |
|
|
PrabakarV
New User
Joined: 21 Dec 2007 Posts: 88 Location: My Desk
|
|
|
|
Thanks Sambhaji. I finally managed to find a solution to this one. i believe it wil work. need to test it immediately.
Code: |
PARA:
PERFORM VARYING WS-SUB1 FROM WS-SUB1 BY 1 UNTIL WS-SUB1 > 99
OR (CONV-LINE-NUMBER (WS-SUB1) = (ZERO OR SPACES OR LOW VALUES))
MOVE CONV-LINE-NUMBER (WS-SUB1)
TO HOLD-LINE-NUMBER (WS-SUB2 WS-SUB3)
ADD +1 TO WS-SUB3
IF WS-SUB3 > 18
MOVE +1 TO WS-SUB3
ADD +1 TO WS-SUB2
GO TO PARA
END-IF
END-PERFORM |
|
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
If CONV-LINE-NUMBER is defined as Display-Numeric, then you're probably going to get a compilation-error, because you're checking this field directly for LOW-VALUES and SPACES.
Instead, check for NOT NUMERIC.
Mr. Bill |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
PrabakarV, Why you have not gone for simple move shown by Bill? |
|
Back to top |
|
|
PrabakarV
New User
Joined: 21 Dec 2007 Posts: 88 Location: My Desk
|
|
|
|
Sambhaji, because i am not authorized change that variable declaration... i just need to process it... |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
My guess.... Is it interview question??? |
|
Back to top |
|
|
PrabakarV
New User
Joined: 21 Dec 2007 Posts: 88 Location: My Desk
|
|
|
|
better luck next time mate... they have given me copybook that i cant chagne it but should use.... what i can i do other than to find a solution.... |
|
Back to top |
|
|
ridgewalker58
New User
Joined: 26 Sep 2008 Posts: 51 Location: New York
|
|
|
|
??? And there is NO group level over the ARRAY-1 and ARRAY-2???
Seems strange.
If there were a group level over the arrays
01 ARRAY-1-GROUP-LEVEL. --and-- 01 ARRAY-2-GROUP-LEVEL.
*** then the SIMPLE MOVE statement would do the trick
MOVE ARRAY-1-GROUP-LEVEL TO ARRAY-2-GROUP-LEVEL.
MOVE SPACES TO ARRAY-2-GROUP-LEVEL (99:18).
.ARRAY 1
Code:
05 CONV-LINE-DATA OCCURS 99.
10 CONV-LINE-NUMBER PIC 9(02).
ARRAY2
Code:
05 HOLD-LINE-DATA-H OCCURS 6 TIMES.
07 HOLD-LINE-DATA-HOSP OCCURS 18.
10 HOLD-LINE-NUMBER-H PIC 9(02). |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
PrabakarV wrote: |
Thanks Sambhaji. I finally managed to find a solution to this one. i believe it wil work. need to test it immediately.
Code: |
PARA:
PERFORM VARYING WS-SUB1 FROM WS-SUB1 BY 1 UNTIL WS-SUB1 > 99
OR (CONV-LINE-NUMBER (WS-SUB1) = (ZERO OR SPACES OR LOW VALUES))
MOVE CONV-LINE-NUMBER (WS-SUB1)
TO HOLD-LINE-NUMBER (WS-SUB2 WS-SUB3)
ADD +1 TO WS-SUB3
IF WS-SUB3 > 18
MOVE +1 TO WS-SUB3
ADD +1 TO WS-SUB2
GO TO PARA
END-IF
END-PERFORM |
|
You have a GO TO from within your perform. This is not good practice, and is unnecessary. If you just remove the GO TO it'll be better, it will find the end of the if, the end of the perform structure and just normally continue the perform.
I assume "LOW VALUES" is a typo. Always, please, copy-and-paste your code here rather than re-type, else we may get led astray by a typo.
You seem to think the first table is not initialised. Have you confirmed this? Usually if a table contains uninitialised values there will be a count on the record for how many entries are occupied, and your other tests would not be necessary. If you need them, check in your Cobol manuals as the compiler option NUMPROC might get in your way (check on option ZWB if NUMPROC(NOPFD)).
Are you absolutely sure you can't validly have zero somewhere in the middle of the table?
Are you sure that is the data-mapping you want? No more logic than fill as much of the second table one at a time as you can. Do you set the second table, each time, to some starting value? If not, you are going to get a mix of data. If the first table the first time has 10 entries, you will copy 10 to the second table. If the second time the first has only one, you will copy one, but it will "look" like there are 10 if you use similar code to test for the presence of values in the second table.
We assume SUB2 and SUB3 are given a value of one somewhere before the perform.
Why the dumb names for your subscripts? Doesn't the data mean anything in business terms? Why don't you name your subscripts reflecting that, which will make the code easier to understand for anyone picking it up later (which may be you, a few months down the line).
I think the WS-SUB1 FROM WS-SUB1 will cause confusion to the reader. Someone will wonder whether the value changes each time through the loop.
Whoever "designed" the data structure in the first place did you no favours, with no group item (as ridgewalker pointed out and as my example would need). |
|
Back to top |
|
|
PrabakarV
New User
Joined: 21 Dec 2007 Posts: 88 Location: My Desk
|
|
|
|
Quote: |
I assume "LOW VALUES" is a typo. Always, please, copy-and-paste your code here rather than re-type, else we may get led astray by a typo. |
- yes. Typo
Quote: |
Are you absolutely sure you can't validly have zero somewhere in the middle of the table? |
its already taken care.
Quote: |
Are you sure that is the data-mapping you want? |
No. Not really. It was given to me. I need to do process it. sometimes u got that as you are told
Quote: |
We assume SUB2 and SUB3 are given a value of one somewhere before the perform. |
Yes Bill. Moved 1 to them. |
|
Back to top |
|
|
|