‎2007 Nov 28 6:27 AM
How can we create a new file on application server through Code....
Please its urgent....
‎2007 Nov 28 6:31 AM
Use the TCODE CG3Z to upload a file from desktop to application server.
the source path will be the path of the file on ur desktop and the target file will have the path of application server. If u want to create a new file say generate or create else say overwrite.
‎2007 Nov 28 6:32 AM
check help for
OPEN DATASET dsn.
Effect
Opens the specified file. If you do not use any additions, the file is opened for reading in binary mode. If you do not specify a directory, the system uses the directory defined in the profile parameter DIR_HOME.
The return code is set as follows:
SY-SUBRC = 0:
File opened.
SY-SUBRC = 8:
File could not be opened.
Example
DATA:
dsn(20) VALUE '/usr/test.dat',
rec(80).
OPEN DATASET dsn.
IF sy-subrc = 0.
DO.
READ DATASET dsn INTO rec.
IF sy-subrc <> 0.
EXIT.
ELSE.
WRITE / rec.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET dsn.
Opens the file 'test.dat' from the 'usr' directory on the application server. The data record is 80 bytes long.
‎2007 Nov 28 6:35 AM
HI
see this report program where EXCEL to INTERNAL table and then to APPLICATION SERVER
REPORT ZSD_EXCEL_INT_APP.
parameter: file_nm type localfile.
types : begin of it_tab1,
f1(20),
f2(40),
f3(20),
end of it_tab1.
data : it_tab type table of ALSMEX_TABLINE with header line,
file type rlgrap-filename.
data : it_tab2 type it_tab1 occurs 1,
wa_tab2 type it_tab1,
w_message(100) TYPE c.
at selection-screen on value-request for file_nm.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
* PROGRAM_NAME = SYST-REPID
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
STATIC = 'X'
* MASK = ' '
CHANGING
file_name = file_nm
EXCEPTIONS
MASK_TOO_LONG = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
start-of-selection.
refresh it_tab2[].clear wa_tab2.
file = file_nm.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '10'
i_end_row = '35'
tables
intern = it_tab
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at it_tab.
case it_tab-col.
when '002'.
wa_tab2-f1 = it_tab-value.
when '004'.
wa_tab2-f2 = it_tab-value.
when '008'.
wa_tab2-f3 = it_tab-value.
endcase.
at end of row.
append wa_tab2 to it_tab2.
clear wa_tab2.
endat.
endloop.
data : p_file TYPE rlgrap-filename value 'TEST3.txt'.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
*--- Display error messages if any.
IF sy-subrc NE 0.
MESSAGE e001(zsd_mes).
EXIT.
ELSE.
*---Data is downloaded to the application server file path
LOOP AT it_tab2 INTO wa_tab2.
TRANSFER wa_tab2 TO p_file.
ENDLOOP.
ENDIF.
*--Close the Application server file (Mandatory).
CLOSE DATASET p_file.
loop at it_tab2 into wa_tab2.
write : / wa_tab2-f1,wa_tab2-f2,wa_tab2-f3.
endloop.
‎2007 Nov 28 6:35 AM
Hi,
refer to this code:
*&----
*& Report Z8SAPNA_PROGRAM_DWNLOAD
&----
*& Program : Z8SAPNA_PROGRAM_DWNLOAD *
*& Developer : Sapna Agarwal *
----
Change No. Change On Change By Description *
----
*
----
REPORT Z8SAPNA_PROGRAM_DWNLOAD
NO STANDARD PAGE HEADING
LINE-COUNT 30(3)
LINE-SIZE 400
MESSAGE-ID Z8sapna8.
**REPORT Z8SAPNA_PROGRAM_DWNLOAD MESSAGE-ID Z8SAPNA7.
----------------------------------------------------------------------
Program for(description)
----------------------------------------------------------------------
1. a)At selection-screen the user should have an input for program name-
should be a range with f4 key.
This is done by creating a search help in se11 (Z8SAPNA_SH)
b)Radiobuttons should be provided for downloading the Data to Presentation
server or application server.(CG3Z)
*
----------------------------------------------------------------------
2. On display of the output ,
A list of program names should be displayed with checkbox provided.
----------------------------------------------------------------------
3. Finally downloading the selected program into applcn/ presntn server
acc to the user
----------------------------------------------------------------------
*MODIFICATION: (15th feb)
4. Making the program interactive for downloading the names of the fm used
in the clicked programs.
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
----
T A B L E D E C L E R A T I O N *
----
**-- Transparent table used
TABLES: TRDIR. "System table TRDIR.
----
T Y P E D E C L E R A T I O N *
----
TYPES: BEGIN OF REP_LIST,
NAME TYPE NAME,
END OF REP_LIST.
***********************************************************************
TABLE TYPES.
***********************************************************************
DATA : type_REP_LIST TYPE TABLE OF REP_LIST.
*************************************************************************
*WORK-AREA
*************************************************************************
DATA : WA_PROG TYPE REP_LIST.
----
D A T A D E C L E R A T I O N *
----
DATa: check_box(1) type c,
len type i,
COUNTER(10) TYPE N.
*=======INTERNAL TABLE FOR DOWNLOADING DATA TO PRESNTN SERVER=========
DATA: begin of it_PRES occurs 0,
row(2000) type c,
end of it_PRES.
*=======INTERNAL TABLE FOR DOWNLOADING DATA TO PRESNTN SERVER=========
DATA: begin of it_APPL occurs 0,
row(2000) type c,
end of it_APPL.
*=======FILE FOR DOWNLOADING DATA TO PRESNTN SERVER=========
DATA: e_file like rlgrap-filename." value './'. "'./SAPNA'.
*****declaration of the files downloading variable........
DATA: sapna_file1 TYPE string,
PROG_PATH TYPE C.
----
I N I T I A L I Z A T I O N *
----
INITIALIZATION.
**-- Clear all internal tables
CLEAR: wa_prog.
**-- Refresh all internal tables
REFRESH:TYPE_REP_LIST.
======================================================================
SELECTION SCREEN DEFAULT
======================================================================
SELECTION-SCREEN BEGIN OF BLOCK CHARLY1 WITH FRAME TITLE TEXT-000.
SELECTION-SCREEN BEGIN OF BLOCK main WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP 1.
SELECT-OPTIONS: P_NAME for TRDIR-NAME matchcode object Z8SAPNA_SH.
SELECTION-SCREEN END OF BLOCK main.
SELECTION-SCREEN BEGIN OF BLOCK main1 WITH FRAME TITLE text-003.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: P_Server RADIOBUTTON GROUP grp1 DEFAULT 'X'.
SELECTION-SCREEN: COMMENT 10(20) TEXT-005 FOR FIELD P_Server.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: A_Server RADIOBUTTON GROUP grp1 .
SELECTION-SCREEN: COMMENT 10(20) TEXT-006 FOR FIELD A_Server.
SELECTION-SCREEN: END OF LINE.
SELECTION-SCREEN END OF BLOCK MAIN1.
SELECTION-SCREEN END OF BLOCK CHARLY1 .
----
A T S E L E C T I O N S C R E E N ( V A L I D A T I O N S ) *
----
AT SELECTION-SCREEN.
*----
SELECT NAME
INTO CORRESPONDING FIELDS OF TABLE TYPE_REP_LIST
FROM TRDIR
WHERE NAME IN P_NAME.
IF SY-SUBRC <> 0.
MESSAGE E001.
ENDIF.
*=======================================================================
START-OF-SELECTION.
set pf-status 'CHECK'.
PERFORM ZF_DATA_FETCH.
PERFORM ZF_DATA_DISPLAY.
AT USER-COMMAND.
PERFORM ZF_USER_TASK.
PERFORM ZF_TOP-OF-PAGE.
&----
*& Form ZF_DATA_FETCH
&----
text
----
--> p1 text
<-- p2 text
----
form ZF_DATA_FETCH .
Retreival of data into the reqd table***
SELECT NAME
INTO CORRESPONDING FIELDS OF TABLE TYPE_REP_LIST
FROM TRDIR
WHERE NAME IN P_NAME.
IF SY-SUBRC <> 0.
MESSAGE e001.
ENDIF.
endform. " ZF_DATA_FETCH
&----
*& Form ZF_DATA_DISPLAY
&----
text
----
--> p1 text
<-- p2 text
----
form ZF_DATA_DISPLAY .
********Printing of Program names*********
LOOP AT TYPE_REP_LIST INTO WA_PROG.
WRITE:/ check_box as checkbox, WA_PROG-NAME COLOR 2.
hide WA_PROG-NAME.
ENDLOOP.
clear wa_prog.
DESCRIBE TABLE TYPE_REP_LIST LINES LEN.
endform. " ZF_DATA_DISPLAY
&----
*& Form ZF_USER_TASK
&----
text
----
--> p1 text
<-- p2 text
----
form ZF_USER_TASK .
case sy-ucomm.
WHEN 'DOWNLOAD'.
IF P_SERVER = 'X'.
COUNTER = 1.
CHECK_BOX = SPACE. "CLEAR CHECKBOX
set pf-status 'CHECK' excluding 'DOWNLOAD'.
**
DO .
Read line sy-index field value check_box wa_prog.
IF SY-SUBRC <> 0. "IF NO RECORD SELECTED
EXIT.
ENDIF.
Read the selected entries**************
IF CHECK_BOX = 'X'.
CLEAR IT_PRES.
REFRESH IT_PRES.
read report WA_PROG-NAME into IT_PRES.
This concatenation helps in saving of the
***selected program into files
CONCATENATE 'D:\SAPNA\' COUNTER '.TXT' INTO SAPNA_FILE1.
**********Downloading data to PRESENTATION server****
call function 'GUI_DOWNLOAD'
exporting
filename = sapna_File1
tables
data_tab = IT_PRES[].
COUNTER = COUNTER + 1.
endif.
enddo.
*=======================================================
*======================================================
ELSE. " FOR APPLICATION SERVER
COUNTER = 1.
CHECK_BOX = SPACE. "CLEAR CHECKBOX
set pf-status 'CHECK' excluding 'DOWNLOAD'.
**
DO .
Read line sy-index field value check_box wa_prog.
IF SY-SUBRC <> 0. "IF NO RECORD SELECTED
EXIT.
ENDIF.
Read the selected entries**************
IF CHECK_BOX = 'X'.
CLEAR IT_PRES.
REFRESH IT_PRES.
read report WA_PROG-NAME into IT_PRES.
This concatenation helps in saving of the
***selected program into files
CONCATENATE '.\SAPNA11' COUNTER '.TXT' INTO SAPNA_FILE1.
CONCATENATE './' wa_prog-name INTO e_FILE.
OPEN DATASET e_FILE FOR OUTPUT IN TEXT MODE encoding default .
lOOP AT it_pres into wa_prog.
transfer wa_prog to e_file . "e_FILE.
If sy-subrc = 0.
message s009.
else.
message e010.
endif.
ENDLOOP.
close dataset e_FILE.
endif.
enddo.
exit.
ENDIF.
***********************************************
WHEN 'F-MODULE'.
**********************************************
ENDCASE.
endform. " ZF_USER_TASK
&----
*& Form ZF_TOP-OF-PAGE
&----
text
----
--> p1 text
<-- p2 text
----
form ZF_TOP-OF-PAGE .
endform. " ZF_TOP-OF-PAGE
This program will show how to download in Presnttn server as well as applctn server..
Do assign points for the same.
Regards,
S. agarwal
‎2007 Nov 28 6:45 AM
Hi ..
These are the statements to Create a new file on Application Server.
Eg:
Open Dataset .. "To open the file
Transfer .... "To send the variable data to file
Close dataset .. "To close the file
See the F1 help for Syntax on these commands.
‎2012 Jul 06 12:58 PM
I have used that statemnet but its not working...but anyways Thanks for your response...