‎2008 Jul 30 6:40 AM
hi
lets suppose i have 3000 records in internal table and now there is requirement, to create files on application server first with 1000 records then another 1000 and rest 1000 records, with a single execution of the program.
pls tell me how i write to this logic in abap program.
‎2008 Jul 30 6:43 AM
try it like this:
open dataset w_fname3 for output in text mode encoding default.
open dataset w_fname2 for output in text mode encoding default.
open dataset w_fname1 for output in text mode encoding default.
loop at itab into wa.
if sy-tabix LE 1000.
transfer wa to w_fname1.
elseif sy-tabix GT 1000 and sy-tabix LE 2000.
transfer wa to w_fname2.
elseif sy-tabix GT 2000 and sy-tabix LE 3000.
transfer wa to w_fname3.
endif.
endloop.
close dataset w_fname1.
close dataset w_fname2.
close dataset w_fname3.With luck,
Pritam.
‎2008 Jul 30 6:46 AM
Hi,
Use Data sets to upload / download the data into application server.......
Basic Form of the OPEN DATASET Statement
To open a file on the application server, use the OPEN statement as follows:
Syntax
OPEN DATASET <dsn> [Additions].
This statement opens the file <dsn>. If you do not specify any additions for the mode, the file is opened in binary mode for reading. SY-SUBRC returns 0 if the system opens the file. Otherwise, SY-SUBRC is set to 8.
You enter the filename <dsn> either as a literal or as a field containing the actual name of the file. If you do not specify a path, the system opens the file in the directory in which the R/3 System is running on the application server. To open a file, the user under which the R/3 System is running must have the requisite authorizations at operating system level.
Filenames are platform-specific. You must therefore use file- and pathnames that conform to the rules of the operating system under which your R/3 System is running. However, you can also use logical filenames to ensure that your programs are not operating system-specific. For further information, refer to Using Platform-Independent Filenames.
DATA FNAME(60).
FNAME = '/tmp/myfile'.
OPEN DATASET 'myfile'.
OPEN DATASET FNAME.
This example works as long as your R/3 System is running under UNIX. The program opens the file "myfile" in the directory in which the R/3 System is running, and also opens the file "myfile" in directory "/tmp". However, you would have to change the filename for other operating systems. For example, for OpenVMS, you could write the following:
FNAME = '[TMP]myfile.BIN'
OPEN DATASET 'myfile.BIN'.
Reward Points if useful
Raghunath.S
9986076729
‎2008 Jul 30 6:47 AM
Hi,
Here is a code to create file on application server..
REPORT ZDOWNLOAD_APPL_DEMO.TYPES : BEGIN OF ST_DEMO,
REG_NO(10) TYPE C,
NAME(20) TYPE C,
ADDR(20) TYPE C,
END OF ST_DEMO.DATA : WA_DEMO TYPE ST_DEMO,
IT_DEMO TYPE TABLE OF ST_DEMO,
L_FNAME TYPE STRING .PARAMETERS: P_FNAME(128) TYPE C DEFAULT '\usr\sap\SRI\SYS\src\DOWN.TXT' OBLIGATORY.
L_FNAME = P_FNAME.
WA_DEMO-REG_NO = '100001'.
WA_DEMO-NAME = 'ANAND'.
WA_DEMO-ADDR = 'NAGARKOVIL'.
APPEND WA_DEMO TO IT_DEMO.WA_DEMO-REG_NO = '100002'.
WA_DEMO-NAME = 'VIKRAM'.
WA_DEMO-ADDR = 'CHENNAI'.
APPEND WA_DEMO TO IT_DEMO. OPEN DATASET L_FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
WRITE :5 'REG NUM',16 'NAME',37 'ADDRESS' .
LOOP AT IT_DEMO INTO WA_DEMO.
IF SY-SUBRC = 0.
TRANSFER WA_DEMO TO L_FNAME.
WRITE :/5 WA_DEMO-REG_NO,16 WA_DEMO-NAME,37 WA_DEMO-ADDR.
ENDIF.
ENDLOOP.
I hope u may get some help from this ..
Thanks & Regards
Ashu Singh
‎2008 Jul 30 6:52 AM
Hii!
Check out this sample code
REPORT z_sdn.
DATA: fname(40),
w_line TYPE i,
w_idx TYPE i VALUE 1.
DATA:
BEGIN OF fs_flight,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
END OF fs_flight.
DATA:
t_flight LIKE
TABLE OF
fs_flight.
DATA:
t_flight1 LIKE
TABLE OF
fs_flight.
SELECT-OPTIONS:
s_carrid FOR fs_flight-carrid,
s_connid FOR fs_flight-connid.
fname = '.\ztest46.csv'.
PERFORM get_flight_data.
OPEN DATASET fname FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
DESCRIBE TABLE t_flight LINES w_line.
DO 10 TIMES.
READ TABLE t_flight INDEX w_idx INTO fs_flight.
TRANSFER fs_flight TO fname.
ENDDO.
IF sy-subrc EQ 0.
WRITE: 'File Opened On Apps Server'.
ELSE.
WRITE: 'File could not be opened'.
ENDIF.
CLOSE DATASET fname.
w_idx = w_idx + 1.
OPEN DATASET fname FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
DESCRIBE TABLE t_flight LINES w_line.
DO 10 TIMES.
READ TABLE t_flight INDEX w_idx INTO fs_flight.
TRANSFER fs_flight TO fname.
ENDDO.
CLOSE DATASET fname.
*&---------------------------------------------------------------------*
*& Form get_flight_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_flight_data .
SELECT carrid
connid
fldate
FROM sflight
INTO TABLE t_flight
WHERE carrid IN s_carrid
AND connid IN s_connid.
ENDFORM. " get_flight_data
Regards
Abhijeet
‎2008 Jul 30 6:54 AM
Hi,
CONCATENATE
w_phy_path_tx " Physical path
c_error " file type
c_sep " seperator
wa_dir_list-name "directory name
INTO
w_error_tx. " file name in application server
REPLACE c_ext_txt IN w_error_tx WITH c_extn.
CONDENSE w_error_tx.
Open error file to write error info
OPEN DATASET w_error_tx FOR OUTPUT IN TEXT MODE ENCODING DEFAULT
IGNORING CONVERSION ERRORS .
IF sy-subrc = 0.
LOOP AT t_error INTO wa_error.
Get the legacy compaign code
READ TABLE t_zfa_map INTO wa_zfa_map WITH KEY
fanum = wa_error-fanum
BINARY SEARCH.
IF sy-subrc = 0.
wa_error-fanum = wa_zfa_map-altfa.
TRANSFER wa_error TO w_error_tx.
CLEAR: wa_error, wa_zfa_map.
ENDIF.
ENDLOOP.
ENDIF.
CLOSE DATASET w_error_tx.
IF sy-subrc <> 0.
MESSAGE i055 INTO w_message_tx. " 'File could not be closed !'.
PERFORM sub_write_audit_log USING w_message_tx
w_error_tx
space.
CLEAR : w_message_tx.
LEAVE LIST-PROCESSING.
ENDIF.
Populate 3000 records into 3 different internal tables.
and create 3 different files in applicatipn server.
‎2008 Jul 30 6:57 AM
‎2008 Jul 30 7:03 AM
Hi Vipin,
The Class 'CL_RSAN_UT_APPSERV_FILE_WRITER' have the method 'APPSERVER_FILE_WRITE' to write the data to Application server.
For your requirement,
1. Get the App server path,
2. Loop the Main internal table
3. build the internal table to send to file in App server if the record reached 1000 the call the method which is mentioned above.
4. repeat the above steps for 2000,3000 etc....
type: ty_str type string.
data: it_str type standard table of ty_str,
wa_str type ty_str,
l_str type string.
Loop it_final into wa_final.
concatenate wa_final-f1 wa_final-f2 into l_str.
wa_str = l_str.
append wa_str into it_str.
clear wa_str.
if sy-tabix = 1000.
call method CL_RSAN_UT_APPSERV_FILE_WRITER=>APPSERVER_FILE_WRITE
exporting
I_FILENAME = l_file_path_name " Filename with App Path
I_DATA_TAB = it_str.
refresh it_str.
endif.
Regards,
Boobalan S