compile subroutine gl_acct_valid(ConvType, DataIo, Branch, ReturnedValue)
begin condition
pre:
post:
end condition
declare function msg, fieldcount, get_property

$insert logical
$insert msg_equates
$insert popup_equates

equ valid$         to 0    ;* successful
equ invalid_msg$   to 1    ;* bad data       -   print error message window
equ invalid_conv$  to 2    ;* bad conversion -          "         "
equ invalid_nomsg$ to 3    ;* bad but do not print the error message window
equ CrLf$          to char(13):char(10)

PlantCode = get_property( @window:'.PLANT', 'VALUE' )
City = ''
if PlantCode = 'M' then
  PopupId = 'LSL2**GL_ACCTS_MESA'
  City = 'Mesa'
end else
  PopupId = 'LSL2**GL_ACCTS'
  City = 'Tempe'
end
ReturnedValue = DataIo       
status() = Valid$
begin case
   case ConvType = 'ICONV'
       GlAcctInfo = xlate( 'SYSREPOSPOPUPS', PopupId, pdisplay$, 'X' )
       * build array of codes only
       GlCodes = ''
       GlCnt = fieldcount( GlAcctInfo, @vm )
       for i = 1 to GlCnt
           GlCodes := GlAcctInfo<1,i,1>:@fm
       next i
       GlCodes[-1,1] = ''
       locate DataIo in GlCodes using @fm setting Fpos else
           MsgInfo = ''
           MsgInfo<mtext$> = quote( DataIo ):' is not a valid General Ledger Account for ':City:'.'
           MsgInfo<micon$> = '!'
           Void = msg( '', MsgInfo )
           status() = invalid_nomsg$
       end
   case ConvType = 'OCONV'
      * no output
      ReturnedValue = DataIo
   case otherwise$
      ReturnedValue = ''
      status() = invalid_conv$
end case
return
