Menu

Char fields left filled with zeros problem

Help
2006-09-12
2013-04-11
  • Nobody/Anonymous

    Hello,

    I have this problem: when calling a RFC using tables and putting numeric chars only in char fields, they get left filled with zeros till de width of the field, i.e if in python a do 1, i get in sap 001 in 3 char length fields,

    I'im using pysaprfc and SAP 4.6B

    Any ideas?

    Thanks.

     
    • Nobody/Anonymous

      I think this is the code in pysap.py which is doing the conversion  (over line 200), but i don't know the reason why is doing it?

      elif v.isdigit():
                      try:
                          v1=int(v)
                          if v1<=sys.maxint: v=v1
                      except ValueError:
                          self.int_value=v.ljust(self._length_)
                      else:
                          if isinstance(v,int):
                              self.int_value='%0*d' % (self._length_,v)
                          else:
                              self.int_value=v.ljust(self._length_)

      Any help from the author?

      Thanks

       
    • Klavdij Voncina

      Klavdij Voncina - 2006-09-12

      The purpose of this code was to automatically format string containing numbers to ABAP format for numerical strings (numc) - right aligned with leading zeroes. SAP uses this quite offten to format  fields like customer or material numbers which can be both alphanumerical (left aligned) and digits-only (leading zeroes) and I wanted the string  to be easly compatible with values as store in database.
      Latter I changed my mind - this kind of under-the-hood formating may lead to errors - and current CVS version doesn't use it anymore.

      Klavdij

       
    • Nobody/Anonymous

      Thank you Klavdij for your quick anwser, so I think I can comment previous lines without hurt (I will test)because they are at the part of the code which treat with the STRING data type.

      A question thought, Is it safe to use the code from CVS right now?

      Thanks.

      Manuel Segarra

       
    • Klavdij Voncina

      Klavdij Voncina - 2006-09-13

      Code in CVS is in "pre-release" state and should be fairly safe. I'm using it in couple of my projects and it seems rather stable.

      Klavdij

       
    • Nobody/Anonymous

      Hello,
      I have a similar problem using pysap. Example executed in idle:

      # get the interface
      >>> r_func=zhl_conn.get_interface('Y_4Q4_REQUEST_LICENCE_MESEQUI')
      >>> r_func.keys()
      ['RETURN_TAB', 'GRUPPENID', 'LIZSCHL']
      # assigne values to the import keys
      >>> r_func['GRUPPENID']='1514100'
      >>> r_func['LIZSCHL']='PCDELUN70099103AVS'
      # call the function
      >>> rc=r_func()
      # print the return_tab
      >>> for i in r_func['RETURN_TAB']:
          print i
         
      tdformat = '1 E:'
      tdline = '00000000. GruppenID nicht vorhanden'
      >>>
      # Expected:
      tdformat = '0 M:'
      tdline = 'PCDELUN70099103AVS' Lizenz OK

      Reason is that the lenght of r_func['GRUPPENID'] is doubled (type of GRUPPENID in SAP is CHAR length 8)AND the value then is filled with leading zeros. The left part of the value is then sent to SAP
      >>> r_func['GRUPPENID']
      '0000000001514100'
      >>>

      What happens ?

      Thanks in advance

      Winfried Diehm

       
    • Nobody/Anonymous

      got the last version (1.43) from CVS. this works but is rather slow

      Winfried

       

Log in to post a comment.