;==File=================================================================;
; POHEDRF.DBL	Contains code for processing purchase order header.
;=======================================================================;
; Copyright 2000 by TAH Software Systems (TAH), Oklahoma City, Oklahoma ;
;									;
;	TAH provides this software under a license and may only be	;
;	used in accordance with the terms and conditions of such	;
;	license and with the inclusion of the above Copyright notice.	;
;==Function=============================================================;
;=======================================================================;
;	pohedr_lookup	Lookup routine for purchase order header.
;==Changes==============================================================;
;=======================================================================;
.subroutine pohedr_lookup

	a_inp_id	,n		; IN  - input window ID
	a_dtb_chan	,n		; IN  - database table channel
	a_dtb_table	,a		; IN  - database table record
	a_dtb_key	,a		; IN  - database table key

.start nopage,nolist
.include "WND:tools.def"
.include "UTS:utcomm.gbl"
.include "POS:pocomm.gbl"
.include "POS:pohedr.rec"

record	pohedr_find			; record for pohedr lookup
	phif_order	,d6
	phif_vend	,d8
	key_find_data	,a50
	 key0_key	,a8	@key_find_data	; Lookup key for order number
	  key0_comp	,a2	@key0_key
	  key0_order	,d6	@key0_key+2
	 key1_key	,a8	@key_find_data	; Lookup key for vendor ID
	  key1_vend	,d8	@key1_key
	key_len		,d2		; Length of data in lookup key
	key_no		,d1		; Relative key number for search
	abort		,d1
.start nopage,list

.proc
	xcall e_enter
	xcall get_search ('POHEDR',pohedr_find,abort)
	if (abort.eq.FALSE) call do_lookup
	xcall e_exit
	xreturn

do_lookup,
	key0_comp = ut_cmcomp
	key_len = 2
	key_no = 0
	if (phif_order) then
	  begin
	    key0_comp = ut_cmcomp		; lookup by order no
	    key0_order = phif_order
	    key_len = %trim(key0_key)
	    key_no = 0
	  end
	 else
	  if (phif_vend)
	    begin
	      key1_vend = phif_vend		; lookup by vendor ID
	      key_len = %trim(key1_key)
	      key_no = 1
	    end
	if (key_len)
	  begin
	    xcall ut_find ('pohedr',a_dtb_chan,a_dtb_table,key_find_data(1:key_len),key_no,1)
	    if (a_dtb_table)
	      begin
		xcall db_read (a_dtb_chan,a_dtb_table,a_dtb_key,0,'M',1,,opcde)
		if (.not.opcde) xcall i_display (a_inp_id,'set_show',a_dtb_table)
	      end
	  end
	return
.end
;=======================================================================;

