cancel
Showing results for 
Search instead for 
Did you mean: 

Transports using a batch script

Former Member
0 Kudos

Hi Folks,

I have a specific requirement, I am trying to automate transports by using the command tp import all using a batch script.

Things are running fine but I am unable to capture the return code into a variable.

Once if I get the return code I can validate the success and failure of TR.

Please suggest a solution.

Thanks in advance.

Thanks,
Pavan

Accepted Solutions (1)

Accepted Solutions (1)

ACE-SAP
Active Contributor
0 Kudos

Hi

This is not easy as TP command does not set any RC.

The only way I found was to process the TP log file in order to be able to grab the RC that is only ouput to console.

But this should be done in a dirty "GOTO" loop  to wait until the import is over.

Regards

Tp import  [...] > "%log%" 2>&1

:TEST_RC_IMP

  set rc=9999

  for /f "tokens=2 delims=:" %%y in ('more %log% ^| findstr /C:"tp finished with return code"') do (set /A rc=%%y && echo OT=%%o RC=%%y )

  rem wait for the tp command to end

  if /I !rc! EQU 9999 goto :TEST_RC_IMP

  if /I !rc! GEQ 8 (

     echo Error on importing order %%o , RC=!rc! >> "%global_log%"    

  ) ELSE (echo %%o : !rc!  >> "%global_log%")

Former Member
0 Kudos

Hi Yves,

Could you please explain how the for loop is working to chop the return code in to the variable RC.

Thanks,

Pavan

ACE-SAP
Active Contributor
0 Kudos

I just grab the RC code by performing a search for a string (tp finished with return code) in the log more %log% | findstr /C:"tp finished with return code"

I used it in a "for" command to be able to extract the value of the RC that is after the ':' in the line I found. The for /f "tokens=2 delims=:"    extracts the second field (tokens=2) using ':' as a separator and put it in the %y variable and then to the RC variable.

To be able to  see the content the RC variable outside of the "for" loop (with !RC!) you should enable delayed expansion by the beginning of your script with the here under command
setlocal ENABLEDELAYEDEXPANSION

Answers (2)

Answers (2)

Former Member
0 Kudos

Thank you all,

For your valuable inputs

Thanks,

Pavan

former_member188883
Active Contributor
0 Kudos

Hi Pavan,

1) You can divert the output of script to a log file

   for eg. ./import_tr >> trout.log

2) You may check the return code from transaction code STMS

Regards,

Deepak Kori

Former Member
0 Kudos

Hi Deepak,

Redirecting the output to a log file is fine but during the runtime I need to pick up the return code from the log file and check the success or failure using a if condition.

Reagan
Advisor
Advisor
0 Kudos

It all depends on how the script is made.

There is a script available on SCN used for mass transports.

I would suggest you to check that and adapt your script accordingly.

Regards

RB

divyanshu_srivastava3
Active Contributor
0 Kudos

Hi Pavan,

If you can write a correct algorithm to get this function then you can covert that into a batch script for this purpose. For eg. You have have to use a filter to get the return code from log files you can search a pattern and save the output in a new file. For this you can use findstr command of windows. So, it's all about replacing you algo with correct script.

Regards

Former Member
0 Kudos

give me two weeks or so and I will translate this to a Windows Powershell script.

Former Member
0 Kudos

Hello RB,

I have already checked that link and  written the script using batch programming.

In that shell script the return code is fetched into $RC, that's the point where I am facing the problem in batch script unable to capture that return code into a variable.

Thanks,

Pavan

divyanshu_srivastava3
Active Contributor
0 Kudos

Hi Pavan,

Shell script and batch script are different, where shell is rich n intensive and batch is limited. You can't always map them completely. If you know programming, write a program for doing this some supported language of your OS , OR Yves has presented a read-made script, just fine tune it and apply in your landscape.

Regards,

Divyanshu

Former Member
0 Kudos

Hi Srivastava,

The code must be written in batch script, what you said is right.

I will go with Yves script.

Thanks,

Pavan