Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

call a unix script from ABAP program

Former Member
0 Likes
538

Can anybody help me on how to call a unix script from an ABAP program

Regards

Anjali

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
408

Hi try the below code

parameters : p_sfile(60) lower case

"File to be moved

"Eg : /home/in/SFILE1.txt

p_dfile(60) lower case.

"File's Destination

"Eg: /home/archive/SFILE1.txt

data : t_btcxpm

like btcxpm occurs 0,

p_addparam

like sxpgcolist-parameters.

concatenate

'/home/ABAP/scripts/Archive_file.sh'

p_sfile

p_dfile

into p_addparam separated by space.

refresh t_btcxpm. clear t_btcxpm.

call function 'SXPG_CALL_SYSTEM'

exporting

commandname = 'ZSHELL'

additional_parameters = p_addparam

tables

exec_protocol = t_btcxpm

exceptions

no_permission = 1

command_not_found = 2

parameters_too_long = 3

security_risk = 4

wrong_check_call_interface = 5

program_start_error = 6

program_termination_error = 7

x_error = 8

parameter_expected = 9

too_many_parameters = 10

illegal_command = 11

others = 12.

if sy-subrc = 0.

write : /

'File',p_sfile,'moved to',p_dfile.

else.

write : / 'Error Occured'.

endif.

3 REPLIES 3
Read only

Former Member
0 Likes
408

Hi

You have to define it by trx SM69 and call it by fm SXPG_COMMAND_EXECUTE.

Max

Read only

Former Member
0 Likes
409

Hi try the below code

parameters : p_sfile(60) lower case

"File to be moved

"Eg : /home/in/SFILE1.txt

p_dfile(60) lower case.

"File's Destination

"Eg: /home/archive/SFILE1.txt

data : t_btcxpm

like btcxpm occurs 0,

p_addparam

like sxpgcolist-parameters.

concatenate

'/home/ABAP/scripts/Archive_file.sh'

p_sfile

p_dfile

into p_addparam separated by space.

refresh t_btcxpm. clear t_btcxpm.

call function 'SXPG_CALL_SYSTEM'

exporting

commandname = 'ZSHELL'

additional_parameters = p_addparam

tables

exec_protocol = t_btcxpm

exceptions

no_permission = 1

command_not_found = 2

parameters_too_long = 3

security_risk = 4

wrong_check_call_interface = 5

program_start_error = 6

program_termination_error = 7

x_error = 8

parameter_expected = 9

too_many_parameters = 10

illegal_command = 11

others = 12.

if sy-subrc = 0.

write : /

'File',p_sfile,'moved to',p_dfile.

else.

write : / 'Error Occured'.

endif.

Read only

Former Member
0 Likes
408

do you mean I have to write the script in SM69, then call that script using the function module?