Difference between revisions of "SAP PM BAPI CA01"

From SapWiki
(Created page with " <nowiki>*&---------------------------------------------------------------------* *& Report ZPP_CREAR_HR *& *&----------------------------------------------------------------...")
 
 
Line 6: Line 6:
 
*&---------------------------------------------------------------------*
 
*&---------------------------------------------------------------------*
  
REPORT  ZPP_CREAR_HR.
+
REPORT  zpp_crear_hr.
 
*--------------------------------------------------------------------*
 
*--------------------------------------------------------------------*
type-POOLs : SLIS.
+
TYPE-POOLS : slis.
  
Data: Begin of gs_data,
+
DATA: BEGIN OF gs_data,
      MATERIAL        like BAPI1012_MTK_C-MATERIAL,        "Material
+
        material                      LIKE bapi1012_mtk_c-material,        "Material
      PLANT          like BAPI1012_MTK_C-PLANT,            "Centro
+
        plant                          LIKE bapi1012_mtk_c-plant,            "Centro
      TASK_LIST_GROUP like BAPI1012_TSK_C-TASK_LIST_GROUP,  "Grp. Hoja de Ruta
+
        task_list_group                LIKE bapi1012_tsk_c-task_list_group,  "Grp. Hoja de Ruta
      GROUP_COUNTER  like BAPI1012_TSK_C-GROUP_COUNTER,    "Contador
+
        group_counter                  LIKE bapi1012_tsk_c-group_counter,    "Contador
      IDENT_KEY      like BAPI1012_TSK_C-IDENT_KEY,        "Pto. Inspección
+
        ident_key                      LIKE bapi1012_tsk_c-ident_key,        "Pto. Inspección
      INSPPOINT_PARTIALLOT_ASSGNMT like BAPI1012_TSK_C-INSPPOINT_PARTIALLOT_ASSGNMT, "Datos Parciales
+
        insppoint_partiallot_assgnmt  LIKE bapi1012_tsk_c-insppoint_partiallot_assgnmt, "Datos Parciales
      DYN_MODIF_LEVEL like BAPI1012_TSK_C-DYN_MODIF_LEVEL,  "Nivel Dinamizacion
+
        dyn_modif_level                LIKE bapi1012_tsk_c-dyn_modif_level,  "Nivel Dinamizacion
      ACTIVITY        like BAPI1012_OPR_C-ACTIVITY,        "Numero de Operacion
+
        activity                      LIKE bapi1012_opr_c-activity,        "Numero de Operacion
      WORK_CNTR      like BAPI1012_OPR_C-WORK_CNTR,        "Puesto de Trabajo
+
        work_cntr                      LIKE bapi1012_opr_c-work_cntr,        "Puesto de Trabajo
      CONTROL_KEY    like BAPI1012_OPR_C-CONTROL_KEY,      "Clave de Control
+
        control_key                    LIKE bapi1012_opr_c-control_key,      "Clave de Control
      DESCRIPTION    like BAPI1012_OPR_C-DESCRIPTION,      "Descrip. Operación
+
        description                    LIKE bapi1012_opr_c-description,      "Descrip. Operación
      INSP_POINT_COMPLT_FLOW_VARIANT like BAPI1012_OPR_C-INSP_POINT_COMPLT_FLOW_VARIANT, "Variante de Proceso
+
        insp_point_complt_flow_variant LIKE bapi1012_opr_c-insp_point_complt_flow_variant, "Variante de Proceso
      TIME_GRID      like BAPI1012_OPR_C-TIME_GRID,        "Secuencial Hora
+
        time_grid                      LIKE bapi1012_opr_c-time_grid,        "Secuencial Hora
      TIME_FACTOR    like BAPI1012_OPR_C-TIME_FACTOR,      " Factor de Tiempo
+
        time_factor                    LIKE bapi1012_opr_c-time_factor,      " Factor de Tiempo
      TIME_UNIT      like BAPI1012_OPR_C-TIME_UNIT,        "Unidad de Tiempo
+
        time_unit                      LIKE bapi1012_opr_c-time_unit,        "Unidad de Tiempo
      DENOMINATOR    like BAPI1012_OPR_C-DENOMINATOR,      "Denominador para conversión u.medida hoja ruta y operación
+
        denominator                    LIKE bapi1012_opr_c-denominator,      "Denominador para conversión u.medida hoja ruta y operación
      NOMINATOR      like BAPI1012_OPR_C-NOMINATOR,        "Contador para conversión u.medida hoja de ruta y operación
+
        nominator                      LIKE bapi1012_opr_c-nominator,        "Contador para conversión u.medida hoja de ruta y operación
      base_quantity   like BAPI1012_OPR_C-base_quantity,    "Cantidad base
+
        base_quantity                 LIKE bapi1012_opr_c-base_quantity,    "Cantidad base
      INSPCHAR        like BAPI1012_CHA_C-INSPCHAR,        "Numero de Caracteristica
+
        inspchar                      LIKE bapi1012_cha_c-inspchar,        "Numero de Caracteristica
      CHAR_DESCR      like BAPI1012_CHA_C-CHAR_DESCR,      "Texto breve para característica inspección
+
        char_descr                    LIKE bapi1012_cha_c-char_descr,      "Texto breve para característica inspección
      MSTR_CHAR      like BAPI1012_CHA_C-MSTR_CHAR,        "Caracteristica
+
        mstr_char                      LIKE bapi1012_cha_c-mstr_char,        "Caracteristica
      SMPL_PROCEDURE  like BAPI1012_CHA_C-SMPL_PROCEDURE,  "Procedimiento
+
        smpl_procedure                LIKE bapi1012_cha_c-smpl_procedure,  "Procedimiento
      SMPL_UNIT      like BAPI1012_CHA_C-SMPL_UNIT,        "Unidad de Medida
+
        smpl_unit                      LIKE bapi1012_cha_c-smpl_unit,        "Unidad de Medida
      SMPL_QUANT      like BAPI1012_CHA_C-SMPL_QUANT,      "Cantidad para muestra
+
        smpl_quant                    LIKE bapi1012_cha_c-smpl_quant,      "Cantidad para muestra
      DYN_MODIF_RULE  like BAPI1012_CHA_C-DYN_MODIF_RULE,  "Regla Dinamizacion
+
        dyn_modif_rule                LIKE bapi1012_cha_c-dyn_modif_rule,  "Regla Dinamizacion
      SPC_CRITERION_KEY like BAPI1012_CHA_C-SPC_CRITERION_KEY,"Criterio SPC
+
        spc_criterion_key              LIKE bapi1012_cha_c-spc_criterion_key, "Criterio SPC
      UP_TOL_LMT      like BAPI1012_CHA_C-UP_TOL_LMT,        "Tolerancia Superior
+
        up_tol_lmt                    LIKE bapi1012_cha_c-up_tol_lmt,        "Tolerancia Superior
      LW_TOL_LMT      like BAPI1012_CHA_C-LW_TOL_LMT,        "Tolerancia Inferior
+
        lw_tol_lmt                    LIKE bapi1012_cha_c-lw_tol_lmt,        "Tolerancia Inferior
      FORMULA_CHECK_BY_SAP like BAPI1012_CHA_C-FORMULA_CHECK_BY_SAP, "Verificar y calcular fórmula en QM
+
        formula_check_by_sap          LIKE bapi1012_cha_c-formula_check_by_sap, "Verificar y calcular fórmula en QM
      FORMULA_FIELD_1 like BAPI1012_CHA_C-FORMULA_FIELD_1,
+
        formula_field_1                LIKE bapi1012_cha_c-formula_field_1,
      FORMULA_FIELD_2 like BAPI1012_CHA_C-FORMULA_FIELD_2,
+
        formula_field_2                LIKE bapi1012_cha_c-formula_field_2,
      TASK_MEASURE_UNIT like BAPI1012_TSK_C-TASK_MEASURE_UNIT,
+
        task_measure_unit              LIKE bapi1012_tsk_c-task_measure_unit,
       end of gs_data.
+
       END OF gs_data.
data gt_data like TABLE OF gs_data.
+
DATA gt_data LIKE TABLE OF gs_data.
  
data: begin of gs_data_material,
+
DATA: BEGIN OF gs_data_material,
  MATERIAL like BAPI1012_MTK_C-MATERIAL,            "Material
