how to create a file in application server with abap programing - abap

I have a file in my D: drive of my computer and I want to copy this file to an SAP application server so that I am able to see my file with transaction AL11.
I know that I can create a file with AL11 but I want do this in ABAP.
Of course in my search I find this code but I cannot solve my problem with it.
data: unixcom like rlgrap-filename.
data: begin of tabl occurs 500,
line(400),
end of tabl.
dir =
unixcom = 'mkdir mydir'. "command to create dir
"to execute the unix command
call 'SYSTEM' id 'COMMAND' field unixcom
id 'TAB' field tabl[].

To upload the file to the application server, there are three steps to be followed. To open the file use the below statement:
Step1: OPEN DATASET file name FOR INPUT IN TEXT MODE ENCODING DEFAULT.
To write into the application server use.
Step2: TRANSFER name TO file name.
Dont forget to close the file once it is transferred.
Step3: CLOSE DATASET file name.
Plese mark with correct answer, if it helps! :)

If you want to do this using ABAP you could create a small report that uses the function module GUI_UPLOAD to get the file from your local disk into an internal table and then write it to the application server with something like this:
lv_filename = '\\path\to\al11\directory\file.txt'.
OPEN DATASET lv_filename FOR OUTPUT IN TEXT MODE ENCODING UTF-8.
LOOP AT lt_contents INTO lv_line.
TRANSFER lv_line TO lv_filename.
ENDLOOP.
CLOSE DATASET lv_filename.

I used CG3Z transaction and with this transaction I was able to copy a file in the application server directory.

Related

I am trying to copy a file, but getting error message

