f_find_spt.srf 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. $PBExportHeader$f_find_spt.srf
  2. global type f_find_spt from function_object
  3. end type
  4. forward prototypes
  5. global function integer f_find_spt (string arg_sptcode, ref s_spt arg_s_spt)
  6. end prototypes
  7. global function integer f_find_spt (string arg_sptcode, ref s_spt arg_s_spt);Int rslt = 1
  8. Long cnt = 0
  9. String ls_sptcode,ls_name,ls_find_code
  10. Long ll_sptid
  11. Boolean if_find = False
  12. IF Trim(arg_sptcode) = '' THEN
  13. rslt = 0
  14. GOTO ext
  15. END IF
  16. SELECT u_spt.sptid
  17. INTO :ll_sptid
  18. FROM u_spt
  19. WHERE ( sptcode = :arg_sptcode OR Name = :arg_sptcode )
  20. And inuse = 1;
  21. IF sqlca.SQLCode <> 0 THEN
  22. IF Pos(Trim(arg_sptcode),'%') = 0 THEN
  23. ls_find_code = '%'+ Trim(arg_sptcode) + '%'
  24. ELSE
  25. ls_find_code = Trim(arg_sptcode)
  26. END IF
  27. SELECT count(*) INTO :cnt
  28. FROM u_spt
  29. WHERE ( sptcode LIKE :ls_find_code OR Name LIKE :ls_find_code )
  30. And inuse = 1;
  31. IF sqlca.SQLCode <> 0 THEN
  32. rslt = 0
  33. GOTO ext
  34. END IF
  35. IF cnt <> 1 THEN
  36. rslt = 0
  37. GOTO ext
  38. END IF
  39. SELECT u_spt.sptid
  40. INTO :ll_sptid
  41. FROM u_spt
  42. WHERE ( sptcode LIKE :ls_find_code OR Name LIKE :ls_find_code )
  43. And inuse = 1;
  44. IF sqlca.SQLCode <> 0 THEN
  45. rslt = 0
  46. GOTO ext
  47. END IF
  48. if_find = True
  49. ELSE
  50. if_find = True
  51. END IF
  52. IF if_find THEN
  53. SELECT u_spt.sptid,
  54. u_spt.name,
  55. u_spt.sptcode
  56. INTO :ll_sptid,
  57. :ls_name,
  58. :ls_sptcode
  59. FROM u_spt
  60. Where ( sptid = :ll_sptid );
  61. arg_s_spt.sptid = ll_sptid
  62. arg_s_spt.sptcode = ls_sptcode
  63. arg_s_spt.Name = ls_name
  64. END IF
  65. ext:
  66. RETURN rslt
  67. end function