+
        material                    LIKE bapi1012_mtk_c-material,            "Material
PLANT like BAPI1012_MTK_C-PLANT,                  "Centro
+
        plant                        LIKE bapi1012_mtk_c-plant,                  "Centro
TASK_LIST_GROUP like BAPI1012_TSK_C-TASK_LIST_GROUP, "Grp. Hoja de Ruta
+
        task_list_group              LIKE bapi1012_tsk_c-task_list_group, "Grp. Hoja de Ruta
GROUP_COUNTER like BAPI1012_TSK_C-GROUP_COUNTER,  "Contador
+
        group_counter                LIKE bapi1012_tsk_c-group_counter,  "Contador
IDENT_KEY like BAPI1012_TSK_C-IDENT_KEY,          "Pto. Inspección
+
        ident_key                    LIKE bapi1012_tsk_c-ident_key,          "Pto. Inspección
INSPPOINT_PARTIALLOT_ASSGNMT like BAPI1012_TSK_C-INSPPOINT_PARTIALLOT_ASSGNMT, "Datos Parciales
+
        insppoint_partiallot_assgnmt LIKE bapi1012_tsk_c-insppoint_partiallot_assgnmt, "Datos Parciales
DYN_MODIF_LEVEL like BAPI1012_TSK_C-DYN_MODIF_LEVEL, "Nivel Dinamizacion
+
        dyn_modif_level              LIKE bapi1012_tsk_c-dyn_modif_level, "Nivel Dinamizacion
  end of gs_data_material.
+
      END OF gs_data_material.
  
data: begin of gs_data_operacion,
+
DATA: BEGIN OF gs_data_operacion,
MATERIAL like BAPI1012_MTK_C-MATERIAL,            "Material
+
        material                      LIKE bapi1012_mtk_c-material,            "Material
PLANT like BAPI1012_MTK_C-PLANT,                  "Centro
+
        plant                          LIKE bapi1012_mtk_c-plant,                  "Centro
TASK_LIST_GROUP like BAPI1012_TSK_C-TASK_LIST_GROUP, "Grp. Hoja de Ruta
+
        task_list_group                LIKE bapi1012_tsk_c-task_list_group, "Grp. Hoja de Ruta
GROUP_COUNTER like BAPI1012_TSK_C-GROUP_COUNTER,  "Contador
+
        group_counter                  LIKE bapi1012_tsk_c-group_counter,  "Contador
  ACTIVITY like BAPI1012_OPR_C-ACTIVITY,            "Numero de Operacion
+
        activity                      LIKE bapi1012_opr_c-activity,            "Numero de Operacion
WORK_CNTR like BAPI1012_OPR_C-WORK_CNTR,          "Puesto de Trabajo
+
        work_cntr                      LIKE bapi1012_opr_c-work_cntr,          "Puesto de Trabajo
CONTROL_KEY like BAPI1012_OPR_C-CONTROL_KEY,      "Clave de Control
+
        control_key                    LIKE bapi1012_opr_c-control_key,      "Clave de Control
DESCRIPTION like BAPI1012_OPR_C-DESCRIPTION,      "Descrip. Operación
+
        description                    LIKE bapi1012_opr_c-description,      "Descrip. Operación
INSP_POINT_COMPLT_FLOW_VARIANT like BAPI1012_OPR_C-INSP_POINT_COMPLT_FLOW_VARIANT, "Variante de Proceso
+
        insp_point_complt_flow_variant LIKE bapi1012_opr_c-insp_point_complt_flow_variant, "Variante de Proceso
TIME_GRID like BAPI1012_OPR_C-TIME_GRID,          "Secuencial Hora
+
        time_grid                      LIKE bapi1012_opr_c-time_grid,          "Secuencial Hora
TIME_FACTOR like BAPI1012_OPR_C-TIME_FACTOR,      " Factor de Tiempo
+
        time_factor                    LIKE bapi1012_opr_c-time_factor,      " Factor de Tiempo
TIME_UNIT like BAPI1012_OPR_C-TIME_UNIT,          "Unidad de Tiempo
+
        time_unit                      LIKE bapi1012_opr_c-time_unit,          "Unidad de Tiempo
  DENOMINATOR like BAPI1012_OPR_C-DENOMINATOR,
+
        denominator                    LIKE bapi1012_opr_c-denominator,
NOMINATOR    like BAPI1012_OPR_C-NOMINATOR,
+
        nominator                      LIKE bapi1012_opr_c-nominator,
base_quantity like BAPI1012_OPR_C-base_quantity,
+
        base_quantity                 LIKE bapi1012_opr_c-base_quantity,
  end of gs_data_operacion.
+
      END OF gs_data_operacion.
  
data: begin of gs_data_cha,
+
DATA: BEGIN OF gs_data_cha,
MATERIAL like BAPI1012_MTK_C-MATERIAL,            "Material
+
        material            LIKE bapi1012_mtk_c-material,            "Material
PLANT like BAPI1012_MTK_C-PLANT,                  "Centro
+
        plant                LIKE bapi1012_mtk_c-plant,                  "Centro
TASK_LIST_GROUP like BAPI1012_TSK_C-TASK_LIST_GROUP, "Grp. Hoja de Ruta
+
        task_list_group      LIKE bapi1012_tsk_c-task_list_group, "Grp. Hoja de Ruta
GROUP_COUNTER like BAPI1012_TSK_C-GROUP_COUNTER,  "Contador
+
        group_counter        LIKE bapi1012_tsk_c-group_counter,  "Contador
ACTIVITY like BAPI1012_OPR_C-ACTIVITY,            "Numero de Operacion
+
        activity            LIKE bapi1012_opr_c-activity,            "Numero de Operacion
INSPCHAR like BAPI1012_CHA_C-INSPCHAR,            "Numero de Caracteristica
+
        inspchar            LIKE bapi1012_cha_c-inspchar,            "Numero de Caracteristica
CHAR_DESCR like BAPI1012_CHA_C-CHAR_DESCR,
+
        char_descr          LIKE bapi1012_cha_c-char_descr,
MSTR_CHAR like BAPI1012_CHA_C-MSTR_CHAR,          "Caracteristica
+
        mstr_char            LIKE bapi1012_cha_c-mstr_char,          "Caracteristica
SMPL_PROCEDURE like BAPI1012_CHA_C-SMPL_PROCEDURE,"Procedimiento
+
        smpl_procedure      LIKE bapi1012_cha_c-smpl_procedure, "Procedimiento
SMPL_UNIT like BAPI1012_CHA_C-SMPL_UNIT,          "Unidad de Medida
+
        smpl_unit            LIKE bapi1012_cha_c-smpl_unit,          "Unidad de Medida
SMPL_QUANT like BAPI1012_CHA_C-SMPL_QUANT,        "Cantidad para muestra
+
        smpl_quant          LIKE bapi1012_cha_c-smpl_quant,        "Cantidad para muestra
DYN_MODIF_RULE like BAPI1012_CHA_C-DYN_MODIF_RULE,"Regla Dinamizacion
+
        dyn_modif_rule      LIKE bapi1012_cha_c-dyn_modif_rule, "Regla Dinamizacion
SPC_CRITERION_KEY like BAPI1012_CHA_C-SPC_CRITERION_KEY,"Criterio SPC
+
        spc_criterion_key    LIKE bapi1012_cha_c-spc_criterion_key, "Criterio SPC
UP_TOL_LMT like BAPI1012_CHA_C-UP_TOL_LMT,        "Tolerancia Superior
+
        up_tol_lmt          LIKE bapi1012_cha_c-up_tol_lmt,        "Tolerancia Superior
LW_TOL_LMT like BAPI1012_CHA_C-LW_TOL_LMT,        "Tolerancia Inferior
+
        lw_tol_lmt          LIKE bapi1012_cha_c-lw_tol_lmt,        "Tolerancia Inferior
FORMULA_CHECK_BY_SAP like BAPI1012_CHA_C-FORMULA_CHECK_BY_SAP,
+
        formula_check_by_sap LIKE bapi1012_cha_c-formula_check_by_sap,
FORMULA_FIELD_1 like BAPI1012_CHA_C-FORMULA_FIELD_1,
+
        formula_field_1      LIKE bapi1012_cha_c-formula_field_1,
FORMULA_FIELD_2 like BAPI1012_CHA_C-FORMULA_FIELD_2,
+
        formula_field_2      LIKE bapi1012_cha_c-formula_field_2,
END OF gs_data_cha.
+
      END OF gs_data_cha.
  
data gt_data_material like table of gs_data_material.
+
DATA gt_data_material LIKE TABLE OF gs_data_material.
data gt_data_operacion like table of gs_data_operacion.
+
DATA gt_data_operacion LIKE TABLE OF gs_data_operacion.
data gt_data_cha like table of gs_data_cha.
+
DATA gt_data_cha LIKE TABLE OF gs_data_cha.
  
 +
DATA decstel(2) TYPE c.
  
data DECSTEL(2) TYPE C.
+
DATA gd_tfile TYPE ibipparms-path.
  
data gd_tfile type IBIPPARMS-PATH.
+
TYPES: BEGIN OF ty_log,
 +
        material        LIKE bapi1012_mtk_c-material,            "Material
 +
        plant          LIKE bapi1012_mtk_c-plant,                  "Centro
 +
        task_list_group LIKE bapi1012_tsk_c-task_list_group, "Grp. Hoja de Ruta
 +
        group_counter  LIKE bapi1012_tsk_c-group_counter,  "Contador
 +
        type           TYPE bapi_mtype,
 +
        message        TYPE bapi_msg,
 +
      END OF ty_log.
  
types: begin of ty_log,
+
DATA gt_log TYPE TABLE OF ty_log.
MATERIAL like BAPI1012_MTK_C-MATERIAL,            "Material
+
DATA gs_log LIKE LINE OF gt_log.
PLANT like BAPI1012_MTK_C-PLANT,                  "Centro
 
TASK_LIST_GROUP like BAPI1012_TSK_C-TASK_LIST_GROUP, "Grp. Hoja de Ruta
 
GROUP_COUNTER like BAPI1012_TSK_C-GROUP_COUNTER,  "Contador
 
        type type BAPI_MTYPE,
 
        message type BAPI_MSG,
 
end of ty_log.
 
  
data gt_log type TABLE OF ty_log.
 
data gs_log like LINE OF gt_log.
 
 
*alv data
 
data gr_table  type ref to cl_salv_table.
 
data: gr_selections type ref to cl_salv_selections,
 
      gt_rows      type salv_t_row.
 
data: gr_functions type ref to cl_salv_functions_list.
 
 
*--------------------------------------------------------------------*
 
*--------------------------------------------------------------------*
 
*--------------------------------------------------------------------*
 
*--------------------------------------------------------------------*
PARAMETERS: p_file type string LOWER CASe OBLIGATORY,
+
PARAMETERS: p_file TYPE string LOWER CASE OBLIGATORY,
             p_test type BAPIFLAG DEFAULT 'X'.
+
             p_test TYPE bapiflag DEFAULT 'X'.
  
 
*--------------------------------------------------------------------*
 
*--------------------------------------------------------------------*
at selection-screen on value-request for p_file.
+
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
 
*--------------------------------------------------------------------*
 
*--------------------------------------------------------------------*
 
   gd_tfile = p_file.
 
   gd_tfile = p_file.
  
   call function 'F4_FILENAME'
+
   CALL FUNCTION 'F4_FILENAME'
 
     EXPORTING
 
     EXPORTING
 
       field_name = 'P_FILE'
 
       field_name = 'P_FILE'
Line 137: Line 131:
 
       file_name  = gd_tfile.
 
       file_name  = gd_tfile.
  
   move gd_tfile to p_file.
+
   MOVE gd_tfile TO p_file.
 
*--------------------------------------------------------------------*
 
*--------------------------------------------------------------------*
 
START-OF-SELECTION.
 
START-OF-SELECTION.
Line 145: Line 139:
  
 
*--------------------------------------------------------------------*
 
*--------------------------------------------------------------------*
end-of-SELECTION.
+
END-OF-SELECTION.
 
*--------------------------------------------------------------------*
 
*--------------------------------------------------------------------*
   if gt_data[] is INITIAL.
+
   IF gt_data[] IS INITIAL.
     write:/ 'No se seleccionaron datos'.
+
     WRITE:/ 'No se seleccionaron datos'.
 
     RETURN.
 
     RETURN.
   endif.
+
   ENDIF.
  
 
   PERFORM crear_hoja_de_ruta.
 
   PERFORM crear_hoja_de_ruta.
Line 163: Line 157:
 
*  <--  p2        text
 
*  <--  p2        text
 
*----------------------------------------------------------------------*
 
*----------------------------------------------------------------------*
FORM get_task_list_group using i_change
+
FORM get_task_list_group USING i_change
                               gs_bapi_mtk type BAPI1012_MTK_C
+
                               gs_bapi_mtk TYPE bapi1012_mtk_c
                                 gs_bapi_tsk  type BAPI1012_TSK_C.
+
                                 gs_bapi_tsk  TYPE bapi1012_tsk_c.
  
 
   DATA: BEGIN OF ls_h,
 
   DATA: BEGIN OF ls_h,
Line 192: Line 186:
 
   DELETE lt_mtk_int WHERE loekz = 'X'.
 
   DELETE lt_mtk_int WHERE loekz = 'X'.
 
*  IF gs_cntrl-flg_change_mode = const-flg_yes.
 
*  IF gs_cntrl-flg_change_mode = const-flg_yes.
   if i_change = 'X'.
+
   IF i_change = 'X'.
 
     DELETE lt_mtk_int WHERE plnal <> gs_bapi_mtk-group_counter.
 
     DELETE lt_mtk_int WHERE plnal <> gs_bapi_mtk-group_counter.
 
   ENDIF.
 
   ENDIF.
 
   DESCRIBE TABLE lt_mtk_int LINES ls_h-lin.
 
   DESCRIBE TABLE lt_mtk_int LINES ls_h-lin.
   IF ls_h-lin = 1 OR i_change is INITIAL.
+
   IF ls_h-lin = 1 OR i_change IS INITIAL.
 
     READ TABLE lt_mtk_int INTO ls_mtk_int INDEX 1.
 
     READ TABLE lt_mtk_int INTO ls_mtk_int INDEX 1.
 
     CHECK: sy-subrc = 0.
 
     CHECK: sy-subrc = 0.
Line 230: Line 224:
 
*      text
 
*      text
 
*----------------------------------------------------------------------*
 
*----------------------------------------------------------------------*
form crear_hoja_de_ruta.
+
FORM crear_hoja_de_ruta.
  
   data lt_MATERIALTASKALLOCATION type TABLE OF BAPI1012_MTK_C .
+
   DATA lt_materialtaskallocation TYPE TABLE OF bapi1012_mtk_c .
   data lt_task type TABLE OF BAPI1012_TSK_C.
+
   DATA lt_task TYPE TABLE OF bapi1012_tsk_c.
   data lt_OPERATION type TABLE OF BAPI1012_OPR_C.
+
   DATA lt_operation TYPE TABLE OF bapi1012_opr_c.
   data lt_INSPCHARACTERISTIC type TABLE OF BAPI1012_CHA_C.
+
   DATA lt_inspcharacteristic TYPE TABLE OF bapi1012_cha_c.
  
   data ls_MATERIALTASKALLOCATION type BAPI1012_MTK_C .
+
   DATA ls_materialtaskallocation TYPE bapi1012_mtk_c .
   data ls_task type BAPI1012_TSK_C.
+
   DATA ls_task TYPE bapi1012_tsk_c.
   data ls_OPERATION type BAPI1012_OPR_C.
+
   DATA ls_operation TYPE bapi1012_opr_c.
   data ls_INSPCHARACTERISTIC type BAPI1012_CHA_C.
+
   DATA ls_inspcharacteristic TYPE bapi1012_cha_c.
  
   data lt_return type TABLE OF bapiret2.
+
   DATA lt_return TYPE TABLE OF bapiret2.
   data ls_return like LINE OF lt_return.
+
   DATA ls_return LIKE LINE OF lt_return.
  
  
   loop at gt_data into gs_data.
+
   LOOP AT gt_data INTO gs_data.
     clear: gt_data_material[].
+
     CLEAR: gt_data_material[].
     clear: gt_data_operacion[].
+
     CLEAR: gt_data_operacion[].
     clear: gt_data_cha[].
+
     CLEAR: gt_data_cha[].
  
 
     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
 
     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
 
       EXPORTING
 
       EXPORTING
         INPUT = gs_data-GROUP_COUNTER
+
         input = gs_data-group_counter
 
       IMPORTING
 
       IMPORTING
         OUTPUT = gs_data-GROUP_COUNTER.
+
         output = gs_data-group_counter.
  
 
     CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
 
     CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
 
       EXPORTING
 
       EXPORTING
         INPUT       = gs_data-MATERIAL
+
         input       = gs_data-material
 
       IMPORTING
 
       IMPORTING
         OUTPUT       = gs_data-MATERIAL
+
         output       = gs_data-material
 
       EXCEPTIONS
 
       EXCEPTIONS
         LENGTH_ERROR = 1
+
         length_error = 1
 
         OTHERS      = 2.
 
         OTHERS      = 2.
     IF SY-SUBRC <> 0.
+
     IF sy-subrc <> 0.
       clear gs_data-MATERIAL.
+
       CLEAR gs_data-material.
 
     ENDIF.
 
     ENDIF.
  
 
     CALL FUNCTION 'CONVERSION_EXIT_NUMCV_INPUT'
 
     CALL FUNCTION 'CONVERSION_EXIT_NUMCV_INPUT'
 
       EXPORTING
 
       EXPORTING
         INPUT = gs_data-ACTIVITY
+
         input = gs_data-activity
 
       IMPORTING
 
       IMPORTING
         OUTPUT = gs_data-ACTIVITY.
+
         output = gs_data-activity.
  
     MOVE-CORRESPONDING gs_data to gs_data_material.
+
     MOVE-CORRESPONDING gs_data TO gs_data_material.
     MOVE-CORRESPONDING gs_data to gs_data_operacion.
+
     MOVE-CORRESPONDING gs_data TO gs_data_operacion.
     MOVE-CORRESPONDING gs_data to gs_data_cha.
+
     MOVE-CORRESPONDING gs_data TO gs_data_cha.
  
     append gs_data_material to gt_data_material.
+
     APPEND gs_data_material TO gt_data_material.
     append gs_data_operacion to gt_data_operacion.
+
     APPEND gs_data_operacion TO gt_data_operacion.
     append gs_data_cha to gt_data_cha.
+
     APPEND gs_data_cha TO gt_data_cha.
 
*  ENDLOOP.
 
*  ENDLOOP.
  
  
     loop at gt_data_material into gs_data_material.
+
     LOOP AT gt_data_material INTO gs_data_material.
       clear: lt_OPERATION[],
+
       CLEAR: lt_operation[],
             lt_INSPCHARACTERISTIC[],
+
             lt_inspcharacteristic[],
             lt_MATERIALTASKALLOCATION[],
+
             lt_materialtaskallocation[],
 
             lt_task[],
 
             lt_task[],
 
             lt_return[].
 
             lt_return[].
Line 295: Line 289:
 
*    gs_data-GROUP_COUNTER = 2.
 
*    gs_data-GROUP_COUNTER = 2.
  
       MOVE-CORRESPONDING gs_data to ls_MATERIALTASKALLOCATION.
+
       MOVE-CORRESPONDING gs_data TO ls_materialtaskallocation.
       if ls_MATERIALTASKALLOCATION-MATERIAL is NOT INITIAL.
+
       IF ls_materialtaskallocation-material IS NOT INITIAL.
         append ls_MATERIALTASKALLOCATION to lt_MATERIALTASKALLOCATION.
+
         APPEND ls_materialtaskallocation TO lt_materialtaskallocation.
       endif.
+
       ENDIF.
  
       MOVE-CORRESPONDING gs_data to ls_task.
+
       MOVE-CORRESPONDING gs_data TO ls_task.
       ls_task-TASK_LIST_USAGE = '1'.
+
       ls_task-task_list_usage = '1'.
       ls_task-TASK_LIST_STATUS = '4'.
+
       ls_task-task_list_status = '4'.
  
 
       ls_task-valid_from = sy-datum.
 
       ls_task-valid_from = sy-datum.
Line 308: Line 302:
  
 
*    ls_task-TASK_MEASURE_UNIT = 'KI'.  "CA
 
*    ls_task-TASK_MEASURE_UNIT = 'KI'.  "CA
       APPEND ls_task to lt_task.
+
       APPEND ls_task TO lt_task.
  
  
       loop at gt_data_operacion into gs_data_operacion where
+
       LOOP AT gt_data_operacion INTO gs_data_operacion WHERE
           MATERIAL =  gs_data_material-MATERIAL
+
           material =  gs_data_material-material
           and PLANT   = gs_data_material-plant
+
           AND plant   = gs_data_material-plant
           and TASK_LIST_GROUP = gs_data_material-TASK_LIST_GROUP
+
           AND task_list_group = gs_data_material-task_list_group
           and GROUP_COUNTER = gs_data_material-GROUP_COUNTER
+
           AND group_counter = gs_data_material-group_counter
         and ACTIVITY is NOT INITIAL.
+
         AND activity IS NOT INITIAL.
  
         ls_OPERATION-TASK_LIST_GROUP = gs_data_material-TASK_LIST_GROUP.
+
         ls_operation-task_list_group = gs_data_material-task_list_group.
         ls_OPERATION-GROUP_COUNTER   = gs_data_material-GROUP_COUNTER.
+
         ls_operation-group_counter   = gs_data_material-group_counter.
         ls_OPERATION-ACTIVITY = gs_data_operacion-ACTIVITY.
+
         ls_operation-activity = gs_data_operacion-activity.
         ls_OPERATION-WORK_CNTR = gs_data_operacion-WORK_CNTR.
+
         ls_operation-work_cntr = gs_data_operacion-work_cntr.
         ls_OPERATION-CONTROL_KEY = gs_data_operacion-CONTROL_KEY.
+
         ls_operation-control_key = gs_data_operacion-control_key.
         ls_OPERATION-DESCRIPTION = gs_data_operacion-DESCRIPTION.
+
         ls_operation-description = gs_data_operacion-description.
         ls_OPERATION-INSP_POINT_COMPLT_FLOW_VARIANT = gs_data_operacion-INSP_POINT_COMPLT_FLOW_VARIANT.
+
         ls_operation-insp_point_complt_flow_variant = gs_data_operacion-insp_point_complt_flow_variant.
         ls_OPERATION-TIME_GRID = gs_data_operacion-TIME_GRID.
+
         ls_operation-time_grid = gs_data_operacion-time_grid.
         ls_OPERATION-TIME_FACTOR = gs_data_operacion-TIME_FACTOR.
+
         ls_operation-time_factor = gs_data_operacion-time_factor.
         ls_OPERATION-TIME_UNIT = gs_data_operacion-TIME_UNIT.
+
         ls_operation-time_unit = gs_data_operacion-time_unit.
         ls_OPERATION-DENOMINATOR = gs_data_operacion-DENOMINATOR.
+
         ls_operation-denominator = gs_data_operacion-denominator.
         ls_OPERATION-NOMINATOR   = gs_data_operacion-NOMINATOR.
+
         ls_operation-nominator   = gs_data_operacion-nominator.
         ls_OPERATION-base_quantity = gs_data_operacion-base_quantity.
+
         ls_operation-base_quantity = gs_data_operacion-base_quantity.
  
         append ls_OPERATION to lt_OPERATION.
+
         APPEND ls_operation TO lt_operation.
  
         loop at gt_data_cha into gs_data_cha where
+
         LOOP AT gt_data_cha INTO gs_data_cha WHERE
                 MATERIAL =  gs_data_material-MATERIAL
+
                 material =  gs_data_material-material
                 and PLANT   = gs_data_material-plant
+
                 AND plant   = gs_data_material-plant
                 and TASK_LIST_GROUP = gs_data_material-TASK_LIST_GROUP
+
                 AND task_list_group = gs_data_material-task_list_group
                 and GROUP_COUNTER = gs_data_material-GROUP_COUNTER
+
                 AND group_counter = gs_data_material-group_counter
                 and ACTIVITY = gs_data_operacion-ACTIVITY
+
                 AND activity = gs_data_operacion-activity
                 and INSPCHAR is NOT INITIAL.
+
                 AND inspchar IS NOT INITIAL.
  
           ls_INSPCHARACTERISTIC-TASK_LIST_GROUP = gs_data_material-TASK_LIST_GROUP.
+
           ls_inspcharacteristic-task_list_group = gs_data_material-task_list_group.
           ls_INSPCHARACTERISTIC-GROUP_COUNTER   = gs_data_material-GROUP_COUNTER.
+
           ls_inspcharacteristic-group_counter   = gs_data_material-group_counter.
           ls_INSPCHARACTERISTIC-ACTIVITY = gs_data_cha-ACTIVITY.
+
           ls_inspcharacteristic-activity = gs_data_cha-activity.
           ls_INSPCHARACTERISTIC-INSPCHAR = gs_data_cha-INSPCHAR.
+
           ls_inspcharacteristic-inspchar = gs_data_cha-inspchar.
           ls_INSPCHARACTERISTIC-MSTR_CHAR = gs_data_cha-MSTR_CHAR.
+
           ls_inspcharacteristic-mstr_char = gs_data_cha-mstr_char.
           ls_INSPCHARACTERISTIC-SMPL_PROCEDURE = gs_data_cha-SMPL_PROCEDURE.
+
           ls_inspcharacteristic-smpl_procedure = gs_data_cha-smpl_procedure.
           ls_INSPCHARACTERISTIC-SMPL_UNIT = gs_data_cha-SMPL_UNIT.
+
           ls_inspcharacteristic-smpl_unit = gs_data_cha-smpl_unit.
           ls_INSPCHARACTERISTIC-SMPL_QUANT = gs_data_cha-SMPL_QUANT.
+
           ls_inspcharacteristic-smpl_quant = gs_data_cha-smpl_quant.
           ls_INSPCHARACTERISTIC-DYN_MODIF_RULE = gs_data_cha-DYN_MODIF_RULE.
+
           ls_inspcharacteristic-dyn_modif_rule = gs_data_cha-dyn_modif_rule.
           ls_INSPCHARACTERISTIC-SPC_CRITERION_KEY = gs_data_cha-SPC_CRITERION_KEY .
+
           ls_inspcharacteristic-spc_criterion_key = gs_data_cha-spc_criterion_key .
           ls_INSPCHARACTERISTIC-UP_TOL_LMT = gs_data_cha-UP_TOL_LMT.
+
           ls_inspcharacteristic-up_tol_lmt = gs_data_cha-up_tol_lmt.
           ls_INSPCHARACTERISTIC-LW_TOL_LMT = gs_data_cha-LW_TOL_LMT.
+
           ls_inspcharacteristic-lw_tol_lmt = gs_data_cha-lw_tol_lmt.
           ls_INSPCHARACTERISTIC-FORMULA_CHECK_BY_SAP = gs_data_cha-FORMULA_CHECK_BY_SAP.
+
           ls_inspcharacteristic-formula_check_by_sap = gs_data_cha-formula_check_by_sap.
           ls_INSPCHARACTERISTIC-FORMULA_FIELD_1 = gs_data_cha-FORMULA_FIELD_1 .
+
           ls_inspcharacteristic-formula_field_1 = gs_data_cha-formula_field_1 .
           ls_INSPCHARACTERISTIC-FORMULA_FIELD_2 = gs_data_cha-FORMULA_FIELD_2 .
+
           ls_inspcharacteristic-formula_field_2 = gs_data_cha-formula_field_2 .
           ls_INSPCHARACTERISTIC-CHAR_DESCR = gs_data_cha-CHAR_DESCR.
+
           ls_inspcharacteristic-char_descr = gs_data_cha-char_descr.
  
           append ls_INSPCHARACTERISTIC to lt_INSPCHARACTERISTIC.
+
           APPEND ls_inspcharacteristic TO lt_inspcharacteristic.
  
         endloop.
+
         ENDLOOP.
  
       endloop.
+
       ENDLOOP.
  
 
*    MOVE-CORRESPONDING gs_data to ls_OPERATION.
 
*    MOVE-CORRESPONDING gs_data to ls_OPERATION.
Line 370: Line 364:
 
*    APPEND ls_INSPCHARACTERISTIC to lt_INSPCHARACTERISTIC.
 
*    APPEND ls_INSPCHARACTERISTIC to lt_INSPCHARACTERISTIC.
  
       data ld_testrun TYPE  BAPIFLAG.
+
       DATA ld_testrun TYPE  bapiflag.
  
 
       ld_testrun = 'X'.
 
       ld_testrun = 'X'.
  
       data ld_BOMUSAGE type BAPI1012_CONTROL_DATA-BOM_USAGE .
+
       DATA ld_bomusage TYPE bapi1012_control_data-bom_usage .
  
       ld_BOMUSAGE = '1'. "fabricacion
+
       ld_bomusage = '1'. "fabricacion
  
 
       CALL FUNCTION 'BAPI_ROUTING_CREATE'
 
       CALL FUNCTION 'BAPI_ROUTING_CREATE'
      EXPORTING
+
        EXPORTING
        TESTRUN                      = p_test
+
          testrun                = p_test
*   PROFILE                     =
+
*         PROFILE               =
        BOMUSAGE                    = ld_BOMUSAGE
+
          bomusage              = ld_bomusage
*   APPLICATION                 =
+
*         APPLICATION           =
 
* IMPORTING
 
* IMPORTING
*   GROUP                       =
+
*         GROUP                 =
*   GROUPCOUNTER                 =
+
*         GROUPCOUNTER           =
 
         TABLES
 
         TABLES
          TASK                        = lt_task
+
          task                  = lt_task
          MATERIALTASKALLOCATION      = lt_MATERIALTASKALLOCATION
+
          materialtaskallocation = lt_materialtaskallocation
*   SEQUENCE                     =
+
*         SEQUENCE               =
          OPERATION                    = lt_OPERATION
+
          operation              = lt_operation
*   LENGTHCALCULATION           =
+
*         LENGTHCALCULATION     =
*   SUBOPERATION                 =
+
*         SUBOPERATION           =
*   REFERENCEOPERATION           =
+
*         REFERENCEOPERATION     =
*   WORKCENTERREFERENCE         =
+
*         WORKCENTERREFERENCE   =
*   COMPONENTALLOCATION         =
+
*         COMPONENTALLOCATION   =
*   PRODUCTIONRESOURCE           =
+
*         PRODUCTIONRESOURCE     =
          INSPCHARACTERISTIC           = lt_INSPCHARACTERISTIC
+
           inspcharacteristic    = lt_inspcharacteristic
*   TEXTALLOCATION               =
+
*         TEXTALLOCATION         =
*   TEXT                         =
+
*         TEXT                   =
          RETURN                      = lt_return
+
          return                = lt_return.
                  .
 
  
       MOVE-CORRESPONDING gs_data_material to gs_log.
+
       MOVE-CORRESPONDING gs_data_material TO gs_log.
       loop at lt_return into ls_return where type = 'E' or type = 'A'.
+
       LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'.
         MOVE-CORRESPONDING ls_return to gs_log.
+
         MOVE-CORRESPONDING ls_return TO gs_log.
         append gs_log to gt_log.
+
         APPEND gs_log TO gt_log.
       endloop.
+
       ENDLOOP.
  
       if sy-subrc <> 0.
+
       IF sy-subrc <> 0.
 
         CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
 
         CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
 
*    EXPORTING
 
*    EXPORTING
Line 416: Line 409:
 
*    IMPORTING
 
*    IMPORTING
 
*      RETURN        =
 
*      RETURN        =
                  .
+
          .
 
         gs_log-type = 'S'.
 
         gs_log-type = 'S'.
 
         gs_log-message = 'Hoja de ruta creada'.
 
         gs_log-message = 'Hoja de ruta creada'.
         append gs_log to gt_log.
+
         APPEND gs_log TO gt_log.
       endif.
+
       ENDIF.
 
*    BREAK-POINT.
 
*    BREAK-POINT.
 
     ENDLOOP.
 
     ENDLOOP.
Line 430: Line 423:
  
  
endform.                    "select_data
+
ENDFORM.                    "select_data
  
 
*&---------------------------------------------------------------------*
 
*&---------------------------------------------------------------------*
Line 437: Line 430:
 
*      text
 
*      text
 
*----------------------------------------------------------------------*
 
