cancel
Showing results for 
Search instead for 
Did you mean: 

Perl SAP::Rfc: Array reference to what sets arguments correctly?

Former Member
0 Kudos

I'm backporting from sapnwrfc to SAP::Rfc so I can use the allow_start_program function in the old rfcsdk.

I've got sapnwrfc code working but not SAP::Rfc.

How do I set the arguments to the TEXT_LINES interface of the RFC_READ_TEXT rfc (TEXT_LINES is a bidirectional array, I give SAP a reference to a list of name value pairs and it gives me a reference to a list of strings in TDLINE)?

This works in sapnwrfc:


$fds = $conn->function_lookup('RFC_READ_TEXT');
$fs = $fds->create_function_call;
$fs->TEXT_LINES([{'MANDT'    => $CLIENT,
                  'TDOBJECT' => $text_object,
                  'TDNAME'   => $text_name,
                  'TDID'     => $text_id,
                  'TDSPRAS'  => 'E',
                  'COUNTER'  => '',
                  'TDFORMAT' => '',
                  'TDLINE'   => ''}]);
$fs->invoke;

How do I do the same thing in SAP::Rfc?

This results in no errors, but no records or messages either, it's like the RFC isn't even being called.

At first I thought the $structure methods weren't modifying the $interface, but a printout via Dumper confirms the name value pairs are set. But I wonder, if setting them in the structure is the right place.


my $interface = $rfc->discover('RFC_READ_TEXT');  
my $structure = $interface->tab('TEXT_LINES')->structure;
$structure->MANDT($CLIENT);
$structure->TDOBJECT($text_object);
$structure->TDNAME($text_name);
$structure->TDID($text_id);
$structure->TDSPRAS('E');
$structure->COUNTER(0);
$structure->TDFORMAT('');
$structure->TDLINE('');
$rfc->callrfc($interface);

At least this generates an error message saying SAP can't find the record (because this does not result in any name value pairs in the VALUE array I suspect. The names and values get all jumbled up as elements).


my $interface = $rfc->discover('RFC_READ_TEXT');  
$interface->TEXT_LINES(['MANDT'    => $CLIENT,
                  'TDOBJECT' => $text_object,
                  'TDNAME'   => $text_name,
                  'TDID'     => $text_id,
                  'TDSPRAS'  => 'E',
                  'COUNTER'  => '',
                  'TDFORMAT' => '',
                  'TDLINE'   => '']);
$rfc->callrfc($interface);

Results:


print Dumper($interface->tab('TEXT_LINES'));
$VAR1 = bless( {
                 'NAME' => 'TEXT_LINES',
                 'VALUE' => [
                              'MANDT',
                              '096',
                              'TDOBJECT',
                              'ROUTING',
                              'TDNAME',
                              '096N500338750000006800000035',
                              'TDID',
                              'PLPO',
                              'TDSPRAS',
                              'E',
                              'COUNTER',
                              '',
                              'TDFORMAT',
                              '',
                              'TDLINE',
                              ''
                            ],

Snip

And I suspect it should look like this because that's how VALUE looks when I call it via sapnwrfc:


print Dumper($interface->tab('TEXT_LINES'));
$VAR1 = bless( {
                 'name' => 'TEXT_LINES',
                 'value' => [{
                              'MANDT' => '096',
                              'TDOBJECT'=> 'ROUTING',
                              'TDNAME'=>  '096N500338750000006800000035',
                              'TDID' =>  'PLPO',
                              'TDSPRAS' =>  'E',
                              'COUNTER' => '',
                              'TDFORMAT' => '',
                              'TDLINE' => ''
                            }],

I've tried dozens of different ways to feed the SAP::Rfc interface the arguments, but nothing has worked. I've looked at all the example code provided in CPAN but they all seem to involve simple single arguments to the interface. I've looked at most of the 60 threads involving SAP::Rfc but found nothing that has worked.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

What you need is something like:

my $interface = $rfc->discover('RFC_READ_TEXT');

my $structure = $interface->tab('TEXT_LINES')->structure;

$structure->MANDT($CLIENT);

...

$interface->TEXT_LINES([$structure->value()]);

$rfc->callrfc($interface);

$structure is a helper object for constructing a correctly formated string representation of the table row. You have to retrieve the string representation ($str->value()), and then use that as a value passed into the array ref for the table value.

Cheers.

Answers (2)

Answers (2)

Former Member
0 Kudos

Oh wait!

I think this works:


$interface->TEXT_LINES([$structure->value()]);

Former Member
0 Kudos

Yes - this is correct - unfortunately in the example I provided above the square brackets I put in my example got converted so they dont appear.

Cheers.

Former Member
0 Kudos

Yea, I tried that but it generates errors.

It generates errors because Iface.pm is expecting an array but gets a string '$structure->value()':


my $interface = $rfc->discover('RFC_READ_TEXT');    
my $structure = $interface->tab('TEXT_LINES')->structure;
$structure->MANDT($CLIENT);
$structure->TDOBJECT($text_object);
$structure->TDNAME($text_name);
$structure->TDID($text_id);
$structure->TDSPRAS('E');
$structure->COUNTER('0');
$structure->TDFORMAT('');
$structure->TDLINE('');
$interface->TEXT_LINES($structure->value());

Can't use string ("096ROUTING   096N500338750000006") as an ARRAY ref while "strict refs" in use at /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/SAP/Iface.pm line 567.