‎2007 Oct 08 4:11 PM
Hi gurus,
I have a condition where I need to upload the file to my program, the file may either come from the system or from the application server, so basically I need to ask user from which way it is coming and then if the user entered that its coming from the computer then I need to ask him the location of the file and same as in the case if user selects applications server,
So far what I know is that first we need to use the radio buttons to ask the user to select either of the option and then as per his selection we need him to enter the file location. For this I tried the below code and this code allows me to select either of the option and now I have two more concerns, as soon as I select the radio button which says that file is coming from the server I should ask the user to enter the file location. I believe this could achieve by using CALL FUNCTION 'F4_FILENAME' and once he selected the file location then I need to upload that file using the function module WS_UPLOAD, so can you please tell me how to get this thing done.
REPORT Z_TEST1 .
*--- Radiobuttons
PARAMETERS: p_up RADIOBUTTON GROUP a DEFAULT 'X' USER-COMMAND rb,
p_list RADIOBUTTON GROUP a.
PARAMETERS: p_pcfile LIKE rlgrap-filename OBLIGATORY
MODIF ID ccc.
Parameters: p_unix LIKE rlgrap-filename OBLIGATORY DEFAULT '.\'
MODIF ID ddd.
*----
AT SELECTION-SCREEN
*----
AT SELECTION-SCREEN OUTPUT.
IF p_up = 'X' .
LOOP AT SCREEN.
CASE screen-group1.
WHEN 'CCC'.
screen-input = 1. "Enable
screen-invisible = 0. "Disable
MODIFY SCREEN.
WHEN 'DDD'.
screen-input = 0.
screen-invisible = 1.
MODIFY SCREEN.
ENDCASE.
CALL FUNCTION 'F4_FILENAME' "allows user to select path/file
EXPORTING
program_name = 'ZMMINT_PO_CONVERSION'
dynpro_number = syst-dynnr
field_name = 'p_up'
IMPORTING
file_name = p_up.
ENDLOOP.
ENDIF.
IF p_list = 'X'.
LOOP AT SCREEN.
CASE screen-group1.
WHEN 'CCC'.
screen-input = 0.
screen-invisible = 1.
MODIFY SCREEN.
WHEN 'DDD'.
screen-input = 1.
screen-invisible = 0.
MODIFY SCREEN.
ENDCASE.
ENDLOOP.
ENDIF.
Thanks in advance
Rajeev Gupta
Message was edited by:
Rajeev Gupta
‎2007 Oct 08 4:23 PM
Hi,
Ur code is fine.
use
at selection-screen on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
start of selection.
if presentaion server is selected.
GUI_UPLOAD.
How ever u cant do F4 for app server. For that you can default the values for the parameters in initialisation event as below
initialisation.
p_file = 'SAP\USR\test.txt'
‎2007 Oct 08 4:16 PM
To upload file from presentation server, here is the code -
parameters: p_file type localfile.
at selection-screen on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
exporting
static = 'X'
changing
file_name = p_file.
start-of-selection.
file_str = p_file.
call function 'GUI_UPLOAD'
exporting
filename = file_str
tables
data_tab = itab
exceptions
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
others = 17.
To upload file from application server, here is the code -
REPORT zuploadtab .
PARAMETERS: p_infile LIKE rlgrap-filename
OBLIGATORY DEFAULT /usr/sap/..
DATA: ld_file LIKE rlgrap-filename.
*Internal tabe to store upload data
TYPES: BEGIN OF t_record,
name1 like pa0002-VORNA,
name2 like pa0002-name2,
age type i,
END OF t_record.
DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,
wa_record TYPE t_record.
*Text version of data table
TYPES: begin of t_uploadtxt,
name1(10) type c,
name2(15) type c,
age(5) type c,
end of t_uploadtxt.
DATA: wa_uploadtxt TYPE t_uploadtxt.
*String value to data in initially.
DATA: wa_string(255) type c.
constants: con_tab TYPE x VALUE 09′.
*START-OF-SELECTION
START-OF-SELECTION.
ld_file = p_infile.
OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
ELSE.
DO.
CLEAR: wa_string, wa_uploadtxt.
READ DATASET ld_file INTO wa_string.
IF sy-subrc NE 0.
EXIT.
ELSE.
SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1
wa_uploadtxt-name2
wa_uploadtxt-age.
MOVE-CORRESPONDING wa_uploadtxt TO wa_upload.
APPEND wa_upload TO it_record.
ENDIF.
ENDDO.
CLOSE DATASET ld_file.
ENDIF.
You need to change your internal table structure as per your file format.
You also need to combine these code samples as per your requirement in your program.
Hope this helps.
ashish
‎2007 Oct 08 4:23 PM
Hi,
Ur code is fine.
use
at selection-screen on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
start of selection.
if presentaion server is selected.
GUI_UPLOAD.
How ever u cant do F4 for app server. For that you can default the values for the parameters in initialisation event as below
initialisation.
p_file = 'SAP\USR\test.txt'
‎2007 Oct 08 4:29 PM
Hey sreejith , first of all thanks for the reply,
Well as of now I have written the following code:
REPORT Z_TEST1 .
*--- Radiobuttons
PARAMETERS: p_up RADIOBUTTON GROUP a DEFAULT 'X' USER-COMMAND rb,
p_list RADIOBUTTON GROUP a.
PARAMETERS: p_pcfile LIKE rlgrap-filename OBLIGATORY
MODIF ID CCC.
Parameters: p_unix LIKE rlgrap-filename OBLIGATORY DEFAULT '.\tmp'
MODIF ID DDD.
*----
AT SELECTION-SCREEN
*----
AT SELECTION-SCREEN OUTPUT.
IF p_up = 'X' .
LOOP AT SCREEN.
CASE screen-group1.
WHEN 'CCC'.
screen-input = 1. "Enable
screen-invisible = 0. "Disable
MODIFY SCREEN.
WHEN 'DDD'.
screen-input = 0.
screen-invisible = 1.
MODIFY SCREEN.
ENDCASE.
ENDLOOP.
CALL FUNCTION 'F4_FILENAME' "allows user to select path/file
EXPORTING
program_name = 'Z_TEST1'
dynpro_number = syst-dynnr
field_name = 'p_pcfile'
IMPORTING
file_name = p_pcfile.
ENDIF.
IF p_list = 'X'.
LOOP AT SCREEN.
CASE screen-group1.
WHEN 'CCC'.
screen-input = 0.
screen-invisible = 1.
MODIFY SCREEN.
WHEN 'DDD'.
screen-input = 1.
screen-invisible = 0.
MODIFY SCREEN.
ENDCASE.
ENDLOOP.
Now whats going on is as soon as I run my program it asks the user to enter the location of the file, although as per the logic once user selected that the file is cioming from system using radio button then only it should ask for the file location. Moreover I will really appreciate your efforts if you can just help me out how to upload the file using ws-upload/gui-upload oncer enters the file location in detail.
Thanks
Rajeev Gupta
Message was edited by:
Rajeev Gupta
‎2007 Oct 08 4:33 PM
Put this code in a separate event -
At selection-screen on value-request for p_pcfile.
CALL FUNCTION 'F4_FILENAME' "allows user to select path/file
EXPORTING
program_name = 'Z_TEST1'
dynpro_number = syst-dynnr
field_name = 'p_pcfile'
IMPORTING
file_name = p_pcfile.
ashish
‎2007 Oct 08 4:39 PM
Hey thanks a lot aashish, that problem is resolved now and the only problem that is left is that once user enters the file location then I need to use the gui-upload function module, so how to chieve this. I mean if user selects the file from the system then I need to use gui_upload and if user enters the file from the application server then I need to use Open data set and Read data set.
Thanks
Rajeev Gupta
‎2007 Oct 08 4:41 PM
I have already given sample code in my earlier answers. Please alter the same as per your requirement. You need to pass correct internal table (as your file structure will be different).
Hope this helps.
ashish