Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

At times there would be some requirement to create folders dynamically, particularly when the output needs to be split into different files and stored in separate locations.

In this document i am explaining a scenario where there are 10 plant names and we need to create folders for all the 10 plant names to store the corresponding output files. Below is an example table with 10 plant names -

Row_IdPlant_names
1A
2B
3C
4D
5E
6F
7G
8H
9I
10J

I have to create 10 folders with plant names on it, like A, B, C etc..

You have to declare three global variables - $COUNT (for looping from row_id 1 to 10), $MAX_ROW (to end the loop at max row number) and $PLANT_NAME for capturing the 10 plant names in the loop one by one.

Place a script after the dataflow and insert the below code.

$COUNT = 1; # start the count at 1

$MAX_ROW = sql('datastorename','select max(ROW_ID) from tablename'); # capture the rowid in a variable

print( $MAX_ROW ); # optional to see the row nos

while ( $COUNT <= $MAX_ROW) # initialize the looping

          begin

          $PLANT_NAME = sql('datastorename','select PLANT_NAME from tablename where ROW_ID = [$COUNT]'); # selecting plant names one by one

          print($PLANT_NAME); # optional capture of plant name

          exec( 'cmd', 'mkdir C:\Users\XYZ\[$PLANT_NAME]',8 ); # create folder using dos command mkdir

          $COUNT = $COUNT + 1; # looping with counting row id

          end # end of loop

This will generate 10 folders with names A, B, C etc..

Hope this helps.

Arun

2 Comments
Labels in this area