Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nulls in Cobol

Status
Not open for further replies.

lbzh

Programmer
Aug 7, 2004
25
0
0
US
I am doing a Move of an Occurs field to a variable with a Usage of X(6).

The field contains in some instances the Null Value for each byte.

For instance we have the following 2 records:

123456
000000


where 000000= x'00' in each byte position.

How can I write an If statement with a Move to transform the 6 Nulls to 6 blanks.

Thanks


 
INSPECT INPUT-FIELD REPLACING LOW-VALUES BY SPACES

or

IF INPUT-FIELD EQUAL LOW-VALUES
MOVE SPACES TO INPUT-FIELD
END-IF

depending on your needs.
 
David,

Sorry but... Wrong!

Your code will test for input-field equal to a single LOW-VALUE followed by five (5) spaces, in the case of the original post. Your test will evaluate to not equal for both of the examples.

Tom Morrison
 
Absolutely true. I'm just used to passing strings back and forth to DLLs and OCX controls, where a null in the first character means that the string is empty. Force of habit :)

I'd either write a loop to test all characters or go with the LOW-VALUES thingamajiggy.

.DaviD.
 
k5tm

Out of curiosity, I tried the following:

Code:
if input-field = all x"00"
  continue
end-if

and it compiles just fine. I guess this is an alternative, but maybe just ACU supports it?

I'll take those browny points back now, thank you very much :)

.DaviD.
 
David, your new code should work.
Personally I use this:
IF INPUT-FIELD EQUAL ALL LOW-VALUE
MOVE SPACE TO INPUT-FIELD
END-IF

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I tried the suggestion:

IF INPUT-FIELD EQUAL LOW-VALUES
MOVE SPACES TO INPUT-FIELD
END-IF

and it worked great.

Thanks all for your input.

 
W.R.T. [tt]ALL X'00'[/tt] vs. [tt]LOW-VALUES[/tt]:

While in most cases these two produce identical results, there are situations where they do not.

The code [tt]ALL X'00'[/tt] will behave as expected in the presence of [tt]PROGRAM COLLATING SEQUENCE[/tt] specifying an alphabet that does not have the ordinal 1 as its lowest character position. An example might help understand this.
Code:
       identification division.
       program-id. bizarre-low-values.
       environment division.
       configuration section.
       object-computer.  my-ascii-computer
               program collating sequence is backward-alphabet.
       special-names.
           alphabet backward-alphabet is
               91, 90, 
               89, 88, 87, 86, 85, 84, 83, 82, 81, 80,
               79, 78, 77, 76, 75, 74, 73, 72, 71, 70,
               69, 68, 67, 66.
       data division.
       working-storage section.
       01  an-item     pic x(6).
       procedure division.
       a.  move low-values to an-item.
           display an-item.
           stop run.
The result that is display (on an ASCII native implementation) is...

ZZZZZZ

LOW-VALUES does not always equal ALL X"00".

Tom Morrison
 
Hmmm ....

Never thought (or even heard) of that sort of thing. Sounds like pretty obscure Cobol, if you ask me, but ok - you can take the browny points back [smile]

.DaviD.
 
David,

I think you can keep your brownie points!

I agree with the last code you posted, which used [tt]ALL X"00"[/tt]. It was PHV that posted [tt]LOW-VALUES[/tt]. In the problem posed by the original post, your code would work in all cases (even in the case of an obscure program collating sequence); PHV's would not.

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top