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: 

What is the Unix command to concatenate two files and merget it in to one ?

babu_kilari4
Active Contributor
0 Kudos

Hi Experts,

I have three jobs and each job creates a file. I want to run one more job which clubs these three files and merges it in to one.

I know the process of opening each file and appending it in to the target file using DATASET concept.

Instead of that, I want any UNIX Shell command so that I can call that directly from ABAP and execute it

Any help on this would be highly appreciated

Thanks in advance.

Babu Kilari

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello Babu,

We can very well call an OS command from within ABAP, but in your case, I don't think that is really required. Please find below a logic that might be helpful to you.

You have three files, whose contents needs to be merged into a single file.

Read the contents of each file and store it into an internal table.

DATA: command LIKE rs37a-line.
DATA: BEGIN OF tabl OCCURS 0,
          line(2000),
      END OF tabl.

command = 'cat /tmp/file1.txt'.

CALL 'SYSTEM' ID 'COMMAND' FIELD command
              ID 'TAB'     FIELD tabl-*sys*.

Internal table 'tabl' will contain the contents of the file.

Accumulate all the contents into a single file and upload to the application server using OPEN DATASET, TRANSFER DATASET and CLOSE DATASET.

Let me know if you need a more detailed explanation.

Regards

Sabu.

4 REPLIES 4

Former Member
0 Kudos

Hello Babu,

We can very well call an OS command from within ABAP, but in your case, I don't think that is really required. Please find below a logic that might be helpful to you.

You have three files, whose contents needs to be merged into a single file.

Read the contents of each file and store it into an internal table.

DATA: command LIKE rs37a-line.
DATA: BEGIN OF tabl OCCURS 0,
          line(2000),
      END OF tabl.

command = 'cat /tmp/file1.txt'.

CALL 'SYSTEM' ID 'COMMAND' FIELD command
              ID 'TAB'     FIELD tabl-*sys*.

Internal table 'tabl' will contain the contents of the file.

Accumulate all the contents into a single file and upload to the application server using OPEN DATASET, TRANSFER DATASET and CLOSE DATASET.

Let me know if you need a more detailed explanation.

Regards

Sabu.

0 Kudos

My main aim here is to eliminate one more internal table. Because, there will be lakhs of records and i dont want to loop on that final internal table using DATASET.

Simple Unix Command which combines the three files should do. Thats what I am searching for..

Thanks,

Babu Kilari

0 Kudos

Try this:

DATA: command LIKE rs37a-line.
DATA: BEGIN OF tabl OCCURS 0,
          line(2000),
      END OF tabl.
 
command = 'cat /tmp/file1.txt /tmp/file2.txt /tmp/file3.txt > /tmp/file4.txt'.
 
CALL 'SYSTEM' ID 'COMMAND' FIELD command
              ID 'TAB'     FIELD tabl-*sys*.

Regards

Sabu.

babu_kilari4
Active Contributor
0 Kudos

Thanx a lot for the reply