10-10-2008 9:38 AM
Hi...
data: begin of itab occurs 0,
f1, f2, f3, f4, f5,
end of itab.
call function 'GUI_UPLOAD'
exporting
filename = 'File Path'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
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
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
loop at itab.
write:/ itab-f1,
itab-f2,
itab-f3,
itab-f4,
itab-f5.
endloop.
My problem is..,
My excel sheet is having following entries..,
t w w g g
r e d h b
e w f b d
But my program giving output as..,
P
P ï ý
0.1. / #*
î
Ç t
&
Þ # é
0.1. ç í ® Ì*
Ø
â
û
0.1. u2122 # u0161*
Y Ô # #
V
= #
[
u2020 # Í
. $ u2014 § ý
#
#
What is the problem.?
Thanks,
Naveen.I
10-10-2008 9:42 AM
Hi,
Use function module ASLM_EXCEL_TO_INTERNAL_TABLE to upload excel to internal table. It uploads data according to row and column. Modify it as per your need.
Regards,
Dhanunjaya Reddy
10-10-2008 9:42 AM
Hi,
Use function module ASLM_EXCEL_TO_INTERNAL_TABLE to upload excel to internal table. It uploads data according to row and column. Modify it as per your need.
Regards,
Dhanunjaya Reddy
10-10-2008 10:04 AM
Hi Danunjay/Mukesh..,
Following program is jumping into Dump, let me know if any issues about parameter passing...?
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = 'File Path\File name.xlsx'
i_begin_col = 'A'
i_begin_row = 1
i_end_col = 'E'
i_end_row = 3
tables
intern = itab
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 2
* OTHERS = 3
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
loop at itab.
write:/ itab-f1,
itab-f2,
itab-f3,
itab-f4,
itab-f5.
endloop.
Thanks,
Naveen.I
10-10-2008 10:08 AM
hi,
check this.
DATA: BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE alsmex_tabline.
DATA: END OF itab.
PARAMETERS: filename LIKE rlgrap-filename MEMORY ID M01,
begcol TYPE i DEFAULT 1 NO-DISPLAY,
begrow TYPE i DEFAULT 1 NO-DISPLAY,
endcol TYPE i DEFAULT 100 NO-DISPLAY,
endrow TYPE i DEFAULT 32000 NO-DISPLAY.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = 'UR Filename'
i_begin_col = begcol
i_begin_row = begrow
i_end_col = endcol
i_end_row = endrow
TABLES
intern = itab
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
loop at itab.
write:/ itab-value.
endloop.
10-10-2008 9:42 AM
Hi,
Save Excel as Text (Tab Delimited) file and then use GUI_Upload
Regards,
Vishal
10-10-2008 9:43 AM
Hi
filename = 'File Path'
are you passing the right file name
Regards
Madhan
10-10-2008 9:43 AM
Hi,
Try using this FM TEXT_CONVERT_XLS_TO_SAP.
in i_tab_raw_data pass rawdata
& in i_filename pass w_filenm(filename of excel thru path)
use FM CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = pr_file
mask = ',*.xls.'
mode = 'O'
title = 'Upload File'(i03)
IMPORTING
filename = pr_file
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
to get filename.
then
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR =
I_LINE_HEADER =
i_tab_raw_data = rawdata
i_filename = w_filenm
TABLES
i_tab_converted_data = itab1
EXCEPTIONS
conversion_failed = 1
OTHERS = 2
Regards,
Amit
10-10-2008 9:44 AM
Hi Naveen,
The FM GUI_UPLOAD does not works properly for excel sheets.
there are other FM
1. ALSM_EXCEL_TO_INTERNAL_TABLE
2.TEXT_CONVERT_XLS_TO_SAP
regards
Kumar M
10-10-2008 9:53 AM
10-10-2008 9:56 AM
Hi Amit..
If I change File type as 'DAT'... Giving error "Wrong value for file type'.
Hi Madhu/Vishal..
Here my requirement is to get file from excel type only.
Hi Madhan..,
I dont think it will not give error if i pass incorrect file path. Its correct file path, which iam passing.
Thanks,
Naveen.I
10-10-2008 10:07 AM
Hi,
No need of changing it to DAT.
Let it be saved as .xls only..
and try using the FM's as i said earlier..it has worked for me for all BDC's ..it will surely work for u as well..
tell mw if there's any more prob
Regards,
Amit
10-10-2008 10:09 AM
Hi Naveen,
Example ur filename is a.xls
Here's the code , very simple
PARAMETER:pr_file LIKE rlgrap-filename OBLIGATORY.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pr_file.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = pr_file
mask = ',*.xls.'
mode = 'O'
title = 'Upload File'(i03)
IMPORTING
filename = pr_file
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
START-OF-SELECTION.
WRITE pr_file TO w_filenm.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR =
I_LINE_HEADER =
i_tab_raw_data = rawdata
i_filename = w_filenm
TABLES
i_tab_converted_data = itab1
EXCEPTIONS
conversion_failed = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
10-10-2008 10:10 AM
Hi Amit Lyer..
What is the parameter i_tab_raw_data in the function module TEXT_CONVERT_XLS_TO_SAP given by you?
Thanks,
Naveen.I
10-10-2008 10:13 AM
Hi,
Its Amit Iyer.
btw ..no parameter for it..just hardcode it as rawdata in the Function module. declare it as
DATA: rawdata(4096) TYPE c OCCURS 0.
Regards,
Amit
10-10-2008 10:24 AM
Hi Try the following code:
data it_dtab type table of string.
"it_utab your upload file structure
data c_hdrln type i 2. " To skip the header in excel file
call function 'FAA_FILE_UPLOAD_EXCEL'
exporting
i_filename = l_filename
* I_TEST =
* I_UCOMM =
* I_MAXCOLS =
i_delimiter = ','
tables
et_filecontent = it_dtab
exceptions
error_accessing_file = 1
others = 2
.
perform delimit_comma2utab tables it_dtab it_utab
using c_hdrln.
" Processing the table IT_DTAB( data with comma separation ) " to transfer the data to IT_UTAB
form delimit_comma2utab tables pt_dtab
pt_utab structure wa_utab
using p_hline type i.
data: l_fld1 type string,
l_fld2 like l_fld1,
l_type,
l_flg type i,
l_idx type i.
field-symbols: <fs> type any.
refresh pt_utab.
clear : wa_dtab, wa_utab,l_flg.
loop at pt_dtab into wa_dtab.
* Skipping the Header Line of Excel sheet
if sy-tabix <= p_hline or wa_dtab is initial.
continue.
endif.
* Storing the entire line data to local field
l_fld2 = wa_dtab.
* Here we use Field symbols to store each field of structure wa_utab
* and splitting the data from local field l_fld2 to corresponding field in
* WA_UTAB
do.
l_idx = sy-index.
* Reading the Field Name for Utab based on the selection
read table it_fnam index l_idx into wa_fnam.
if sy-subrc = 0.
assign component wa_fnam-name of structure wa_utab to <fs>.
if sy-subrc = 0.
find ',' in l_fld2.
if sy-subrc = 0.
split l_fld2 at ',' into l_fld1 l_fld2.
if sy-subrc = 0.
* Catching Excepition while uploading wrong layout eXcel file
catch system-exceptions conversion_errors = 4
others = 8.
<fs> = l_fld1.
endcatch.
if sy-subrc <> 0.
message e021.
endif.
unassign <fs>.
else.
exit.
endif.
else.
* Copying the Last Column of the Row
if l_fld2 is not initial.
<fs> = l_fld2.
endif.
exit.
endif.
else.
exit.
endif.
else.
exit.
endif.
enddo.
if wa_utab is initial.
exit.
endif.
if wa_utab is not initial." AND l_flg = 2.
append wa_utab to pt_utab.
clear wa_utab.
endif.
endloop.
endform. " delimit_comma2utab
Regards*,
Jey
10-10-2008 10:26 AM
Hi Amit..,
I am defining the rawdata as you said..
data: begin of itab occurs 0,
f1, f2, f3, f4, f5,
end of itab.
data: rawdata(4096) type c occurs 0.
call function 'TEXT_CONVERT_XLS_TO_SAP'
exporting
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
i_tab_raw_data = rawdata
i_filename = <file path>
tables
i_tab_converted_data = itab
* EXCEPTIONS
* CONVERSION_FAILED = 1
* OTHERS = 2
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
loop at itab.
write:/ itab-f1,
itab-f2,
itab-f3,
itab-f4,
itab-f5.
endloop.
After excution of this code I am getting following microsoft windows message pop-up...
The file you are trying to open , 'dhfgjgfwqhgfh.tmp', is in a different format than specified by the file extension. verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
If I give YES. Its giving correct ouput.
Let me know if i can rectify this error with any other coding...
Also let me know why we are passing rawdata here...???
Thanks,
Naveen.I
10-10-2008 10:29 AM
'TEXT_CONVERT_XLS_TO_SAP' expects a file extension XLS
'dhfgjgfwqhgfh.tmp' has extension TMP
10-10-2008 10:37 AM
Yeah Maen..,
My file on desktop Book1.xls
I am passing the parameter filename as 'path\Book1.xls'.
Even then I am getting this issue. Ok I will consult my basis people on this.
Let me know about that RAWDATA variable declaration and.,
Why ALSM_EXCEL_TO_INTERNAL_TABLE function module is not working in my case.. where I am doing mistae?
Hi Goutham Chakravarthi.. My Code is similer to your's But still its jumping into dump. Why?
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = 'File Path\File name.xlsx'
i_begin_col = 'A'
i_begin_row = 1
i_end_col = 'E'
i_end_row = 3
tables
intern = itab
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 2
* OTHERS = 3
.
if sy-subrc 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
loop at itab.
write:/ itab-f1,
itab-f2,
itab-f3,
itab-f4,
itab-f5.
endloop.
Thanks,
Naveen.I
10-10-2008 10:57 AM
Hi naveen,
Dont hardcode the path, fetch the file path thru the FM WS_FILENAME_GET, here u c that in mask we have mask = ',*.xls.'
im not sure why rawdata is being used but i used it the way i saw it the very 1st time..and have been using it for last 1 yr w/o any prob.
Amit
10-10-2008 10:58 AM
Hi Naveen,
Refer below code-
-
Type pools
TYPE-POOLS: truxs.
DATA: tab_raw_data TYPE truxs_t_text_data,
l_filename TYPE rlgrap-filename.
DATA: BEGIN OF t_ampl OCCURS 0,
bmatn TYPE ampl-bmatn, "Internal Material Number
ematn TYPE ampl-ematn, "MPN Material
datub(10), "Valid to date
END OF t_ampl.
Upload input excel file
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_tab_raw_data = tab_raw_data
i_filename = l_filename
TABLES
i_tab_converted_data = t_ampl
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
File upload is not successful
MESSAGE e004.
EXIT.
ELSE.
File upload is successful
MESSAGE i005.
ENDIF.
Note - here 'i_tab_converted_data' can have any number of fields according to your input excel file.
Regards,
Aparna
10-10-2008 11:05 AM
Naveen,
Has somebody hacked your account?
Anyway the problem in your code is you have given 'A' and 'E'
for column. they should be integers i believe. also check the extension. whether you put 'xlsx' or 'xls'
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = 'File Path\File name.xls'
i_begin_col = 'A' " <- Should be a integer. so 1 here
i_begin_row = 1
i_end_col = 'E' " <- Should be a integer. so 5 here
i_end_row = 3
tables
intern = itab
Cheers,
Kothand
10-10-2008 11:12 AM
Hi...,
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = 'File Path\File name.xls'
i_begin_col = 1
i_begin_row = 1
i_end_col = 5
i_end_row = 3
tables
intern = itab
Is also giving following Dump Analysis.
Error analysis
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_DYN_CALL_ILLEGAL_TYPE', was
not caught and
therefore caused a runtime error.
The reason for the exception is:
The call to the function module ALSM_EXCEL_TO_INTERNAL_TABLE is incorrect:
In the function module interface, you can specify only
fields of a specific type and length under "INTERN".
Although the currently specified field
"ITAB" is the correct type, its length is incorrect.
As I already mentioned my internal table declaration part..
data: begin of itab occurs 0,
f1, f2, f3, f4, f5,
end of itab.
And my excel file...,
t -w -w -g -g
r -e -d -h -b
e -w -f -b -d
Thanks,
Naveen.I
10-10-2008 11:16 AM
Hi Naveen,
If u r using 'ALSM_EXCEL_TO_INTERNAL_TABLE', declare itab as -
DATA: itab TYPE TABLE OF alsmex_tabline WITH HEADER LINE.
not as the way u defined.
Also take local variable for file path as -
l_fname LIKE rlgrap-filename.
move file path to this variable and pass this variable to FM.
Regards,
Aparna
10-10-2008 11:31 AM
Hi...
My EXCEL file is..,
t w w g g
r e d h b
e w f b d
Code To upload By using ALSM_EXCEL_TO_INTERNAL_TABLE Function module..
DATA: itab TYPE TABLE OF alsmex_tabline WITH HEADER LINE.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = 'File Path\name.xls'
i_begin_col = 1
i_begin_row = 1
i_end_col = 5
i_end_row = 3
TABLES
intern = itab
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
loop at itab.
write:/ itab-row,
itab-col,
itab-value.
endloop.
Code To up load By using 'TEXT_CONVERT_XLS_TO_SAP' Function module..
data: begin of itab occurs 0,
f1, f2, f3, f4, f5,
end of itab.
data: rawdata(4096) type c occurs 0.
call function 'TEXT_CONVERT_XLS_TO_SAP'
exporting
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
i_tab_raw_data = rawdata
i_filename = 'File Path\name.xls'
tables
i_tab_converted_data = itab
* EXCEPTIONS
* CONVERSION_FAILED = 1
* OTHERS = 2
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
loop at itab.
write:/ itab-f1,
itab-f2,
itab-f3,
itab-f4,
itab-f5.
endloop.
Thanks to all.
Yes we can get file path from selection screen I am aware of that procedure..,
And Let me know if it is possible to Upload excel file with GUI_UPLOAD function module.
Thanks,
Naveen Inuganti.
10-10-2008 11:40 AM
hi,
did you check my early reply.
the code which i have mentioned is nothing but what you are giving again now.
04-08-2009 1:03 PM
10-10-2008 9:54 AM
Hi Naveen ,
copy that same text and give in notepad .txt file .
u declear data as a lenth 1 and type c .
copy in ur notepad by giving 1 space between each field or give tab space.
and give you file path name correctly in ur FM .
10-10-2008 10:44 AM
Hi Naveen,
Try Using the below program to get the data from the excel.
*&---------------------------------------------------------------------*
*& Form P_UPLOAD_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM p_upload_data .
DATA : gd_scol TYPE i VALUE '1',
gd_srow TYPE i VALUE '2',
gd_ecol TYPE i VALUE '5',
gd_erow TYPE i VALUE '60000'.
DATA: it_tab TYPE filetable,
gd_subrc TYPE i.
DATA : lt_intern TYPE kcde_cells OCCURS 0 WITH HEADER LINE.
DATA : ld_index TYPE i.
FIELD-SYMBOLS : <fs> .
CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
EXPORTING
filename = p_path
i_begin_col = gd_scol
i_begin_row = gd_srow
i_end_col = gd_ecol
i_end_row = gd_erow
TABLES
intern = lt_intern
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
FORMAT COLOR COL_BACKGROUND INTENSIFIED.
WRITE:/ 'Error Uploading file'.
EXIT.
ENDIF.
IF lt_intern[] IS INITIAL.
FORMAT COLOR COL_BACKGROUND INTENSIFIED.
WRITE:/ 'No Data Uploaded'.
EXIT.
ELSE.
SORT lt_intern BY row col.
LOOP AT lt_intern.
MOVE lt_intern-col TO ld_index.
ASSIGN COMPONENT ld_index OF STRUCTURE it_final TO <fs>.
MOVE lt_intern-value TO <fs>.
AT END OF row.
APPEND it_final .
CLEAR it_final.
ENDAT.
ENDLOOP.
ENDIF.
ENDFORM. " P_UPLOAD_DATA
Thanks,
Chidanand
10-10-2008 11:39 AM
Yes. Definitely possible through GUI_UPLOAD. But not in the way you have written. It cannot upload data into multiple column internal table. It should be something in this form
TYPES: BEGIN OF T_ITAB,
LINE(200),
END OF T_ITAB.
DATA: GT_ITAB TYPE TABLE OF T_ITAB.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_filename
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = gt_itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3.
It will give output in the single column. You need to split
based on the requirement.
Cheers,
Kothand
10-10-2008 11:40 AM
10-10-2008 11:47 AM
Hi,
Here is the whole code for one of my BDC's.
REPORT zbdc_upldscales
NO STANDARD PAGE HEADING LINE-SIZE 255 MESSAGE-ID zsd1.
*PROGRAM zsapmsdr001 .
INCLUDE bdcrecx1.
PARAMETER:pr_file LIKE rlgrap-filename OBLIGATORY.
DATA: flag TYPE i VALUE 0.
DATA: flag1 TYPE i VALUE 0.
DATA: flag2 TYPE i VALUE 0.
DATA: flag3 TYPE i VALUE 0.
DATA : BEGIN OF itab OCCURS 0,
schemecode(16) TYPE c,
itemno(5) TYPE c,
fkunnr(10) TYPE c,
fvkbur(4) TYPE c,
feqty(13) TYPE c,
teqty(13) TYPE c,
valdis(11) TYPE c,
disuom(3) TYPE c,
posnr(5) TYPE c,
END OF itab.
DATA : itab1 LIKE STANDARD TABLE OF itab WITH HEADER LINE.
DATA : itab_mstr LIKE STANDARD TABLE OF zscheme_master2 WITH HEADER LINE. " added by amit on 7.2.08
DATA : BEGIN OF scale_auth OCCURS 0.
INCLUDE STRUCTURE zscale_authorize.
DATA: END OF scale_auth.
DATA: BEGIN OF t_excel OCCURS 0.
INCLUDE STRUCTURE alsmex_tabline.
DATA: END OF t_excel.
DATA: BEGIN OF it_kna1 OCCURS 0.
INCLUDE STRUCTURE kna1.
DATA : END OF it_kna1.
DATA: BEGIN OF it_disc OCCURS 0.
INCLUDE STRUCTURE zscheme_discoun2.
DATA: END OF it_disc.
DATA: w_filenm LIKE rlgrap-filename.
DATA: rawdata(4096) TYPE c OCCURS 0.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pr_file.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = pr_file
mask = ',*.xls.'
mode = 'O'
title = 'Upload File'(i03)
IMPORTING
filename = pr_file
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
START-OF-SELECTION.
WRITE pr_file TO w_filenm.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR =
I_LINE_HEADER =
i_tab_raw_data = rawdata
i_filename = w_filenm
TABLES
i_tab_converted_data = itab1
EXCEPTIONS
conversion_failed = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
***************************************************************
SELECT * FROM zscale_authorize
INTO CORRESPONDING FIELDS OF TABLE scale_auth
WHERE uname = sy-uname.
***************************************************************
SORT itab1 BY fvkbur.
LOOP AT itab1.
READ TABLE scale_auth WITH KEY fvkbur = itab1-fvkbur.
IF sy-subrc = 0.
flag = 0.
ELSE.
flag = 1.
ENDIF.
IF flag = 1.
MESSAGE e000 WITH 'User not authorized for this Sales Office'.
EXIT.
ENDIF.
ENDLOOP.
addded by amit on 7.2.08 for control date validation*****************************
SELECT *
FROM zscheme_master2
INTO CORRESPONDING FIELDS OF TABLE itab_mstr
FOR ALL ENTRIES IN itab1
WHERE scheme = itab1-schemecode.
LOOP AT itab_mstr.
IF itab_mstr-ctrldate < sy-datum.
flag1 = 1.
EXIT.
ENDIF.
CLEAR itab_mstr.
ENDLOOP.
IF flag1 = 1.
MESSAGE e000 WITH 'Cannot update scales after control date'.
EXIT.
ENDIF.
*********************************************************
LOOP AT itab1.
SELECT * FROM kna1 INTO TABLE it_kna1
WHERE kunnr = itab1-fkunnr.
IF sy-subrc = 4.
flag2 = 1.
ENDIF.
IF flag2 = 1.
MESSAGE e000 WITH 'Customer 'itab1-fkunnr' does not exist in Customer master'.
ENDIF.
CLEAR itab1.
ENDLOOP.
*************************************************************
LOOP AT itab_mstr.
SELECT * FROM zscheme_discoun2
INTO CORRESPONDING FIELDS OF TABLE it_disc
WHERE schemecode = itab_mstr-scheme.
ENDLOOP.
LOOP AT it_disc.
LOOP AT itab1 WHERE schemecode = it_disc-schemecode
AND itemno = it_disc-itemno.
IF itab1-valdis > it_disc-valacr.
flag3 = 1.
ENDIF.
IF flag3 = 1.
MESSAGE e000 WITH 'Discount val cant be greater than accrual value'.
ENDIF.
ENDLOOP.
CLEAR itab1.
CLEAR it_disc.
ENDLOOP.
*************************************************************
PERFORM open_group.
LOOP AT itab1.
PERFORM bdc_dynpro USING 'SAPMSVMA' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'VIEWNAME'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=UPD'.
PERFORM bdc_field USING 'VIEWNAME'
'ZSCHEME_DISSCAL2'.
PERFORM bdc_field USING 'VIMDYNFLDS-LTD_DTA_NO'
'X'.
PERFORM bdc_dynpro USING 'SAPLZSCHEME_DISSCAL2' '9100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'ZSCHEME_DISSCAL2-SCHEMECODE(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=NEWL'.
PERFORM bdc_dynpro USING 'SAPLZSCHEME_DISSCAL2' '9100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'ZSCHEME_DISSCAL2-POSNR(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=SAVE'.
PERFORM bdc_field USING 'ZSCHEME_DISSCAL2-SCHEMECODE(01)'
itab1-schemecode.
PERFORM bdc_field USING 'ZSCHEME_DISSCAL2-ITEMNO(01)'
itab1-itemno.
PERFORM bdc_field USING 'ZSCHEME_DISSCAL2-FKUNNR(01)'
itab1-fkunnr.
PERFORM bdc_field USING 'ZSCHEME_DISSCAL2-FVKBUR(01)'
itab1-fvkbur.
PERFORM bdc_field USING 'ZSCHEME_DISSCAL2-FEQTY(01)'
itab1-feqty.
PERFORM bdc_field USING 'ZSCHEME_DISSCAL2-TEQTY(01)'
itab1-teqty.
PERFORM bdc_field USING 'ZSCHEME_DISSCAL2-PERDIS(01)'
''.
PERFORM bdc_field USING 'ZSCHEME_DISSCAL2-VALDIS(01)'
itab1-valdis.
PERFORM bdc_field USING 'ZSCHEME_DISSCAL2-DISUOM(01)'
itab1-disuom.
PERFORM bdc_field USING 'ZSCHEME_DISSCAL2-POSNR(01)'
itab1-posnr.
PERFORM bdc_dynpro USING 'SAPLZSCHEME_DISSCAL2' '9100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'ZSCHEME_DISSCAL2-SCHEMECODE(02)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENDE'.
PERFORM bdc_dynpro USING 'SAPMSVMA' '0100'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/EBACK'.
PERFORM bdc_field USING 'BDC_CURSOR'
'VIEWNAME'.
PERFORM bdc_transaction USING 'SM30'.
CLEAR itab1.
ENDLOOP.
PERFORM close_group.