File Coverage

blib/lib/SAP/BC/Iface.pm
Criterion Covered Total %
statement 24 203 11.8
branch 0 88 0.0
condition 0 12 0.0
subroutine 8 41 19.5
pod 0 9 0.0
total 32 353 9.0


line stmt bran cond sub pod time code
1             package SAP::BC::Iface;
2              
3 1     1   5 use strict;
  1         2  
  1         39  
4 1     1   5 use vars qw($VERSION $AUTOLOAD);
  1         2  
  1         1249  
5              
6              
7             # Globals
8              
9             # Valid parameters
10             my $VALID = {
11             NAME => 1,
12             PARAMETERS => 1,
13             TABLES => 1,
14             EXCEPTIONS => 1
15             };
16              
17             $VERSION = '0.03';
18              
19             # empty destroy method to stop capture by autoload
20 0     0     sub DESTROY {
21             }
22              
23             sub AUTOLOAD {
24              
25 0     0     my $self = shift;
26 0           my @parms = @_;
27 0 0         my $type = ref($self)
28             or die "$self is not an Object in autoload of Iface";
29 0           my $name = $AUTOLOAD;
30 0           $name =~ s/.*://;
31              
32             # Autoload parameters and tables
33 0 0         if ( exists $self->{PARAMETERS}->{uc($name)} ) {
    0          
34 0           &Parm($self, $name);
35             } elsif ( exists $self->{TABLES}->{uc($name)} ) {
36 0           &Tab($self, $name);
37             } else {
38 0           die "Parameter $name does not exist in Interface - no autoload";
39             };
40             }
41              
42              
43             # Construct a new SAP::Interface object
44             sub new {
45              
46 0     0 0   my $proto = shift;
47 0   0       my $class = ref($proto) || $proto;
48 0           my $self = {
49             PARAMETERS => {},
50             TABLES => {},
51             EXCEPTIONS => {},
52             @_
53             };
54 0 0         die "No RFC Name supplied to Interface !" if ! exists $self->{NAME};
55              
56             # Validate parameters
57 0 0         map { delete $self->{$_} if ! exists $VALID->{$_} } keys %{$self};
  0            
  0            
58 0           $self->{NAME} = $self->{NAME};
59              
60             # create the object and return it
61 0           bless ($self, $class);
62 0           return $self;
63             }
64              
65              
66             # get the name
67             sub name {
68              
69 0     0 0   my $self = shift;
70 0           return $self->{NAME};
71              
72             }
73              
74              
75             # Add an export parameter Object
76             sub addParm {
77              
78 0     0 0   my $self = shift;
79 0 0         die "No parameter supplied to Interface !" if ! @_;
80 0           my $parm;
81 0 0         if (my $ref = ref($_[0])){
82 0 0         die "This is not an Parameter for the Interface - $ref ! "
83             if $ref ne "SAP::BC::Parms";
84 0           $parm = $_[0];
85             } else {
86 0           $parm = SAP::BC::Parms->new( @_ );
87             };
88              
89 0           return $self->{PARAMETERS}->{$parm->name()} = $parm;
90              
91             }
92              
93              
94             # Access the export parameters
95             sub Parm {
96              
97 0     0 0   my $self = shift;
98 0 0         die "No parameter name supplied for interface" if ! @_;
99 0           my $parm = uc(shift);
100 0 0         die "Export $parm Does not exist in interface !"
101             if ! exists $self->{PARAMETERS}->{$parm};
102 0           return $self->{PARAMETERS}->{$parm};
103              
104             }
105              
106              
107             # Return the parameter list
108             sub Parms {
109              
110 0     0 0   my $self = shift;
111 0           return sort { $a->name() cmp $b->name() } values %{$self->{PARAMETERS}};
  0            
  0            
112              
113             }
114              
115              
116             # Add an Table Object
117             sub addTab {
118              
119 0     0 0   my $self = shift;
120 0 0         die "No Table supplied for interface !" if ! @_;
121 0           my $table;
122 0 0         if ( my $ref = ref($_[0]) ){
123 0 0         die "This is not a Table for interface: $ref ! "
124             if $ref ne "SAP::BC::Tab";
125 0           $table = $_[0];
126             } else {
127 0           $table = SAP::BC::Tab->new( @_ );
128             };
129 0           return $self->{TABLES}->{$table->name()} = $table;
130              
131             }
132              
133              
134             # Access the Tables
135             sub Tab {
136              
137 0     0 0   my $self = shift;
138 0 0         die "No Table name supplied for interface" if ! @_;
139 0           my $table = uc(shift);
140 0 0         die "Table $table Does not exist in interface !"
141             if ! exists $self->{TABLES}->{ $table };
142 0           return $self->{TABLES}->{ $table };
143              
144             }
145              
146              
147             # Return the Table list
148             sub Tabs {
149              
150 0     0 0   my $self = shift;
151 0           return sort { $a->name() cmp $b->name() } values %{$self->{TABLES}};
  0            
  0            
152              
153             }
154              
155              
156             # Empty The contents of all tables in an interface
157             sub emptyTables {
158              
159 0     0 0   my $self = shift;
160 0           map {
161 0           my $table = $self->{TABLES}->{ $_ };
162 0           $table->empty();
163 0           } keys %{$self->{TABLES}};
164              
165             }
166              
167              
168             =head1 NAME
169              
170             SAP::BC::Iface - Perl extension for parsing and creating an Interface Object. The interface object would then be passed to the SAP::BC::XMLRFC object to carry out the actual call, and return of values.
171              
172             =head1 SYNOPSIS
173              
174             use SAP::BC::Iface;
175             $iface = new SAP::BC::Iface( NAME =>"SAPBC:ServiceName" );
176              
177             NAME is mandatory.
178              
179             =head1 DESCRIPTION
180              
181             This class is used to construct a valid interface object ( SAP::BC::Iface.pm ).
182             The constructor requires the parameter value pairs to be passed as
183             hash key values ( see SYNOPSIS ).
184             Generally you would not create one of these manually as it is far easier to use the "discovery" functionality of the SAP::BC::XMLRFC->Iface() method. Tis takes the name of an existing BC service, and returns a fully formed interface object.
185              
186             Methods:
187             new
188             use SAP::BC::Iface;
189             $iface = new SAP::BC::Iface( NAME =>"SAPBC:ServiceName" );
190              
191             Create a new Interface object.
192              
193              
194             =head1 Exported constants
195              
196             NONE
197              
198             =cut
199              
200             package SAP::BC::Tab;
201              
202 1     1   12 use strict;
  1         2  
  1         30  
