cancel
Showing results for 
Search instead for 
Did you mean: 

How to write a script in BODS

0 Kudos

Hi,

Can anyone help me in writing a script in BODS.

Requirement is like:

  • After a job has run, the output (executed file) should move from the target folder to other server.

Please help me as I am new to BODS.

Regards,

Anurag.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Arun,

I've tried this before too but it doesn't work. The job has run successfully with out any errors, but failed to perform the file transfer which is in the .bat file.

PFB screenshots for ref:

Regards,

Anurag.

former_member198401
Active Contributor
0 Kudos

exec('CMD','\\frgows55\BODS_Target\NAFTA\script_bods.bat',8);

Just CMD. No need of typing CMD.exe.

Regards

Arun Sasi

former_member187605
Active Contributor
0 Kudos

The job has not run successfully, there is an error, written to your trace file: "the system cannot find the path specified".

That's due to the backslashes used in the folder path. The backslash is used as an escape character in DS scripting. Try to print('\\frgows55\BODS_Target\NAFTA\script_bods.bat') and see what happens.

Use exec('cmd','\\\\frgows55\BODS_Target\NAFTA\script_bods.bat',8);

Answers (5)

Answers (5)

0 Kudos

Dirik... you beauty!!

Thanks a lot man..!

Finally I can sleep peacefully tonight!

Thanks a lot everyone for your guidance.

Arun Thanks to you too! For your examples and speedy reply.

Many thanks everyone. Cheers!

Regards,

Anurag.

0 Kudos

HI All,

I've written a script which actually met my scenario. (Downloading files from FTP)

Now can any one tell me how to call that bat file in BODS script?

suppose the .bat file name is script.

how do I call that .bat file in BODS script?

Thanks in advance!

Regards,

Anurag.

former_member198401
Active Contributor
0 Kudos

very simple!

Command in the script will look like something

exec('CMD','C:\Scripts\TestScript.bat',8);

If you get any error while executing the above then try to print the output of exec() function as below

print(exec('CMD','C:\Scripts\TestScript.bat',8));

Regards

Arun Sasi

0 Kudos

My file is in FTP (Filezilla) which needs to be copied to my job server (frgows55). Now somebody please tell me how to write a script. And please explain.

former_member198401
Active Contributor
0 Kudos

Filezilla uses the SFTP protocol. Google it and you will find lot of material

Regards

Arun Sasi

former_member187605
Active Contributor
0 Kudos

Create a file location object with the Filezilla settings. Then simply, in a script:

     copy_from_remote_system(“Filezilla”, “file.txt”);

0 Kudos

Hi Dirk,

Is File location object available with my version of Designer?

PFB screenshot:

If yes, can you share some notes how to use file location object?

Thanks in Advance!

Regards,

Anurag.

former_member187605
Active Contributor
0 Kudos

Oh no, it isn't. I am sorry about that. It's been introduced in DS 4.2 SP5. You're still on SP3.

0 Kudos

Ohh

So is there any alternate way to transfer files from FTp to job server?

Regards,

Anurag.

former_member187605
Active Contributor
0 Kudos

Sure, the old manual style, use the exec buitl-in function in in combination with OS-level scripting. Carefully check Arun's example.

former_member208402
Active Contributor
0 Kudos

Hi Naha anurag,

We have new functions added in BODS 4.2

1. file_copy

2. file_move

you can move files using  any of the above functions.

or you can also use the above logic posted by madhusudhan.

please refer the below link for more information on file_copy and file_move functions.

http://help.sap.com/businessobject/product_guides/sbods42/en/ds_42_reference_en.pdf

Thanks,

Ravi Kiran.

0 Kudos

Hi Ravi,

Will this thing works with the below scenario:

  • picking up file from FTP and transferring it to Job server?

Many thanks for your reply.

Regards,

Naga Anurag S

former_member187605
Active Contributor
0 Kudos

Yes!

0 Kudos

Hi Dirk

can you give an example for this?

That would be grateful.

Thanks in Advance!

regards,

Anurag.

former_member187605
Active Contributor
0 Kudos

Sure, check out section 2.3.12 File location object in the SAP Data Services Reference Guide (url as given before). The function you need is actually called copy_from_remote_system:

     copy_from_remote_system(“flo_ftp_1”, “prod.txt”)

This function uses the FTP information in the file location object flo_ftp_1 to copy the file named prod.txt that is located in a remote directory.

former_member198401
Active Contributor
0 Kudos

Here's a sample script which I had written..

@echo off

set USER=user_name

set "PASSWORD=password"

set LOCAL_DIR=D:\Data\Proj\Source

set FILE_NAME=filename.txt

set dt=%date:~7,2%-%date:~4,2%-%date:~10,4%_%time:~0,2%_%time:~3,2%_%time:~6,2%

del D:\Data\Proj\ftpcommand.txt

echo USER %USER%>>D:\Data\Proj\ftpcommand.txt

echo %PASSWORD%>>D:\Data\Proj\ftpcommand.txt

echo lcd D:\Data\Proj\Source>>D:\Data\Proj\ftpcommand.txt

echo CD /FTP_Folder>>D:\Data\Proj\ftpcommand.txt

echo ascii>>D:\Data\Proj\ftpcommand.txt

echo MGET filename.txt>>D:\Data\Proj\ftpcommand.txt

echo disconnect>>D:\Data\Delfi\ftpcommand.txt

echo bye>>D:\Data\Proj\ftpcommand.txt

ftp -n -i -s:D:\Data\Proj\ftpcommand.txt  FTP_SERVER_IP

/* Copy File from Source folder to Backup Folder on Job Server */

copy D:\Data\Proj\Source\filename.txt D:\Data\Proj\Backup\filename.txt_%dt%.txt

Dont do a copy paste Use your own logic as per the requirement

Regards

Arun Sasi

0 Kudos

Hi Arun,

can you please tell me the script to be written in a batch file where

  • I have to pickup a file from FTP and copy to some other place.

PF attached script, please tell me what changes to be done to the script to acquire the above mentioned scenario.

Thanks in Advance!

regards,

Anurag.

former_member198401
Active Contributor
0 Kudos

looks good!!

Try to run the above script in a batch file from command prompt and check if you have any issues.

If its doing the required then try running the script from BODS job

Regards

Arun Sasi

0 Kudos

PFA the script is it good???

But the above script is working with scenario:

  • uploading files to FTP from job server.

My scenario is:

  • Download files from FTP and place it in job server.

Can you suggest any idea.

Regards,

Anurag.

former_member223526
Participant
0 Kudos

Hi Naga,

See the code below,

print ('*** Moving file to [$G_FILE_DIRECTORY]archive\\');

$G_NextJobCmd = 'move "' || $G_FILE_DIRECTORY || $G_FILE_NAME || '" "' || $G_File_Directory2 || 'archive\\' ;

exec( 'cmd', $G_NextJobCmd, 0 );


$G_FILE_DIRECTORY : Variable with the source path

$G_FILE_NAME : Variable with file name.

$G_File_Directory2 : Varaible with target directory.


Thanks,


Madhusudhan K.

0 Kudos

Thanks Madhusudhan for your reply.  I''ll try this.

Regards,

Naga Anurag S