Application Development 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: 

UNIX command and SXPG_COMMAND_EXECUTE

Former Member
0 Kudos

HI all,

Let me explain my requirement:

I need to move all files from source dir to target.

For that i need to read source dir and target dir from selection screen.

I wrote UNIX command as follows:

"mv -f /common/home/edw/parsekb/b2/* /common/home/edw/parsekb/b1"

where i m specifying the src and target dir.

so i need to pass the parmeters as srcdir and targetdir?

how should i do it?

i knw i need to create a command in SM69,then what will be the parameters in that case?

and how to call that from ABAP ?

if anybody give me explaination w.r.t. coding steps then that will be gr8.

but pls specify SM69 steps and ABAP both

Thanx in advance

4 REPLIES 4

Former Member
0 Kudos

You can use ARCHIVFILE_SERVER_TO_SERVER function module instead of writing your own code.

Cheers.

Sanjay

Former Member
0 Kudos

Hi h k,

1. I suppose a new command has already been created

thru SM69.

The Unix Command is MV (with additional required parameters )

So in SM69

a) Just Write mv ( in the field for os command)

b) Leave blank the field of parameters for os command

c) Tick the checkbox for 'Additional parameters allowed'

2. Now the question for passing additional parameters :

a) u must be having 2 variables / parameters

one for source dir, and other for target dir.

b) concatenate them in one another variable

eg. concatenate srcdir trgdir TD into myvar.

3. Now when calling the FM,

there is one optional parameter

ADDITIONAL_PARAMETERS

Pass the new variable MYVAR into this parameter.

HOPE This Helps

Regards,

Amit Mittal.

Former Member
0 Kudos

Hi!

1. Create your shell script your_shell_script.sh:

src=$1

dst=$2

mv -f $src $dst

2. Create your command Z_YOUR_COMMAND using SM69:

- Operating system command: /bin/sh (the path to your shell interpretator)

- Parameters for operating system command:

/home/sap/bin/your_shell_script.sh (the path to your shell script)

- Set "Additional parameters allowed" checkbox

3. Call your command from ABAP:

data:

param type sxpgcolist-parameters.

status type extcmdexex-status,

exitcode type extcmdexex-exitcode,

it_log type table of btcxpm.

p_src = '/common/home/edw/parsekb/b2/*'.

p_dst = '/common/home/edw/parsekb/b1'.

concatenate p_src p_dst into param separated by space.

CALL FUNCTION 'SXPG_CALL_SYSTEM'

EXPORTING

COMMANDNAME = 'Z_YOUR_COMMAND'

ADDITIONAL_PARAMETERS = param

IMPORTING

STATUS = status

EXITCODE = exitcode

TABLES

EXEC_PROTOCOL = it_log

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 = 99.

if sy-subrc <> 0.

*TODO: add your error handling logic

endif.

Regards,

Maxim.

former_member188685
Active Contributor
0 Kudos

Hi Why are u worrying for this u try this

Program it will solve ur problem.

u have to pass the Unix command as paramter.

in selection screen give this and try

<b>mv -f /common/home/edw/parsekb/b2/* /common/home/edw/parsekb/b1</b>

REPORT ZTEST line-size 400

no standard page heading.

selection-screen begin of block ucmd with frame title text-001.

parameters: unixcom like rlgrap-filename. " ...SAP Interface file

selection-screen end of block ucmd.

data: begin of tabl occurs 500,

line(400),

end of tabl.

data: lines type i.

*----


start-of-selection.

refresh tabl.

call 'SYSTEM' id 'COMMAND' field unixcom

id 'TAB' field tabl[].

describe table tabl lines lines.

loop at tabl.

write:/01 tabl-line.

endloop.

skip 2.

if lines = 0.

write:/ 'NO Occurances were found'.

else.

write:/ 'Command was successfully executed' color col_total.

write:/ 'Number of entries in Search' color col_total,

lines color 6.

endif.

regards

vijay