09-25-2008 5:34 AM
Hi All,
I am working in Data Migration. In my requirement the extraction Programs say like Material extraction program should be run in background mode, and the downloaded file should be sits in the sharing folder via the Application server.
My BASIS people created a directory in AL11,
DIR_FPR with share folder path *
fpysrv12\SAP Ag Landscape\Private\Data Migration*
But when run my program for testing in foreground its not creating a file in the given path. Basically the file is sitting in DIR_HOME directory.
How to assign our own directory in datasets programs. Is it possible to create a file in share folder via the Application server concept?
Regards,
Anil.
09-25-2008 11:43 AM
hi use the
open dataset p_file for output in text mode encoding default .
if sy-subrc ne 0.
exit.
endif.
loop the data here...
close dataset p_file .
09-25-2008 11:34 AM
If you are using OPEN DATASET statements, then you could try defining logical paths & files using the FILE transaction code.
Use the FM FILE_GET_NAME to derive the actual file path by passing the logical path or file.
hope this helps
09-25-2008 11:40 AM
go through this...this is similar to your req.
report zpm306_prd_parts_energy_meter message-id zpm no standard page
heading.
tables:konp,makt,wb2_v_mkpf_mseg2.
type-pools:slis.
data:begin of st_ausp,
objek type ausp-objek,
atflv type ausp-atflv,
end of st_ausp.
data:begin of st_final,
atflv type ausp-atflv,
matnr_i(50) type c,
maktx type makt-maktx,
menge type p decimals 0,
end of st_final.
data:begin of st_prd,
matnr_i(50) type c,
bwart_i type wb2_v_mkpf_mseg2-bwart_i,
menge_i type wb2_v_mkpf_mseg2-menge_i,
end of st_prd.
data:wk_atinn type cabn-atinn.
data:wa_char type cabn-atnam.
data:pfile type string.
constants:co_localpath(30) type c value 'C:\METERID_REPORT\METERID.xls'.
*The folder name METERID is case sensitive..any change maded ...do
*reflect it in the folder name in the server
constants:co_remotepath(40) type c value '/METERID/meterid.xls'.
**********
constants:co_checked(1) type c value 'X'.
data:it_ausp like standard table of st_ausp initial size 0.
data:it_final like standard table of st_final initial size 0.
data:it_prd like standard table of st_prd initial size 0.
parameters:frath like mkpf-frath .
parameters:mblnr like mkpf-mblnr .
parameters:pa_char type cabn-atnam obligatory.
parameters:pa_plant type wb2_v_mkpf_mseg2-werks_i obligatory.
select-options:so_date for wb2_v_mkpf_mseg2-budat no-extension
obligatory,
so_cls for konp-bomat.
selection-screen skip 1.
selection-screen begin of line.
selection-screen comment 1(15) text-002 for field op_xl.
parameters:op_xl radiobutton group a user-command op1.
selection-screen comment 25(9) text-003 for field op_alv.
parameters:op_alv radiobutton group a default 'X'.
selection-screen end of line.
selection-screen skip 1.
parameters:so_def radiobutton group b default 'X' user-command op2.
parameters:so_loc radiobutton group b .
at selection-screen output.
if op_alv = co_checked.
loop at screen.
if screen-name = 'SO_DEF'.
screen-active = '0'.
endif.
if screen-name = 'SO_LOC'.
screen-active = '0'.
endif.
modify screen.
endloop.
endif.
start-of-selection.
*-Get internal charasteritic ID passing the charasteristic name
perform get_characteristic_id changing pa_char wk_atinn wa_char.
*--Get the details from the AUSP Table for the internal ID
perform do_ausp_fetch tables it_ausp using wk_atinn.
*--Get the production Data based on the parts respective to the ID
perform get_production_data tables it_ausp it_prd
using pa_plant
changing st_prd st_ausp.
*--Build Final Table
perform build_data_for_final_display tables it_ausp it_prd it_final
changing pfile.
sort it_final by atflv ascending.
clear pfile.
if op_alv = co_checked.
perform display_alv tables it_final.
elseif op_xl = co_checked.
if so_loc = co_checked.
pfile = co_localpath.
elseif so_def = co_checked.
pfile = co_remotepath.
endif.
perform download_excel_to_drive tables it_final using pfile.
check so_def = co_checked.
data:os type sxpgcolist-opsystem.
data:host type rfcdisplay-rfchost.
data:commandname type sxpgcolist-name.
data:exec_protocol type standard table of btcxpm.
os = sy-opsys.
host = sy-host.
commandname = 'ZSURESH'. "SAP Unix Command Name
call function 'SXPG_COMMAND_EXECUTE'
exporting
commandname = commandname
operatingsystem = os
targetsystem = host
stdout = 'X'
stderr = 'X'
terminationwait = 'X'
tables
exec_protocol = exec_protocol[].
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endif.
end-of-selection.
*&---------------------------------------------------------------------*
*& Form Display_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FIELDCAT text
* -->P_ALVFLD text
*----------------------------------------------------------------------*
form display_alv tables p_final structure st_final.
data:wk_layout type slis_layout_alv.
data:alvfld type slis_fieldcat_alv.
data:fieldcat like standard table of alvfld.
*--Bulid Specifications for ALV
wk_layout-colwidth_optimize = 'X'.
clear alvfld.
refresh fieldcat.
alvfld-fieldname = 'ATFLV'.
alvfld-seltext_m = text-006.
alvfld-exponent = '000'.
alvfld-decimals_out = '0'.
append alvfld to fieldcat.
alvfld-fieldname = 'MATNR_I'.
alvfld-seltext_m = text-007.
alvfld-exponent = '0'.
append alvfld to fieldcat.
alvfld-fieldname = 'MAKTX'.
alvfld-seltext_m = text-008.
alvfld-exponent = '0'.
append alvfld to fieldcat.
alvfld-fieldname = 'MENGE'.
alvfld-seltext_m = text-009.
alvfld-exponent = '0'.
append alvfld to fieldcat.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_grid_title = text-005
is_layout = wk_layout
it_fieldcat = fieldcat[]
tables
t_outtab = p_final[].
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " Display_ALV
*&---------------------------------------------------------------------*
*& Form download_Excel_to_C_drive
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_FINAL text
* -->P_IT_HEADING text
* <--P_PFILE text
* <--P_DATE text
*----------------------------------------------------------------------*
form download_excel_to_drive tables p_it_final structure st_final
using p_pfile type string.
if so_def ne co_checked.
data:begin of excel_heading,
text(20) type c,
end of excel_heading.
data:it_heading like standard table of excel_heading initial size 0.
*--Generate the heading for excel data
excel_heading-text = text-006.
append excel_heading to it_heading.
excel_heading-text = text-007.
append excel_heading to it_heading.
excel_heading-text = text-008.
append excel_heading to it_heading.
excel_heading-text = text-009.
append excel_heading to it_heading.
call function 'GUI_DOWNLOAD'
exporting
filename = p_pfile
filetype = 'DAT'
write_field_separator = '#'
header = '00'
trunc_trailing_blanks = 'X'
show_transfer_status = 'X'
tables
data_tab = p_it_final[]
fieldnames = it_heading[].
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
else.
**Download the file to application server.
data:wk_string(250) type c.
data:wk_menge(10) type c.
data:wk_out type p.
data:wk_atflv(50) type c.
open dataset p_pfile for output in text mode encoding default.
if sy-subrc <> 0.
write:'ERROR while opening dataset !!!!!!'.
endif.
concatenate text-006 text-007 text-008 text-009
into wk_string separated by cl_abap_char_utilities=>horizontal_tab.
transfer wk_string to p_pfile.
loop at p_it_final into st_final.
clear wk_out.
clear wk_menge.
clear wk_atflv.
wk_out = st_final-atflv.
wk_atflv = wk_out.
wk_menge = st_final-menge.
condense wk_menge.
condense wk_atflv.
concatenate wk_atflv st_final-matnr_i st_final-maktx wk_menge
into wk_string separated by
cl_abap_char_utilities=>horizontal_tab.
transfer wk_string to p_pfile.
endloop.
close dataset p_pfile.
endif.
endform. " download_Excel_to_C_drive
*&---------------------------------------------------------------------*
*& Form get_characteristic_ID
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_PA_CHAR text
* <--P_WK_ATINN text
*----------------------------------------------------------------------*
form get_characteristic_id changing p_pa_char type cabn-atnam
p_wk_atinn type cabn-atinn
pwa_char type cabn-atnam.
translate p_pa_char to upper case. "#EC TRANSLANG
call function 'CONVERSION_EXIT_ATINN_INPUT'
exporting
input = p_pa_char
importing
output = p_wk_atinn.
pwa_char = p_wk_atinn.
*--if the output is same to the input then there is no such number.
*--as per the functional module output
if pwa_char = pa_char.
message i838 with pa_char.
stop.
elseif pwa_char is initial.
message i838 with pa_char.
stop.
endif.
endform. " get_characteristic_ID
*&---------------------------------------------------------------------*
*& Form do_ausp_fetch
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_AUSP text
* -->P_WK_ATINN text
*----------------------------------------------------------------------*
form do_ausp_fetch tables p_it_ausp structure st_ausp
using p_wk_atinn type cabn-atinn.
select objek atflv into table p_it_ausp
from ausp client specified
where mandt = sy-mandt
and atinn = p_wk_atinn
and atflv in so_cls
and klart = '001'
and lkenz = space.
if sy-subrc <> 0.
message i839 with text-001.
stop.
endif.
endform. " do_ausp_fetch
*&---------------------------------------------------------------------*
*& Form get_production_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_AUSP text
* -->P_IT_PRD text
* <--P_ST_PRD text
* <--P_ST_AUSP text
*----------------------------------------------------------------------*
form get_production_data tables p_it_ausp structure st_ausp
p_it_prd structure st_prd
using p_plant type wb2_v_mkpf_mseg2-werks_i
changing p_st_prd like st_prd
p_st_ausp like st_ausp.
loop at p_it_ausp into p_st_ausp.
select matnr_i bwart_i menge_i into p_st_prd
from wb2_v_mkpf_mseg2 client specified
where mandt = sy-mandt
and budat in so_date
and werks_i = p_plant
and ( bwart_i = '131' or bwart_i = '132' )
and matnr_i = p_st_ausp-objek.
check sy-subrc = 0.
if p_st_prd-bwart_i = '132'.
p_st_prd-menge_i = p_st_prd-menge_i * -1.
endif.
clear p_st_prd-bwart_i.
collect p_st_prd into p_it_prd.
clear p_st_prd.
endselect.
endloop.
endform. " get_production_data
*&---------------------------------------------------------------------*
*& Form build_data_for_final_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_AUSP text
* -->P_IT_PRD text
* -->P_IT_FINAL text
* <--P_PFILE text
*----------------------------------------------------------------------*
form build_data_for_final_display tables p_it_ausp structure st_ausp
p_prd structure st_prd
p_final structure st_final
changing p_pfile type string.
sort p_it_ausp by objek ascending.
*Here P_pfile temporarly used to store material texts.
loop at p_it_ausp into st_ausp.
at new objek.
select maktx into p_pfile from makt
client specified where mandt = sy-mandt
and matnr = st_ausp-objek
and spras = sy-langu.
if sy-subrc <> 0.
clear p_pfile.
endif.
exit.
endselect.
read table p_prd into st_prd with key matnr_i = st_ausp-objek.
if sy-subrc <> 0.
clear st_prd.
endif.
endat.
st_final-atflv = st_ausp-atflv.
st_final-matnr_i = st_ausp-objek.
st_final-menge = st_prd-menge_i.
st_final-maktx = p_pfile.
append st_final to p_final.
clear st_final.
endloop.
endform. " build_data_for_final_display
09-25-2008 11:43 AM
hi use the
open dataset p_file for output in text mode encoding default .
if sy-subrc ne 0.
exit.
endif.
loop the data here...
close dataset p_file .