‎2011 Sep 02 7:59 PM
Hello experts,
I have to discuss an interesting issue with u all ...
I have used FM 'BAPI_INSPECTIONPLAN_CREATE' to upload master inspection plan , everything is working fine .but when goes to upload Quantitative data for some Quantitative characterstic such as .. decimal places , Measurement unit , target value , lower limit , upper limit, not able to upload.
I have tried "C" ,"L" and "N' modes but not able to upload quantitative data.
I have googled a lot but not able to find any solution.
If any one please , put some precious suggestion or solution.
Thanx,
Jeet
‎2011 Sep 05 6:57 AM
Hi Jeet,
I believe you might be missing out on some indicator or flag. If you could post your code, then, it will be helpful in error resolution.
Regards,
Pranav.
‎2011 Sep 06 6:20 AM
Hi Pranav ,
Thanx a lot for showing so much of interest............
Code is as follows:-----
&----
*& Report ZPP_INSPECTION_UPLOAD
*&
&----
*&This Program is used to upload QM inspection Plans using BAPI
*&Note:
*& 1) Provide the Data as per the Template Attached
*& 2) See Sample Text File for Example
&----
REPORT ZPP_INSPECTION.
Type Pool Used for ALV Log Display
TYPE-POOLS : slis,truxs.
Data Declarations for import internal table parameters to BAPI
DATA : t_task TYPE TABLE OF bapi1191_tsk_c WITH HEADER LINE,
t_materialtaskallocation TYPE TABLE OF bapi1191_mtk_c WITH HEADER LINE,
t_inspcharacteristic TYPE TABLE OF bapi1191_cha_c WITH HEADER LINE,
t_operation TYPE TABLE OF bapi1191_opr_c WITH HEADER LINE,
t_return TYPE TABLE OF bapiret2 WITH HEADER LINE.
DATA: file_name TYPE rlgrap-filename.
DATA: raw_data TYPE truxs_t_text_data.
DATA: abap_true TYPE sap_bool.
DATA: program_name TYPE sy-repid.
Local Variables
DATA : v_group TYPE bapi1191_tsk_c-task_list_group,
v_grpcounter TYPE bapi1191_tsk_c-group_counter,
v_file TYPE localfile,
v_row TYPE n,
v_plant LIKE t_task-plant,
v_lines TYPE i,
v_per TYPE p,
v_txt(50) TYPE c.
Declare Internal table for Message tables for ALV Display
INCLUDE zdata_dec.
Structure to Load Data from the Text File
TYPES : BEGIN OF ty_insplan,
plant LIKE t_task-plant,
material LIKE t_materialtaskallocation-material,
tsk_description LIKE t_task-description,
task_list_usage LIKE t_task-task_list_usage,
task_list_status LIKE t_task-task_list_status,
lot_size_from LIKE t_task-lot_size_from,
lot_size_to LIKE t_task-lot_size_to,
planning_work_center LIKE t_task-planning_work_center,
task_measure_unit LIKE t_task-task_measure_unit,
op_activity LIKE t_operation-activity,
control_key LIKE t_operation-control_key,
work_cntr LIKE t_operation-work_cntr,
op_description LIKE t_operation-description,
operation_measure_unit LIKE t_operation-operation_measure_unit,
*nominator LIKE t_operation-nominator,
*cost_rel TYPE c,
ins_activity LIKE t_inspcharacteristic-activity,
inspchar LIKE t_inspcharacteristic-inspchar,
quantitative_ind LIKE t_inspcharacteristic-quantitative_ind,
mstr_char LIKE t_inspcharacteristic-mstr_char,
PMSTR_CHAR LIKE t_inspcharacteristic-pmstr_char,
cha_master_import_modus LIKE t_inspcharacteristic-cha_master_import_modus,
*
char_descr LIKE t_inspcharacteristic-char_descr,
*
method LIKE t_inspcharacteristic-method,
pmethod LIKE t_inspcharacteristic-pmethod,
dec_places like t_inspcharacteristic-dec_places,
meas_unit LIKE t_inspcharacteristic-meas_unit,
*
target_val LIKE t_inspcharacteristic-target_val,
*
up_tol_lmt LIKE t_inspcharacteristic-up_tol_lmt,
*
lw_tol_lmt LIKE t_inspcharacteristic-lw_tol_lmt,
DEF_CODE_GRP_GENERAL LIKE t_inspcharacteristic-DEF_CODE_GRP_GENERAL,
DEF_CODE_GENERAL LIKE t_inspcharacteristic-DEF_CODE_GENERAL,
*
smpl_procedure LIKE t_inspcharacteristic-smpl_procedure,
*
smpl_unit LIKE t_inspcharacteristic-smpl_unit,
*
smpl_quant LIKE t_inspcharacteristic-smpl_quant,
SPC_CRITERION_KEY LIKE t_inspcharacteristic-SPC_CRITERION_KEY,
END OF ty_insplan.
Internal Table to Load and Hold Data from the Text File
DATA : it_insplan TYPE TABLE OF ty_insplan WITH HEADER LINE.
Clear Internal Tables holding Messages
CLEAR it_loghead[].
CLEAR it_logdetail[].
Call Subroutine to Show File Dialog
PERFORM choose_data_file.
Call Subroutine to Load data into Internal table from excel file
PERFORM load_data_from_file.
Determine the number of records in the internal table
DESCRIBE TABLE it_insplan LINES v_lines.
Loop at internal table to load all data
LOOP AT it_insplan.
Call Subroutine to Display the Progress
PERFORM display_progress_timer.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = it_insplan-material
IMPORTING
OUTPUT = it_insplan-material
.
ON CHANGE OF it_insplan-material.
IF it_insplan-ins_activity IS INITIAL AND t_task IS NOT INITIAL.
Call Subroutine to Load the inspection plan
PERFORM call_bapi_and_commit.
Re-initialise the internal tables
PERFORM clear_internal_tables.
ENDIF.
IF it_insplan-plant IS NOT INITIAL.
v_plant = it_insplan-plant.
ENDIF.
ENDON.
IF it_insplan-plant NE space.
Moving Corresponding fields to Material internal table
t_materialtaskallocation-material = it_insplan-material.
t_materialtaskallocation-plant = it_insplan-plant.
t_materialtaskallocation-valid_from = sy-datum.
APPEND t_materialtaskallocation.
Moving Corresponding fields to task internal table
t_task-valid_from = sy-datum.
t_task-description = it_insplan-tsk_description.
t_task-task_list_usage = it_insplan-task_list_usage.
t_task-task_list_status = it_insplan-task_list_status.
t_task-lot_size_from = it_insplan-lot_size_from.
t_task-lot_size_to = it_insplan-lot_size_to.
t_task-planning_work_center = it_insplan-planning_work_center.
t_task-plant = it_insplan-plant.
t_task-task_measure_unit = it_insplan-task_measure_unit.
APPEND t_task.
Moving Corresponding fields to Operation internal table
t_operation-valid_from = sy-datum.
t_operation-activity = it_insplan-op_activity.
t_operation-plant = it_insplan-plant.
t_operation-control_key = it_insplan-control_key.
t_operation-work_cntr = it_insplan-work_cntr.
t_operation-description = it_insplan-op_description.
t_operation-operation_measure_unit = it_insplan-operation_measure_unit.
t_operation-denominator = '1'.
t_operation-nominator = '1'.
t_operation-base_quantity = '1.000'.
APPEND t_operation.
ELSE.
Moving Corresponding fields to Inspection Characteristics internal table
t_inspcharacteristic-activity = it_insplan-ins_activity.
t_inspcharacteristic-inspchar = it_insplan-inspchar.
t_inspcharacteristic-valid_from = sy-datum.
t_inspcharacteristic-mstr_char = it_insplan-mstr_char.
t_inspcharacteristic-pmstr_char = it_insplan-pmstr_char.
t_inspcharacteristic-method = it_insplan-method.
t_inspcharacteristic-pmethod = it_insplan-pmethod.
t_inspcharacteristic-smpl_procedure = it_insplan-smpl_procedure.
t_inspcharacteristic-smpl_unit = it_insplan-smpl_unit.
t_inspcharacteristic-dec_places = it_insplan-dec_places.
t_inspcharacteristic-meas_unit = it_insplan-meas_unit.
t_inspcharacteristic-smpl_quant = it_insplan-smpl_quant.
t_inspcharacteristic-char_descr = it_insplan-char_descr.
IF not it_insplan-target_val is initial.
t_inspcharacteristic-quantitative_ind = it_insplan-quantitative_ind.
t_inspcharacteristic-target_val = it_insplan-target_val.
t_inspcharacteristic-up_tol_lmt = it_insplan-up_tol_lmt.
t_inspcharacteristic-lw_tol_lmt = it_insplan-lw_tol_lmt.
t_inspcharacteristic-cha_master_import_modus = .
*ELSEIF it_insplan-target_val is initial.
*
t_inspcharacteristic-cha_master_import_modus = it_insplan-cha_master_import_modus.
endif.
t_inspcharacteristic-cha_master_import_modus = it_insplan-cha_master_import_modus.
t_inspcharacteristic-def_code_grp_general = it_insplan-def_code_grp_general.
t_inspcharacteristic-def_code_general = it_insplan-def_code_general.
t_inspcharacteristic-spc_criterion_key = it_insplan-spc_criterion_key.
APPEND t_inspcharacteristic.
CLEAR t_inspcharacteristic.
ENDIF.
ENDLOOP.
IF t_task IS NOT INITIAL.
Call Subroutine to upload last inspection plan details
PERFORM call_bapi_and_commit.
ENDIF.
Call Subroutine to Display Log in ALV
PERFORM display_log_list.
&----
*& Form CHOOSE_DATA_FILE
&----
Subroutine to Show File Dialog and select file from the PC
----
FORM choose_data_file .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = file_name
.
ENDFORM. " CHOOSE_DATA_FILE
&----
*& Form LOAD_DATA_FROM_FILE
&----
Subroutine to Load data into Internal table from text file
----
FORM load_data_from_file .
Call Function module to load data from Text File
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR =
I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = raw_data
I_FILENAME = file_name
TABLES
I_TAB_CONVERTED_DATA = it_insplan
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.
ENDFORM. " LOAD_DATA_FROM_FILE
&----
*& Form CALL_BAPI_AND_COMMIT
&----
Subroutine to Load the inspection plans
----
FORM call_bapi_and_commit .
Initialise internal table
REFRESH t_return.
Call Function to Create Inspection Plan
CALL FUNCTION 'BAPI_INSPECTIONPLAN_CREATE'
IMPORTING
group = v_group
groupcounter = v_grpcounter
TABLES
task = t_task
materialtaskallocation = t_materialtaskallocation
operation = t_operation
inspcharacteristic = t_inspcharacteristic
return = t_return.
READ TABLE t_return INDEX 1.
DESCRIBE TABLE t_return.
Check for success message and then Commit, otherwise dont commit
IF t_return-type EQ 'S' AND sy-tfill EQ 1.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
Populate Success message in internal table for ALV Log display
it_loghead-plant = v_plant.
it_loghead-material = t_materialtaskallocation-material.
it_loghead-msgtype = 'S'.
it_loghead-msg = 'Inspection Plan Created Successfully'.
APPEND it_loghead.
MESSAGE e499(sy) with 'Inspection Plan created Successfully'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
Populate Error message in internal table for ALV Log display
it_loghead-plant = v_plant.
it_loghead-material = t_materialtaskallocation-material.
it_loghead-msgtype = 'E'.
it_loghead-msg = 'Inspection Plan Not Created'.
APPEND it_loghead.
Retrieve and populate Error Details for Log Display
CLEAR t_return.
LOOP AT t_return.
it_logdetail-plant = v_plant.
it_logdetail-material = t_materialtaskallocation-material.
it_logdetail-msgtype = t_return-type.
it_logdetail-msg = t_return-message.
IF t_return-parameter IS NOT INITIAL.
CONCATENATE it_logdetail-msg '- Error in parameter'
t_return-parameter INTO it_logdetail-msg SEPARATED BY space.
IF t_return-row IS NOT INITIAL.
v_row = t_return-row.
CONCATENATE it_logdetail-msg '- In Row' v_row
INTO it_logdetail-msg SEPARATED BY space.
ENDIF.
ENDIF.
APPEND it_logdetail.
ENDLOOP.
REFRESH t_return.
*MESSAGE e499(sy) with 'Inspection Plan is not created Successfully'.
ENDIF.
ENDFORM. " CALL_BAPI_AND_COMMIT
&----
*& Form CLEAR_INTERNAL_TABLES
&----
Subroutine to Clear Internal Tables
----
FORM clear_internal_tables .
CLEAR t_materialtaskallocation[].
CLEAR t_task[].
CLEAR t_operation[].
CLEAR t_inspcharacteristic[].
CLEAR t_return[].
ENDFORM. " CLEAR_INTERNAL_TABLES
Please check into it , and let me know if any thing I am missing.
Regards,
Jeet
‎2011 Sep 06 11:14 AM
Hi Jeet,
Specifically, your issue is with the Table parameter 'INSPCHARACTERISTIC'. There are some IF conditions in your code which were not very clear to me and hence, I can recommend you to verify the data in your internal table in De-bugging mode.
If you have a look at the Short-text of that parameter, then, there are some hints.
1. The operation is identified by specifying the operation ID in the field OPERATION_ID. If this is not available, the system then trys to determine the operation using the operation number in the field ACTIVITY.
2. You should enter an inspection characteristic number in the field INSPCHAR to identify inspection characteristics.
3. You can create inspection charactetistics with or without reference to a master inspection characteristic, if you enter a master inspection characteristic (MSTR_CHAR and PMSTR_CHAR fields). Enter the reference for the master inspection characteristic in the field CHA_MASTER_IMPORT_MODUS (mode for reference to the master inspection characteristic).
"L" for reference
In this case, the master inspection characteristic must be completely maintained. In parameter INSPCHARACTERISTIC, you must only enter data in the fields, in which data cannot be transferred from the master inspection characteristic.
"C" for copy (flexible reference)
In this case, the data is copied from the master inspection characteristic to the inspection characteristic.
"N" for creating a flexible reference
In this case, no data is transferred from the master inspection characteristic. You must enter all fields in parameter INSPCHARACTERISTIC.
For "L" or "C", you can copy the control indicators for the inspection characteristic directly from the master inspection characteristic. For "N" or if you do not enter a master inspection characteristic, you must enter the control indicators individually or enter a key for the control indicators in field PRESET_CTRL_INDS_KEY, if you have defined this key in Customizing.
4. If you enter a tolerance key, the data is automatically copied from the tolerance key. If you enter an upper or lower tolerance specification limit, you must also set the control indicator for the upper or lower specification limit.
There are also notes to the BAPI which will be of use to you. Read the BAPI Documentation carefully.
Regards,
Pranav.
‎2011 Sep 16 6:22 AM