cancel
Showing results for 
Search instead for 
Did you mean: 

SAPRFC return columns misaligned

Former Member
0 Kudos

I am new to the SAP world but I have worked extensively w/ PHP over the last 6 years. A client of mine recently converted to SAP and I am trying to write some interfaces in PHP and avoid the .NET connector if possible.

I installed the SAPRFC extension without issue. I ran the sample scripts which appeared at first ran w/o issue. As I began writing my interfaces to some custom RFCs the client had developed, I got some wierd return values. We are expecting a return table w/ 2 fields: MATNO c(18), DESC c(40). However, we are being returned values c(36) and c(80). The return values are running together in the first field and being returned incorrectly. It appears that the saprfc library is misinterpretting return values. We also have an issue where we have 2 import parameters, but the ABAP functions only sees one incoming. This was confirmed by the in-house ABAP developer who watched in some debug mode.

I went back to look at some of the samples again to see what I might be doing wrong, and upon furthur inspection, the samples return incorrect values as well. The username -> user id example has the same symptoms: each return field is doubled in length, and the username field contains both name and id, and the id return value is empty.

Both directions, IMPORT and EXPORT, are mangling the values being passed back and forth. Is there a value or something that I may not be setting somewhere that affects this? Do I need to specify field lengths for all incoming and outgoing parameters? The saprfc_function_debug_info() function returns the wrong data which is why I believe this is a low level issue. Could it be a unicode vs. non-unicode issue? How can I check?

A quick test using the .NET connector shows that the ABAP functions indeed return the correct result, just not through the saprfc php connector.

Please let me know if you need any more info from my side.

Any and all help is hugely appreciated. Thanks in advance for your time.

System Information:

-


OS - Windows Server 2003

PHP - win32 versions 4.3.10, 4.3.11, 5.0.3, 5.0.4

PHP SAPI - CLI

SAPRFC - 1.3.3

SAP release 620

SAP kernel release 640

RFC Protokoll 011

Characters 4103

Integers LIT

Floating P. IE3

Accepted Solutions (0)

Answers (3)

Answers (3)

Detlef_Höhmann
Discoverer
0 Kudos

Hi everybody,

I had the same issues, and they were obviously caused by connecting to a UNICODE system. According to the release notes, the new SAPRFC version 1.4 released last week supports unicode and resolves this problem.

I have just installed 1.4 (by the way, without bothering to upgrade my PHP 5.0.3 to 5.0.4) and my test involving functions SO_USER_LIST_READ and SO_USER_READ_API1 worked just fine.

So: happy upgrading, everyone !

Regards,

Detlef

Former Member
0 Kudos

Hi,

We are having the same issue with the 'return columns misaligned'.

We are connecting to a backend UNICODE SAP system.

We have installed SAPRFC 1.4.1, but are not sure what version of the RFCSDK to use? Should we be using unicode or non-unicode.

If any of you know this, any help would be great!!!

Please help.

Thanks.

JP

Former Member
0 Kudos

This is a weird one !

Do you expect more than one row in your results. If you call saprfc_table_rows do you get the right number of rows?

Do you have the same problem if you append or insert rows into a table (saprfc_table_append,saprfc_table_insert) ?

Not sure if this may be causing your problem but.. If you are running the Zend Optimizer, Make sure that you have the right version matched for the version of PHP you are running. I think from version 4.3.10 you have to be running Zend Optimizer 2.5.1. Check the PHP readme files for more details. I have seen some strange problems caused by this mismatch.

http://www.zend.com/store/products/optimizer-sysreq.php

Also, I'm assuming that you are using IIS6.0

Former Member
0 Kudos

Hi Jason,

Thanks for jumping in! Let me answer you in order:

> This is a weird one !

Indeed!

> Do you expect more than one row in your results.

> If

> you call saprfc_table_rows do you get the right

> number of rows?

Yes, function is returning the correct number of rows, and even the correct data, the issue is with the column lengths.

Example: We have a function that searches our inventory, by item # or description, and it returns up to 99 rows. We have an 18 char item # and a 40 char description. When we call the function w/ no params (default), we get our 99 rows back, but the sap rfc sees the columns as char(36) and char(80), so the first 18 chars of the description are actually returned as part of the item #, and the description field is cut up and unusable.

> Do you have the same problem if you append or insert

> rows into a table

> (saprfc_table_append,saprfc_table_insert) ?

I have not really attempted to write back yet. The select results have been unpredictable and I am worried about messing up data thats already in there.

With the function that I mentioned above, We can properly search by item #, but not by description. Our ABAP developer confirmed that when I pass the description parameter, SAP does not even see it coming in. This makes me nervous about writing data back as I am not sure what it will receive.

The one write back function I did attempt failed, because I was passing a Quantity value, but the ABAP function sees that coming back as a completely different field, as an address field, that is actually the param next to it. The address field then goes through as blank. I have confirmed that I am passing the parameters correctly to the saprfc functions, it is being translated incorrectly on the way across.

> Not sure if this may be causing your problem but.. If

> you are running the Zend Optimizer, Make sure that

> you have the right version matched for the version of

