Table of contents
This gives an overview on how to create the External Commands using SM49, assigning UNIX (or other operating system) file or using a UNIX Command and implementing them. Below given is the step by step approach to the same.
Example: Listing the Files in the required directory.
Create the command in SM49
Navigate to SM49 and Create an External Command
- In the Command section, the Operating System field is protected but may be changed by pressing the search help (F4)
- In the Definition section, for Operating System Command text box we can even give the file path of application server file. All the UNIX coding can be done in the file. So when ever this external command is called, the functionality written in the file gets triggered. For this example write 'ls'.
Create the ABAP program which calls SXPG_COMMAND_EXECUTE
Once the Command is created, then use function module 'SXPG_COMMAND_EXECUTE' as shown below.
The operatingsystem parameter is case sensitive, it must be exactly the same value as in SM69. For example, you must enter "Linux" instead of "LINUX".
CONSTANTS: c_extcom TYPE sxpgcolist-name VALUE 'Z_LIST_FILES', c_oper TYPE syopsys VALUE 'UNIX'. DATA: v_dir_input TYPE sxpgcolist-parameters. " Input Directory DATA: t_result TYPE STANDARD TABLE OF btcxpm. v_dir_input = './sap/tmp'. CALL FUNCTION 'SXPG_COMMAND_EXECUTE' EXPORTING commandname = c_extcom additional_parameters = v_dir_input operatingsystem = c_oper TABLES exec_protocol = t_result 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 wrong_asynchronous_parameters = 12 cant_enq_tbtco_entry = 13 jobcount_generation_error = 14 OTHERS = 15.
T_RESULT will contain the list of files in the specified directory after execution of the function module.
Example of result:
If the command fails, you would get something like that:
ls: ./sap/tmp: No such file or directory
External program terminated with exit code 1
This way we can make use of UNIX coding in SAP.
- SAP Library - Programming Techniques (about SXPG_* function modules)
- Move/copy/delete a file from/to presentation/application server