Exemplo n.º 1
0
 def __init__(self,conn,name,struct_name,fld_name):
         self.__conn=conn
         self.name=name
         self.struct_name=struct_name
         self.fld_name=fld_name
         fld_def=conn.get_fieldlist(struct_name,fld_name)[0][1:]
         struct=pysap.create_struct([('sign','C',1),('option','C',2),('low',)+fld_def,('high',)+fld_def])
         self.__itab=pysap.ItTable(name,struct)
Exemplo n.º 2
0
def create_struct1():
    flds = [('desc', 'C', 20), ('val1', 'N', 10), ('val2', 'N', 5)]
    return pysap.create_struct(flds)
Exemplo n.º 3
0
def create_struct3():
    flds = [('desc', 'C', 25), ('val2', 'N', 5), ('val3', 'N', 10)]
    return pysap.create_struct(flds)
Exemplo n.º 4
0
def create_struct2():
    return pysap.create_struct([('line', 'C', 35)])
Exemplo n.º 5
0
# This example shows how to peruse conversion routine to do value checking.
def inValue(self, v):
    if not v: v = 'H'  # default value
    v = v.upper()
    if v in ('H', 'B', 'T'):
        return v
    else:
        raise ValueError('invalid value')


# This is the output conversion routine.
def outValue(self, v):
    return {'H': 'home', 'B': 'bussiness', 'T': 'test'}.get(v, '')


S = pysap.create_struct([('desc', 'C', 40), ('typ', 'C', 1)])
# Here we set conversion routines for the field 'typ'. set_conversion is a class method. (It sets conversion
# routines for all instances of class S.)
S.set_conversion('typ', inValue, outValue)
s = S()
s['desc'] = 'system 1'
s['typ'] = 'T'
print s
s['desc'] = 'system 2'
# This should trigger a ValueError.
try:
    s['typ'] = 'X'
except ValueError:
    print 'ok'
else:
    print 'Huh?! Something is wrong here.'
Exemplo n.º 6
0
# This example shows how to manipulate SAP structures and internal tables from Python.

# Connection to SAP R/3 system is not needed for this example.

import pysap

# Create field descriptions for the create_struct function
struct1 = (('desc', 'C', 32), ('val1', 'N', 8), ('val2', 'N', 8), ('time',
                                                                   'T'))
struct2 = (('desc', 'C', 40), ('val2', 'N', 8), ('val3', 'N', 5), ('flag', 'C',
                                                                   1))
# Create both structures
S1 = pysap.create_struct(struct1)
S2 = pysap.create_struct(struct2)
# Instantiate S1
s1 = S1()
# Print definition of 'val1' - should print N8
print s1.sap_def('val1')
# Fill in data
s1['desc'] = 'Test values'
s1['val1'] = 100
s1['val2'] = 450
s1['time'] = '8:45:35'  # Use this if you have mxDateTime installed
# s1['time']='84535' # Else use this
# Print it
print s1
# Create an instance of S2 and fill it with values
s2 = S2()
s2['desc'] = 'New long value (almost 40 characters)'
s2['val2'] = 1200
s2['val3'] = 150