2007 Oct 25 12:20 PM
Hi
For uploading data in SAP i am aware of call transaction and sessions method.
i want to know how is Open data set and close data set used, as far as i know it is for fetching data from application server and presentation server.
we use transaction codes in session method and call tranaction method to upload data into a particular transaction.
do we use tcode in open data set and close data set or the data is directly loaded into corrosponding tables. pl clarify.
Also pl send me sample code for simple txn like mm01.
thanks
Quavi.
2007 Oct 25 12:25 PM
hi
Refer this simple exaple
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3ca6358411d1829f0000e829fbfe/content.htm.
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3d42358411d1829f0000e829fbfe/content.htm
Reward if useful
Regards
Raghav
2007 Oct 25 12:26 PM
Hii..
Check this ..
Example:
This is the Simple way you can download the ITAB with Tab delimiter:
DATA : V_REC(200).
OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT ITAB INTO WA.
Concatenate WA-FIELD1 WA-FIELD2
INTO V_REC
SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
TRANSFER V_REC TO P_FILE.
ENDLOOP.
CLOSE DATASET P_FILE.
Note: if there are any Numeric fields ( Type I, P, F) In your ITAB then before CONCATENATE you have to Move them to Char fields ..
Example:
DATA: V_RECORD(200).
OPEN DATASET P_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
DO.
READ DATASET P_FILE INTO V_RECORD.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
SPLIT V_Record at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
INTO WA-FIELD1 WA-FIELD2.
APPEND WA TO ITAB.
ENDDO.
<b>reward if Helpful.</b>
2007 Oct 25 12:52 PM
Hi,
ABAP/4 provides the following statements for handling files on the application server
<b> OPEN DATASET
CLOSE DATASET
DELETE DATASET
READ DATASET
TRANSFER</b>
To open a sequential file on the application server, use the <b>OPEN DATASET <file name> [options]</b> statement .
Use the <b>FOR</b> options to specify the access mode:
<b>FOR INPUT</b> (default) opens an existing file for reading.
<b>FOR OUTPUT</b> opens a file for writing. If the file does not exist, it is created. If the file already exists, its contents are deleted.
<b>FOR APPENDING</b> opens a file for writing. If the file does not exist, it is created. If the file already exists, the system goes to the end of the file to add to it.
Use the<b> IN</b> options to specify the structure of the file:
<b>IN BINARY MODE</b> (default) indicates that the file is not structured in lines (i.e., it is set up byte-by-byte).
<b>IN TEXT MODE</b> indicates that the file is structured in lines.
If you use the <b>MESSAGE <field></b> addition, a system message issued when opening the file will be placed in the character-type <field>.
The <b>AT POSITION <position></b> addition opens the file at a specific <position>, indicated in bytes from the beginning of the file.
To read a sequential file on the application server, use the <b>READ DATASET</b> statement. The basic syntax of this statement is:
<b>READ DATASET <file name> INTO <structure>.</b>
To write to a sequential file on the application server, use the <b>TRANSFER</b> statement. The basic syntax of this statement is:
<b>TRANSFER <structure> TO <file name>.</b>
To close a sequential file on the application server, use the <b>CLOSE DATASET</b> statement. The basic syntax of this statement is:
CLOSE DATASET <file name>.
To delete a sequential file on the application server, use the <b>DELETE DATASET</b> statement. The basic syntax of this statement is:
<b>DELETE DATASET <file name>.</b>
Sample Code:
REPORT Y180DM02.
TABLES: KNA1.
PARAMETERS:
OUTFILE(20) DEFAULT /tmp/bc180_file1
LOWER CASE,
STATE LIKE KNA1-REGIO DEFAULT MA.
DATA: BEGIN OF OUTREC,
KUNNR LIKE KNA1-KUNNR,
REGIO LIKE KNA1-REGIO,
TELF1 LIKE KNA1-TELF1,
END OF OUTREC.
OPEN DATASET OUTFILE FOR OUTPUT IN TEXT MODE.
SELECT * FROM KNA1 WHERE REGIO = STATE.
MOVE-CORRESPONDING KNA1 TO OUTREC.
TRANSFER OUTREC TO OUTFILE.
ENDSELECT.
CLOSE DATASET OUTFILE.
In the example above, we are creating a file with customer information. Specifically, we are transferring the customer number, state, and telephone number (for all customers in a particular state) from the KNA1 table to the /tmp/bc180_file1 file on the application server.
Reward points for useful answers
2007 Oct 25 1:29 PM
i think u have some confusion with this...see by using this statement u can put data in or read data from application server...
then pur this data in internal tables and then using that data u use BDC or BAPI whatever u want..
regards..