203 1     1   4 use vars qw($VERSION);
  1         14  
  1         571  
204              
205             # Globals
206              
207             # Valid parameters
208             my $VALID = {
209             DATA => 1,
210             NAME => 1,
211             STRUCTURE => 1
212             };
213              
214             # Construct a new SAP::BC::Table object.
215             sub new {
216              
217 0     0     my $proto = shift;
218 0   0       my $class = ref($proto) || $proto;
219 0           my $self = {
220             DATA => [],
221             TYPE => "chars",
222             @_
223             };
224              
225 0 0         die "Table Name not supplied !" if ! exists $self->{NAME};
226 0 0         die "Table Structure not supplied !" if ! exists $self->{STRUCTURE};
227              
228             # Validate parameters
229 0 0         map { delete $self->{$_} if ! exists $VALID->{$_} } keys %{$self};
  0            
  0            
230 0           $self->{NAME} = uc($self->{NAME});
231              
232             # create the object and return it
233 0           bless ($self, $class);
234 0           return $self;
235              
236             }
237              
238              
239             # Set/get the table rows - pass a reference to a anon array
240             sub rows {
241              
242 0     0     my $self = shift;
243 0 0         $self->{DATA} = shift if @_;
244 0           return @{$self->{DATA}};
  0            
245              
246             }
247              
248              
249             # Return the next available row from a table
250             sub nextrow {
251              
252 0     0     my $self = shift;
253 0           my $row = shift @{$self->{DATA}};
  0            
254              
255 0           return { map {$self->structure->Fieldname( $_ ) => $row->[$_ - 1] }
  0            
256 0 0         ( 1 .. scalar @{[$self->structure->Fields]} ) } if $row;
257              
258             }
259              
260              
261             # Set/get the structure parameter
262             sub structure {
263              
264 0     0     my $self = shift;
265 0 0         $self->{STRUCTURE} = shift if @_;
266 0           return $self->{STRUCTURE};
267              
268             }
269              
270              
271             # add a row
272             sub addrow {
273              
274 0     0     my $self = shift;
275 0 0         push(@{$self->{DATA}}, @_) if @_;
  0            
276              
277             }
278              
279              
280             # Delete all rows in the table
281             sub empty {
282              
283 0     0     my $self = shift;
284 0           $self->{DATA} = [ ];
285 0           return @{$self->{DATA}};
  0            
286              
287             }
288              
289             # Get the table name
290             sub name {
291              
292 0     0     my $self = shift;
293 0           return $self->{NAME};
294              
295             }
296              
297              
298             # Get the number of rows
299             sub rowcount {
300              
301 0     0     my $self = shift;
302 0           return $#{$self->{DATA}} + 1;
  0            
303              
304             }
305              
306              
307              
308             # Autoload methods go after =cut, and are processed by the autosplit program.
309              
310              
311             =head1 NAME
312              
313             SAP::BC::Tab - Perl extension for parsing and creating Tables to be added to an RFC Iface.
314              
315             =head1 SYNOPSIS
316              
317             use SAP::BC::Tab;
318             $tab1 = new SAP::BC::Tab( NAME => XYZ, VALUE => abc );
319              
320             =head1 DESCRIPTION
321              
322             This class is used to construct a valid Table object to be add to an interface
323             object ( SAP::BC::Iface.pm ).
324             The constructor requires the parameter value pairs to be passed as
325             hash key values ( see SYNOPSIS ).
326              
327             Methods:
328             new
329             use SAP::BC::Tab;
330             $tab1 = new SAP::BC::Tab( NAME => XYZ, ROWLENGTH => 1,
331             DATA => [a, b, c, ..] );
332              
333             rows
334             @r = $tab1->rows( [ row1, row2, row3 .... ] );
335             optionally set and Give the current rows of a table.
336              
337             rowcount
338             $c = $tab1->rowcount();
339             return the current number of rows in a table object.
340              
341              
342             =head1 Exported constants
343              
344             NONE
345              
346             =cut
347              
348             package SAP::BC::Parms;
349              
350 1     1   5 use strict;
  1         2  
  1         33  
351 1     1   5 use vars qw($VERSION);
  1         1  
  1         427  
352              
353             # Globals
354              
355             # Valid parameters
356             my $VALID = {
357             NAME => 1,
358             PHASE => 1,
359             STRUCTURE => 1,
360             TYPE => 1,
361             VALUE => 1
362             };
363              
364             # Valid data types
365             my $VALTYPE = {
366             chars => 1,
367             date => 1,
368             time => 1,
369             int => 1,
370             decimal => 1,
371             num => 1,
372             float => 1
373             };
374              
375             # Construct a new SAP::Parms parameter object.
376             sub new {
377              
378 0     0     my $proto = shift;
379 0   0       my $class = ref($proto) || $proto;
380 0           my $self = {
381             TYPE => "chars",
382             VALUE => undef,
383             PHASE => 'I',
384             @_
385             };
386              
387 0 0         die "Parameter Name not supplied !" if ! exists $self->{NAME};
388 0 0         die "Parameter Type not valid $self->{TYPE} !"
389             if ! exists $VALTYPE->{$self->{TYPE}};
390              
391             # Validate parameters
392 0 0         map { delete $self->{$_} if ! exists $VALID->{$_} } keys %{$self};
  0            
  0            
393 0           $self->{NAME} = uc($self->{NAME});
394              
395             # create the object and return it
396 0           bless ($self, $class);
397 0           return $self;
398             }
399              
400              
401             # Set/get the value of type
402             sub type {
403              
404 0     0     my $self = shift;
405 0 0         $self->{TYPE} = shift if @_;
406 0 0         die "Parameter Type not valid $self->{TYPE} !"
407             if ! exists $VALTYPE->{$self->{TYPE}};
408 0           return $self->{TYPE};
409              
410             }
411              
412              
413             # Set/get the parameter value
414             sub value {
415              
416 0     0     my $self = shift;
417 0 0         $self->{VALUE} = shift if @_;
418 0 0         if ($self->{VALUE}){
419 0           return $self->{VALUE};
420             } else {
421 0           return "";
422             };
423              
424             }
425              
426              
427             # Set/get the parameter structure
428             sub structure {
429              
430 0     0     my $self = shift;
431 0 0         $self->{STRUCTURE} = shift if @_;
432 0           return $self->{STRUCTURE};
433              
434             }
435              
436              
437             # get the name
438             sub name {
439              
440 0     0     my $self = shift;
441 0           return $self->{NAME};
442              
443             }
444              
445              
446              
447             # Below is the stub of documentation for your module. You better edit it!
448              
449             =head1 NAME
450              
451             SAP::BC::Parms - Perl extension for parsing and creating an SAP parameter to be added to an RFC Interface.
452              
453             =head1 SYNOPSIS
454              
455             use SAP::BC::Parms;
456             $imp1 = new SAP::BC::Parms( NAME => XYZ,
457             TYPE => chars, VALUE => abc );
458              
459             =head1 DESCRIPTION
460              
461             This class is used to construct a valid parameter to add to an interface
462             object ( SAP::BC::Iface.pm ).
463             The constructor requires the parameter value pairs to be passed as
464             hash key values ( see SYNOPSIS ).
465              
466             Methods:
467             new
468             use SAP::BC::Parms;
469             $imp1 = new SAP::BC::Parms( NAME => XYZ,
470             TYPE => chars, VALUE => abc );
471              
472             value
473             $v = $imp1->value( [ val ] );
474             optionally set and Give the current value.
475              
476             type
477             $t = $imp1->type( [ type ] );
478             optionally set and Give the current value of type.
479              
480             =head1 Exported constants
481              
482             NONE
483              
484             =cut
485              
486              
487             package SAP::BC::Struc;
488              
489 1     1   6 use strict;
  1         1  
  1         33  
490 1     1   5 use vars qw($VERSION $AUTOLOAD);
  1         1  
  1         1240  
491              
492             # require AutoLoader;
493              
494             # Globals
495              
496             # Valid parameters
497             my $VALID = {
498             NAME => 1,
499             FIELDS => 1
500             };
501              
502             # Valid Field parameters
503             my $FIELDVALID = {
504             NAME => 1,
505             TYPE => 1,
506             POSITION => 1,
507             VALUE => 1
508             };
509              
510              
511             # Valid data types
512             my $VALTYPE = {
513             chars => 1,
514             num => 1,
515             int => 1,
516             date => 1,
517             time => 1,
518             decimal => 1,
519             float => 1
520             };
521              
522             # empty destroy method to stop capture by autoload
523 0     0     sub DESTROY {
524             }
525              
526             sub AUTOLOAD {
527              
528 0     0     my $self = shift;
529 0           my @parms = @_;
530 0 0         my $type = ref($self)
531             or die "$self is not an Object in autoload of Structure";
532 0           my $name = $AUTOLOAD;
533 0           $name =~ s/.*://;
534 0 0         unless ( exists $self->{FIELDS}->{uc($name)} ) {
535 0           die "Field $name does not exist in structure - no autoload";
536             };
537 0           &Fieldvalue($self,$name,@parms);
538             }
539              
540             # Construct a new SAP::export parameter object.
541             sub new {
542              
543 0     0     my $proto = shift;
544 0   0       my $class = ref($proto) || $proto;
545 0           my $self = {
546             FIELDS => {},
547             @_
548             };
549              
550 0 0         die "Structure Name not supplied !" if ! exists $self->{NAME};
551 0           $self->{NAME} = uc($self->{NAME});
552              
553             # Validate parameters
554 0 0         map { delete $self->{$_} if ! exists $VALID->{$_} } keys %{$self};
  0            
  0            
555              
556             # create the object and return it
557 0           bless ($self, $class);
558 0           return $self;
559              
560             }
561              
562              
563             # Set/get structure field
564             sub addField {
565              
566 0     0     my $self = shift;
567              
568 0           my %field = @_;
569 0 0         map { delete $field{$_} if ! exists $FIELDVALID->{$_} } keys %field;
  0            
570 0 0         die "Structure NAME not supplied!" if ! exists $field{NAME};
571 0           $field{NAME} = uc($field{NAME});
572 0           $field{NAME} =~ s/ //g;
573 0 0         die "Structure NAME allready exists - $field{NAME}!"
574             if exists $self->{FIELDS}->{$field{NAME}};
575 0           $field{TYPE} =~ s/ //g;
576              
577 0 0         die "Structure TYPE not supplied!" if ! exists $field{TYPE};
578 0 0         die "Structure Type not valid $field{TYPE} !"
579             if ! exists $VALTYPE->{$field{TYPE}};
580 0           $field{POSITION} = ( scalar keys %{$self->{FIELDS}} ) + 1;
  0            
581              
582 0           return $self->{FIELDS}->{$field{NAME}} =
583 0           { map { $_ => $field{$_} } keys %field };
584              
585             }
586              
587              
588             # Delete a field from the structure
589             sub deleteField {
590              
591 0     0     my $self = shift;
592 0           my $field = shift;
593 0 0         die "Structure field does not exist: $field "
594             if ! exists $self->{FIELDS}->{uc($field)};
595 0           delete $self->{FIELDS}->{uc($field)};
596 0           return $field;
597              
598             }
599              
600              
601             # Set/get the field value and update the overall structure value
602             sub Fieldvalue {
603              
604 0     0     my $self = shift;
605 0           my $field = shift;
606 0 0         $field = ($self->Fields)[$field] if $field =~ /^\d+$/;
607 0 0         die "Structure field does not exist: $field "
608             if ! exists $self->{FIELDS}->{uc($field)};
609 0           $field = $self->{FIELDS}->{uc($field)};
610 0 0         if (scalar @_ > 0){
611 0           $field->{VALUE} = shift @_;
612             }
613              
614 0           return $field->{VALUE};
615              
616             }
617              
618              
619             # get the field name by position
620             sub Fieldname {
621              
622 0     0     my $self = shift;
623 0           my $field = shift;
624             # print "Number: $field \n";
625 0 0         die "Structure field does not exist by array position: $field "
626             if ! ($self->Fields)[$field - 1];
627 0           return ($self->Fields)[$field - 1 ];
628              
629             }
630              
631              
632             # get the name
633             sub Name {
634              
635 0     0     my $self = shift;
636 0           return $self->{NAME};
637              
638             }
639              
640              
641             # return the current set of field names
642             sub Fields {
643              
644 0     0     my $self = shift;
645 0           return sort { $self->{FIELDS}->{$a}->{POSITION} <=>
  0            
646             $self->{FIELDS}->{$b}->{POSITION} }
647 0           keys %{$self->{FIELDS}};
648              
649             }
650              
651              
652              
653              
654             # Below is the stub of documentation for your module. You better edit it!
655              
656             =head1 NAME
657              
658             SAP::BC::Struc - Perl extension for parsing and creating a Structure definition. The resulting structure object is then used for SAP::BC::Parms, and SAP::BC::Tab objects to manipulate complex data elements.
659              
660             =head1 SYNOPSIS
661              
662             use SAP::BC::Struc;
663             $struct = new SAP::BC::Struc( NAME => XYZ, FIELDS => [......] );
664              
665             =head1 DESCRIPTION
666              
667             This class is used to construct a valid structure object - a structure object that would be used in an Export(Parms), Import(Parms), and Table(Tab) object ( SAP::BC::Iface.pm ).
668             The constructor requires the parameter value pairs to be passed as
669             hash key values ( see SYNOPSIS ). The value of each field can either be accessed through $str->Fieldvalue(field1), or through the autoloaded method of the field name eg. $str->field1().
670              
671             Methods:
672             new
673             use SAP::BC::Struc;
674             $str = new SAP::BC::Struc( NAME => XYZ );
675              
676              
677             addField
678             use SAP::BC::Struc;
679             $str = new SAP::BC::Struc( NAME => XYZ );
680             $str->addField( NAME => field1,
681             TYPE => chars );
682             add a new field into the structure object. The field is given a position counter of the number of the previous number of fields + 1. Name is mandatory, but type will be defaulted to chars if omitted.
683              
684              
685             deleteField
686             use SAP::BC::Struc;
687             $str = new SAP::BC::Struc( NAME => XYZ );
688             $str->addField( NAME => field1,
689             TYPE => chars );
690             $str->deleteField('field1');
691             Allow fields to be deleted from a structure.
692              
693              
694             Name
695             $name = $str->Name();
696             Get the name of the structure.
697              
698              
699             Fieldtype
700             $ftype = $str->Fieldtype(field1, [ new field type ]);
701             Set/Get the SAP BC field type of a component field of the structure. This will force the overall value of the structure to be recalculated.
702              
703              
704             Fieldvalue
705             $fvalue = $str->Fieldvalue(field1,
706             [new component value]);
707             Set/Get the value of a component field of the structure. This will force the overall value of the structure to be recalculated.
708              
709              
710             Field
711             $fhashref = $str->Field(field1);
712             Set/Get the value of a component field of the structure. This will force the overall value of the structure to be recalculated.
713              
714              
715             Fields
716             @f = &$struct->Fields();
717             Return an array of the fields of a structure sorted in positional order.
718              
719              
720             =head1 Exported constants
721              
722             NONE
723              
724              
725             =head1 AUTHOR
726              
727             Piers Harding, saprfc@kogut.demon.co.uk.
728              
729             But Credit must go to all those that have helped.
730              
731             =head1 SEE ALSO
732              
733             perl(1), SAP::BC(3), SAP::BC::XMLRFC(3), SAP::BC::Iface(3)
734              
735             =cut
736              
737              
738             1;
739              
740             __END__