‎2008 Feb 09 7:20 AM
Hi
I have a small issue. In which i have to Upload the data from a flat file based on primary key its a customised table in which there are 4 primary keys. Based on this the customer numbers should be updated and on emore thing is the data should not be repeated. In the selection screen i'll provide a path based on this path it will upload all the data in the flat file
Regards
Nanda
‎2008 Feb 09 7:40 AM
Hi,
You can use GUI_UPLOAD data, once data in uploaded you will captured data into the internal table. If you want to filter out the duplicate entries, you can use below statement.
sort itab by <fieldname>."Here you have to use all your four primary keys.
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING <FIELDNAME>." Here you can use all the four fields.
Thanks,
Sriram Ponna.
‎2008 Feb 09 7:40 AM
Hi,
You can use GUI_UPLOAD data, once data in uploaded you will captured data into the internal table. If you want to filter out the duplicate entries, you can use below statement.
sort itab by <fieldname>."Here you have to use all your four primary keys.
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING <FIELDNAME>." Here you can use all the four fields.
Thanks,
Sriram Ponna.
‎2008 Feb 09 7:41 AM
Hi
Can i have a sample coding????
And one more thing is i have to fetch the values from that ztable using primaryu key only
‎2008 Feb 09 7:43 AM
Hi
1. Create a report and in the report declare a internal table similar the structure of the ztable.
2. Now upload the flat file by GUI_UPLOAD functional module.
3. Split the string for each rows from the flat file and populate each field the internal table.
4. By Modify/update command update the internal table data to the stable.
To upload a flat file :
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_file
filetype = 'ASC'
TABLES
data_tab = p_local_table
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 e002 WITH l_file.
ENDIF.
To split each rows of flat file to internal table fields :
DATA: l_cnt TYPE i.
CLEAR: l_cnt, wa_local.
LOOP AT i_local INTO wa_local.
REFRESH i_split[].
SPLIT wa_local AT c_tab INTO TABLE i_split.
CLEAR l_cnt.
ADD 1 TO l_cnt.
CLEAR wa_split.
LOOP AT i_split INTO wa_split.
IF g_file_flag = 'I'.
ASSIGN COMPONENT l_cnt OF STRUCTURE wa_input TO <fs_field>.
ELSEIF g_file_flag = 'A'.
ASSIGN COMPONENT l_cnt OF STRUCTURE wa_asset TO <fs_field>.
ELSEIF g_file_flag = 'C'.
ASSIGN COMPONENT l_cnt OF STRUCTURE wa_cost TO <fs_field>.
ELSEIF g_file_flag = 'D'.
ASSIGN COMPONENT l_cnt OF STRUCTURE wa_depr TO <fs_field>.
ENDIF.
CLEAR <fs_field>.
<fs_field> = wa_split-col.
ADD 1 TO l_cnt.
CLEAR wa_split.
ENDLOOP.
IF g_file_flag = 'I'.
APPEND wa_input TO p_input_tab.
CLEAR: wa_input .
ELSEIF g_file_flag = 'A'.
APPEND wa_asset TO p_asset_tab.
CLEAR: wa_asset .
ELSEIF g_file_flag = 'C'.
APPEND wa_cost TO p_cost_tab.
CLEAR: wa_cost .
ELSEIF g_file_flag = 'D'.
APPEND wa_depr TO p_depr_tab.
CLEAR: wa_depr .
ENDIF.
CLEAR: wa_local .
ENDLOOP.
To modify ztable with internal table
IF NOT lt_itab_modif IS INITIAL.
EZ_ZMMS_PHYINV
CALL FUNCTION 'ENQUEUE_EZ_lt_itab_modif'
EXPORTING
mode_itab = 'E'
mandt = sy-mandt
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc EQ 0.
MODIFY zitab FROM TABLE lt_itab_modif.
CALL FUNCTION 'DEQUEUE_EZ_lt_itab_modif'
Regards
Pavan
‎2008 Feb 09 7:46 AM
Hi,
Below is the sample code :
*&---------------------------------------------------------------------*
*& Report ZCUSTOMER_MASTER_UPLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZCUSTOMER_MASTER_UPLOAD
no standard page heading line-size 255.
*include bdcrecx1.
TABLES : T100. "Company Codes
************************************************************************
* Internal table declaration *
************************************************************************
DATA : begin of it_customer occurs 0, "Internal table for creating customer
INDEX(4), "Index
KUNNR(16), "Customer No
BUKRS(4), "Company code
VKORG(4), "Sales Organization
VTWEG(2), "Distribution Channel
SPART(2), "Division
KTOKD(4), "Account group
ANRED(30), "Title
NAME1(35), "Name1
SORTL(10), "Search field
NAME2(35), "Name2
NAME3(35), "Name3
NAME4(35), "Name4
STRAS(35), "House and street
STREET2(35),
PFACH(10), "PO box
ORT01(35), "City
PSTLZ(10), "Postal code
ORT02(35), "District
PFORT(35), "PO Box city
PSTL2(10), "Postal code
LAND1(3), "Country Key
REGIO(3), "Region
SPRAS(2), "Language key
TELX1(30), "Telex number
TELF1(16), "First telephone number
TELFX(30), "Fax number
TELF2(16), "Second telephone number
TELTX(30), "Second telex number
KNURL(132), "URL
STCEG(20), "VAT Registration number
AKONT(10), "Recon Account
ZUAWA(4), "Sort key
ZTERM(4), "Terms of payment key
ZWELS(10), "List of payment methods to be considered
BZIRK(6), "Sales district
* AWAHR(3), "Order probability
VKBUR(4), "Sales office
VKGRP(3), "Sales group
KDGRP(2), "Customer group
WAERS(5), "Currency
KALKS(1), "Pricing procedure assigned to this customer
VERSG(1), "Customer statistics group
LPRIO(2), "Delivery Priority
VWERK(4), "Delivering Plant
* ANTLF(1) VALUE 9, "Maximum partial deliveries allowed
INCO1(3), "Inco terms1
INCO2(28), "Inco terms2
ZTERM_01(4), "Terms of payment key
KTGRD(2), "Account assignment group
TAXKD_01(1), "Tax classification1
TAXKD_02(1), "Tax classification2
er_message(100),
end of it_customer.
data : begin of it_customer_ext occurs 0, "Internal table for extending customer
KUNNR(16), "Customer No
VKORG(4), "Sales Organization
VTWEG(2), "Distribution channel
SPART(2), "Division
KTOKD(4), "Account group
BZIRK(6), "Sales district
VKBUR(4), "Sales office
VKGRP(3), "Sales group
KDGRP(2), "Customer group
WAERS(5), "Currency
KALKS(1), "Pricing procedure assigned to this customer
VERSG(1), "Customer statistics group
LPRIO(2), "Delivery priority
VWERK(4), "Delivery plant
INCO1(3), "Incoterms (part 1)
INCO2(28), "Incoterms (part 2)
ZTERM(4), "Terms of payment key
KTGRD(2), "Account assignment group for this customer
TAXKD_01(1), "Tax classification1
TAXKD_02(1), "Tax classification2
end of it_customer_ext.
************************************************************************
* Internal table to get the error data *
************************************************************************
DATA : it_error like it_customer occurs 0 with header line.
DATA : BDCDATA like BDCDATA occurs 0 with header line.
DATA : i_msgtab like bdcmsgcoll occurs 0 with header line.
************************************************************************
* Internal table to find the error from the legacy data *
************************************************************************
DATA : begin of it_erfind occurs 0,
INDEX(10), "Index for error file
kunnr(16),
er_message(100), "For Error Message
end of it_erfind.
************************************************************************
* Variables declaration *
************************************************************************
DATA : g_message(200),
time(10),
date(10) ,
v_error_filename like RLGRAP-FILENAME.
date = sy-datum.
time = sy-uzeit.
************************************************************************
* Initialization
************************************************************************
initialization.
* Generating Error file name with date and time.
perform make_file_name.
************************************************************************
* Selection Screen *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
parameter: p_file like IBIPPARMS-PATH obligatory.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE text-005.
parameters : pm_crt radiobutton group g1 default 'X',
pm_ext radiobutton group g1.
SELECTION-SCREEN END OF BLOCK B2.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) text-003.
SELECTION-SCREEN COMMENT 33(79) text-004.
SELECTION-SCREEN end OF LINE.
SELECTION-SCREEN:END OF BLOCK B1.
at selection-screen ON VALUE-REQUEST FOR p_file .
perform get_filename.
************************************************************************
* Start of selection
************************************************************************
start-of-selection.
perform upload_data.
if pm_crt = 'X'. "If Customer creation is selected
perform fill_data_create.
elseif pm_ext = 'X'. "If Customer extension is selected
perform fill_data_extension.
endif.
end-of-selection.
FORM fill_data_create.
loop at it_customer.
perform bdc_dynpro using 'SAPMF02D' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF02D-KTOKD'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02D-KUNNR'
it_customer-KUNNR.
perform bdc_field using 'RF02D-BUKRS'
it_customer-BUKRS.
perform bdc_field using 'RF02D-VKORG'
it_customer-VKORG.
perform bdc_field using 'RF02D-VTWEG'
it_customer-VTWEG.
perform bdc_field using 'RF02D-SPART'
it_customer-SPART.
perform bdc_field using 'RF02D-KTOKD'
it_customer-KTOKD.
perform bdc_dynpro using 'SAPMF02D' '0110'.
perform bdc_field using 'BDC_CURSOR'
'KNA1-KNURL'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNA1-ANRED'
it_customer-ANRED.
perform bdc_field using 'KNA1-NAME1'
it_customer-NAME1.
perform bdc_field using 'KNA1-SORTL'
it_customer-SORTL.
perform bdc_field using 'KNA1-NAME2'
it_customer-NAME2.
perform bdc_field using 'KNA1-NAME3'
it_customer-NAME3.
perform bdc_field using 'KNA1-NAME4'
it_customer-NAME4.
perform bdc_field using 'KNA1-STRAS'
it_customer-STRAS.
perform bdc_field using 'KNA1-STREET2'
it_customer-STREET2.
perform bdc_field using 'KNA1-PFACH'
it_customer-PFACH.
perform bdc_field using 'KNA1-ORT01'
it_customer-ORT01.
perform bdc_field using 'KNA1-PSTLZ'
it_customer-PSTLZ.
perform bdc_field using 'KNA1-ORT02'
it_customer-ORT02.
perform bdc_field using 'KNA1-PFORT'
it_customer-PFORT.
perform bdc_field using 'KNA1-PSTL2'
it_customer-PSTL2.
perform bdc_field using 'KNA1-LAND1'
it_customer-LAND1.
perform bdc_field using 'KNA1-REGIO'
it_customer-REGIO.
perform bdc_field using 'KNA1-SPRAS'
it_customer-SPRAS.
perform bdc_field using 'KNA1-TELX1'
it_customer-TELX1.
perform bdc_field using 'KNA1-TELF1'
it_customer-TELF1.
perform bdc_field using 'KNA1-TELFX'
it_customer-TELFX.
perform bdc_field using 'KNA1-TELF2'
it_customer-TELF2.
perform bdc_field using 'KNA1-TELTX'
it_customer-TELTX.
perform bdc_field using 'KNA1-KNURL'
it_customer-KNURL.
if it_customer-KTOKD = 'Z002' or
it_customer-KTOKD = 'Z003' or
it_customer-KTOKD = 'Z004' or
it_customer-KTOKD = 'Z005' or
it_customer-KTOKD = 'Z006' or
it_customer-KTOKD = 'Z007'.
perform customer_001.
elseif it_customer-KTOKD = 'Z011'.
perform customer_002.
else.
perform customer_003.
endif.
perform bdc_transaction tables i_msgtab using 'XD01' 'A' 'L' .
* ***********************************************************************
* To fetch the error message from the standard error table
* ***********************************************************************
select single * from T100 where SPRSL = 'E'
and ARBGB = SY-MSGID
and MSGNR = SY-MSGNO.
G_MESSAGE = T100-TEXT.
* **********************************************************************
* subroutine to change the error message for every document number
* **********************************************************************
perform REPLACE_PARAMETERS using SY-MSGV1
SY-MSGV2
SY-MSGV3
SY-MSGV4
changing G_MESSAGE.
write: / 'System variables:'.
skip.
write: / ' Sy-msgty:', SY-MSGTY.
write: / ' Sy-msgid:', SY-MSGID.
write: / ' Sy-msgno:', SY-MSGNO.
write: / ' Sy-msgv1:', SY-MSGV1.
write: / ' Sy-msgv2:', SY-MSGV2.
write: / ' Sy-msgv3:', SY-MSGV3.
write: / ' Sy-msgv4:', SY-MSGV4.
skip.
write: / 'Message:'.
skip.
write: / SY-MSGTY, G_MESSAGE.
* ***********************************************************************
* To find out the error in the legacy data if there is anything and pass
* the document no with error message to the seperate internal table
* called it_erfind
* ***********************************************************************
if sy-msgty = 'E'.
it_erfind-index = it_customer-index.
it_erfind-er_message = G_MESSAGE.
append it_erfind.
endif.
* Finally we are segregating the error and downloading the error data.
* ----------------------------------------------------------------------*
at last.
* To segregate the error
* ----------------------------------------------------------------------*
perform segregate_error.
* To download the error from it_error internal table with err mesg
* ----------------------------------------------------------------------*
perform error_download.
perform display_message.
endat.
endloop.
clear it_customer.
ENDFORM.
FORM fill_data_extension.
loop at it_customer_ext.
perform bdc_dynpro using 'SAPMF02D' '0107'.
perform bdc_field using 'BDC_CURSOR'
'RF02D-KTOKD'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02D-KUNNR'
it_customer_ext-KUNNR.
perform bdc_field using 'RF02D-VKORG'
it_customer_ext-VKORG.
perform bdc_field using 'RF02D-VTWEG'
it_customer_ext-VTWEG.
perform bdc_field using 'RF02D-SPART'
it_customer_ext-SPART.
perform bdc_field using 'RF02D-KTOKD'
it_customer_ext-KTOKD.
if it_customer_ext-KTOKD = 'Z002' or
it_customer_ext-KTOKD = 'Z003' or
it_customer_ext-KTOKD = 'Z004' or
it_customer_ext-KTOKD = 'Z005' or
it_customer_ext-KTOKD = 'Z006' or
it_customer_ext-KTOKD = 'Z007' or
it_customer_ext-KTOKD = 'Z011'.
perform customer_extension_001.
else.
perform customer_extension_002.
endif.
perform bdc_transaction tables i_msgtab using 'VD01' 'N' 'L' .
* ***********************************************************************
* To fetch the error message from the standard error table
* ***********************************************************************
select single * from T100 where SPRSL = 'E'
and ARBGB = SY-MSGID
and MSGNR = SY-MSGNO.
G_MESSAGE = T100-TEXT.
* **********************************************************************
* subroutine to change the error message for every document number
* **********************************************************************
perform REPLACE_PARAMETERS using SY-MSGV1
SY-MSGV2
SY-MSGV3
SY-MSGV4
changing G_MESSAGE.
write: / 'System variables:'.
skip.
write: / ' Sy-msgty:', SY-MSGTY.
write: / ' Sy-msgid:', SY-MSGID.
write: / ' Sy-msgno:', SY-MSGNO.
write: / ' Sy-msgv1:', SY-MSGV1.
write: / ' Sy-msgv2:', SY-MSGV2.
write: / ' Sy-msgv3:', SY-MSGV3.
write: / ' Sy-msgv4:', SY-MSGV4.
skip.
write: / 'Message:'.
skip.
write: / SY-MSGTY, G_MESSAGE.
* ***********************************************************************
* To find out the error in the legacy data if there is anything and pass
* the document no with error message to the seperate internal table
* called it_erfind
* ***********************************************************************
if sy-msgty = 'E'.
it_erfind-kunnr = it_customer_ext-kunnr.
it_erfind-er_message = G_MESSAGE.
append it_erfind.
endif.
* Finally we are segregating the error and downloading the error data.
* ----------------------------------------------------------------------*
at last.
* To segregate the error
* ----------------------------------------------------------------------*
perform segregate_error.
* To download the error from it_error internal table with err mesg
* ----------------------------------------------------------------------*
perform error_download.
perform display_message.
endat.
endloop.
clear it_customer_ext.
ENDFORM.
*****************************************************************************
*This subroutine is used to fill the data for the Account groups
*Z002,Z003,Z004,Z005,Z006 AND Z007
*****************************************************************************
FORM customer_001.
perform bdc_dynpro using 'SAPMF02D' '0120'.
perform bdc_field using 'BDC_CURSOR'
'KNA1-TXJCD'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_dynpro using 'SAPMF02D' '0360'.
perform bdc_field using 'BDC_CURSOR'
'KNVK-NAMEV(01)'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_dynpro using 'SAPMF02D' '0310'.
perform bdc_field using 'BDC_CURSOR'
'KNVV-VERSG'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNVV-BZIRK'
it_customer-BZIRK.
perform bdc_field using 'KNVV-VKBUR'
it_customer-VKBUR.
perform bdc_field using 'KNVV-VKGRP'
it_customer-VKGRP.
perform bdc_field using 'KNVV-VERSG'
it_customer-VERSG.
perform bdc_dynpro using 'SAPMF02D' '0324'.
perform bdc_field using 'BDC_CURSOR'
'KNVP-PARVW(01)'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
* perform bdc_transaction using 'XD01'.
ENDFORM.
*****************************************************************************
*This subroutine is used to fill the data for the Account group Z011
*****************************************************************************
FORM customer_002.
perform bdc_dynpro using 'SAPMF02D' '0120'.
perform bdc_field using 'BDC_CURSOR'
'KNA1-LIFNR'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_dynpro using 'SAPMF02D' '0125'.
perform bdc_field using 'BDC_CURSOR'
'KNA1-NIELS'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_dynpro using 'SAPMF02D' '0130'.
perform bdc_field using 'BDC_CURSOR'
'KNBK-BANKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_dynpro using 'SAPMF02D' '0340'.
perform bdc_field using 'BDC_CURSOR'
'RF02D-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_dynpro using 'SAPMF02D' '0370'.
perform bdc_field using 'BDC_CURSOR'
'RF02D-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNA1-CIVVE'
'X'.
perform bdc_dynpro using 'SAPMF02D' '0360'.
perform bdc_field using 'BDC_CURSOR'
'KNVK-NAMEV(01)'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_dynpro using 'SAPMF02D' '0310'.
perform bdc_field using 'BDC_CURSOR'
'KNVV-VERSG'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNVV-BZIRK'
it_customer-BZIRK.
perform bdc_field using 'KNVV-VERSG'
it_customer-VERSG.
perform bdc_dynpro using 'SAPMF02D' '0324'.
perform bdc_field using 'BDC_CURSOR'
'KNVP-PARVW(01)'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
ENDFORM.
*****************************************************************************
*This subroutine is used to fill the data for the Account groups
*Z020,Z021,Z022,Z023,Z200,Z201.
*****************************************************************************
FORM customer_003.
perform bdc_dynpro using 'SAPMF02D' '0120'.
perform bdc_field using 'BDC_CURSOR'
'KNA1-STCEG'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNA1-STCEG'
it_customer-STCEG.
perform bdc_dynpro using 'SAPMF02D' '0125'.
perform bdc_field using 'BDC_CURSOR'
'KNA1-NIELS'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_dynpro using 'SAPMF02D' '0130'.
perform bdc_field using 'BDC_CURSOR'
'KNBK-BANKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_dynpro using 'SAPMF02D' '0340'.
perform bdc_field using 'BDC_CURSOR'
'RF02D-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_dynpro using 'SAPMF02D' '0370'.
perform bdc_field using 'BDC_CURSOR'
'RF02D-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNA1-CIVVE'
'X'.
perform bdc_dynpro using 'SAPMF02D' '0360'.
perform bdc_field using 'BDC_CURSOR'
'KNVK-NAMEV(01)'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_dynpro using 'SAPMF02D' '0210'.
perform bdc_field using 'BDC_CURSOR'
'KNB1-KNRZE'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNB1-AKONT'
it_customer-AKONT.
perform bdc_field using 'KNB1-ZUAWA'
it_customer-ZUAWA.
perform bdc_dynpro using 'SAPMF02D' '0215'.
perform bdc_field using 'BDC_CURSOR'
'KNB1-ZWELS'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNB1-ZTERM'
it_customer-ZTERM.
perform bdc_field using 'KNB1-ZWELS'
it_customer-ZWELS.
perform bdc_dynpro using 'SAPMF02D' '0220'.
perform bdc_field using 'BDC_CURSOR'
'KNB5-MAHNA'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_dynpro using 'SAPMF02D' '0230'.
perform bdc_field using 'BDC_CURSOR'
'KNB1-VRSNR'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_dynpro using 'SAPMF02D' '0610'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'BDC_CURSOR'
'RF02D-KUNNR'.
perform bdc_dynpro using 'SAPMF02D' '0310'.
perform bdc_field using 'BDC_CURSOR'
'KNVV-VERSG'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNVV-BZIRK'
it_customer-BZIRK.
* perform bdc_field using 'KNVV-AWAHR'
* it_customer-AWAHR.
perform bdc_field using 'KNVV-VKBUR'
it_customer-VKBUR.
perform bdc_field using 'KNVV-VKGRP'
it_customer-VKGRP.
perform bdc_field using 'KNVV-KDGRP'
it_customer-KDGRP.
perform bdc_field using 'KNVV-WAERS'
it_customer-WAERS.
perform bdc_field using 'KNVV-KALKS'
it_customer-KALKS.
perform bdc_field using 'KNVV-VERSG'
it_customer-VERSG.
perform bdc_dynpro using 'SAPMF02D' '0315'.
perform bdc_field using 'BDC_CURSOR'
'KNVV-VWERK'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNVV-LPRIO'
it_customer-LPRIO.
* perform bdc_field using 'KNVV-KZAZU'
* 'X'.
perform bdc_field using 'KNVV-VWERK'
it_customer-VWERK.
* perform bdc_field using 'KNVV-ANTLF'
* it_customer-ANTLF.
perform bdc_dynpro using 'SAPMF02D' '0320'.
perform bdc_field using 'BDC_CURSOR'
'KNVV-KTGRD'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNVV-INCO1'
it_customer-INCO1.
perform bdc_field using 'KNVV-INCO2'
it_customer-INCO2.
perform bdc_field using 'KNVV-ZTERM'
it_customer-ZTERM_01.
perform bdc_field using 'KNVV-KTGRD'
it_customer-KTGRD.
perform bdc_dynpro using 'SAPMF02D' '1350'.
perform bdc_field using 'BDC_CURSOR'
'KNVI-TAXKD(02)'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNVI-TAXKD(01)'
it_customer-TAXKD_01.
perform bdc_field using 'KNVI-TAXKD(02)'
it_customer-TAXKD_02.
perform bdc_dynpro using 'SAPMF02D' '0324'.
perform bdc_field using 'BDC_CURSOR'
'KNVP-PARVW(01)'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
* perform bdc_transaction using 'XD01'.
ENDFORM.
FORM customer_extension_001.
perform bdc_dynpro using 'SAPMF02D' '0310'.
perform bdc_field using 'BDC_CURSOR'
'KNVV-VERSG'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNVV-BZIRK'
it_customer_ext-BZIRK.
if not it_customer_ext-KTOKD = 'Z011'.
perform bdc_field using 'KNVV-VKBUR'
it_customer_ext-VKBUR.
perform bdc_field using 'KNVV-VKGRP'
it_customer_ext-VKGRP.
endif.
perform bdc_field using 'KNVV-VERSG'
it_customer_ext-VERSG.
perform bdc_dynpro using 'SAPMF02D' '0324'.
perform bdc_field using 'BDC_CURSOR'
'KNVP-PARVW(01)'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
ENDFORM.
FORM customer_extension_002.
perform bdc_dynpro using 'SAPMF02D' '0310'.
perform bdc_field using 'BDC_CURSOR'
'KNVV-VERSG'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNVV-BZIRK'
it_customer_ext-BZIRK.
* perform bdc_field using 'KNVV-AWAHR'
* '100'.
perform bdc_field using 'KNVV-VKBUR'
it_customer_ext-VKBUR.
perform bdc_field using 'KNVV-VKGRP'
it_customer_ext-VKGRP.
perform bdc_field using 'KNVV-KDGRP'
it_customer_ext-KDGRP.
perform bdc_field using 'KNVV-WAERS'
it_customer_ext-WAERS.
perform bdc_field using 'KNVV-KALKS'
it_customer_ext-KALKS.
perform bdc_field using 'KNVV-VERSG'
it_customer_ext-VERSG.
perform bdc_dynpro using 'SAPMF02D' '0315'.
perform bdc_field using 'BDC_CURSOR'
'KNVV-VWERK'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNVV-LPRIO'
it_customer_ext-LPRIO.
* perform bdc_field using 'KNVV-KZAZU'
* 'X'.
perform bdc_field using 'KNVV-VWERK'
it_customer_ext-VWERK.
* perform bdc_field using 'KNVV-ANTLF'
* '9'.
perform bdc_dynpro using 'SAPMF02D' '0320'.
perform bdc_field using 'BDC_CURSOR'
'KNVV-KTGRD'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_field using 'KNVV-INCO1'
it_customer_ext-INCO1.
perform bdc_field using 'KNVV-INCO2'
it_customer_ext-INCO2.
perform bdc_field using 'KNVV-ZTERM'
it_customer_ext-ZTERM.
perform bdc_field using 'KNVV-KTGRD'
it_customer_ext-KTGRD.
perform bdc_dynpro using 'SAPMF02D' '1350'.
perform bdc_field using 'BDC_CURSOR'
'RF02D-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'=VW'.
perform bdc_dynpro using 'SAPMF02D' '0324'.
perform bdc_field using 'BDC_CURSOR'
'KNVP-PARVW(01)'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
ENDFORM.
*Subrotine to replace the parameters
*----------------------------------------------------------------------*
FORM REPLACE_PARAMETERS USING P_PAR_1 P_PAR_2 P_PAR_3
P_PAR_4 CHANGING P_MESSAGE.
* erst mal pruefen, ob numerierte Parameter verwendet wurden
*----------------------------------------------------------------------*
DO.
REPLACE '&1' WITH P_PAR_1 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&2' WITH P_PAR_2 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&3' WITH P_PAR_3 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&4' WITH P_PAR_4 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
* falls keine numerierten Parameter vorh., ersetzen wie gehabt
*----------------------------------------------------------------------*
REPLACE '&' WITH P_PAR_1 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_2 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_3 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_4 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
*Subroutine to segregate the error data from the legacy data
*----------------------------------------------------------------------*
FORM segregate_error.
loop at it_erfind.
if pm_crt = 'X'.
loop at it_customer where index = it_erfind-index.
move-corresponding it_customer to it_error.
it_error-er_message = it_erfind-er_message.
append it_error.
endloop.
elseif pm_ext = 'X'.
loop at it_customer_ext where kunnr = it_erfind-kunnr.
move-corresponding it_customer_ext to it_error.
it_error-er_message = it_erfind-er_message.
append it_error.
endloop.
endif.
endloop.
ENDFORM.
********************************************************************
*Subroutine to download the error data from the it_error table.
********************************************************************
FORM error_download.
if it_error[] is not initial.
call function 'WS_DOWNLOAD'
exporting
CODEPAGE = 'IBM'
FILENAME = v_error_filename
FILETYPE = 'DAT'
tables
DATA_TAB = IT_ERROR.
endif.
ENDFORM.
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
* ENDIF.
ENDFORM.
FORM bdc_transaction tables MESSTAB USING TCODE CTUMODE CUPDATE .
CALL TRANSACTION TCODE USING BDCDATA
MODE CTUMODE
UPDATE CUPDATE
MESSAGES INTO MESSTAB.
REFRESH BDCDATA.
clear BDCDATA.
ENDFORM. " bdc_transaction
********************************************************************
* Uploading data file to internal table. *
********************************************************************
FORM upload_data.
if pm_crt = 'X'.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = p_file
* CODEPAGE = 'IBM '
FILETYPE = 'DAT'
TABLES
DATA_TAB = it_customer
EXCEPTIONS
CONVERSION_ERROR = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3
NO_BATCH = 4
UNKNOWN_ERROR = 5
GUI_REFUSE_FILETRANSFER = 6
OTHERS = 7.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
elseif pm_ext = 'X'.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = p_file
* CODEPAGE = 'IBM '
FILETYPE = 'DAT'
TABLES
DATA_TAB = it_customer_ext
EXCEPTIONS
CONVERSION_ERROR = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3
NO_BATCH = 4
UNKNOWN_ERROR = 5
GUI_REFUSE_FILETRANSFER = 6
OTHERS = 7.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endif.
{size:13}Here you can use sort and delete statement to delete the duplicate entries.{size}
ENDFORM.
*&---------------------------------------------------------------------*
*& Form display_message
*&---------------------------------------------------------------------*
FORM display_message .
if it_error[] is initial.
message i019(zmsg). "Success
else.
message e020(zmsg). "Failed
endif.
ENDFORM. " display_message
*&---------------------------------------------------------------------*
*& Form get_filename
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_filename .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = p_file
IMPORTING
FILE_NAME = p_file .
if sy-subrc NE 0 .
write : / 'Enter File Name'.
endif.
ENDFORM. " get_filename
*&---------------------------------------------------------------------*
*& Form make_file_name
*&---------------------------------------------------------------------*
FORM make_file_name .
write sy-datum to date MM/DD/YYYY.
write sy-uzeit to time USING EDIT MASK ' __ __ __'.
concatenate Text-002 date time '.txt'
into v_error_filename.
ENDFORM. " make_file_name
Thanks,
Sriram Ponna.
‎2008 Feb 09 7:49 AM
HI
I dont want any BDC to upload just a simple report which fetches the data based on primary key so plz give me any simple coding
Regards
Nanda
‎2008 Feb 09 9:42 AM
‎2008 Feb 09 10:33 AM
Hi
Do one thing. First upload the data into your internal table and from there update it to your ztable after updating u can use
delete adjacent duplicates comparing .....
Regards
Pavan
‎2008 Feb 09 10:35 AM
Hi,
In ur text file u want to upload put all the data like below...
1 2 3 4 hi
1 2 3 5 hello
2 3 4 5 welcome1) one record per line
2) columns are seperated by tabs....
data : begin of itab occurs 0,
field1 type p,
field2 type p,
field3 type P,
field4 type p,
desc type char10,
end of itab.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\a.txt' "path and file name important
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
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-field1,itab-field2,itab-field3,itab-field4,itab-desc.
endloop.Cheers,
jose.
‎2008 Feb 09 10:40 AM
Hi Jose
Plz clear some of my doubts. I have to specify the path through my selection screen. So how to declare that selection screen??
By using this GUI_UPLOAD can i get the data into my Ztable??
Regards
Nanda
‎2008 Feb 09 10:49 AM
Hi,
change the above code like dis.........
data : begin of itab occurs 0,
field1 type p,
field2 type p,
field3 type P,
field4 type p,
desc type char10,
end of itab.
data: filepath_g(100),
filepath type string.
CALL FUNCTION 'AL_POPUP_FOR_LOCAL_PATH'
EXPORTING
DOC_TYPE = 'txt'
IMPORTING
FILERETURN = filepath_g
.
filepath = filepath_g.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filepath
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
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-field1,itab-field2,itab-field3,itab-field4,itab-desc.
endloop.now u hav all the data in itab.........use modify syntax to update ur ztable.
Cheers,
jose
‎2008 Feb 09 10:53 AM
Hi Jose
Thanks for ur reply. I think by using this pop up FM i'll get a pop up to specify a path right?????????
After using the Modify statement the database will be automatically get updated with my new values right????
So now at the same time i dont want any duplicate entries also. That is if it is having already an entry then it should not enter that value to the ztable??? how to perform this???
‎2008 Feb 09 11:23 AM
ya..........
For updating ur database table u can use one of the foll 3 commands
1) insert to create a new entry in DBtable
2) update to edit existing entries (if there is no entry with the specified key it ll do nothing)
3) modify to edit existing entries (if there is no entry with the specified key it ll create a new record)
Seems that first option (insert) ll be aplicable for u....
note : if ur using insert and if a record already exists with the same key....it dumps............
DATA itab1 LIKE itab OCCURS 0. " deleting the duplicate records
SELECT *
FROM ztable
INTO itab1
FOR ALL ENTRIES IN itab
WHERE field1 = itab-field1
AND field2 = itab-field2
AND field3 = itab-field3
AND field4 = itab-field4.
LOOP AT itab.
READ TABLE itab1 WITH KEY field1 = itab-field1
field2 = itab-field2
field3 = itab-field3
field4 = itab-field4.
IF sy-subrc IS INITIAL.
DELETE itab.
ENDIF.
ENDLOOP.
INSERT ztable FROM TABLE itab. "updatingCheers,
jose.