*----------------------------------------------------------------------*
form upload.
+
FORM upload.
  
 
   CALL FUNCTION 'GUI_UPLOAD'
 
   CALL FUNCTION 'GUI_UPLOAD'
 
     EXPORTING
 
     EXPORTING
       FILENAME               = p_file
+
       filename               = p_file
       FILETYPE               = 'DAT'
+
       filetype               = 'DAT'
 
     TABLES
 
     TABLES
       DATA_TAB               = gt_data
+
       data_tab               = gt_data
 
     EXCEPTIONS
 
     EXCEPTIONS
       FILE_OPEN_ERROR         = 1
+
       file_open_error         = 1
       FILE_READ_ERROR         = 2
+
       file_read_error         = 2
       NO_BATCH               = 3
+
       no_batch               = 3
       GUI_REFUSE_FILETRANSFER = 4
+
       gui_refuse_filetransfer = 4
       INVALID_TYPE           = 5
+
       invalid_type           = 5
       NO_AUTHORITY           = 6
+
       no_authority           = 6
       UNKNOWN_ERROR           = 7
+
       unknown_error           = 7
       BAD_DATA_FORMAT         = 8
+
       bad_data_format         = 8
       HEADER_NOT_ALLOWED     = 9
+
       header_not_allowed     = 9
       SEPARATOR_NOT_ALLOWED   = 10
+
       separator_not_allowed   = 10
       HEADER_TOO_LONG         = 11
+
       header_too_long         = 11
       UNKNOWN_DP_ERROR       = 12
+
       unknown_dp_error       = 12
       ACCESS_DENIED           = 13
+
       access_denied           = 13
       DP_OUT_OF_MEMORY       = 14
+
       dp_out_of_memory       = 14
       DISK_FULL               = 15
+
       disk_full               = 15
       DP_TIMEOUT             = 16
+
       dp_timeout             = 16
 
       OTHERS                  = 17.
 
       OTHERS                  = 17.
   IF SY-SUBRC <> 0.
+
   IF sy-subrc <> 0.
 
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
 
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
 
*        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 
*        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
Line 469: Line 462:
  
  
endform.                    "upload
+
ENDFORM.                    "upload
  
 
*&---------------------------------------------------------------------*
 
*&---------------------------------------------------------------------*
Line 479: Line 472:
 
*... Create Instance
 
*... Create Instance
 
   TRY.
 
   TRY.
    cl_salv_table=>factory( IMPORTING r_salv_table = DATA(gr_table)
+
      cl_salv_table=>factory( IMPORTING r_salv_table = DATA(gr_table)
                            CHANGING t_table = gt_log ).
+
                              CHANGING t_table = gt_log ).
 
     CATCH cx_salv_msg.
 
     CATCH cx_salv_msg.
 
   ENDTRY.
 
   ENDTRY.
  
 
*... Enable Generic ALV functions
 
*... Enable Generic ALV functions
   data(gr_functions) = gr_table->get_functions( ).
+
   DATA(gr_functions) = gr_table->get_functions( ).
 
**  gr_functions->set_default( ).
 
**  gr_functions->set_default( ).
 
   gr_functions->set_all( ).
 
   gr_functions->set_all( ).
  
   data(lr_columns) = gr_table->get_columns( ).
+
   DATA(lr_columns) = gr_table->get_columns( ).
 
 
* set column text
 
  TRY.
 
      data(lr_column) = lr_columns->get_column( 'EQUIPMENT_O' ).
 
      lr_column->set_long_text( 'Equipo Original' ).
 
      lr_column->set_medium_text( 'Equi.Ori.' ).
 
      lr_column->set_short_text( 'Equi.Ori.' ).
 
    CATCH cx_salv_not_found.
 
    CATCH cx_salv_existing.
 
    CATCH cx_salv_data_error.
 
  ENDTRY.
 
  
 
*... Display table
 
*... Display table

Latest revision as of 16:00, 5 April 2020

*&---------------------------------------------------------------------*
*& Report  ZPP_CREAR_HR
*&
*&---------------------------------------------------------------------*
*& Descripcion   : Creación de Hojas de Ruta (CA01)
*&---------------------------------------------------------------------*

REPORT  zpp_crear_hr.
*--------------------------------------------------------------------*
TYPE-POOLS : slis.

DATA: BEGIN OF gs_data,
        material                       LIKE bapi1012_mtk_c-material,         "Material
        plant                          LIKE bapi1012_mtk_c-plant,            "Centro
        task_list_group                LIKE bapi1012_tsk_c-task_list_group,  "Grp. Hoja de Ruta
        group_counter                  LIKE bapi1012_tsk_c-group_counter,    "Contador
        ident_key                      LIKE bapi1012_tsk_c-ident_key,        "Pto. Inspección
        insppoint_partiallot_assgnmt   LIKE bapi1012_tsk_c-insppoint_partiallot_assgnmt, "Datos Parciales
        dyn_modif_level                LIKE bapi1012_tsk_c-dyn_modif_level,  "Nivel Dinamizacion
        activity                       LIKE bapi1012_opr_c-activity,         "Numero de Operacion
        work_cntr                      LIKE bapi1012_opr_c-work_cntr,        "Puesto de Trabajo
        control_key                    LIKE bapi1012_opr_c-control_key,      "Clave de Control
        description                    LIKE bapi1012_opr_c-description,      "Descrip. Operación
        insp_point_complt_flow_variant LIKE bapi1012_opr_c-insp_point_complt_flow_variant, "Variante de Proceso
        time_grid                      LIKE bapi1012_opr_c-time_grid,        "Secuencial Hora
        time_factor                    LIKE bapi1012_opr_c-time_factor,      " Factor de Tiempo
        time_unit                      LIKE bapi1012_opr_c-time_unit,        "Unidad de Tiempo
        denominator                    LIKE bapi1012_opr_c-denominator,      "Denominador para conversión u.medida hoja ruta y operación
        nominator                      LIKE bapi1012_opr_c-nominator,        "Contador para conversión u.medida hoja de ruta y operación
        base_quantity                  LIKE bapi1012_opr_c-base_quantity,    "Cantidad base
        inspchar                       LIKE bapi1012_cha_c-inspchar,         "Numero de Caracteristica
        char_descr                     LIKE bapi1012_cha_c-char_descr,       "Texto breve para característica inspección
        mstr_char                      LIKE bapi1012_cha_c-mstr_char,        "Caracteristica
        smpl_procedure                 LIKE bapi1012_cha_c-smpl_procedure,   "Procedimiento
        smpl_unit                      LIKE bapi1012_cha_c-smpl_unit,        "Unidad de Medida
        smpl_quant                     LIKE bapi1012_cha_c-smpl_quant,       "Cantidad para muestra
        dyn_modif_rule                 LIKE bapi1012_cha_c-dyn_modif_rule,   "Regla Dinamizacion
        spc_criterion_key              LIKE bapi1012_cha_c-spc_criterion_key, "Criterio SPC
        up_tol_lmt                     LIKE bapi1012_cha_c-up_tol_lmt,        "Tolerancia Superior
        lw_tol_lmt                     LIKE bapi1012_cha_c-lw_tol_lmt,        "Tolerancia Inferior
        formula_check_by_sap           LIKE bapi1012_cha_c-formula_check_by_sap, "Verificar y calcular fórmula en QM
        formula_field_1                LIKE bapi1012_cha_c-formula_field_1,
        formula_field_2                LIKE bapi1012_cha_c-formula_field_2,
        task_measure_unit              LIKE bapi1012_tsk_c-task_measure_unit,
      END OF gs_data.
DATA gt_data LIKE TABLE OF gs_data.

DATA: BEGIN OF gs_data_material,
        material                     LIKE bapi1012_mtk_c-material,            "Material
        plant                        LIKE bapi1012_mtk_c-plant,                  "Centro
        task_list_group              LIKE bapi1012_tsk_c-task_list_group, "Grp. Hoja de Ruta
        group_counter                LIKE bapi1012_tsk_c-group_counter,  "Contador
        ident_key                    LIKE bapi1012_tsk_c-ident_key,          "Pto. Inspección
        insppoint_partiallot_assgnmt LIKE bapi1012_tsk_c-insppoint_partiallot_assgnmt, "Datos Parciales
        dyn_modif_level              LIKE bapi1012_tsk_c-dyn_modif_level, "Nivel Dinamizacion
      END OF gs_data_material.