> PHP you are running.

Thank you, but we are not currently running the Zend Optimizer. Should we be, or does it not matter?

> Also, I'm assuming that you are using IIS6.0

Actually, everything is CLI for the time being. We will eventually be building out web apps using IIS but our initial work will be CLI only.

Thanks for your time and help. Let me know if there is any other information I can provide.

- M

Former Member
0 Kudos

Just out of curiosity what is CLI?

Do you have the ability to test with Apache ?

johna69
Product and Topic Expert
Product and Topic Expert
0 Kudos

Your problem could well be an encoding issue. Both your column sizes have doubled.

Is your R/3 system configured as unicode?

CLI - Command Line Interface. PHP scripts can be run from a shell much like Perl scripts.

Former Member
0 Kudos

Hi John,

Thanks for jumping in. How could I determine if it is an encoding issue? Can I pass the encoding as parameter somehwere?

According to System -> Status, The R/3 setup is using unicode. Is there a way to configure this or some alternate access/conversion method if this is causing the issues?

Thanks for your help.

- M

johna69
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Michael,

This one may take a little more investigation. The SAPRFC project has this line "Non-Unicode SAP R/3 release above 4.0B supported", so I am not sure what support you would have for Unicode.

Another option you have if the unicode problem is unsurmountable with SAPRFC is to use SOAP. If you have PHP5 you can use the built in extension. If you are using PHP4 there are other implementations you can use. I have used NUSoap with PHP4.

Regards

John

johna69
Product and Topic Expert
Product and Topic Expert
0 Kudos

There is an example of PHP5 SOAP integration here:

/people/john.astill/blog/2005/06/06/phpsoap-and-saprfc

Former Member
0 Kudos

John,

Thanks for the heads up. Does anyone know if/when SAPRFC will support unicode systems? Will the recently announced partnership w/ Zend lead to an 'official' php connector (fingers crossed!) ?

I am perfectly comfortable using SOAP to make these calls instead of RFC. Could you tell me how to access the appropriate wsdl files? Do I need to get IIS or Apache running on the SAP server? Is there 'built-in' support or do we need to use the SAPRouter? Is it possible to use wsdl generated from VS.NET for the .NET connector with php?

Thanks again so much for your help thus far. This forum has been a great resource. I hope in the near future I can use my experience to jump in and help out with other peoples issues.

johna69
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Michael,

The weblog I just posted gives you a scenario for accessing the wsdl files. This assumes that your R/3 server is setup to provide web services. You will need to ask your R/3 expert about that one.

If you can get the wsdl files from your R/3 server then you do not need the .NET connector, IIS or Apache running on the SAP Server.

SAPRFC is a Source Forge project that has their own forums, you may need to ask there about the possibility for unicode support.

Former Member
0 Kudos

I've not come across that at all - not to say I won't in the near future though.

Can you give us some info on the SAP side? What type of system you are connecting too? What SP level the system has?

You stated you have a 620 with 640 kernel?

Former Member
0 Kudos

Hello Craig,

Thanks for the quick response. I don't know much about the SAP side unfortunately... the politics of this install has had me pretty far removed except for loong business meetings and receiving ~50 pages of RFC function definitions.

I ran the SapInfo.exe tool which told me I have a 620 with 640 kernel. I know it is an R/3 system. I am not sure what you mean by SP level. If you tell me how to retrieve that info, I will look and let you know right away.

If you need any code examples that I used to determine this problem please let me know that too.

Thanks again for your help. I am looking forward to gettingon w/ the PHP coding!

- M

Former Member
0 Kudos

Hi Michael,

The SP level is the level the system has been patched to.

If you can login to the system in your SAPGUI in the top right you can click on System and then Status a box will pop up and show you the info or just ask your ABAP guy.

Did you run the saprfc_test.php page the comes with SAPRFC? Run that login, remember your code page!, then give the function module name you are calling then do the generate PHP code and then check through the results. See if the fields are defined correctly there.

Former Member
0 Kudos

Hi Craig,

Thanks for the info. Our SAP system is at Patch Level 40.

> Did you run the saprfc_test.php page the comes with

> SAPRFC?

I did not run this script as it required us to use a web browser but our environment is currently only Command Line Interface (CLI). I do not have access to apache in this setup, and the IIS box is not yet ready to run. I can see if I can get it set up to test this script, but I do not know yet.

Our PHP apps will basically be a middleware that will interface between SAP and some very old dbase systems and csv files, which is why we are not using a web interface currently. Is there a way to run the saprfc_test.php file interactively or another program that may yield similar results?

Thanks again.

- M

Former Member
0 Kudos

Strange indeed!

If you could get a qucik Apache install done with PHP, not a complicated thing, you could test the script it might just be the way you are accessing the function.

Could you post some of your code here for the function call?

Former Member
0 Kudos

Craig,

The reason I cannot set up apache right now is an install rights issue on the network. I am looking to see if I can set up the IIS box today to get this tested. I will post back in a bit when I have a status update. In the mean time, here is a code post with the resulting output:

(Note: I have also tested using the straight saprfc_* functions w/o the saprfc class, this example was just what I had handy... same results either way.)

