‎2007 Apr 26 6:28 AM
Hi ,
In BDC ,we do validation of data in flat files before uploading data into SAP.
Can any body let me know about this with an example code?
Regards
‎2007 Apr 26 6:29 AM
hi,
chk out the below code
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = p_path
receiving
RESULT = l_bool.
p_path is the file path and l_bool returns whether file exists or not.
regards,
Navneeth.K
‎2007 Apr 26 6:29 AM
hi,
chk out the below code
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = p_path
receiving
RESULT = l_bool.
p_path is the file path and l_bool returns whether file exists or not.
regards,
Navneeth.K
‎2007 Apr 26 6:31 AM
hi,
i hope the above piece of code solves your problem
regards,
Navneeth.K
‎2007 Apr 26 6:33 AM
we upload the flat file in a internal table in the program.
Then we can validates its various fields with respect to some standard or master or custom table or functional module.
seee the validetion of asset class, company code and cost center below.
LOOP AT p_input_table INTO wa_input.
CLEAR: l_anlkl,
l_flag.
g_no_read = g_no_read + 1.
* To pick up the asset class from the asset class file corresponding to the legacy class
READ TABLE p_asset_table INTO wa_asset
BINARY SEARCH WITH KEY lclass = wa_input-lclass.
IF sy-subrc = 0.
l_anlkl = wa_asset-anlkl.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = l_anlkl
IMPORTING
output = l_anlkl.
* To validate asset class
CALL FUNCTION 'AM_ASSET_CLASS_READ'
EXPORTING
i_anlkl = l_anlkl
TABLES
t_ankb = i_ankb
t_ankv = i_ankv
EXCEPTIONS
klasse_nicht_vorhanden = 1
i_anlkl_fehlt = 2
OTHERS = 3.
IF sy-subrc <> 0. " asset class not valid
MOVE-CORRESPONDING wa_input TO wa_error_file.
wa_error_file-mssg1 = text-028.
l_flag = 'X'.
ELSE.
la_generaldata-assetclass = l_anlkl.
ENDIF.
ELSE.
MOVE-CORRESPONDING wa_input TO wa_error_file.
wa_error_file-mssg1 = text-071.
l_flag = 'X'.
ENDIF.
CALL FUNCTION 'ZFAA_FORMAT_FIELDS'
EXPORTING
zinput = wa_input-txt50
IMPORTING
zoutput = wa_input-txt50.
CALL FUNCTION 'ZFAA_FORMAT_FIELDS'
EXPORTING
zinput = wa_input-txa50
IMPORTING
zoutput = wa_input-txa50.
* To pick up the cost center from cost center file corresponding to legacy dept
READ TABLE p_cost_table INTO wa_cost
BINARY SEARCH WITH KEY ldept = wa_input-kostl.
IF sy-subrc = 0.
* To validate company code
READ TABLE p_t093c INTO wa_t093c BINARY SEARCH WITH KEY bukrs = wa_cost-bukrs.
IF sy-subrc <> 0. "company code not valid
IF l_flag <> 'X'.
MOVE-CORRESPONDING wa_input TO wa_error_file.
l_flag = 'X'.
wa_error_file-mssg1 = text-029.
ELSE.
CONCATENATE wa_error_file-mssg1 text-029
INTO wa_error_file-mssg1 SEPARATED BY ','.
* wa_error_file-mssg2 = text-029.
ENDIF.
ELSE.
la_key-companycode = wa_cost-bukrs.
ENDIF.
* to validate cost centre
READ TABLE p_csks INTO wa_csks BINARY SEARCH WITH KEY kostl = wa_cost-kostl.
IF sy-subrc <> 0. "cost center not valid
IF l_flag <> 'X'.
MOVE-CORRESPONDING wa_input TO wa_error_file.
l_flag = 'X'.
wa_error_file-mssg1 = text-030.
ELSE.
CONCATENATE wa_error_file-mssg1 text-030
INTO wa_error_file-mssg1 SEPARATED BY ','.
ENDIF.
* wa_error_file-mssg3 = text-030.
ELSE.
la_timedependentdata-costcenter = wa_cost-kostl.
la_timedependentdata-plant = wa_cost-werks.
la_timedependentdata-location = wa_cost-loc.
la_timedependentdata-room = wa_input-room.
la_timedependentdatax-costcenter = 'X'.
la_timedependentdatax-plant = 'X'.
la_timedependentdatax-location = 'X'.
la_timedependentdatax-room = 'X'.
ENDIF.
‎2007 Apr 26 6:36 AM
Hi Ravi,
U can try like this....
Check whether the EBELN is related to that particular Company code
IF NOT p_bukrs IS INITIAL.
SELECT SINGLE bukrs
FROM ekko
INTO ekko
WHERE bukrs EQ p_bukrs AND
ebeln = v_ebeln.
IF sy-subrc NE 0.
wa_bdcindata-message = text-062.
APPEND wa_bdcindata TO i_errdata_leg.
CLEAR: wa_bdcindata,
wa_bdcindata_init.
CONTINUE.
ENDIF.
ENDIF.
Regards,
Suresh.
‎2007 Apr 26 6:40 AM
hi Ravi,
in case the file is from presentation server then my above piece of code of will work else if it is from application server then use the foll code.
open dataset p_path for input in text mode encoding default.
if sy-subrc <> 0.
l_bool = ' '.
endif.
p_path is the file path
and l_bool returns whether file is present or not.
hope it solves your query.
regards,
Navneeth.K
‎2007 Apr 26 6:43 AM
Hi,
Is your query not yet solved what is the problem you are facing.
from where are you hetting your file (appln server or presentation server)
regards,
Navneeth.K
‎2007 Apr 26 9:46 AM