03-14-2007 6:33 AM
Hi i have been asked to upload data from excel sheet to MEK1.The excel sheet may be present on the presentation server or application server.it also has to an option for test mode.it also has to have capture the error that may occur from reading the file at the location specified or if filename is incorrect or empty.
can u guys please help me in this!!!
03-14-2007 6:36 AM
Hi,
See the sample code and do accordingly:
report ZSDBDCP_PRICING no standard page heading
line-size 255.
----
Includes
----
include zbdcrecx1.
----
Internal Tables
----
*--Internal Table To hold condition records data from flat file.
Data: begin of it_pricing occurs 0,
key(4),
f1(4),
f2(4),
f3(2),
f4(18),
f5(16),
end of it_pricing.
*--Internal Table To hold condition records header .
data : begin of it_header occurs 0,
key(4),
f1(4),
f2(4),
f3(2),
end of it_header.
*--Internal Table To hold condition records details .
data : begin of it_details occurs 0,
key(4),
f4(18),
f5(16),
end of it_details.
data : v_sno(2),
v_rows type i,
v_fname(40).
start-of-selection.
refresh : it_pricing,it_header,it_details.
clear : it_pricing,it_header,it_details.
CALL FUNCTION 'UPLOAD'
EXPORTING
FILENAME = 'C:\WINDOWS\Desktop\pricing.txt'
FILETYPE = 'DAT'
TABLES
DATA_TAB = it_pricing
EXCEPTIONS
CONVERSION_ERROR = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3
NO_BATCH = 4
UNKNOWN_ERROR = 5
GUI_REFUSE_FILETRANSFER = 6
OTHERS = 7.
WRITE : / 'Condition Records ', P_FNAME, ' on ', SY-DATUM.
OPEN DATASET P_FNAME FOR INPUT IN TEXT MODE.
if sy-subrc ne 0.
write : / 'File could not be uploaded.. Check file name.'.
stop.
endif.
CLEAR : it_pricing[], it_pricing.
DO.
READ DATASET P_FNAME INTO V_STR.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
write v_str.
translate v_str using '#/'.
SPLIT V_STR AT ',' INTO it_pricing-key
it_pricing-F1 it_pricing-F2 it_pricing-F3
it_pricing-F4 it_pricing-F5 .
APPEND it_pricing.
CLEAR it_pricing.
ENDDO.
IF it_pricing[] IS INITIAL.
WRITE : / 'No data found to upload'.
STOP.
ENDIF.
loop at it_pricing.
At new key.
read table it_pricing index sy-tabix.
move-corresponding it_pricing to it_header.
append it_header.
clear it_header.
endat.
move-corresponding it_pricing to it_details.
append it_details.
clear it_details.
endloop.
perform open_group.
v_rows = sy-srows - 8.
loop at it_header.
perform bdc_dynpro using 'SAPMV13A' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RV13A-KSCHL'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RV13A-KSCHL'
it_header-f1.
perform bdc_dynpro using 'SAPMV13A' '1004'.
perform bdc_field using 'BDC_CURSOR'
'KONP-KBETR(01)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'KOMG-VKORG'
it_header-f2.
perform bdc_field using 'KOMG-VTWEG'
it_header-f3.
**Table Control
v_sno = 0.
loop at it_details where key eq it_header-key.
v_sno = v_sno + 1.
clear v_fname.
CONCATENATE 'KOMG-MATNR(' V_SNO ')' INTO V_FNAME.
perform bdc_field using v_fname
it_details-f4.
clear v_fname.
CONCATENATE 'KONP-KBETR(' V_SNO ')' INTO V_FNAME.
perform bdc_field using v_fname
it_details-f5.
if v_sno eq v_rows.
v_sno = 0.
perform bdc_dynpro using 'SAPMV13A' '1004'.
perform bdc_field using 'BDC_OKCODE'
'=P+'.
perform bdc_dynpro using 'SAPMV13A' '1004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
endif.
endloop.
*--Save
perform bdc_dynpro using 'SAPMV13A' '1004'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_transaction using 'VK11'.
endloop.
perform close_group.
Reward if useful.
Regards,
Anji
03-14-2007 6:40 AM
hi Sushant
Please try with this type of selection screen
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_logfp TYPE filename-fileintern
DEFAULT c_lfn MODIF ID app , " Logical file Path
p_appfl TYPE filename-fileextern
MODIF ID app, " Application File Name
p_prefl TYPE rlgrap-filename
MODIF ID pre. " Presentation File Name
SELECTION-SCREEN : END OF BLOCK b1.
SELECTION-SCREEN : BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS : p_appser RADIOBUTTON GROUP grp
DEFAULT 'X' USER-COMMAND rad1, " Application server
p_preser RADIOBUTTON GROUP grp. " Presentation Server
SELECTION-SCREEN : END OF BLOCK b2.
SELECTION-SCREEN : BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
PARAMETERS : p_pfname LIKE ibipparms-path . "Error file Path
SELECTION-SCREEN : END OF BLOCK b3.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_prefl.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = p_prefl.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_pfname.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = p_pfname.
AT SELECTION-SCREEN.
IF sy-ucomm NE c_rad1.
This subroutine is used for validation of the selection screen entries
IF p_appser EQ c_x.
IF NOT p_appfl IS INITIAL.
*This subroutine generate the physical path using FILE_GET_NAME function
*module.
PERFORM physical_file.
ELSE.
*Input File Name on Application server is mandatory.
MESSAGE e009 WITH p_appfl.
ENDIF.
ENDIF.
IF p_preser = c_x.
IF p_prefl IS INITIAL .
*File Name on Presentation server is mandatory
MESSAGE e009 WITH p_prefl.
ELSE.
MOVE p_prefl TO v_flname.
ENDIF.
IF p_pfname IS INITIAL.
MESSAGE e046.
ENDIF.
ENDIF.
AT SELECTION-SCREEN OUTPUT .
CONSTANTS: lc_app(3) TYPE c VALUE 'APP', "Modif ID STO
lc_pre(3) TYPE c VALUE 'PRE', "Modif ID MAT
lc_1(1) TYPE c VALUE '1', "Flag = 1
lc_0(1) TYPE c VALUE '0'. "Flag = 0
IF p_appser = c_x.
LOOP AT SCREEN.
IF screen-group1 = lc_app.
screen-input = lc_1.
MODIFY SCREEN.
ELSEIF screen-group1 = lc_pre.
screen-input = lc_0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ELSE.
LOOP AT SCREEN.
IF screen-group1 = lc_pre.
screen-input = lc_1.
MODIFY SCREEN.
ELSEIF screen-group1 = lc_app.
screen-input = lc_0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
Its very helful for u
Reward all the helpful answers..
With Regards
Navin Khedikar
ENDIF.
03-14-2007 7:08 AM
03-14-2007 6:49 AM
hi
u can use the fm f4_dxfilename_toprecursion to get the files on presentation or application server. if u know the file name u can search for it.
u can check the correctness of file name through the above.
to make sure its not empty u can make it obligatory.or give a message
if f1 is initial
message.e000(bctrain) with 'enter field value'.
endif.
hope this helps..a bit