04-21-2006 6:30 PM
Hi,
My requirement is to tranfer 5 internal table contents to 5 different files in application server. To achieve this in one go I used feild symbols & I was successful in it. But now a change has come in where the filepath needs to be flexible depending upon the environment & client where I am running this program. Hence I want help on converting the hardcoding of file path to the one which will be given in the selection screen.
Following is the code that I am using :-
Uploading the details of first internal table
WA_FILE-TABLENAME = 'IT_GLAC_BUKRS'.
WA_FILE-WA = 'WA_GLAC_BUKRS'.
WA_FILE-FILEPATH = '/usr/sap/Gl_Account_Text.txt'.
APPEND WA_FILE TO IT_FILE.
Uploading the details of second internal table
WA_FILE-TABLENAME = 'IT_PRCTR'.
WA_FILE-WA = 'WA_PRCTR'.
WA_FILE-FILEPATH = '/usr/sap/Profit_Center_Text.txt'.
APPEND WA_FILE TO IT_FILE.
Perform to transfer the files to application server
LOOP AT IT_FILE INTO WA_FILE.
PERFORM TRANSFER_DATA USING WA_FILE-TABLENAME
WA_FILE-WA
WA_FILE-FILEPATH.
ENDLOOP.
*&----
*& Form TRANSFER_DATA
*&----
Perform to transfer the files to application server
*----
-->P_WA_FILE_TABLENAME text
-->P_WA_FILE_WA text
-->P_WA_FILE_FILEPATH text
*----
FORM TRANSFER_DATA USING DATA_TAB
WA
FILE.
ASSIGN (DATA_TAB) TO <FS_DATATAB>.
ASSIGN (WA) TO <FS_WA>.
OPEN DATASET FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC = 0.
LOOP AT <FS_DATATAB> INTO <FS_WA>.
TRANSFER <FS_WA> TO FILE.
ENDLOOP.
ENDIF.
CLOSE DATASET FILE.
Thank You,
SB.
04-21-2006 8:51 PM
Is this what you are looking for?
parameters: p_file1 LIKE rlgrap-filename DEFAULT '/usr/sap/Gl_Account_Text.txt',
p_file2 LIKE rlgrap-filename DEFAULT '/usr/sap/Profit_Center_Text.txt',
p_file3 LIKE rlgrap-filename DEFAULT ....
p_file4 ....
p_file5....
You can then simply use the same existing code where you are appending IT_FILE,
but instead of WA_FILE-FILEPATH = '/usr/sap/Gl_Account_Text.txt', you can now say WA_FILE-FILEPATH = p_file1.
04-21-2006 6:51 PM
WA_FILE-FILEPATH = '/usr/sap/Gl_Account_Text.txt'
you can use
concatenate '/usr/sap/' sy-SYSID sy-MANDT 'Gl_Account_Text.txt' into WA_FILE-FILEPATH.
condense WA_FILE-FILEPATH.
Regards
Aman
04-21-2006 6:53 PM
Hi,
Couple of questions, are you taking the path for multiple files as input from the selection screen?
If yes, why can't you append them to the internal table, just like the way you are already doing so that you don't have to change anything, jsut take the values from the parameters from the parameters and pass that to the Work area in your code and the rest of your coding does NOT have to change, right?
Let me know, if the coding is something else? Publish / explain the way you are getting file names.
regards,
Ravi
Note : Please mark the helpful answers
04-21-2006 8:44 PM
Hi Ravi,
All the 5 files have to be in the same directory... & what I see now is that this directory path needs to be given in selection screen...
Thank You,
SB.
04-21-2006 7:26 PM
Hi,
Using Logical File names is the best suited solution for your problem. Instead of hardcoded physical file name, get it dynamically from the Logical file name definition.
Read the documentation on Logical file names and their usage in FM documentation for FILE_GET_NAME.
Hope this helps.
Regards,
Nagaraju Chidurupalli
04-21-2006 8:51 PM
Is this what you are looking for?
parameters: p_file1 LIKE rlgrap-filename DEFAULT '/usr/sap/Gl_Account_Text.txt',
p_file2 LIKE rlgrap-filename DEFAULT '/usr/sap/Profit_Center_Text.txt',
p_file3 LIKE rlgrap-filename DEFAULT ....
p_file4 ....
p_file5....
You can then simply use the same existing code where you are appending IT_FILE,
but instead of WA_FILE-FILEPATH = '/usr/sap/Gl_Account_Text.txt', you can now say WA_FILE-FILEPATH = p_file1.