2007 Sep 24 11:57 AM
My requirement is to open and save a file..
For that i need the file dialog window for opening and saving
Which function module we can use this in R/3
My requirement is to open and save a file..
For that i need the file dialog window for opening and saving
Which function module we can use this in R/3
2007 Sep 24 12:08 PM
2007 Sep 24 12:12 PM
Hi
&----
*& Report Z_KAR_ASSIGN4_INTERFACE
*&
&----
*&
*&
&----
REPORT z_kar_assign4_interface.
********************************
Data declaration
*********************************
TABLES: cepc.
Structure
TYPES: BEGIN OF ty_cepc,
bukrs LIKE cepc-bukrs,
prctr LIKE cepc-prctr,
datbi LIKE cepc-datbi,
kokrs LIKE cepc-kokrs,
datab LIKE cepc-datab,
verak LIKE cepc-verak,
khinr LIKE cepc-khinr,
txjcd LIKE cepc-txjcd,
ktext LIKE cepct-ktext,
ltext LIKE cepct-ltext,
abtei LIKE cepc-abtei,
segment LIKE cepc-segment,
END OF ty_cepc.
Internal table & workarea
DATA: t_cepc TYPE STANDARD TABLE OF ty_cepc,
w_cepc TYPE ty_cepc.
*********************************
Selecton screen
*********************************
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE t1.
SELECT-OPTIONS s_prctr FOR cepc-prctr NO-EXTENSION .
SELECT-OPTIONS s_datbi FOR cepc-datbi NO-EXTENSION .
SELECT-OPTIONS s_kokrs FOR cepc-kokrs NO-EXTENSION .
SELECT-OPTIONS s_bukrs FOR cepc-bukrs NO-EXTENSION .
SELECT-OPTIONS s_khinr FOR cepc-khinr NO-EXTENSION .
SELECTION-SCREEN END OF BLOCK bl1.
SELECTION-SCREEN BEGIN OF BLOCK bl2 WITH FRAME TITLE t2.
PARAMETER: r_opt1 RADIOBUTTON GROUP gp1,
r_opt2 RADIOBUTTON GROUP gp1.
SELECTION-SCREEN END OF BLOCK bl2.
SELECTION-SCREEN BEGIN OF BLOCK bl3 WITH FRAME TITLE t3.
PARAMETER: p_prefil LIKE rlgrap-filename OBLIGATORY DEFAULT '.\kar1'.
SELECTION-SCREEN END OF BLOCK bl3.
*************************************
Initialization
*************************************
INITIALIZATION.
t1 = 'Selection parameters'.
t2 = 'Download type'.
t3 = 'File path'.
**************************************
Start of selection
**************************************
START-OF-SELECTION.
SELECT cepcbukrs cepcprctr cepcdatbi cepckokrs cepcdatab cepcverak cepckhinr cepctxjcd cepctktext cepctltext cepcabtei cepcsegment
INTO TABLE t_cepc
FROM cepc INNER JOIN cepct ON cepcprctr = cepctprctr
WHERE cepcprctr IN s_prctr AND cepcdatbi IN s_datbi AND cepckokrs IN s_kokrs AND cepcbukrs IN s_bukrs AND cepc~khinr IN s_khinr.
IF sy-subrc <> 0.
MESSAGE i000(z_kar_assign4).
No records found
ENDIF.
test output
LOOP AT t_cepc INTO w_cepc.
WRITE:/ w_cepc-bukrs, w_cepc-prctr, w_cepc-datbi, w_cepc-kokrs, w_cepc-datab, w_cepc-verak, w_cepc-khinr, w_cepc-txjcd, w_cepc-ktext, w_cepc-ltext, w_cepc-abtei, w_cepc-segment.
ENDLOOP.
********************************************
At selection screen
********************************************
AT SELECTION-SCREEN ON s_prctr.
SELECT SINGLE prctr INTO cepc-prctr FROM cepc WHERE prctr IN s_prctr.
IF sy-subrc <> 0.
MESSAGE e004(z_kar_assign4).
Invalid profit center
ENDIF.
AT SELECTION-SCREEN ON s_datbi.
SELECT SINGLE datbi INTO cepc-datbi FROM cepc WHERE datbi IN s_datbi.
IF sy-subrc <> 0.
MESSAGE e005(z_kar_assign4).
Invalid date
ENDIF.
AT SELECTION-SCREEN ON s_kokrs.
SELECT SINGLE kokrs INTO cepc-kokrs FROM tka01 WHERE kokrs IN s_kokrs.
IF sy-subrc <> 0.
MESSAGE e006(z_kar_assign4).
Invalid controlling area
ENDIF.
AT SELECTION-SCREEN ON s_bukrs.
SELECT SINGLE bukrs INTO cepc-bukrs FROM t001 WHERE bukrs IN s_bukrs.
IF sy-subrc <> 0.
MESSAGE e008(z_kar_assign4).
Invalid Company code
ENDIF.
AT SELECTION-SCREEN ON s_khinr.
SELECT SINGLE khinr INTO cepc-khinr FROM cepc WHERE khinr IN s_khinr.
IF sy-subrc <> 0.
MESSAGE e007(z_kar_assign4).
Invalid profit center area
ENDIF.
*AT SELECTION-SCREEN.
SELECT cepcbukrs cepcprctr cepcdatbi cepckokrs cepcdatab cepcverak cepckhinr cepctxjcd cepctktext cepctltext cepcabtei cepcsegment
INTO TABLE t_cepc
FROM cepc INNER JOIN cepct ON cepcprctr = cepctprctr
WHERE cepcprctr IN s_prctr AND cepcdatbi IN s_datbi AND cepckokrs IN s_kokrs AND cepcbukrs IN s_bukrs AND cepc~khinr IN s_khinr.
IF sy-subrc <> 0.
MESSAGE e000(z_kar_assign4).
No records found
*
ENDIF.
*************************************
End of selection
*************************************
END-OF-SELECTION.
IF r_opt1 = 'X'.
PERFORM do_app_download.
ELSEIF r_opt2 = 'X'.
PERFORM do_pre_download.
ENDIF.
******************************
subroutines
******************************
&----
*& Form do_app_download
&----
text
----
--> p1 text
<-- p2 text
----
FORM do_app_download .
Open file for writing
*----
OPEN DATASET p_prefil FOR OUTPUT IN TEXT MODE ENCODING DEFAULT
WITH SMART LINEFEED.
IF sy-subrc <> 0.
MESSAGE e001(z_kar_assign4).
File could not be opened for output
ELSE.
LOOP AT t_cepc INTO w_cepc.
TRANSFER w_cepc TO p_prefil.
IF sy-subrc <> 0.
MESSAGE e009(z_kar_assign4).
Error occured when writing into file
ENDIF.
ENDLOOP.
ENDIF.
Check if contents are written to the file
*----
*Close file
*----
CLOSE DATASET p_prefil.
IF sy-subrc <> 0.
MESSAGE e003(z_kar_assign4).
File could not be closed
ENDIF.
ENDFORM. " do_app_download
&----
*& Form do_pre_download
&----
text
----
--> p1 text
<-- p2 text
----
FORM do_pre_download .
DATA: fn TYPE string.
fn = p_prefil.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = fn
filetype = 'ASC'
TABLES
data_tab = t_cepc[]
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
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. " do_pre_download
Hope this is useful.
Regards,
Karen
<b><REMOVED BY MODERATOR></b>
Message was edited by:
Alvaro Tejada Galindo
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |