Class SAP::Tab
In: lib/SAP/Rfc.rb
Parent: BaseParm
Array TabArray SAPRfc Rfc Tools BaseParm Parm Tab Ticket Struct Iface Field SAP dot/f_0.png

Methods

chop   empty   hashRows   new   nextHashRow   reset   rows   unchop   value=  

Attributes

data  [R] 
data  [W] 
intype  [R] 
len  [R] 
like  [R] 
name  [R] 
optional  [R] 
structure  [R] 
structure  [W] 
type  [R] 
unicode  [W] 
unicode  [R] 
value  [R] 

Public Class methods

[Source]

      # File lib/SAP/Rfc.rb, line 1936
1936:     def initialize(name, structure=nil, len=0, unicode=nil, value=SAP::TabArray.new(len.to_i))
1937:       if name.instance_of?(Hash)
1938:         args = name
1939:         raise "Table must have a name" unless args.has_key?(:name)
1940:         @name = args[:name].to_s.upcase
1941:         raise "Parameter must have a like defining the DDIC ref (#{@name})" unless args.has_key?(:like)
1942:         @like = args[:like]
1943:         @optional = args[:optional] || " "
1944:         @optional = "X" if @optional == true
1945:         @type = RFCTABLE
1946:         @unicode = args[:unicode] || nil
1947:       else
1948:         @name = name.to_s.upcase
1949:         @structure = structure
1950:         @type = RFCTABLE
1951:         @intype = RFCTYPE_BYTE
1952:         @len = len.to_i
1953:         @value = value
1954:         @unicode = unicode
1955:       end
1956:                         @value.unicode = self.unicode
1957:                         @data = []
1958:     end

Public Instance methods

[Source]

      # File lib/SAP/Rfc.rb, line 2016
2016:     def chop
2017:       if self.structure.instance_of?(SAP::Struct) && self.unicode
2018:                           #puts "chop: #{self.name}"
2019:                           #self.data.clear
2020:                           #self.data = []
2021:                                 newdata = []
2022:                                 self.value.each{|row|
2023:                                   line = []
2024:                         self.structure.fields.each{|fld|
2025:                           val = row[fld.name] || ""
2026:             case fld.intype
2027:               when RFCTYPE_BCD
2028:                   val.sub!(/^\s+([\s\-\+]\d.*)$/, '\1')
2029:                   val = 0 if ! val || val == ""
2030:                       val = sprintf("%0" + ((fld.intlen*2) + (fld.decimals > 0 ? 1 : 0)).to_s + "." + fld.decimals.to_s + "f", val);
2031:                       val.gsub!(/\./,"")
2032:                   if val.slice!(0,1) == "-"
2033:                         val += "d"
2034:                   else
2035:                         val += "c"
2036:                 end
2037:                 val = [val].pack("H*")
2038:               when RFCTYPE_FLOAT
2039:                 val = [val.to_i].pack("d")
2040:               when RFCTYPE_INT
2041:                 val = [val.to_i].pack("l")
2042:               when RFCTYPE_INT2
2043:                 val = [val.to_i].pack("S")
2044:               when RFCTYPE_INT1
2045:                 val = val.to_i.chr
2046:               when RFCTYPE_DATE
2047:                                         if val.to_i == 0
2048:                                               val = "00000000"
2049:                                             end
2050:                 val = val.to_s.ljust(fld.intlen)
2051:               when RFCTYPE_TIME
2052:                                      if val.to_i == 0
2053:                                              val = "000000"
2054:                                              end
2055:                 val = val.to_s.ljust(fld.intlen)
2056:               when RFCTYPE_NUM
2057:                 val = sprintf("%0" + fld.intlen.to_s + "d", val.to_i) 
2058:               else 
2059:                 val = val.to_s.ljust(fld.intlen)
2060:             end
2061:                                line.push(val)
2062:                              }
2063:                              #self.data.push(line)
2064:                                         newdata.push(line)
2065:                                 }
2066:                                 #self.value.clear
2067:         #@value = SAP::TabArray.new(@len, self.unicode)
2068:                                 self.empty
2069:                                 self.data = newdata
2070:                         end
2071:                 end

[Source]

      # File lib/SAP/Rfc.rb, line 2139
2139:     def empty
2140:       @value = SAP::TabArray.new(@len, self.unicode)
2141:                         self.data = []
2142:     end

[Source]

      # File lib/SAP/Rfc.rb, line 2129
2129:     def hashRows
2130:       @value.each do |row|
2131:         yield self.unicode ? row : @structure.toHash(row)
2132:       end
2133:     end

[Source]

      # File lib/SAP/Rfc.rb, line 2123
2123:     def nextHashRow
2124:       while row = @value.shift
2125:         yield self.unicode ? row : @structure.toHash(row)
2126:       end
2127:     end
reset()

Alias for empty

[Source]

      # File lib/SAP/Rfc.rb, line 2135
2135:     def rows
2136:       return @value.map {|x| self.unicode ? x : @structure.toHash(x)}
2137:     end

[Source]

      # File lib/SAP/Rfc.rb, line 2074
2074:     def unchop
2075:       if self.structure.instance_of?(SAP::Struct) && self.unicode
2076:                           #puts "unchop: #{self.name}"
2077:         newval = SAP::TabArray.new(@len, self.unicode)
2078:                                 self.value.each do |row|
2079:                                   line = {}
2080:               self.structure.fields.each do |fld|
2081:                 fldval = row.shift
2082:                 case fld.intype
2083:                     when RFCTYPE_BCD
2084:                       chars = fldval.unpack("H*").first.split(//)
2085:                                                     while (chars.last == "0")
2086:                                                 chars.unshift(chars.pop())
2087:                                                end
2088:                                                   if chars.pop == "d"
2089:                                                     chars.unshift('-')
2090:                                                   end
2091:                                                   if fld.decimals != 0
2092:                                                     chars = [chars.slice(0, (chars.length - fld.decimals)),
2093:                                                               ".",
2094:                                                               chars.slice((chars.length - fld.decimals), (chars.length - 1))]
2095:                                                     chars.flatten!
2096:                                                   end
2097:                                                   value = chars.join("")
2098:                   when RFCTYPE_FLOAT
2099:                         value = fldval.unpack("d").first
2100:                       when RFCTYPE_INT
2101:                         value = fldval.unpack("l").first
2102:                       when RFCTYPE_INT2
2103:                         value = fldval.unpack("S").first
2104:                       when RFCTYPE_INT1
2105:                       value = fldval[0]
2106:                     when RFCTYPE_NUM
2107:                         value = fldval 
2108:                       else 
2109:                         value = fldval
2110:                   end
2111:                                line[fld.name] = value
2112:           end
2113:                                         newval.push(line)
2114:         end
2115:                                 self.empty
2116:                           #self.value.clear
2117:                           self.value = newval
2118:                           #self.data.clear
2119:                           #self.data = []
2120:                   end
2121:                 end

[Source]

      # File lib/SAP/Rfc.rb, line 1960
1960:     def value=(val)
1961:       length = @len
1962:       val.map! {|x| 
1963:                           if self.unicode
1964:                                   unless x.instance_of?(Hash)
1965:                               raise "in unicode parameter (#{self.name}) must be passed an array of hashes of field values" 
1966:                             end
1967: #                                 self.structure.value = "".ljust(self.structure.length)
1968:                                         row = {}
1969:                                   self.structure.fields.each{|fld|
1970:                                           fldval = x[fld.name] || ""
1971:             case fld.intype
1972:               when RFCTYPE_BCD
1973:                       fldval.sub!(/^\s+([\s\-\+]\d.*)$/, '\1')
1974:                       fldval = 0 if ! fldval || fldval == ""
1975:               when RFCTYPE_FLOAT
1976:                 fldval = fldval.to_i || 0
1977:               when RFCTYPE_INT
1978:                 fldval = fldval.to_i || 0
1979:               when RFCTYPE_INT2
1980:                 fldval = fldval.to_i || 0
1981:               when RFCTYPE_INT1
1982:                 fldval = fldval.to_i || 0
1983:               when RFCTYPE_DATE
1984:                                         if fldval.to_i == 0
1985:                                                 fldval = "00000000"
1986:                                               end
1987:                 fldval = fldval.to_s.ljust(fld.intlen)
1988:               when RFCTYPE_TIME
1989:                                         if fldval.to_i == 0
1990:                                                 fldval = "000000"
1991:                                               end
1992:                 fldval = fldval.to_s.ljust(fld.intlen)
1993:               when RFCTYPE_NUM
1994:                 fldval = sprintf("%0" + fld.intlen.to_s + "d", fldval.to_i) 
1995:               else 
1996:                                               #puts "adjusting: #{self.name}/#{fld.name} (#{fldval}) to #{fldval.unicode_length}"
1997:                 fldval = fldval.unicode_adjust(fld.intlen)
1998:                                               #puts "#{self.name}/#{fld.name} now (#{fldval}) of #{fldval.unicode_length}"
1999:             end
2000:             row[fld.name] = fldval
2001:                                         }
2002:           x = row
2003:         else
2004:           if x.instance_of?(Hash)
2005: #                                   self.structure.value = "".ljust(self.structure.length)
2006:                               x.each_key{|key| self.structure.getField(key).value = x[key] }
2007:             x = self.structure.value.to_s
2008:                             end
2009:                             x.ljust(length)
2010:                           end
2011:                         }
2012:                         #puts "Table now: ", val.inspect
2013:       @value = val
2014:     end

[Validate]