DATA: BEGIN OF gs_data_operacion,
        material                       LIKE bapi1012_mtk_c-material,            "Material
        plant                          LIKE bapi1012_mtk_c-plant,                  "Centro
        task_list_group                LIKE bapi1012_tsk_c-task_list_group, "Grp. Hoja de Ruta
        group_counter                  LIKE bapi1012_tsk_c-group_counter,  "Contador
        activity                       LIKE bapi1012_opr_c-activity,            "Numero de Operacion
        work_cntr                      LIKE bapi1012_opr_c-work_cntr,          "Puesto de Trabajo
        control_key                    LIKE bapi1012_opr_c-control_key,      "Clave de Control
        description                    LIKE bapi1012_opr_c-description,      "Descrip. Operación
        insp_point_complt_flow_variant LIKE bapi1012_opr_c-insp_point_complt_flow_variant, "Variante de Proceso
        time_grid                      LIKE bapi1012_opr_c-time_grid,          "Secuencial Hora
        time_factor                    LIKE bapi1012_opr_c-time_factor,      " Factor de Tiempo
        time_unit                      LIKE bapi1012_opr_c-time_unit,          "Unidad de Tiempo
        denominator                    LIKE bapi1012_opr_c-denominator,
        nominator                      LIKE bapi1012_opr_c-nominator,
        base_quantity                  LIKE bapi1012_opr_c-base_quantity,
      END OF gs_data_operacion.

DATA: BEGIN OF gs_data_cha,
        material             LIKE bapi1012_mtk_c-material,            "Material
        plant                LIKE bapi1012_mtk_c-plant,                  "Centro
        task_list_group      LIKE bapi1012_tsk_c-task_list_group, "Grp. Hoja de Ruta
        group_counter        LIKE bapi1012_tsk_c-group_counter,  "Contador
        activity             LIKE bapi1012_opr_c-activity,            "Numero de Operacion
        inspchar             LIKE bapi1012_cha_c-inspchar,            "Numero de Caracteristica
        char_descr           LIKE bapi1012_cha_c-char_descr,
        mstr_char            LIKE bapi1012_cha_c-mstr_char,          "Caracteristica
        smpl_procedure       LIKE bapi1012_cha_c-smpl_procedure, "Procedimiento
        smpl_unit            LIKE bapi1012_cha_c-smpl_unit,          "Unidad de Medida
        smpl_quant           LIKE bapi1012_cha_c-smpl_quant,        "Cantidad para muestra
        dyn_modif_rule       LIKE bapi1012_cha_c-dyn_modif_rule, "Regla Dinamizacion
        spc_criterion_key    LIKE bapi1012_cha_c-spc_criterion_key, "Criterio SPC
        up_tol_lmt           LIKE bapi1012_cha_c-up_tol_lmt,        "Tolerancia Superior
        lw_tol_lmt           LIKE bapi1012_cha_c-lw_tol_lmt,        "Tolerancia Inferior
        formula_check_by_sap LIKE bapi1012_cha_c-formula_check_by_sap,
        formula_field_1      LIKE bapi1012_cha_c-formula_field_1,
        formula_field_2      LIKE bapi1012_cha_c-formula_field_2,
      END OF gs_data_cha.

DATA gt_data_material LIKE TABLE OF gs_data_material.
DATA gt_data_operacion LIKE TABLE OF gs_data_operacion.
DATA gt_data_cha LIKE TABLE OF gs_data_cha.

DATA decstel(2) TYPE c.

DATA gd_tfile TYPE ibipparms-path.

TYPES: BEGIN OF ty_log,
         material        LIKE bapi1012_mtk_c-material,            "Material
         plant           LIKE bapi1012_mtk_c-plant,                  "Centro
         task_list_group LIKE bapi1012_tsk_c-task_list_group, "Grp. Hoja de Ruta
         group_counter   LIKE bapi1012_tsk_c-group_counter,  "Contador
         type            TYPE bapi_mtype,
         message         TYPE bapi_msg,
       END OF ty_log.

DATA gt_log TYPE TABLE OF ty_log.
DATA gs_log LIKE LINE OF gt_log.

*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
PARAMETERS: p_file TYPE string LOWER CASE OBLIGATORY,
            p_test TYPE bapiflag DEFAULT 'X'.

*--------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*--------------------------------------------------------------------*
  gd_tfile = p_file.

  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = gd_tfile.

  MOVE gd_tfile TO p_file.
*--------------------------------------------------------------------*
START-OF-SELECTION.
*--------------------------------------------------------------------*

  PERFORM upload.

*--------------------------------------------------------------------*
END-OF-SELECTION.
*--------------------------------------------------------------------*
  IF gt_data[] IS INITIAL.
    WRITE:/ 'No se seleccionaron datos'.
    RETURN.
  ENDIF.

  PERFORM crear_hoja_de_ruta.

  PERFORM display_log.
*&---------------------------------------------------------------------*
*&      Form  get_task_list_group
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_task_list_group USING i_change
                               gs_bapi_mtk TYPE bapi1012_mtk_c
                                gs_bapi_tsk  TYPE bapi1012_tsk_c.

  DATA: BEGIN OF ls_h,
          valid_to TYPE sydatum,
          lin      TYPE i,
        END OF ls_h,
        ls_mtk_int TYPE maplb,
        lt_mtk_int TYPE TABLE OF maplb,
        ls_tsk_int TYPE plko.

  ls_h-valid_to = sy-datum.
* read material task allocation
  CALL FUNCTION 'CP_DB_MAPL_READ'
    EXPORTING
      datub      = ls_h-valid_to
      datuv      = gs_bapi_mtk-valid_from
      matnr      = gs_bapi_mtk-material
      werks      = gs_bapi_mtk-plant
    TABLES
      matpl      = lt_mtk_int
    EXCEPTIONS
      no_records = 1
      OTHERS     = 2.
  CHECK: sy-subrc = 0.
* delete deleted material task allocations
  DELETE lt_mtk_int WHERE loekz = 'X'.
*  IF gs_cntrl-flg_change_mode = const-flg_yes.
  IF i_change = 'X'.
    DELETE lt_mtk_int WHERE plnal <> gs_bapi_mtk-group_counter.
  ENDIF.
  DESCRIBE TABLE lt_mtk_int LINES ls_h-lin.
  IF ls_h-lin = 1 OR i_change IS INITIAL.
    READ TABLE lt_mtk_int INTO ls_mtk_int INDEX 1.
    CHECK: sy-subrc = 0.
*    gs_cntrl-task_list_group = ls_mtk_int-plnnr.
  ELSE.
    SORT lt_mtk_int BY datuv DESCENDING.
    LOOP AT lt_mtk_int INTO ls_mtk_int.
* read task list header
      CALL FUNCTION 'CI03_READ_PLKO'
        EXPORTING
          i_plnty         = ls_mtk_int-plnty
          i_plnnr         = ls_mtk_int-plnnr
          i_plnal         = ls_mtk_int-plnal
          i_date          = ls_mtk_int-datuv
        IMPORTING
          e_plko          = ls_tsk_int
        EXCEPTIONS
          tl_not_existent = 1
          tl_not_valid    = 2
          OTHERS          = 3.
      CHECK: sy-subrc = 0.
      IF ls_tsk_int-verwe = gs_bapi_tsk-task_list_usage.
*        gs_cntrl-task_list_group = ls_tsk_int-plnnr.
        EXIT.
      ENDIF.
    ENDLOOP.
  ENDIF.

