Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting an "Invalid date" error when structure element is empty/null #10

Open
jlbenc opened this issue Aug 5, 2017 · 0 comments
Open

Comments

@jlbenc
Copy link

jlbenc commented Aug 5, 2017

I've ran into an issue where I'm referencing a field in a structure (which is of type date) that gives a error when it's not populated, but works fine when it's been set.

Am I using the library correctly? Or is this s bug?

I've ran the code below in IRB:

require 'nwrfc'
include NWRFC

SAP_USER = 'user'
SAP_PASS = "***pass**" 

SAP_HOST = "172.17.x.x"
SAP_SYSNR = "00"
SAP_MANDT = "300"

connection = Connection.new( {
	'user' => SAP_USER, 
	"passwd" => SAP_PASS, 
	"client" => SAP_MANDT, 
	"ashost" => SAP_HOST, 
	"sysnr" => SAP_SYSNR })

function = connection.get_function("BAPI_USER_GET_DETAIL")
fc = function.get_function_call
fc[:USERNAME]="INACTIVEUSER"
fc.invoke
# Works fine when called on an inactive user (where "valid to" date is set)
fc[:LOGONDATA][:GLTGB] #  => #<Date: 2011-06-13 ((2455726j,0s,0n),+0s,2299161j)>
fc[:LOGONDATA][:GLTGB].to_s  #  => "2011-06-13"

# Metadata for field:
 fc[:LOGONDATA].member_metadata :GLTGB
# => {:name=>"GLTGB", :type=>:RFCTYPE_DATE, :nucLength=>8, :ucLength=>16, :decimals=>0, :typeDescHandle=>#<FFI::Pointer address=0x00000000000000>}

# Now call for an ACTIVE user (where the :GLBTB entry is not yet populated)
fc[:USERNAME]="ACTIVEUSER"
fc.invoke

fc[:LOGONDATA][:GLTGB].to_s
# BOOM!
ArgumentError: invalid date
        from /home/vagrant/.rvm/gems/ruby-2.2.5/gems/nwrfc-0.0.9/lib/nwrfc/datacontainer.rb:43:in `parse'
        from /home/vagrant/.rvm/gems/ruby-2.2.5/gems/nwrfc-0.0.9/lib/nwrfc/datacontainer.rb:43:in `[]'
        from (irb):70
        from /home/vagrant/.rvm/rubies/ruby-2.2.5/bin/irb:11:in `<main>'


# Other fields which are set return correct data:
fc[:LOGONDATA][:LTIME].to_s # "2017-08-05 10:48:11 +0000"
@jlbenc jlbenc changed the title Getting an "Invalid date" error when structure element is epmty/null Getting an "Invalid date" error when structure element is empty/null Aug 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant