# Everyday perl
# An everyday perl script, showing some useful techniques
# Here, the task is:
# Search in a text for occurrences of
# setFieldValue( ..., "<field>" )
# getFieldValue( ..., "<field>" )
# Print the field names in a structured list, sorted and without duplicates
# Print such a field name list for each file
# that is introduced by a line containing its name, ending with .js,
#
# Techniques employed:
#
# - Attaching text right after the script with __DATA__, and reading it with special file handle <DATA>
# (For looping several times, it could be reset with "seek" between the loops,
# see http://stackoverflow.com/questions/4459601)
# - Avoiding globals, passing data references between the subroutines
# - Using a Hash of Arrays (HoA) for keeping track of the field lists per file
# - Using the compact notion "@$..." for dereferencing an array
# - Using an auxiliary hash (%unique_fields) for making the field list unique
# - Using statement modifiers " ... if ... " instead of braced code blocks
use strict;
use warnings;
output(
search( )
);
sub search {
my $fields = {};
my $names;
while (<DATA>) {
$names = ($fields->{$1} = []) if (/^(\w+\.js.*)/);
push @$names, $1 if $names and /[sg]etFieldValue.*?"(.*)"/ ;
}
return $fields;
}
sub output {
my $fields = shift;
my $sep = '-' x 80 . "\n";
my %unique_fields;
foreach (keys %$fields) {
print "\n$sep$_\n$sep";
%unique_fields = map { $_ => 1} sort @{$fields->{$_}};
foreach (sort keys %unique_fields) { print "$_\n" }
}
}
__DATA__
ZFG_AUKTION
auktion.js auktion javascript
109 : // Ermittlung der Zeile
110 : lRow = lDataTable.fnGetPosition( iInput.parentNode )[0];
111 :
112 : // Ermittlung weiterer Berechnungs-Parameter
113 : lObetr = iInput.value;
114 : lOwaer = getFieldValue( lDataTable, lRow, "owaer" );
115 : lOwaer_lief = getFieldValue( lDataTable, lRow, "owaer_lief" );
116 :
117 : doRequest(
118 : toRelative( "/zfg/auktion?"+
119 : "event=obetr_changed"+
120 : "&obetr="+lObetr+
135 : setMessage("msg", calculations.error, "warning" );
136 : //return; andere Ergebniswerte trotzem eintragen
137 : }
138 :
139 : var lDataTable = getDataTable( iTableId );
140 : setFieldValue( lDataTable, iRow, "obetr_lief", calculations.obetr_lief );
141 : }
142 :
143 : function getDataTable( tableID ) {
144 :
145 : var lDataTable;
151 : }
152 : return lDataTable;
153 :
154 : }
155 :
156 : function getFieldValue( iDataTable, iRow, iColName) {
157 : var lColIndx = iDataTable.fnGetColumnIndex(iColName);
158 : var lData = iDataTable.fnGetData( iRow, lColIndx);
159 : if (lData.match(/<span/i) || lData.match(/<div/i))
160 : {
161 : return jQuery(lData).text(); // Inhalt des span 'herauslösen':
169 : return lData;
170 : }
171 : }
172 :
173 :
174 : function setFieldValue( iDataTable, iRow, iColName, iValue) {
175 : if (iValue){
176 : lColIndx = iDataTable.fnGetColumnIndex(iColName);
177 : iDataTable.fnUpdate( iValue, iRow, lColIndx );
178 : }
179 : }
zfg_offerte
offerte.js JS-Funktionen
143 :
144 : // genericSubmit( "main__gofablehnen" );
145 :
146 : }
147 :
148 : function setFieldValue( iDataTable, iRow, iColName, iValue) {
149 : var lColIndx;
150 : if (iValue){
151 : lColIndx = iDataTable.fnGetColumnIndex(iColName);
152 : iDataTable.fnUpdate( iValue, iRow, lColIndx );
153 : }
zfg_ausschreib
ausschreib.js
579 : lDataTable = getDataTable( tableID );
580 : // Ermittlung der Zeile
581 : lRow = lDataTable.fnGetPosition( iInput.parentNode )[0];
582 :
583 : // Ermittlung weiterer Berechnungs-Parameter
584 : owaer = getFieldValue( lDataTable, lRow, "owaer_of" );
585 : hwaer = getFieldValue( lDataTable, lRow, "hwaer" );
586 : /*
587 : * Nur für VK- Sicht:
588 : * zur Berechnung der BP sind sehr viele Parameter nötig
589 : * deshalb wird dafür die Offertposition + Session-ID übergeben,
590 : * aus der der Requestbehandler alle nötigen Infos ermitteln kann
591 : */
592 : if (tableID == "zfg_ausschreib_bew_vk"){
593 : belnr_of = getFieldValue( lDataTable, lRow, "belnr_of" );
594 : posnr_of = getFieldValue( lDataTable, lRow, "posnr_of" );
595 : vkmat = getFieldValue( lDataTable, lRow, "vkmat_vk" );
596 : status_of = getFieldValue( lDataTable, lRow, "status_of" );
597 : sap_appcontext = get_appcontext();
598 : }
599 : */
600 : if (tableID == "zfg_ausschreib_bew_vk"){
601 : belnr_of = getFieldValue( lDataTable, lRow, "belnr_of" );
602 : posnr_of = getFieldValue( lDataTable, lRow, "posnr_of" );
603 : vkmat = getFieldValue( lDataTable, lRow, "vkmat_vk" );
604 : status_of = getFieldValue( lDataTable, lRow, "status_of" );
605 : sap_appcontext = get_appcontext();
606 : }
607 :
608 : */
609 : if (tableID == "zfg_ausschreib_bew_vk"){
610 : belnr_of = getFieldValue( lDataTable, lRow, "belnr_of" );
611 : posnr_of = getFieldValue( lDataTable, lRow, "posnr_of" );
612 : vkmat = getFieldValue( lDataTable, lRow, "vkmat_vk" );
613 : status_of = getFieldValue( lDataTable, lRow, "status_of" );
614 : sap_appcontext = get_appcontext();
615 : }
616 :
617 : // wenn Betrag in Lieferantenwährung eingegeben wurde:
591 : */
592 : if (tableID == "zfg_ausschreib_bew_vk"){
593 : belnr_of = getFieldValue( lDataTable, lRow, "belnr_of" );
594 : posnr_of = getFieldValue( lDataTable, lRow, "posnr_of" );
595 : vkmat = getFieldValue( lDataTable, lRow, "vkmat_vk" );
596 : status_of = getFieldValue( lDataTable, lRow, "status_of" );
597 : sap_appcontext = get_appcontext();
598 : }
599 :
600 : // wenn Betrag in Lieferantenwährung eingegeben wurde:
601 : if (iSource == "owaer"){
661 : lTd = getTd( lDataTable, lRow , "obetr_of" );
662 :
663 : // Ermittlung der Werte für Vergleich Obetr vs. Obetr_MGB
664 : lObetr_mgb = iInput.value;
665 : if (iSource == "hwaer"){
666 : lObetr = getFieldValue( lDataTable, lRow, "obetr_hwaer");}
667 : if (iSource == "owaer"){
668 : lObetr = getFieldValue( lDataTable, lRow, "obetr_of");}
669 : if ( Number(lObetr) <= Number(lObetr_mgb) ){
670 : setClass(lTd,"green");
671 : resetClass(lTd,"red");
672 : }
690 : break;
691 : }
692 : return lDataTable;
693 : }
694 :
695 : function getFieldValue( iDataTable, iRow, iColName) {
696 : var lColIndx = iDataTable.fnGetColumnIndex(iColName);
697 : var lData = iDataTable.fnGetData( iRow, lColIndx);
698 : if (lData.match(/<span/i) || lData.match(/<div/i))
699 : {
700 : return jQuery(lData).text(); // Inhalt des span 'herauslösen':
707 : {
708 : return lData;
709 : }
710 : }
711 :
712 : function setFieldValue( iDataTable, iRow, iColName, iValue) {
713 : if (iValue){
714 : lColIndx = iDataTable.fnGetColumnIndex(iColName);
715 : iDataTable.fnUpdate( iValue, iRow, lColIndx );
716 : }
717 : }
722 : return iDataTable.fnGetTd( lTr, lColIndx );
723 : }
724 :
725 : function setCalculatedFieldsEK( tableID, iRow, calculations ) {
726 : var lDataTable = getDataTable( tableID );
727 : setFieldValue( lDataTable, iRow, "obetr_mgb_hwaer", calculations.obetr_mgb_hwaer );
728 : setFieldValue( lDataTable, iRow, "obetr_mgb_of", calculations.obetr_mgb_owaer );
729 : }
730 :
731 : function setCalculatedFieldsVK( tableID, iRow, calculations ) {
732 : var lDataTable = getDataTable( tableID );
733 : setFieldValue( lDataTable, iRow, "obetr_mgb_hwaer", calculations.obetr_mgb_hwaer );
734 : setFieldValue( lDataTable, iRow, "obetr_mgb_of", calculations.obetr_mgb_owaer );
735 : setFieldValue( lDataTable, iRow, "bp_via_vk", calculations.bp_via );
736 : setFieldValue( lDataTable, iRow, "bp_dir_vk", calculations.bp_dir );
737 : }
937 : // hauptsächlich aus hidden fields:
938 : apmgb = byId("posDet_apmgb").value;
939 : belnr_of = byId("posDet_belnr_of").value;
940 : posnr_of = byId("posDet_posnr_of").value;
941 : ekmat = byId("posDet_matnr").value;
942 : vkmat = getFieldValue( lDataTable, lRow, "vkmat" );
943 : sap_appcontext = get_appcontext();
944 : doRequest(
945 : toRelative( "/zfg/ausschreibung?"+
946 : "event=calculateItemVK"+
947 : "&ap_mgb="+apmgb+