12-15-2006 12:59 PM
Dear gurus,
I want to write a bapi such that
i have to take some datas from Mara table
and convert this as .CSV file anf write it into
the application server ( it is located in differnt place)
can i have the code for this??
thanx in advance
senthil
12-18-2006 9:13 AM
Hello Senthil,
What is the sy-subrc when u execute OPEN stmt? I think it must be non zero and this is because the path which u are specifing would be wrong.
12-15-2006 1:19 PM
12-15-2006 2:36 PM
U can write a BAPI in which u can include the select code to fetch data from MARA.
The internal table data can be either sent to Application server or presentation server...If sending to presentation server u can convert to .CSV and use GUI_DOWNLOAD...but if u want to send data to Application server u have to use...Open Dataset....Transfer Dataset....Close Dataset.
12-18-2006 7:17 AM
12-18-2006 7:26 AM
Hi Senthil,
Please refer the following link to download a file to the application server using OPEN DATASET..TRANSFER..CLOSE DATASET.
<a href="http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3c8c358411d1829f0000e829fbfe/frameset.htm">http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3c8c358411d1829f0000e829fbfe/frameset.htm</a>
Regards,
Chetan.
PS: Reward points if this helps.
12-18-2006 7:38 AM
try to like this to send data to application server
tables mara.
data:begin of itab occurs 0,
matnr like mara-matnr,
mtart like mara-mtart,
matkl like mara-matkl,
end of itab.
data:file(200) type c value 'c:/ (give here applicationserer name)'.
select matnr
mtart
matkl
from mara
into table itab
where matnr = mara-matnr.
open dataset file for output in binary mode or text mode.
loop at itab.
transfer itab to file.
endloop.
close dataset file.
if it helpful kindly reward me.
regards,
ravi
12-18-2006 8:12 AM
hi thanks for the reply
when i am executing the code
TABLES mara.
DATA:BEGIN OF itab OCCURS 0,
matnr LIKE mara-matnr,
mtart LIKE mara-mtart,
matkl LIKE mara-matkl,
END OF itab.
DATA:file(200) TYPE c VALUE 'c:/XXX/'.
IF sy-subrc EQ 0.
SELECT matnr mtart matkl
FROM mara INTO TABLE itab
WHERE matnr = matnr.
ELSE.
ENDIF.
OPEN DATASET file FOR OUTPUT IN BINARY MODE .
LOOP AT itab.
TRANSFER itab TO file.
ENDLOOP.
CLOSE DATASET file.
it says
The file "c:/XXX/" has not been opened.
and throws a short dump
what could be the problem
senthil
12-18-2006 8:31 AM
hi senthil,
the file name u r giving may be wrong..pls go to transaction AL11 and it wil give u directories list and u can choose any appropriate directory and then open ur file from tht particular directory for e.g -
'/usr/local/sapdata/amit.dat' ,where /usr/local/sapdata/ is the directory which exists in AL11 and amit.dat is the file name ,hence pls change the file name u have given as per the directories which u see in Al11..ex code -
parameters: P_DSNI(75) TYPE C DEFAULT
'/usr/local/sapdata/amit.dat' LOWER CASE.
data: begin of itab occurs 0,
pernr(8),
sp1(1) value ',',
werks(4),
sp2(1) value ',',
persg(1),
sp3(1) value ',',
persk(2),
end of itab.
OPEN DATASET P_DSNI FOR OUTPUT IN LEGACY TEXT MODE.
PERFORM FETCH_DATA.
&----
*& Form FETCH_DATA
&----
text
----
--> p1 text
<-- p2 text
----
FORM FETCH_DATA .
SELECT * FROM PA0001 WHERE PERNR IN S_PERNR.
MOVE-CORRESPONDING PA0001 TO ITAB.
TRANSFER ITAB TO P_DSNI.
APPEND ITAB.
ENDSELECT.
CLOSE DATASET P_DSNI.
ENDFORM.
hope this helps..
pls reward poitns if helpful
12-18-2006 9:06 AM
12-18-2006 9:13 AM
Hello Senthil,
What is the sy-subrc when u execute OPEN stmt? I think it must be non zero and this is because the path which u are specifing would be wrong.
12-18-2006 9:17 AM
Sy-subrc is non-zero only
what else i have do changes for that
senthil
12-18-2006 9:29 AM
just confrm the directory from al11 thts it..ur directory seems to be wrong and also check if u have access to transaction AL11 or not,it can also be the cause of error..can u try out any directory which u see in AL11 and then specify filename..it shud work..
12-18-2006 9:31 AM
Hello Senthil,
It is clear then that the directory which u have specified is not available. What is the path u are giving? Check in AL11 if that dir exists.
12-18-2006 10:07 AM