ENDFORM.                    " get_task_list_group
*&---------------------------------------------------------------------*
*&      Form  select_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM crear_hoja_de_ruta.

  DATA lt_materialtaskallocation TYPE TABLE OF bapi1012_mtk_c .
  DATA lt_task TYPE TABLE OF bapi1012_tsk_c.
  DATA lt_operation TYPE TABLE OF bapi1012_opr_c.
  DATA lt_inspcharacteristic TYPE TABLE OF bapi1012_cha_c.

  DATA ls_materialtaskallocation TYPE bapi1012_mtk_c .
  DATA ls_task TYPE bapi1012_tsk_c.
  DATA ls_operation TYPE bapi1012_opr_c.
  DATA ls_inspcharacteristic TYPE bapi1012_cha_c.

  DATA lt_return TYPE TABLE OF bapiret2.
  DATA ls_return LIKE LINE OF lt_return.


  LOOP AT gt_data INTO gs_data.
    CLEAR: gt_data_material[].
    CLEAR: gt_data_operacion[].
    CLEAR: gt_data_cha[].

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = gs_data-group_counter
      IMPORTING
        output = gs_data-group_counter.

    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
      EXPORTING
        input        = gs_data-material
      IMPORTING
        output       = gs_data-material
      EXCEPTIONS
        length_error = 1
        OTHERS       = 2.
    IF sy-subrc <> 0.
      CLEAR gs_data-material.
    ENDIF.

    CALL FUNCTION 'CONVERSION_EXIT_NUMCV_INPUT'
      EXPORTING
        input  = gs_data-activity
      IMPORTING
        output = gs_data-activity.

    MOVE-CORRESPONDING gs_data TO gs_data_material.
    MOVE-CORRESPONDING gs_data TO gs_data_operacion.
    MOVE-CORRESPONDING gs_data TO gs_data_cha.

    APPEND gs_data_material TO gt_data_material.
    APPEND gs_data_operacion TO gt_data_operacion.
    APPEND gs_data_cha TO gt_data_cha.
*  ENDLOOP.


    LOOP AT gt_data_material INTO gs_data_material.
      CLEAR: lt_operation[],
             lt_inspcharacteristic[],
             lt_materialtaskallocation[],
             lt_task[],
             lt_return[].

*    clear gs_data-TASK_LIST_GROUP.
*    gs_data-GROUP_COUNTER = 2.

      MOVE-CORRESPONDING gs_data TO ls_materialtaskallocation.
      IF ls_materialtaskallocation-material IS NOT INITIAL.
        APPEND ls_materialtaskallocation TO lt_materialtaskallocation.
      ENDIF.

      MOVE-CORRESPONDING gs_data TO ls_task.
      ls_task-task_list_usage = '1'.
      ls_task-task_list_status = '4'.

      ls_task-valid_from = sy-datum.
      ls_task-valid_to_date = '99991231'.

*    ls_task-TASK_MEASURE_UNIT = 'KI'.  "CA
      APPEND ls_task TO lt_task.


      LOOP AT gt_data_operacion INTO gs_data_operacion WHERE
           material =  gs_data_material-material
           AND plant    = gs_data_material-plant
           AND task_list_group = gs_data_material-task_list_group
           AND group_counter  = gs_data_material-group_counter
        AND activity IS NOT INITIAL.

        ls_operation-task_list_group = gs_data_material-task_list_group.
        ls_operation-group_counter   = gs_data_material-group_counter.
        ls_operation-activity = gs_data_operacion-activity.
        ls_operation-work_cntr  = gs_data_operacion-work_cntr.
        ls_operation-control_key  = gs_data_operacion-control_key.
        ls_operation-description  = gs_data_operacion-description.
        ls_operation-insp_point_complt_flow_variant  = gs_data_operacion-insp_point_complt_flow_variant.
        ls_operation-time_grid  = gs_data_operacion-time_grid.
        ls_operation-time_factor  = gs_data_operacion-time_factor.
        ls_operation-time_unit  = gs_data_operacion-time_unit.
        ls_operation-denominator  = gs_data_operacion-denominator.
        ls_operation-nominator   = gs_data_operacion-nominator.
        ls_operation-base_quantity = gs_data_operacion-base_quantity.

        APPEND ls_operation TO lt_operation.

        LOOP AT gt_data_cha INTO gs_data_cha WHERE
                 material =  gs_data_material-material
                 AND plant    = gs_data_material-plant
                 AND task_list_group = gs_data_material-task_list_group
                 AND group_counter  = gs_data_material-group_counter
                 AND activity = gs_data_operacion-activity
                 AND inspchar IS NOT INITIAL.

          ls_inspcharacteristic-task_list_group = gs_data_material-task_list_group.
          ls_inspcharacteristic-group_counter   = gs_data_material-group_counter.
          ls_inspcharacteristic-activity = gs_data_cha-activity.
          ls_inspcharacteristic-inspchar  = gs_data_cha-inspchar.
          ls_inspcharacteristic-mstr_char  = gs_data_cha-mstr_char.
          ls_inspcharacteristic-smpl_procedure  = gs_data_cha-smpl_procedure.
          ls_inspcharacteristic-smpl_unit  = gs_data_cha-smpl_unit.
          ls_inspcharacteristic-smpl_quant  = gs_data_cha-smpl_quant.
          ls_inspcharacteristic-dyn_modif_rule  = gs_data_cha-dyn_modif_rule.
          ls_inspcharacteristic-spc_criterion_key  = gs_data_cha-spc_criterion_key .
          ls_inspcharacteristic-up_tol_lmt  = gs_data_cha-up_tol_lmt.
          ls_inspcharacteristic-lw_tol_lmt  = gs_data_cha-lw_tol_lmt.
          ls_inspcharacteristic-formula_check_by_sap  = gs_data_cha-formula_check_by_sap.
          ls_inspcharacteristic-formula_field_1  = gs_data_cha-formula_field_1 .
          ls_inspcharacteristic-formula_field_2  = gs_data_cha-formula_field_2 .
          ls_inspcharacteristic-char_descr = gs_data_cha-char_descr.

          APPEND ls_inspcharacteristic TO lt_inspcharacteristic.

        ENDLOOP.

      ENDLOOP.

*    MOVE-CORRESPONDING gs_data to ls_OPERATION.
*    MOVE-CORRESPONDING gs_data to ls_INSPCHARACTERISTIC.
*    append ls_OPERATION to lt_OPERATION.
*    APPEND ls_INSPCHARACTERISTIC to lt_INSPCHARACTERISTIC.

      DATA ld_testrun TYPE  bapiflag.

      ld_testrun = 'X'.

      DATA ld_bomusage TYPE  bapi1012_control_data-bom_usage .

      ld_bomusage = '1'. "fabricacion

      CALL FUNCTION 'BAPI_ROUTING_CREATE'
        EXPORTING
          testrun                = p_test
*         PROFILE                =
          bomusage               = ld_bomusage
*         APPLICATION            =
* IMPORTING
*         GROUP                  =
*         GROUPCOUNTER           =
        TABLES
          task                   = lt_task
          materialtaskallocation = lt_materialtaskallocation
*         SEQUENCE               =
          operation              = lt_operation
*         LENGTHCALCULATION      =
*         SUBOPERATION           =
*         REFERENCEOPERATION     =
*         WORKCENTERREFERENCE    =
*         COMPONENTALLOCATION    =
*         PRODUCTIONRESOURCE     =
          inspcharacteristic     = lt_inspcharacteristic
*         TEXTALLOCATION         =
*         TEXT                   =
          return                 = lt_return.

      MOVE-CORRESPONDING gs_data_material TO gs_log.
      LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'.
        MOVE-CORRESPONDING ls_return TO gs_log.
        APPEND gs_log TO gt_log.
      ENDLOOP.

      IF sy-subrc <> 0.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*     EXPORTING
*       WAIT          =
*     IMPORTING
*       RETURN        =
          .
        gs_log-type = 'S'.
        gs_log-message = 'Hoja de ruta creada'.
        APPEND gs_log TO gt_log.
      ENDIF.
*    BREAK-POINT.
    ENDLOOP.
  ENDLOOP.
*PERFORM get_task_list_group using 'X'
*                               ls_MATERIALTASKALLOCATION
*                                ls_task.



ENDFORM.                    "select_data

*&---------------------------------------------------------------------*
*&      Form  upload
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM upload.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = p_file
      filetype                = 'DAT'
    TABLES
      data_tab                = gt_data
    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.


ENDFORM.                    "upload

*&---------------------------------------------------------------------*
*&      Form  display_log
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM display_log.
*... Create Instance
  TRY.
      cl_salv_table=>factory( IMPORTING r_salv_table = DATA(gr_table)
                               CHANGING t_table = gt_log ).
    CATCH cx_salv_msg.
  ENDTRY.

*... Enable Generic ALV functions
  DATA(gr_functions) = gr_table->get_functions( ).
**  gr_functions->set_default( ).
  gr_functions->set_all( ).

  DATA(lr_columns) = gr_table->get_columns( ).

*... Display table
  gr_table->display( ).

ENDFORM.                    "display_log