Ordinarily, we need to move a data file from one directory (say, the input directory) to another directory (say, the processed directory) after processing it. In such situations in ABAP, we generally loop through and read the input file, then move the data to the target directory. However, using a UNIX Command in SAP ABAP can simplify this process by allowing you to execute shell commands directly from ABAP to handle file operations more efficiently.
Fault:
In the event that the info record has enormous volume, this course of moving the document starting with one envelope then onto the next by circling is tedious and raises a ruckus around town of the framework.
Another option is to make an Outside Working Framework Order in SAP Exchange SM69 and use it in the program by calling the SAP standard FM ‘SXPG_COMMAND_EXECUTE’.
Fault:
ABAPers normally don’t have approval to this Exchange SM69 and they need to rely upon Premise/Security to get another order made. Premise/Security thusly needs to have every one of the endorsements set up to make these orders. At some point because of review issue, the outer order can’t be made.
The most efficient solution is to generate the UNIX command in SAP ABAP automatically and then copy the data file directly to the target path.
Sample code to write UNIX command in SAP ABAP
* This is a code showing how to create and use COPY command of UNIX in ABAP
PARAMETERS: * Input file path p_input TYPE localfile, * Processed file path p_proc TYPE localfile. * Declare the Types to file data TYPES: BEGIN OF L_X_OUTPUT, *sys*(200), " Please note, there are asterisk before and after sys (i.e.*sys*) END OF L_X_OUTPUT. * * Internal table to store file data DATA l_i_output TYPE STANDARD TABLE OF l_x_output WITH HEADER LINE. * * Variable for the UNIX command DATA: l_v_unix_comm(255) TYPE c. * Copy command of UNIX CONCATENATE 'cp' p_input p_proc INTO l_v_unix_comm SEPARATED BY space. * For example the Copy command is stored as below * cp ‘/data/interfaces/input/input_file’ ‘/data/interfaces/processed/processed_file’ * Examples of UNIX Command *• mv filename1 filename2 --- moves a file (i.e. gives it a different name, or moves it into a *different directory (see below) *• cp filename1 filename2 --- copies a file * Execute the UNIX Copy command. * This command will copy the file from input file path to the processed file path CALL 'SYSTEM' ID 'COMMAND' FIELD l_v_unix_comm ID 'TAB' FIELD l_i_output-*sys*. IF sy-subrc eq 0. write: 'File is copied successfully using UNIX command in ABAP'. ENDIF.
Trial:
Step1: Execute the above program
Step2: Document is duplicated effectively
Approval
Step3: Information document which is to be replicated
Step4: Document which is duplicated effectively
Benefit of this Tip
1) Don’t bother circling through the record again to duplicate it to another way.
2) Don’t bother relying upon Premise/Security group to get another Outside Working Framework Orders made in T Code SM69 and don’t bother calling the standard FM to utilize that Order.
3) We can compose every one of the orders which are perceived by UNIX.
YOU MAY BE INTERESTED IN
SPTA Parallel Processing Framework in ABAP