2008 May 28 10:38 AM
Hi all,
I have requirement to Upload cost condition records from TXT file.
This program will use insted of entering manuval entries through VK11.
The Selection screen has TABLE NAME and CONDITION TYPE and INPUT FILE fields.
The user can enter TABLE name and CONITION TYPE and INPUT file.
So, that table needs to update with that TXT file record.
Kindly give me some inputs for desiging program if it is through that is very great.
Thanks in advance,
Regards,
JBR
Hi all,
I have requirement to Upload cost condition records from TXT file.
This program will use insted of entering manuval entries through VK11.
The Selection screen has TABLE NAME and CONDITION TYPE and INPUT FILE fields.
The user can enter TABLE name and CONITION TYPE and INPUT file.
So, that table needs to update with that TXT file record.
Kindly give me some inputs for desiging program if it is through that is very great.
Thanks in advance,
Regards,
JBR
2008 May 28 11:05 AM
hi
check this program to upload the condition records with transation code vk11
report Z_ZVK11
no standard page heading line-size 255.
parameters: p_file1 like rlgrap-filename.
parameters: p radiobutton group g1,
q radiobutton group g1,
r radiobutton group g1.
CONSTANTS : C_TRANS_VK11(4) VALUE 'VK11'.
data : cnt TYPE n,
fld(25) TYPE c.
data: begin of t_pricing occurs 0,
level(10) type c,
f1(10),
f2(10),
f3(10),
f4(10),
f5(10),
f6(10),
end of t_pricing.
data: begin of t_header_acdc occurs 0,
VKORG(04),
VTWEG(02),
SPART(02),
REGIO(03),
TAXK1(01),
end of t_header_acdc.
data: begin of t_header_car occurs 0,
ALAND(03),
VSTEL(04),
WKCOU(03),
REGIO(03),
TAXM1(01),
end of t_header_car.
data: begin of t_header_pdc occurs 0,
ALAND(04),
WKCOU(03),
REGIO(03),
TAXM1(01),
end of t_header_pdc.
data: begin of t_item occurs 0,
TAXK1(02),
KBETR(10),
DATAB(10),
DATBI(10),
MWSK1(02),
end of t_item.
DATA: IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,
IT_BDC_MESSAGES LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.
PERFORM file_selection.
PERFORM data_upload.
PERFORM table_control .
start-of-selection.
if p = 'X'.
loop at t_header_acdc.
CLEAR IT_BDCDATA.
REFRESH IT_BDCDATA.
perform initial.
perform acdc.
perform bdc_dynpro using 'SAPMV13A' '1995'.
perform item.
perform calltrans.
endloop.
elseif q = 'X'.
loop at t_header_car.
CLEAR IT_BDCDATA.
REFRESH IT_BDCDATA.
perform initial.
perform car.
perform bdc_dynpro using 'SAPMV13A' '1993'.
perform item.
perform calltrans.
endloop.
else.
loop at t_header_pdc.
CLEAR IT_BDCDATA.
REFRESH IT_BDCDATA.
perform initial.
perform pdc.
perform bdc_dynpro using 'SAPMV13A' '1994'.
perform item.
perform calltrans.
endloop.
endif.
form initial.
perform bdc_dynpro using 'SAPMV13A' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RV13A-KSCHL'.
perform bdc_field using 'BDC_OKCODE'
'=ANTA'.
perform bdc_field using 'RV13A-KSCHL'
'UTXJ'.
endform.
form acdc.
perform bdc_dynpro using 'SAPLV14A' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RV130-SELKZ(01)'.
perform bdc_field using 'BDC_OKCODE'
'=WEIT'.
perform bdc_field using 'RV130-SELKZ(01)'
'X'.
perform bdc_dynpro using 'SAPMV13A' '1995'.
perform bdc_field using 'BDC_CURSOR'
'KONP-MWSK1(01)'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'KOMG-VKORG'
t_header_acdc-vkorg.
perform bdc_field using 'KOMG-VTWEG'
t_header_acdc-vtweg.
perform bdc_field using 'KOMG-SPART'
t_header_acdc-spart.
perform bdc_field using 'KOMG-REGIO'
t_header_acdc-regio.
perform bdc_field using 'KOMG-TAXK1'
t_header_acdc-taxk1.
endform.
form item.
cnt = 0.
loop at t_item.
cnt = cnt + 1.
if p = 'X'.
CONCATENATE 'KOMG-TAXM1(' cnt ')' INTO fld.
perform bdc_field using fld
t_item-taxk1.
else.
CONCATENATE 'KOMG-TAXK1(' cnt ')' INTO fld.
perform bdc_field using fld
t_item-taxk1.
endif.
CONCATENATE 'KONP-KBETR(' cnt ')' INTO fld.
perform bdc_field using fld
t_item-kbetr.
CONCATENATE 'RV13A-DATAB(' cnt ')' INTO fld.
perform bdc_field using fld
t_item-datab.
CONCATENATE 'RV13A-DATBI(' cnt ')' INTO fld.
perform bdc_field using fld
t_item-datbi.
CONCATENATE 'KONP-MWSK1(' cnt ')' INTO fld.
perform bdc_field using fld
t_item-mwsk1.
if cnt = 5.
cnt = 0.
endif.
perform bdc_field using 'BDC_CURSOR' fld.
perform bdc_field using 'BDC_OKCODE' '/00'.
perform bdc_field using 'BDC_OKCODE' '=p+'.
perform bdc_field using 'BDC_OKCODE' '/11'.
endloop.
endform.
form car.
perform bdc_dynpro using 'SAPLV14A' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RV130-SELKZ(02)'.
perform bdc_field using 'BDC_OKCODE'
'=WEIT'.
perform bdc_field using 'RV130-SELKZ(01)'
''.
perform bdc_field using 'RV130-SELKZ(02)'
'X'.
perform bdc_dynpro using 'SAPMV13A' '1993'.
perform bdc_field using 'BDC_CURSOR'
'KONP-MWSK1(01)'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'KOMG-ALAND'
t_header_car-aland.
perform bdc_field using 'KOMG-VSTEL'
t_header_car-vstel.
perform bdc_field using 'KOMG-WKCOU'
t_header_car-wkcou.
perform bdc_field using 'KOMG-REGIO'
t_header_car-regio.
perform bdc_field using 'KOMG-TAXM1'
t_header_car-taxm1.
endform.
form pdc.
perform bdc_dynpro using 'SAPLV14A' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RV130-SELKZ(03)'.
perform bdc_field using 'BDC_OKCODE'
'=WEIT'.
perform bdc_field using 'RV130-SELKZ(01)'
''.
perform bdc_field using 'RV130-SELKZ(03)'
'X'.
perform bdc_dynpro using 'SAPMV13A' '1994'.
perform bdc_field using 'BDC_CURSOR'
'KONP-MWSK1(01)'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'KOMG-ALAND'
t_header_pdc-aland.
perform bdc_field using 'KOMG-WKCOU'
t_header_pdc-wkcou.
perform bdc_field using 'KOMG-REGIO'
t_header_pdc-regio.
perform bdc_field using 'KOMG-TAXM1'
t_header_pdc-taxm1.
endform.
form calltrans.
CALL TRANSACTION C_TRANS_VK11 USING IT_BDCDATA MODE 'A'
UPDATE 'S'
MESSAGES INTO IT_BDC_MESSAGES.
endform.
----
FORM data_upload *
----
........ *
----
form data_upload.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = p_file1
FILETYPE = 'DAT'
TABLES
DATA_TAB = t_pricing
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
OTHERS = 10
.
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.
----
FORM file_selection *
----
........ *
----
form file_selection.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'p_file1'
IMPORTING
FILE_NAME = p_file1
.
endform.
Form BDC_DYNPRO
FORM BDC_DYNPRO using program dynpro.
CLEAR IT_BDCDATA.
IT_BDCDATA-PROGRAM = PROGRAM.
IT_BDCDATA-DYNPRO = DYNPRO.
IT_BDCDATA-DYNBEGIN = 'X'.
APPEND IT_BDCDATA.
endform.
*Form BDC_FIELD
FORM bdc_field using fnam fval.
CLEAR IT_BDCDATA.
IT_BDCDATA-FNAM = FNAM.
IT_BDCDATA-FVAL = FVAL.
APPEND IT_BDCDATA.
ENDFORM.
Table Control
FORM table_control .
LOOP AT t_pricing.
If t_pricing-level = 'H_acdc'.
t_header_acdc-vkorg = t_pricing-f1.
t_header_acdc-vtweg = t_pricing-f2.
t_header_acdc-spart = t_pricing-f3.
t_header_acdc-regio = t_pricing-f4.
t_header_acdc-taxk1 = t_pricing-f5.
APPEND t_header_acdc.
elseif t_pricing-level = 'H_car'.
t_header_car-aland = t_pricing-f1.
t_header_car-vstel = t_pricing-f2.
t_header_car-wkcou = t_pricing-f3.
t_header_car-regio = t_pricing-f4.
t_header_car-taxm1 = t_pricing-f5.
APPEND t_header_car.
elseif t_pricing-level = 'H_pdc'.
t_header_pdc-aland = t_pricing-f1.
t_header_pdc-wkcou = t_pricing-f2.
t_header_pdc-regio = t_pricing-f3.
t_header_pdc-taxm1 = t_pricing-f4.
APPEND t_header_pdc.
else.
t_item-taxk1 = t_pricing-f1.
t_item-kbetr = t_pricing-f2.
t_item-datab = t_pricing-f3.
t_item-datbI = t_pricing-f4.
t_item-mwsk1 = t_pricing-f5.
APPEND t_item.
endif.
ENDLOOP.
ENDFORM.
thanks
sitaram
2008 May 28 2:36 PM
Hi
Use the below function module and pass your text file name along with path to w_file. And take the data into it_flagfile.
After that split each line into your respective table fields according to the given separator in each line. after that go with BDC or what ever.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = w_file
filetype = 'ASC'
TABLES
data_tab = it_flatfile
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