Code:

-


<?php

// saprfc-class-library

require_once 'saprfc.php';

// Create saprfc-instance

$rfclogin_data = array(

'logindata' => array(

'ASHOST' => 'xxxx', // application server

'SYSNR' => 'xx', // system number

'CLIENT' => 'xxx', // client

'USER' => 'xxx', // user

'PASSWD' => 'xxx' // password

),

'show_errors' => false, // let class printout errors

'debug' => false // detailed debugging information

);

$sap = new saprfc($rfclogin_data);

// Function params

$rfc_function = 'SO_USER_LIST_READ';

$rfc_params = array(

array('IMPORT', 'USER_GENERIC_NAME', '*'),

array('TABLE', 'USER_DISPLAY_TAB', array())

);

// Call-Function

$result = $sap->callFunction($rfc_function, $rfc_params);

// Call successfull?

if ($sap->getStatus() == SAPRFC_OK) {

// Yes, print out the Userlist

echo "SAP Name\t - \tUser #\n--


\n";

foreach ($result['USER_DISPLAY_TAB'] as $user) {

$sap_name = $user['SAPNAM'];

$user_no = $user['USRNO'];

// Obfuscation for support post

$sap_name = substr($sap_name, 0, 3) . str_repeat('X', strlen($sap_name) - 3);

echo "{$sap_name}\t --- \t{$user_no}\n";

}

}

else {

// No, print long Version of last Error

$sap->printStatus();

// or print your own error-message with the strings received from

// $sap->getStatusText() or $sap->getStatusTextLong()

}

// Logoff/Close saprfc-connection LL/2001-08

$sap->logoff();

?>

-


This should result in a list formatted like:

JOEUSER --- JOEUSER

BOBUSER --- BOBUSER

Note the three dashes between the two fields. In my output, the dashes are at the end and the username field length is too long.

Result:

-


SAP Name --- User #

-


ALEXXXXXXXXXXXXXXXXXX ---

ALIXXXXXXXXXXXXX ---

ARNXXXXXXXXXXXXXXXX ---

BALXXXXXXXXXXXXXXXXXXX ---

BEUXXXXXXXXXXXXXXXXX ---

BEUXXXXXXXXXXXXXXXXX ---

BEZXXXXXXXXXXXXXXXX ---

BLAXXXXXXXXXXXXXXX ---

BRAXXXXXXXXXXXXXXXXXX ---

CAKXXXXXXXXXXXXXXX ---

CARXXXXXXXXXXXXXXXXXXX ---

CHAXXXXXXXXXXXXXX ---

...

I will let you know as soon as I can get IIS up and running. Let me know if you need anything else. Thanks for helping me through this on the weekend... The deadlines are looming and your help is invaluable!!

- M

Former Member
0 Kudos

Craig,

Here is my status with the saprfc_test.php script so far:

IIS is installed.

I got PHP running w/ IIS.

I loaded the php_saprfc.dll into php.ini, restarted IIS, went to look at phpinfo()... nothing.

I unloaded saprfc.dll, phpinfo() works again.

I try to dl() the saprfc.dll, php errors out that dl() is disabled on multithreaded web servers.

There is nothing in the php error log when I load the saprfc.dll, but all .php pages just spin until they timeout.

Any ideas where I can go from here?

TIA,

- M

Former Member
0 Kudos

Just grasping but it almost seems as though you have a corrupt dll??

It's 6 AM at the moment I'll be heading to work here shortly and then I can look some more.

Former Member
0 Kudos

Thanks Craig!

I'll be here!

Former Member
0 Kudos

I've been doing some testing however I only have Apache at my disposal and I've not had any problems

Perhaps Jason or John will pop in with some ideas soon.

Former Member
0 Kudos

Craig,

Thanks for your work on this. I am on the other side of the world, and its 23:00 right now, but I will try to get in touch w/ the sysadmin and have him install apache to test this out.

Is there something that the saprfc_test.php script will tell me that I could find out another way in the mean time? I can't run the script through the browser for now, but I can test out anything else from the command line while I wait to get apache up and running.

I think the same problem will be present when apache is installed, which is why if there are any other ideas I am willing to try those out.

You mentioned a possibly corrupt dll... were you referring to librfc.dll or the php_saprfc.dll?

Could this be a unicode issue? Where can I find a unicode vs. non-unicode librfc.dll to test this theory?

Thanks!

- M

Former Member
0 Kudos

You can check the JCo connector download that contains the librfc dll files.

If you look at this weblog you'll see the code I used to access a FM with PHP: /people/sap.user72/blog/2005/05/17/php-howto-your-system-status-rz20

It might give you an idea on a way to make the call.

Former Member
0 Kudos

If you are using the SAPRFC binary then it should be compiled with Non-unicode Support.

The other key component required for the SAPRFC to function is the librfc32.dll.

Installing the SAP GUI will make this dll available. If the GUI is already installed, check the version, an upgrade may be available.

Once you have checked your GUI, issue this command from the command line (your key environment)

"c:\ php -i "

Could you post the output of this command. (I'm assuming the PHP.exe is in your command path )