View previous topic :: View next topic
|
Author |
Message |
ankit.jain
New User
Joined: 02 Jul 2009 Posts: 18 Location: Mumbai
|
|
|
|
I have a group of variables defined as follows:
Code: |
10 GROUP1.
15 VAR1 PIC X(06).
15 VAR2 PIC X(20).
15 VAR3 PIC X(04).
.....
.....
.....
15 VAR10 PIC X(01).
15 VAR11 PIC S9(05) COMP-3.
15 VAR12 PIC X(01).
15 VAR13 PIC X(29).
15 GROUPA.
20 VARA1 PIC X(03).
20 VARA2 PIC X(03).
20 VARA3 PIC X(04).
|
I need to find out if ANY of the variables under GROUP1 have some value or they are just initialized (being spaces or zeroes). If ANY of the variables have some value, some processing needs to be done.
I applied the following code for this …
Code: |
IF GROUP1 > SPACES
OR VAR11 > ZEROES
NEXT SENTENCE (To perform the required processing)
ELSE
GO TO EXIT. (Do not perform any processing) |
However, this code is failing in the following scenario:
Code: |
10 GROUP1.
15 VAR1 PIC X(06). (SPACES)
15 VAR2 PIC X(20). (SPACES)
15 VAR3 PIC X(04). (SPACES)
.....
.....
.....
15 VAR10 PIC X(01). (SPACES)
15 VAR11 PIC S9(05) COMP-3.
15 VAR12 PIC X(01). (SPACES)
15 VAR13 PIC X(29). (SPACES)
15 GROUPA.
20 VARA1 PIC X(03). (VALUE = 123)
20 VARA2 PIC X(03). (VALUE = 456)
20 VARA3 PIC X(04). (VALUE = 7789) |
I expected program control will go to NEXT SENTENCE and do some processing (as per the code shown above). However, it is going to EXIT. This happens for any variable that appears after the COMP-3 variable.
Is there any solution to this? Or any other way to fulfill my requirement – I just need to find if any of the variables under GROUP1 have some value other than spaces (for alphanumeric) or zeroes (for COMP-3).
Please help urgently!
Thanks,
Ankit |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
Quote: |
Please help urgently! |
since we reply on our own time and free of charge
we do not do urgently |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
another example of someone who does not bother to understand the code that he lays.
if you would look at the hex for a group:
Code: |
01 PRIM-GROUP-1.
03 FILLER-11 PIC X(10) VALUE SPACES.
03 FILLER-12 PIC S9(3) COMP-3 VALUE ZERO.
03 SECONDARY-GROUP.
05 FILLER-3 PIC X(03) VALUE '123'.
|
Code: |
444444444400FFF
00000000000C123
|
and the hex for spaces
Code: |
444444444444444
000000000000000
|
which is greater?
as long as you continue to place PACKED-DECIMAL before X-type,
you will continue to have this problem.
the only time the first compare (group) will work is when the PD field contains a value that cause the one of the bytes (i only have 2 in my example where as you have 3) contains a hex value gt 40. |
|
Back to top |
|
|
Eshwar CICS
New User
Joined: 18 May 2011 Posts: 47 Location: India
|
|
|
|
Ankit...you know the root cause...then try:
1. grouping the variables before and after the comp-3 variable in to two different sets and perform IF on those group variables.
or
2. Use reference modification in IF condition to check the values before and after comp-3 variable.
or
3. Declare another instance of same group variable(which does not get modified) and compare with the group variable to know whether the initial state of the group variable got changed. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
I need to find out if ANY of the variables under GROUP1 have some value or they are just initialized (being spaces or zeroes). |
Is this done by the application somewhere? If not, you really need to talk to your site support group. There are options to allow memory to be intiialized, typically to LOW-VALUES (X'00'), but not every site does this. If your site does not, and your application does not initialize memory, then there's a good chance you'll get random data in those variables. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Don't you already know if you put any data in the table?
If you want a really lazy way to do it: define a piece of storage at least as long as your table. When you have set your table to its initial values, move the table to the new piece of storage. If, later, you have forgotten whether you put anything in the table, you can compare the whole table to the new piece of storage. If equal, there is nothing in it. |
|
Back to top |
|
|
ankit.jain
New User
Joined: 02 Jul 2009 Posts: 18 Location: Mumbai
|
|
|
|
Thank you all for your quick replies !
Let me first explain what I need to finally achieve with my requirement – by checking if fields of the group variable contains spaces or zeroes only.
I need to convert the records of a VSAM file (say INPUT FILE) such that some information from these records are moved out and written to another VSAM file (say OUTPUT FILE) as new records. The information that I need to move out from the INPUT FILE is GROUP1 group variable.
The problem is that the GROUP1 record should only be written to the OUTPUT FILE, if it has some information which means that its alphanumeric fields are > SPACES and the numeric/packed decimal fields are > ZEROES.
Hope this information gives you more insight into my problem/requirement. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
So either code out a bunch of IFs, for each field, setting a flag if non-space/zero or...
Put your copybook in Working Storage. Move space to the 01-level. Move zero to any numeric items. Then do the bit I said above.
Now read into your working-storage 01. Compare it to the new 01 which just contains the "nothing there" values. If equal, you don't want the record, else you do. |
|
Back to top |
|
|
ankit.jain
New User
Joined: 02 Jul 2009 Posts: 18 Location: Mumbai
|
|
|
|
dbzTHEdinosauer,
I think you are trying to explain in your example that 000CF1F2F3 > 4040404040. Is my understanding correct? If so, then I got what you are trying to say and understand the problem with my code. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
no, you have it back-asswards.
this is true:
000CF1F2F3 < 4040404040
this is false
IF GROUP1 > SPACES
the solution is to change the order of your elements,
and place the comp-3 value at the end in another group.
and only compare groups with x-type elements to spaces.
do not mix element datatypes within a group.
you will have to compare each non-xtype element (comp-3 in this case)
separately.
because future maintainers of this code will probably only know as much as you do, and add elements in the wrong place,
and thus screw up this silly code.
each field should be compared to spaces/zero and a routine performed
tryng to perform this silly compare here makes not sense.
you still have to compare each field to determine disposition.
and I was not trying to explain anything.
i explained the problem. - actually the symptom
(your lack of knowledge and unwillingness to think about what you were doing
is the problem |
|
Back to top |
|
|
ankit.jain
New User
Joined: 02 Jul 2009 Posts: 18 Location: Mumbai
|
|
|
|
Quote: |
000CF1F2F3 > 4040404040 |
I put it wrong in my post. I had to write 000CF1F2F3 < 4040404040 |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Don't use ">" (even if you find typing GREATER THAN tiring).
For your alpha fields, are you certain that none can contain LOW-VALUES?
For your numeric, are you certain that none are negative?
Use NOT EQUAL TO. |
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
Bill Woodger wrote: |
Don't use ">" (even if you find typing GREATER THAN tiring).
|
Seriously? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Sorry Don, I mean for this particular requirement. Not as a general rule
:-) |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
You can do like this:
Code: |
10 GROUP1.
15 VAR1 PIC X(06).
15 VAR2 PIC X(20).
15 VAR3 PIC X(04).
.....
.....
.....
15 VAR10 PIC X(01).
15 VAR11 PIC S9(05) COMP-3.
15 VAR12 PIC X(01).
15 VAR13 PIC X(29).
15 GROUPA.
20 VARA1 PIC X(03).
20 VARA2 PIC X(03).
20 VARA3 PIC X(04).
10 REFERENCE-GROUP1.
15 FILLER PIC X(06) VALUE SPACES.
15 FILLER PIC X(20) VALUE SPACES.
15 FILLER PIC X(04) VALUE SPACES.
.....
.....
.....
15 FILLER PIC X(01) VALUE SPACES.
15 FILLER PIC S9(05) COMP-3 VALUE 0.
15 FILLER PIC X(01) VALUE SPACES.
15 FILLER PIC X(29) VALUE SPACES.
15 FILLER.
20 FILLER PIC X(03) VALUE SPACES.
20 FILLER PIC X(03) VALUE SPACES.
20 FILLER PIC X(04) VALUE SPACES.
IF GROUP1 NOT = REFERENCE-GROUP1 THEN
<some values>
ELSE
<all empty>
END-IF |
|
|
Back to top |
|
|
ankit.jain
New User
Joined: 02 Jul 2009 Posts: 18 Location: Mumbai
|
|
|
|
Eshwar,
Thanks for your reply !
All the solutions you provided will resolve my problem. However,
Quote: |
1. grouping the variables before and after the comp-3 variable in to two different sets and perform IF on those group variables. |
I cannot "group" the variables before and after separately as I am dealing with the layout of a file.
Quote: |
2. Use reference modification in IF condition to check the values before and after comp-3 variable. |
I know this is one of the ways but but reference modifications is something we want to avoid as per our coding standards. But is not other solution works, we may use it.
Quote: |
3. Declare another instance of same group variable(which does not get modified) and compare with the group variable to know whether the initial state of the group variable got changed. |
This is an excellent suggestion! |
|
Back to top |
|
|
ankit.jain
New User
Joined: 02 Jul 2009 Posts: 18 Location: Mumbai
|
|
|
|
Bill and Marso,
Thanks for your suggestion !
You both suggested the solution similar to what Eshwar suggested
Quote: |
Declare another instance of same group variable(which does not get modified) and compare with the group variable to know whether the initial state of the group variable got changed. |
I think that is one of the best solutions to my problem.
Thanks, |
|
Back to top |
|
|
ankit.jain
New User
Joined: 02 Jul 2009 Posts: 18 Location: Mumbai
|
|
|
|
All,
Thanks for your suggestions !
I now understand the root cause of my problem and its probable solutions. Out of the possible solutions, I would need to see which solution our site would want to have.
Thanks to dbzTHEdinosauer who helped me understand the problem with what I coded ! |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Yes, all three are the same.
I think your final choice might depend on whether or not this is a once-off.
If it is, you can pick.
If it is for some reason a permanent thing, my particular version is more maintainable :-)
Code: |
01 which-will-hold-data.
05 lots of items, PIC X, PIC 9 of some sort, doesn't matter.
01 which-will-hold-"initial"-state PIC X(?) |
By whatever means you like, set all of the elementary items to their initial value (which can be anything).
MOVE which-will-hold-data TO which-will-hold-"initial"-state
Then later in the program
Code: |
if which-will-hold-data EQUAL TO which-will-hold-"initial"-state
do your stuff with an "empty" record
else
do your stuff with a "data" record
endif |
? for the length of the data can be longer, because it will pad to space from the move and compare correctly.
Or, you can make it the correct length, and when you are setting it up you can use LENGTH OF to check that it is the same length as the file record. Then, if the file record lenght is changed your program will notice (after a recompile) and you can ensure that the length of the new 01 is changed as well. |
|
Back to top |
|
|
|