I am new to postgres, probably missing something silly like (the correct name of my directory). Can someone guide me?
I am following book instructions, Practical SQL by Anthony DeBarros
Code:
copy us_counties_2010 from 'C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv' with (FORMAT CSV, HEADER);
Error:
ERROR: could not open file
"C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv" for reading:
Permission denied HINT: COPY FROM instructs the PostgreSQL server
process to read a file. You may want a client-side facility such as
psql's \copy. SQL state: 42501
copy us_counties_2010 from
'C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv' with (FORMAT
CSV, HEADER);
Expected:
Query returned successfully: 3143 rows affected
Actual:
ERROR: could not open file
"C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv" for reading:
Permission denied HINT: COPY FROM instructs the PostgreSQL server
process to read a file. You may want a client-side facility such as
psql's \copy. SQL state: 42501
All that is to be done is:
Go to Properties of that particular file by right clicking on it. Then, go to Security tab of the displayed Properties dialog box. Click on Edit option. Permissions dialog box appears, then click on Add button. Type 'Everyone' (without apostrophes) in the "Enter the object names to select" description box and click on OK button. Then, make sure all the checkboxes of "Permissions for Everyone" are selected by just ticking the "Full Control" check box to allow the control access without any restriction. Then, Apply and OK all the tabs to apply all the changes done.
You can now run/execute the query without any errors.
As the message tells you, Postres is not allowed to read the file.
If you want to fix that open the Task Manager, and click on "Show processes from all users". Look for the rows with the image name postgres.exe (likely more than one). Remember the value in the column "User Name" (it's probably NETWORK SERVICE). Open the properties of your file, add that user in the "Security" tab and grant read access to them.
Or use psql's \copy as the message suggests.
copy us_counties_2010 (your column name)//(country_code, latitude, longitude, country, population)
FROM 'D:\us_counties_2010 .csv' DELIMITER ',' csv HEADER
Your csv file should be in other than C drive. It can't access your C drive. Store it in D drive or any other it will work perfect.
Change the Location of data file and path to Drive['D:\us_counties_2010.csv' ] it will work.
The permission is denied because your files[us_counties_2010.csv] is in 'C' Drive ['C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv'] which is a Windows Drive and permissions are restricted and may not be changed easily & impossible without administrative privileges.
Good Luck & happy programming!
If you are using PSQL, run it as administrator, then you shouldn't have any problem when you are using COPY
In the case when creating a table as well as importing data from a CSV file, we can skip the query and use the program itself. To do this, simply right-click on your table in the tree on the left and select the Import/Export… menu item.
A window will appear with the slider set to Import. Then select the source file and set the format to CSV. Set the Header to Yes if your file has a header. The only thing left is to select the delimiter (usually a comma).
When you click OK, the data will be imported.
For a better understanding, you can refer original article.
https://learnsql.com/blog/how-to-import-csv-to-postgresql/
copy us_counties_2010 from 'C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv' with (FORMAT CSV, HEADER,DELIMITER ',');
Use this code instead of that

pentaho data integration dynamic file name

New to PDI here. Need to output data from a view in a postgresql database to a file daily. The output file will be like xxxx_20160427.txt, so need to append the dynamic date in the file name. How to do it?
EDIT-----------------
I was not clear here by asking how to add dynamic date, I was trying to add not just date but optional other parts to the file name. E.g adding a serial no (01) at the end: xxxx_2016042701.txt etc. So my real question is how to make a dynamic file name? In other ETL tool e.g. SSIS it will be a simple expression. Not sure how it is done in PDI?
In your Text file output step, simply check "Include date in filename?" under the files tab.
You can create a dynamic filename variable with a Modified Java Script value STEP.
and then in the Text File Output STEP click on "Accept file name from field", and select your variable declared from previous step (filename_var on this example).

BIDS Import from changing file name [wildcard?]

I'm attempting to create a process to import data. I created the entire process and it works, but I'm having trouble creating the variable to find the file name of the csv i want to import automatically. Each time a new csv is uploaded to me it has a timestamp on it. I want to be able to grab that file no matter what the name is and do work to it.
So for example this week the file name would be
filename_4-14-2014.csv
And next week
filename_4_21_2014.csv
And so on into eternity. . .
Is there a way to create a variable that picks up the full file name even though its changing?
After doing some poking around, I've discovered the following...
You can use a file system task to perform the copy operation I was referring to. You can set the input file and the output file as variables. This way you can always know that the file you use for import is always named the same, and has the right data.
You just need to add the variables and a File System Task to your package.
Ok so to accomplish what I wanted I created a Foreach Loop Container. Using the foreach loop container I had it look for any files ending with .csv in my specified folder by using a wildcard [denoted by asterisk: *.csv] .
Within the Foreach Loop container is as follows.
Step 1: File System Task - rename file.
Step 2: Data Flow Task - Import data to sql
Step 3: File System Task - Copy the file to another folder, append datetime to filename
Step 4: File System Task - Delete source file.
I used variables to get all the file and folder names plus datetimes.

Where does gui_upload uploads the files?

Simply, where does gui_upload function uploads the files in Application Server. How can I find the location of them, or is there any tcode that I can find last uploaded files or search by name ?
Thanks.
gui_upload function does not upload file to the Application server. it just reads a file from the presentation layer into an internal table. You will then need to use some other function to write this internal table to a file on the application server.
Hope this helps.
I can confirm both previous answers.
If you'd like to upload a text/csv file for example to an application server, you can use the following code.
Using GUI_UPLOAD to actually read the provided input file to an internal table:
lv_filename = p_filebp.
CLEAR lt_data_tab.
IF NOT lv_filename IS INITIAL.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_filename
TABLES
data_tab = lt_data_tab
EXCEPTIONS
file_open_error = 1
OTHERS = 17.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDIF.
Check if there was data in the text file, and has been transferred into the internal table correctly.
If so, upload it to a file on the application server. You can provide a path yourself where you want to see this uploaded:
READ TABLE lt_data_tab INDEX 1.
IF sy-subrc <> 0.
WRITE: / 'No data in input file.'.
ELSE.
CONCATENATE '/interfaces/' sy-sysid '/CRM_ACTIVITIES/' sy-datum '_INPUT.CSV' INTO p_serinp.
OPEN DATASET p_serinp FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
EXIT.
ENDIF.
LOOP AT lt_data_tab.
TRANSFER lt_data_tab TO p_serinp.
CLEAR lt_data_tab.
ENDLOOP.
CLOSE DATASET p_serinp.
IF sy-subrc = 0.
CLEAR gd_error_text.
CONCATENATE 'Download to file: ' p_serinp ' is finished.'
INTO gd_error_text SEPARATED BY space.
WRITE: / gd_error_text.
ENDIF.
ENDIF.
Keep in mind that, using the OPEN DATASET statement, you can write files anywhere on your network. That if at least you got the required authorizations.
Transaction AL11 can be used to explore the existing folders and files on your SAP system.
I don't have an ABAP stack on hand but I believe what you're looking for is the command OPEN DATASET, or something along those lines. This handles reading and writing files on the application server. The files that are processed via OPEN DATASET can be found with transaction AL11.

Edit the control file in Oracle 10g Release 2

I tried to clone an oracle database server to another oracle database server.
After I completed the cloning, when I tried connecting to the database by starting SQL Plus
I got the following errors:
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/home/oracle/oradata/ccisv2/system01.dbf'
I found that while cloning the control file of the original database location also got cloned.
Now in the new server I have the data files located at a different location. and that is not affected in the control file, which is the reason for the error.
In short I need to change the above path
/home/oracle/oradata/ccisv2/
to a new path
/home2/oracle/oradata/ccisv2/
I am not sure how can I change the control file and edit the path of the data file location.
Changing of the location of datafiles is not possible as I have less space in
/home/oracle/oradata/..
Can some one help me with this one...
You'll need to mount the database (not open it) and re-create the controlfile, renaming the data files in the process (see the CREATE CONTROLFILE command):
STARTUP MOUNT;
CREATE CONTROLFILE REUSE SET DATABASE "ORCL" RESETLOGS
MAXLOGFILES NN
MAXLOGMEMBERS N
MAXDATAFILES 254
MAXINSTANCES 1
MAXLOGHISTORY 1815
LOGFILE
GROUP 1 '/home2/oracle/oradata/ccisv2/REDO01.LOG' SIZE 56M,
GROUP 2 '/home2/oracle/oradata/ccisv2/REDO02.LOG' SIZE 56M,
GROUP 3 '/home2/oracle/oradata/ccisv2/REDO03.LOG' SIZE 56M
DATAFILE
'/home2/oracle/oradata/ccisv2/SYSTEM.DBF',
'/home2/oracle/oradata/ccisv2/USERS.DBF',
'/home2/oracle/oradata/ccisv2/sysaux.DBF',
'/home2/oracle/oradata/ccisv2/TOOLS.DBF',
etc...
CHARACTER SET WE8ISO8859P1;
ALTER DATABASE OPEN RESETLOGS;
QUIT;
All of your database files need to be re-identified in the controlfile with their new location.
Easiest is to just rename the datafiles to the new locations:
startup mount;
alter database rename file '/home/oracle/oradata/ccisv2/system01.dbf' to '/home2/oracle/oradata/ccisv2/system01.dbf';
and do this for all your files.
Normally we would use rman duplicate and use the file_name convert to do this for us.
re-creating the controlfile is also an option, renaming the files is easier.