Help in search instruction



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Help in search instruction

Postby ruizito » Sun Aug 23, 2009 8:57 pm

Hi!
I need to make a validation in a program. For that, I put all the valids numbers in a table. After, I want to make a search instruction for each record of my input file to know if the record is valid.
I'm in home and I don't have a cobol compilator here.
Anyone can compile this code for my and tell me if it works?

The table is:


01 TAB-NIFS.
05 TABLE-NIF OCCURS 50
DEPENDING ON CONT-REG-NIF
INDEXED BY WS-INDEX-NIF.
10 TABLE-NIF-SIZE PIC 9(02) VALUE ZEROS.
10 TABLE-NIF-VALUE PIC X(09) VALUE SPACES.
01 CONT-REG-NIF PIC 9(02) USAGE COMP-3 VALUE ZEROS.


An example of the load table is.

TABLE-NIF-SIZE | TABLE-NIF-VALUE
2 | 21
1 | 1
4 | 1233
3 | 123
9 | 123456789

The search instruction is:

Set ws-index-NIF to 1.

SEARCH TABLE-NIF

At end
set SW-NOTFND to true

When TABLE-NIF-VALUE( 1: TABLE-NIF-SIZE(WS-INDEX-NIF) )(ws-index-NIF) = FILEIN-NIF(1: TABLE-NIF-SIZE(WS-INDEX-NIF) )
set sw-FND to true

End-Search.


Thanks
ruizito
 
Posts: 2
Joined: Sat Feb 23, 2008 6:29 am
Has thanked: 0 time
Been thanked: 0 time

Re: Help in search instruction

Postby dick scherrer » Mon Aug 24, 2009 8:52 am

Hello,

Suggest you download one of the free cobol compilers and install on your pc. A web search for free cobol compiler gives many links. I believe MicroFocus also has a free version.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Help in search instruction

Postby GuyC » Mon Aug 24, 2009 12:41 pm

I haven't tried it in a while, but I don't think you can use index in a reference. i.e. var(1:var2(ix)) won't compile (probably).

and there is an functional error as well with the code provided : any number in file starting with 1 will equal your second entry in the table. You should use the size of the filein-nif to test. : varA(1:sizeofvarA) = varB(1:sizeofvarB)
I can explain it to you, but i can not understand it for you.
GuyC
 
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times

Re: Help in search instruction

Postby dick scherrer » Tue Aug 25, 2009 12:15 am

Hello,

One way to use reference modification on a field in an array is:
 01  HOLD-DTL-ARRAY VALUE SPACES.           
     03  HOLD-DTL OCCURS 900 TIMES.         
        05 CST-HD           PIC X(13).     
        05 RCD-TYP-HD       PIC XX.         
        05 ORD-TYPE-HD      PIC X.         
        05 DTL-NBR-HD       PIC XXX.       
        05 FILLER           PIC X(1200).   


         DISPLAY HOLD-DTL(1) (1:30)       
         DISPLAY HOLD-DTL(2) (1:30)       
         DISPLAY HOLD-DTL(3) (1:30)       
         DISPLAY HOLD-DTL(4) (1:30)       
         DISPLAY HOLD-DTL(5) (1:30)       
         DISPLAY HOLD-DTL(6) (1:30)       
         DISPLAY HOLD-DTL(7) (1:30)       
         DISPLAY HOLD-DTL(8) (1:30)       
         DISPLAY HOLD-DTL(9) (1:30)       

Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Help in search instruction

Postby GuyC » Thu Aug 27, 2009 12:13 pm

display var(ix) (1:30)

is not the same as
display var (1:var2(ix)) 


can be coded as :
move var2(ix) to ws-len
display var(1:ws-len)

but not in a Search
I can explain it to you, but i can not understand it for you.
GuyC
 
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post