**free
// WATSONKWR: This is a simple green-screen program to
//            demonstrate searching the AVKEYWORDS table
//            (approved vendor keywords).  See WATSONKW1R
//            for the actual calls to Watson.
//
dcl-f WATSONKWD workstn sfile(SFL:RRN) indds(ind);

dcl-ds ind qualified;
   exit ind pos(3);
   clearSFL ind pos(50);
   showSFL ind pos(51);
end-ds;

dcl-ds VENDOR qualified;
   num packed(7: 0);
   name char(25);
   keyword char(40);
end-ds;

dcl-s RRN packed(4: 0);
dcl-s QUERY varchar(42);

exec SQL set option naming=*SYS, commit=*NONE;

dou ind.EXIT = *ON;

    ind.ClearSFL = *ON;
    ind.ShowSFL  = *OFF;
    write CTL;
    ind.ClearSFL = *OFF;
    ind.ShowSFL  = *OFF;
    RRN = 0;
    Query = '';

    if Search <> *blanks;

       Query = '%' + %trim(Search) + '%';

       exec SQL declare VENDOR cursor for
          select a.vnum, a.vname, b.vkeyword
            from AVKEYWORDS b
            join AVLIST a on b.VNUM = a.VNUM
           where b.VKEYWORD LIKE :QUERY
           order by b.VNUM;

       exec SQL open VENDOR;
       exec SQL fetch next from VENDOR into :VENDOR;

       dow %subst(sqlstt:1:2)='00' or %subst(sqlstt:1:2)='01';
           opt = ' ';
           num = VENDOR.num;
           name = VENDOR.name;
           kwd  = VENDOR.keyword;
           RRN += 1;
           write SFL;
           ind.ShowSFL = *ON;
           exec SQL fetch next from VENDOR into :VENDOR;
        enddo;

        exec SQL close VENDOR;
        Search = *Blanks;

     endif;

     write FOOTER;
     exfmt CTL;
enddo;

*inlr = *on;
 
