1825911 wait_for_file function

Can someone explain me the logic on the step 4 ( in step 3 it is mentioned as $counter < $list_size) in the SAP Note : 1825911
I tried implementing this SAP Note and seems it is not entering into While loop.
I am bit confused with this logic

$counter = $counter + 1;
print(‘While Loop Counter = ’ || $counter );
#print(’ comma index = ’ || index($file_list , ‘,’, 1));

  1. Add a script in the while loop as follows. It extracts a single file each time from $file_list using simple string functions. It prints the current file in process and remaining file list at the end.
    $counter = $counter + 1;
    print(‘While Loop Counter = ’ || $counter );
    #print(’ comma index = ’ || index($file_list , ‘,’, 1));
    if($counter = $list_size)
    $file_name= $file_list_temp;
    else
    $file_name = substr($file_list_temp , 1, index($file_list, ‘,’,1)-1);
    $file_list_temp = substr($file_list_temp, index($file_list,’,’,1)+1, length($file_list_temp)-index($file_list,’,’,1));
    print(‘Current file in process is ’ || $file_name);
    print(’ Remaining file list is = '|| $file_list_temp);

RUC :us: (BOB member since 2010-05-03)

I think it’s because you don’t have a while loop in the script. I agree that the note is difficult to understand, but here’s my interpretation:-

while ($counter < $list_size)
Begin
$counter = $counter + 1;
print(‘While Loop Counter = ’ || $counter );
#print(’ comma index = ’ || index($file_list , ‘,’, 1));

  if($counter = $list_size) 
  $file_name= $file_list_temp;
  else 
  $file_name = substr($file_list_temp , 1, index($file_list, ',',1)-1);
  $file_list_temp = substr($file_list_temp, index($file_list,',',1)+1,  length ($file_list_temp)-index($file_list,',',1));

   print('Current file in process is ' || $file_name);
   print(' Remaining file list is = '|| $file_list_temp);

  End

Nemesis :australia: (BOB member since 2004-06-09)

It is still an issue, It is not entering into the loop and says success.
Please advice.

First Script before while loop.

wait_for_file('/test/eFeedsRW/MainFrame/Acknowledge_Files/*.TXT', 1, 1, -1,$file_list, $list_size,',');
print('Number of file found = ' || $list_size);
print('Comma separated file list = ' || $file_list);
$file_list_temp = $file_list;
print('File List Temp = ' || $file_list_temp);

Second script within the loop.

Begin 
$counter = $counter + 1; 
print('While Loop Counter = ' || $counter ); 
#print(' comma index = ' || index($file_list , ',', 1)); 

if($counter = $list_size) 
$file_name= $file_list_temp; 
else 
$file_name = substr($file_list_temp , 1, index($file_list, ',',1)-1); 
$file_list_temp = substr($file_list_temp, index($file_list,',',1)+1, length ($file_list_temp)-index($file_list,',',1)); 

print('Current file in process is ' || $file_name); 
print(' Remaining file list is = '|| $file_list_temp); 

End

While_loop_1.PNG
While_loop_2.PNG


RUC :us: (BOB member since 2010-05-03)

I can’t see the variable ‘$counter’ being set anywhere outside of the loop. Are you initialising it to 1 or 0 in a script?


Nemesis :australia: (BOB member since 2004-06-09)

It is a lot easier to have the wait_for_file function only return one file.

Then you just loop until the file name is null. You dont have to mess with indexes or run the risk of blowing out the file list variable. If you need the file count and a counter, you can get the count in a separate call and easily setup a counter to just read off the file number its on.

you process the file, move it, then go back to the top of the loop and select the next file.


jlynn73 :us: (BOB member since 2009-10-27)

I think it is not mentioned in the SAP Notes.
Should I need to hardcode the value in the variable ??
Please advice what should be the default value ??


RUC :us: (BOB member since 2010-05-03)

Not a big surprise. I get the impression that the notes are typed by administrators rather than techies.

No, but you probably need to initialise it to avoid it being evaluated as NULL

I’d try ‘0’, but it depends on when you want your loop to complete.


Nemesis :australia: (BOB member since 2004-06-09)