Material Master + Quality View upload


*&---------------------------------------------------------------------*
*& Report  ZVR_MM_UPLOAD_MM01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zvr_mm_upload_mm01.

TABLES : bapimathead,
         bapi_makt,
         bapi_mara,
         bapi_marax,
         bapi_mard,
         bapi_mardx,
         bapi_marc,
         bapi_marcx,
         bapi_mbew,
         bapi_mbewx,
         bapi_mvke,
         bapi_mvkex,
         bapi1001004_qmat,
         mara,
         tq34.

DATA: itab LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.

TYPES : BEGIN OF ty_final_rm,
         matnr TYPE bapimathead-material,                                         "Material No.
         ind_sector TYPE bapimathead-ind_sector,                                  "Industry Sector
         matl_type TYPE bapimathead-matl_type,                                    "Material Type
         plant TYPE bapi_marc-plant,                                              "Plant
         stge_loc TYPE bapi_mard-stge_loc,                                        "Storage Location
         matl_desc TYPE bapi_makt-matl_desc,                                      "Description

         base_uom TYPE bapi_mara-base_uom,                                        "UOM
         matl_group TYPE bapi_mara-matl_group,                                    "Material Group
         old_mat_no TYPE bapi_mara-old_mat_no,                                    "Old. Material no.
         gross_wt TYPE bapi_marm-gross_wt,                                        "Gross Weight
         unit_of_wt TYPE bapi_marm-unit_of_wt,                                    "Weight unit
         net_weight TYPE bapi_mara-net_weight,                                    "Net Weight
         cust_no TYPE bapi_mara-std_descr,                                        "Cutomer name / Code

         pur_group TYPE bapi_marc-pur_group,                                      "Purchasing Group
         batch_mgmt TYPE bapi_mara-batch_mgmt,                                    "Batch Mang.
         pur_valkey TYPE bapi_mara-pur_valkey,                                    "Purchasing value key
         gr_pr_time TYPE bapi_marc-gr_pr_time,                                    "GR Processing Time (Days)

         mrp_group TYPE bapi_marc-mrp_group,                                      "MRP group
         mrp_type TYPE bapi_marc-mrp_type,                                        "MRP Type
         mrp_ctrler TYPE bapi_marc-mrp_ctrler,                                    "MRP Controller
         lotsizekey TYPE bapi_marc-lotsizekey,                                    "Lot size

         proc_type TYPE bapi_marc-proc_type,                                      "Procurement type
         spproctype TYPE bapi_marc-spproctype,                                    "Special procurement
         iss_st_loc TYPE bapi_marc-iss_st_loc,                                    "Prod. stor. location
         sloc_exprc TYPE bapi_marc-sloc_exprc,                                    "Storage loc. for EP
         plnd_delry TYPE bapi_marc-plnd_delry,                                    "Planned Deliv. Time
         gr_pr_time1 TYPE bapi_marc-gr_pr_time,                                   "GR Processing Time
         sm_key TYPE bapi_marc-sm_key,                                            "SchedMargin key
         plan_strgp TYPE bapi_marc-plan_strgp,                                    "Strategy group

         availcheck TYPE bapi_marc-availcheck,                                    "Availability check

         dep_req_id TYPE bapi_marc-dep_req_id,                                    "Individual/coll.

         stge_bin TYPE bapi_mard-stge_bin,                                        "storage bin
         minremlife TYPE bapi_mara-minremlife,                                    "Min. Rem Self Life
         shelf_life TYPE bapi_mara-shelf_life,                                    "Total self Life
         period_ind_expiration_date TYPE bapi_mara-period_ind_expiration_date,    "Period Ind. For SLED

         serno_prof TYPE bapi_marc-serno_prof,                                    "Serial No. profile
         profit_ctr TYPE bapi_marc-profit_ctr,                                    "Profit Center

*                                                                                                                "insp. setup
         insptype TYPE bapi1001004_qmat-insptype,                                "Inspection Type 1
         ind_insptype_mat_active TYPE bapi1001004_qmat-ind_insptype_mat_active,   "Active

         val_cat TYPE bapi_mbew-val_cat,                                          "Valuation Category
         val_class TYPE bapi_mbew-val_class,                                      "Valuation Class
         price_ctrl TYPE bapi_mbew-price_ctrl,                                    "Price Control
         price_unit TYPE bapi_mbew-price_unit,                                    "Price unit
         moving_pr TYPE bapi_mbew-moving_pr,                                      "Moving Average Price
         std_price TYPE bapi_mbew-std_price,                                      "Standard Price

        END OF ty_final_rm.

TYPES : BEGIN OF ty_final_sfm,
         matnr TYPE bapimathead-material,                                          "Material No.
         ind_sector TYPE bapimathead-ind_sector,                                   "Industry Sector
         matl_type TYPE bapimathead-matl_type,                                     "Material Type
         plant TYPE bapi_marc-plant,                                               "Plant
         stge_loc TYPE bapi_mard-stge_loc,                                         "Storage Location
         sale_org TYPE bapi_mvke-sales_org,                                        "Sale Org.
         dist_chan TYPE bapi_mvke-distr_chan,                                     "Distr. Channel
         matl_desc TYPE bapi_makt-matl_desc,                                       "Description

         base_uom TYPE bapi_mara-base_uom,                                         "UOM
         matl_group TYPE bapi_mara-matl_group,                                     "Material Group
         old_mat_no TYPE bapi_mara-old_mat_no,                                     "Old. Material no.
         gross_wt TYPE bapi_marm-gross_wt,                                        "Gross Weight
         unit_of_wt TYPE bapi_marm-unit_of_wt,                                     "Weight unit
         net_weight TYPE bapi_mara-net_weight,                                     "Net Weight
         cust_no TYPE bapi_mara-std_descr,                                        "Cutomer name / Code

         taxclass_1(5)," TYPE bapi_mlan-taxclass_1,                                     "Tax classification material
         matl_stats TYPE bapi_mvke-matl_stats,                                     "Matl statistics grp
         gen_item_cat_g TYPE bapi_mara-item_cat,                                   "Gen. item cat. grp
         item_cat_g TYPE bapi_mvke-item_cat,                                       "Item category group
         availcheck TYPE bapi_marc-availcheck,                                     "Availability check
         trans_grp TYPE bapi_mara-trans_grp,                                       "Trans. Grp
         loadinggrp TYPE bapi_marc-loadinggrp,                                     "LoadingGrp

         pur_group TYPE bapi_marc-pur_group,                                       "Purchasing Group
         batch_mgmt TYPE bapi_mara-batch_mgmt,                                     "Batch Mang.
         pur_valkey TYPE bapi_mara-pur_valkey,                                     "Purchasing value key
         gr_pr_time TYPE bapi_marc-gr_pr_time,                                     "GR Processing Time (Days)

         mrp_group TYPE bapi_marc-mrp_group,                                       "MRP group
         mrp_type TYPE bapi_marc-mrp_type,                                         "MRP Type
         mrp_ctrler TYPE bapi_marc-mrp_ctrler,                                     "MRP Controller
         lotsizekey TYPE bapi_marc-lotsizekey,                                     "Lot size

         proc_type TYPE bapi_marc-proc_type,                                       "Procurement type
         spproctype TYPE bapi_marc-spproctype,                                     "Special procurement
         iss_st_loc TYPE bapi_marc-iss_st_loc,                                     "Prod. stor. location
         sloc_exprc TYPE bapi_marc-sloc_exprc,                                     "Storage loc. for EP
         inhseprodt TYPE bapi_marc-inhseprodt,                                     "Inhouse Prod. Time
         plnd_delry TYPE bapi_marc-plnd_delry,                                     "Planned Deliv. Time
         gr_pr_time1 TYPE bapi_marc-gr_pr_time,                                    "GR Processing Time
         sm_key TYPE bapi_marc-sm_key,                                             "SchedMargin key

         plan_strgp TYPE bapi_marc-plan_strgp,                                     "Strategy group
         availcheck1 TYPE bapi_marc-availcheck,                                    "Availability check

         dep_req_id TYPE bapi_marc-dep_req_id,                                     "Individual/coll.

         stge_bin TYPE bapi_mard-stge_bin,                                         "storage bin
         minremlife TYPE bapi_mara-minremlife,                                     "Min. Rem Self Life
         shelf_life TYPE bapi_mara-shelf_life,                                     "Total self Life
         period_ind_expiration_date TYPE bapi_mara-period_ind_expiration_date,     "Period Ind. For SLED

         serno_prof1 TYPE bapi_marc-serno_prof,                                    "Serial No. profile
         profit_ctr TYPE bapi_marc-profit_ctr,                                     "Profit Center

*        ???????????????????????                                                  "insp. setup
         insptype TYPE bapi1001004_qmat-insptype,                                "Inspection Type 1
         ind_insptype_mat_active TYPE bapi1001004_qmat-ind_insptype_mat_active,   "Active

         val_cat TYPE bapi_mbew-val_cat,                                           "Valuation Category
         val_class TYPE bapi_mbew-val_class,                                       "Valuation Class
         price_ctrl TYPE bapi_mbew-price_ctrl,                                     "Price Control
         price_unit TYPE bapi_mbew-price_unit,                                     "Price unit
         moving_pr TYPE bapi_mbew-moving_pr,                                       "Moving Average Price
         std_price TYPE bapi_mbew-std_price,                                       "Standard Price

         prod_unit TYPE bapi_marc-prod_unit,                                       "Production Unit
         production_scheduler TYPE bapi_marc-production_scheduler,                 "Production Scheduler
         prodprof TYPE bapi_marc-prodprof,                                         "Production Scheduler Profile
         serno_prof TYPE bapi_marc-serno_prof,                                     "Serial no profile

        END OF ty_final_sfm.

TYPES : BEGIN OF ty_final_fgm,
         matnr TYPE bapimathead-material,                                          "Material No.
         ind_sector TYPE bapimathead-ind_sector,                                   "Industry Sector
         matl_type TYPE bapimathead-matl_type,                                     "Material Type
         plant TYPE bapi_marc-plant,                                               "Plant
         stge_loc TYPE bapi_mard-stge_loc,                                         "Storage Location
         sale_org TYPE bapi_mvke-sales_org,                                        "Sale Org.
         dist_chan TYPE bapi_mvke-distr_chan,                                     "Distr. Channel
         matl_desc TYPE bapi_makt-matl_desc,                                       "Description

         base_uom TYPE bapi_mara-base_uom,                                         "UOM
         matl_group TYPE bapi_mara-matl_group,                                     "Material Group
         old_mat_no TYPE bapi_mara-old_mat_no,                                     "Old. Material no.
         gross_wt TYPE bapi_marm-gross_wt,                                         "Gross Weight
         unit_of_wt TYPE bapi_marm-unit_of_wt,                                     "Weight unit
         net_weight TYPE bapi_mara-net_weight,                                     "Net Weight
         cust_no TYPE bapi_mara-std_descr,                                        "Cutomer name / Code

         taxclass_1(5), "TYPE bapi_mlan-taxclass_1,                                     "Tax classification material
         matl_stats TYPE bapi_mvke-matl_stats,                                     "Matl statistics grp
         gen_item_cat_g TYPE bapi_mara-item_cat,                                   "Gen. item cat. grp
         item_cat_g TYPE bapi_mvke-item_cat,                                       "Item category group
         availcheck TYPE bapi_marc-availcheck,                                     "Availability check
         trans_grp TYPE bapi_mara-trans_grp,                                       "Trans. Grp
         loadinggrp TYPE bapi_marc-loadinggrp,                                     "LoadingGrp

         mrp_group TYPE bapi_marc-mrp_group,                                       "MRP group
         mrp_type TYPE bapi_marc-mrp_type,                                         "MRP Type
         mrp_ctrler TYPE bapi_marc-mrp_ctrler,                                     "MRP Controller
         lotsizekey TYPE bapi_marc-lotsizekey,                                     "Lot size

         proc_type TYPE bapi_marc-proc_type,                                       "Procurement type
         spproctype TYPE bapi_marc-spproctype,                                     "Special procurement
         iss_st_loc TYPE bapi_marc-iss_st_loc,                                     "Prod. stor. location
         sloc_exprc TYPE bapi_marc-sloc_exprc,                                     "Storage loc. for EP
         inhseprodt TYPE bapi_marc-inhseprodt,                                     "Inhouse Prod. Time
         plnd_delry TYPE bapi_marc-plnd_delry,                                     "Planned Deliv. Time
         gr_pr_time1 TYPE bapi_marc-gr_pr_time,                                    "GR Processing Time
         sm_key TYPE bapi_marc-sm_key,                                             "SchedMargin key

         plan_strgp TYPE bapi_marc-plan_strgp,                                     "Strategy group
         availcheck1 TYPE bapi_marc-availcheck,                                    "Availability check

         dep_req_id TYPE bapi_marc-dep_req_id,                                     "Individual/coll.

         stge_bin TYPE bapi_mard-stge_bin,                                         "storage bin
         minremlife TYPE bapi_mara-minremlife,                                     "Min. Rem Self Life
         shelf_life TYPE bapi_mara-shelf_life,                                     "Total self Life
         period_ind_expiration_date TYPE bapi_mara-period_ind_expiration_date,     "Period Ind. For SLED

         serno_prof TYPE bapi_marc-serno_prof,                                     "Serial No. profile
         profit_ctr TYPE bapi_marc-profit_ctr,                                     "Profit Center

*        ???????????????????????                                                   "insp. setup
         insptype TYPE bapi1001004_qmat-insptype,                                  "Inspection Type 1
         ind_insptype_mat_active TYPE bapi1001004_qmat-ind_insptype_mat_active,    "Active

         val_cat TYPE bapi_mbew-val_cat,                                           "Valuation Category
         val_class TYPE bapi_mbew-val_class,                                       "Valuation Class
         price_ctrl TYPE bapi_mbew-price_ctrl,                                     "Price Control
         price_unit TYPE bapi_mbew-price_unit,                                     "Price unit
         moving_pr TYPE bapi_mbew-moving_pr,                                       "Moving Average Price
         std_price TYPE bapi_mbew-std_price,                                       "Standard Price

         prod_unit TYPE bapi_marc-prod_unit,                                       "Production Unit
         production_scheduler TYPE bapi_marc-production_scheduler,                 "Production Scheduler
         prodprof TYPE bapi_marc-prodprof,                                         "Production Scheduler Profile
         serno_prof1 TYPE bapi_marc-serno_prof,                                    "Serial no profile
         batch_mgmt1 TYPE bapi_marc-batch_mgmt,                                    "Batch Mang.


        END OF ty_final_fgm.


TYPES : BEGIN OF ty_mat,
        matnr TYPE matnr,
        message TYPE bapiret2-message,
        END OF ty_mat.

DATA : it_final1 TYPE STANDARD TABLE OF ty_mat,
       wa_final1 TYPE ty_mat.

DATA : it_final_rm TYPE STANDARD TABLE OF ty_final_rm,
       wa_final_rm TYPE ty_final_rm,
       it_final_sfm TYPE STANDARD TABLE OF ty_final_sfm,
       wa_final_sfm TYPE ty_final_sfm,
       it_final_fgm TYPE STANDARD TABLE OF ty_final_fgm,
       wa_final_fgm TYPE ty_final_fgm,
       it_return LIKE bapiret2,
       it_bapi_makt LIKE bapi_makt OCCURS 0 WITH HEADER LINE,
       it_bapi_mlan LIKE bapi_mlan OCCURS 0 WITH HEADER LINE,
       bapi_marm LIKE bapi_marm OCCURS 0 WITH HEADER LINE,
       bapi_marmx LIKE bapi_marmx OCCURS 0 WITH HEADER LINE,
       it_return_msg LIKE bapi_matreturn2 OCCURS 0 WITH HEADER LINE,
       it_matnr TYPE bapimatinr OCCURS 0 WITH HEADER LINE,
       it_return1 TYPE bapireturn1,
       it_tax TYPE bapi_mlan OCCURS 0 WITH HEADER LINE,
       bapi_mlan LIKE bapi_mlan OCCURS 0 WITH HEADER LINE,
       ls_msg LIKE LINE OF it_return_msg.

DATA:  gd_currentrow TYPE i.

DATA : v_day(2),v_month(2),v_year(4),
       v_date(10).

DATA : v_total TYPE i,
       v_success TYPE i,
       v_failure TYPE i,
       v_count TYPE i.

DATA: BEGIN OF gt_msg OCCURS 0,
       count TYPE i,
       message(300),
       type(1),
      END OF gt_msg,
      gs_msg LIKE LINE OF gt_msg.

DATA: gt_quality TYPE STANDARD TABLE OF bapi1001004_qmat WITH HEADER LINE,
      wa_quality LIKE LINE OF gt_quality,
      wa_quality1 LIKE LINE OF gt_quality.

DATA : lv_mrp_grp    TYPE num4,
       lv_sm_key     TYPE num4,
       lv_availcheck TYPE num,
       lv_insptype   TYPE num,
       lv_trans_grp  TYPE num4,
       lv_profit_ctr TYPE num10,
       lv_loadinggrp TYPE num4.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_infile TYPE rlgrap-filename OBLIGATORY MEMORY ID mat_file.

PARAMETERS : r_mat RADIOBUTTON GROUP grp1,
             sf_mat RADIOBUTTON GROUP grp1,
             fg_mat RADIOBUTTON GROUP grp1.
SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infile.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = 'p_infile '
    IMPORTING
      file_name     = p_infile.


START-OF-SELECTION.
  PERFORM get_data_excel.

  IF r_mat = 'X'.
    PERFORM get_data_internal_table_rm.
    PERFORM use_bapi_rm.
  ELSEIF sf_mat = 'X'.
    PERFORM get_data_internal_table_sfm.
    PERFORM use_bapi_sfm.
  ELSEIF fg_mat = 'X'.
    PERFORM get_data_internal_table_fgm.
    PERFORM use_bapi_fgm.
  ENDIF.



*&---------------------------------------------------------------------*
*&      Form  GET_DATA_EXCEL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data_excel .
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = p_infile
      i_begin_col             = '1'
      i_begin_row             = '2'
      i_end_col               = '130'
      i_end_row               = '20000'
    TABLES
      intern                  = itab
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.
  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.                    " GET_DATA_EXCEL
*&---------------------------------------------------------------------*
*&      Form  GET_DATA_INTERNAL_TABLE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data_internal_table_rm.
  SORT itab BY row col.
  READ TABLE itab INDEX 1.
  gd_currentrow = itab-row.
  LOOP AT itab.
    IF itab-row NE gd_currentrow.
      APPEND wa_final_rm TO it_final_rm.
      CLEAR wa_final_rm.
      gd_currentrow = itab-row.
    ENDIF.
    CASE itab-col.
      WHEN '0001'.
        wa_final_rm-matnr = itab-value.
      WHEN '0002'.
        wa_final_rm-ind_sector = itab-value.
      WHEN '0003'.
        wa_final_rm-matl_type = itab-value.
      WHEN '0004'.
        wa_final_rm-plant = itab-value.
      WHEN '0005'.
        wa_final_rm-stge_loc = itab-value.
      WHEN '0006'.
        wa_final_rm-matl_desc = itab-value.
      WHEN '0007'.
        wa_final_rm-base_uom = itab-value.
      WHEN '0008'.
        wa_final_rm-matl_group = itab-value.
      WHEN '0009'.
        wa_final_rm-old_mat_no = itab-value.
      WHEN '0010'.
        wa_final_rm-gross_wt = itab-value.
      WHEN '0011'.
        wa_final_rm-unit_of_wt = itab-value.
      WHEN '0012'.
        wa_final_rm-net_weight = itab-value.
      WHEN '0013'.
        wa_final_rm-cust_no = itab-value.
      WHEN '0014'.
        wa_final_rm-pur_group = itab-value.
      WHEN '0015'.
        wa_final_rm-batch_mgmt = itab-value.
      WHEN '0016'.
        wa_final_rm-pur_valkey = itab-value.
      WHEN '0017'.
        wa_final_rm-gr_pr_time = itab-value.
      WHEN '0018'.
        lv_mrp_grp = itab-value.
        wa_final_rm-mrp_group = lv_mrp_grp.
      WHEN '0019'.
        wa_final_rm-mrp_type = itab-value.
      WHEN '0020'.
        wa_final_rm-mrp_ctrler = itab-value.
      WHEN '0021'.
        wa_final_rm-lotsizekey = itab-value.
      WHEN '0022'.
        wa_final_rm-proc_type = itab-value.
      WHEN '0023'.
        wa_final_rm-spproctype = itab-value.
      WHEN '0024'.
        wa_final_rm-iss_st_loc = itab-value.
      WHEN '0025'.
        wa_final_rm-sloc_exprc = itab-value.
      WHEN '0026'.
        wa_final_rm-plnd_delry = itab-value.
      WHEN '0027'.
        wa_final_rm-gr_pr_time1 = itab-value.
      WHEN '0028'.
        lv_sm_key = itab-value.
        wa_final_rm-sm_key = lv_sm_key+1(3).
      WHEN '0029'.
        wa_final_rm-plan_strgp = itab-value.
      WHEN '0030'.
        lv_availcheck = itab-value.
        wa_final_rm-availcheck = lv_availcheck.
      WHEN '0031'.
        wa_final_rm-dep_req_id = itab-value.
      WHEN '0032'.
        wa_final_rm-stge_bin = itab-value.
      WHEN '0033'.
        wa_final_rm-minremlife = itab-value.
      WHEN '0034'.
        wa_final_rm-shelf_life = itab-value.
      WHEN '0035'.
        wa_final_rm-period_ind_expiration_date = itab-value.
      WHEN '0036'.
        wa_final_rm-serno_prof = itab-value.
      WHEN '0037'.
        lv_profit_ctr = itab-value.
        wa_final_rm-profit_ctr = lv_profit_ctr.
*      WHEN '0038'.
*        wa_final_rm-insp = itab-value.
      WHEN '0039'.
        lv_insptype = itab-value.
        wa_final_rm-insptype = lv_insptype.
      WHEN '0040'.
        wa_final_rm-ind_insptype_mat_active = itab-value.
      WHEN '0041'.
        wa_final_rm-val_cat = itab-value.
      WHEN '0042'.
        wa_final_rm-val_class = itab-value.
      WHEN '0043'.
        wa_final_rm-price_ctrl = itab-value.
      WHEN '0044'.
        wa_final_rm-price_unit = itab-value.
      WHEN '0045'.
        wa_final_rm-moving_pr = itab-value.
      WHEN '0046'.
        wa_final_rm-std_price = itab-value.
      WHEN OTHERS.

    ENDCASE.
    CLEAR : lv_mrp_grp, lv_sm_key, lv_availcheck, lv_insptype.
  ENDLOOP.
  APPEND wa_final_rm TO it_final_rm.
ENDFORM.                    " GET_DATA_INTERNAL_TABLE
*&---------------------------------------------------------------------*
*&      Form  USE_BAPI
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM use_bapi_rm .
  DESCRIBE TABLE it_final_rm LINES v_total.

  LOOP AT it_final_rm INTO wa_final_rm.

    REFRESH : it_bapi_makt[],bapi_marm[],bapi_marmx[], it_return_msg[].

    v_count = sy-tabix.

* Header
    bapimathead-ind_sector = wa_final_rm-ind_sector.
    bapimathead-matl_type = wa_final_rm-matl_type.
    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
      EXPORTING
        input        = wa_final_rm-matnr
      IMPORTING
        output       = wa_final_rm-matnr
      EXCEPTIONS
        length_error = 1
        OTHERS       = 2.

    bapimathead-material = wa_final_rm-matnr.

    bapimathead-basic_view    = 'X'.
    bapimathead-purchase_view = 'X'.
    bapimathead-mrp_view      = 'X'.
    bapimathead-storage_view  = 'X'.
    bapimathead-account_view  = 'X'.
    bapimathead-quality_view  = 'X'.

* Material Description
    it_bapi_makt-matl_desc = wa_final_rm-matl_desc.
    it_bapi_makt-langu = sy-langu.
    APPEND it_bapi_makt.

* Client Data - Basic
    CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
      EXPORTING
        input          = wa_final_rm-base_uom
        language       = sy-langu
      IMPORTING
        output         = bapi_mara-base_uom
      EXCEPTIONS
        unit_not_found = 1
        OTHERS         = 2.

    bapi_mara-matl_group = wa_final_rm-matl_group.
    bapi_mara-old_mat_no = wa_final_rm-old_mat_no.
    bapi_mara-net_weight = wa_final_rm-net_weight.
    bapi_mara-unit_of_wt = wa_final_rm-unit_of_wt.
    bapi_mara-batch_mgmt = wa_final_rm-batch_mgmt.
    bapi_mara-pur_valkey = wa_final_rm-pur_valkey.
    bapi_mara-minremlife = wa_final_rm-minremlife.
    bapi_mara-shelf_life = wa_final_rm-shelf_life.
    bapi_mara-std_descr  = wa_final_rm-cust_no.
    CALL FUNCTION 'CONVERSION_EXIT_PERKZ_INPUT'
      EXPORTING
        input  = wa_final_rm-period_ind_expiration_date
      IMPORTING
        output = wa_final_rm-period_ind_expiration_date.
    bapi_mara-period_ind_expiration_date = wa_final_rm-period_ind_expiration_date.

    bapi_marax-base_uom   = 'X'.
    bapi_marax-matl_group = 'X'.
    bapi_marax-old_mat_no = 'X'.
    bapi_marax-net_weight = 'X'.
    bapi_marax-unit_of_wt = 'X'.
    bapi_marax-batch_mgmt = 'X'.
    bapi_marax-pur_valkey = 'X'.
    bapi_marax-minremlife = 'X'.
    bapi_marax-shelf_life = 'X'.
    bapi_marax-std_descr  = 'X'.
    bapi_marax-period_ind_expiration_date = 'X'.

* Plant - Purchasing
    bapi_marc-plant      = wa_final_rm-plant.
    bapi_marc-pur_group  = wa_final_rm-pur_group.
    bapi_marc-gr_pr_time = wa_final_rm-gr_pr_time.
    bapi_marc-mrp_group  = wa_final_rm-mrp_group.
    bapi_marc-mrp_type   = wa_final_rm-mrp_type.
    bapi_marc-mrp_ctrler = wa_final_rm-mrp_ctrler.
    bapi_marc-lotsizekey = wa_final_rm-lotsizekey.
    bapi_marc-proc_type  = wa_final_rm-proc_type.
    bapi_marc-spproctype = wa_final_rm-spproctype.
    bapi_marc-iss_st_loc = wa_final_rm-iss_st_loc.
    bapi_marc-sloc_exprc = wa_final_rm-sloc_exprc.
    bapi_marc-plnd_delry = wa_final_rm-plnd_delry.
    bapi_marc-gr_pr_time = wa_final_rm-gr_pr_time1.
    bapi_marc-sm_key     = wa_final_rm-sm_key.
    bapi_marc-availcheck = wa_final_rm-availcheck.
    bapi_marc-dep_req_id = wa_final_rm-dep_req_id.
    bapi_marc-serno_prof = wa_final_rm-serno_prof.
    bapi_marc-profit_ctr = wa_final_rm-profit_ctr.
    bapi_marc-plan_strgp = wa_final_rm-plan_strgp.

    bapi_marcx-plant      = wa_final_rm-plant.
    bapi_marcx-pur_group  = 'X'.
    bapi_marcx-gr_pr_time = 'X'.
    bapi_marcx-mrp_group  = 'X'.
    bapi_marcx-mrp_type   = 'X'.
    bapi_marcx-mrp_ctrler = 'X'.
    bapi_marcx-lotsizekey = 'X'.
    bapi_marcx-proc_type  = 'X'.
    bapi_marcx-spproctype = 'X'.
    bapi_marcx-iss_st_loc = 'X'.
    bapi_marcx-sloc_exprc = 'X'.
    bapi_marcx-plnd_delry = 'X'.
    bapi_marcx-gr_pr_time = 'X'.
    bapi_marcx-sm_key     = 'X'.
    bapi_marcx-availcheck = 'X'.
    bapi_marcx-dep_req_id = 'X'.
    bapi_marcx-serno_prof = 'X'.
    bapi_marcx-profit_ctr = 'X'.
    bapi_marcx-plan_strgp = 'X'.

* Storage Locationdata
    bapi_mard-plant    = wa_final_rm-plant.
    bapi_mard-stge_loc = wa_final_rm-stge_loc.
    bapi_mard-stge_bin = wa_final_rm-stge_bin.

    bapi_mardx-plant    = wa_final_rm-plant.
    bapi_mardx-stge_loc = wa_final_rm-stge_loc.
    bapi_mardx-stge_bin = 'X'.

* Account - Valuationdata
    bapi_mbew-val_area   = wa_final_rm-plant.
    bapi_mbew-val_cat    = wa_final_rm-val_cat.
    bapi_mbew-val_class  = wa_final_rm-val_class.
    bapi_mbew-price_ctrl = wa_final_rm-price_ctrl.
    bapi_mbew-price_unit = wa_final_rm-price_unit.
    bapi_mbew-moving_pr  = wa_final_rm-moving_pr.
    bapi_mbew-std_price  = wa_final_rm-std_price.

    bapi_mbewx-val_area   = wa_final_rm-plant.
    bapi_mbewx-val_cat    = 'X'.
    bapi_mbewx-val_class  = 'X'.
    bapi_mbewx-price_ctrl = 'X'.
    bapi_mbewx-price_unit = 'X'.
    bapi_mbewx-moving_pr  = 'X'.
    bapi_mbewx-std_price  = 'X'.

* Units of Measure
    bapi_marm-alt_unit   = wa_final_rm-base_uom.
    bapi_marm-gross_wt   = wa_final_rm-gross_wt.
    bapi_marm-unit_of_wt = wa_final_rm-unit_of_wt.
    APPEND bapi_marm.

    bapi_marmx-alt_unit   = wa_final_rm-base_uom.
    bapi_marmx-gross_wt   = 'X'.
    bapi_marmx-unit_of_wt = 'X'.
    APPEND bapi_marmx.

    CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
      EXPORTING
        headdata             = bapimathead
        clientdata           = bapi_mara
        clientdatax          = bapi_marax
        plantdata            = bapi_marc
        plantdatax           = bapi_marcx
        storagelocationdata  = bapi_mard
        storagelocationdatax = bapi_mardx
        valuationdata        = bapi_mbew
        valuationdatax       = bapi_mbewx
      IMPORTING
        return               = it_return
      TABLES
        materialdescription  = it_bapi_makt
        unitsofmeasure       = bapi_marm
        unitsofmeasurex      = bapi_marmx
        returnmessages       = it_return_msg.


    IF it_return_msg[] IS NOT INITIAL.
      READ TABLE it_return_msg INTO ls_msg WITH KEY type = 'E'.
      IF sy-subrc = 0.
      ELSE.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
      ENDIF.
    ENDIF.

    PERFORM log.

    wa_quality-material = wa_final_rm-matnr.
    wa_quality-plant = wa_final_rm-plant.
    wa_quality-insptype                = wa_final_rm-insptype.
    wa_quality-ind_insptype_mat_active = wa_final_rm-ind_insptype_mat_active.
    wa_quality-ind_auto_assign         = 'X'.
    wa_quality-ind_insp_by_charac      = 'X'.
    wa_quality-ind_skips_allowed       = 'X'.
    wa_quality-ind_automatic_ud        = 'X'.


    IF wa_final_rm-insptype IS NOT INITIAL.
      SELECT SINGLE * FROM tq34 WHERE art = wa_quality-insptype.
      IF sy-subrc = 0.
        wa_quality-ind_insp_with_tsk_list    = tq34-ppl.
        wa_quality-ind_post_to_insp_stock    = tq34-insmk.
        wa_quality-qual_score_procedure      = tq34-qkzverf.
        wa_quality-contr_insp_lot_create     = tq34-chg.
        wa_quality-ind_single_units_possible = tq34-ein.
      ENDIF.

      APPEND wa_quality TO gt_quality.
    ENDIF.

    IF gt_quality[] IS NOT INITIAL.
      CALL FUNCTION 'BAPI_MATINSPCTRL_SAVEREPLICA'
        TABLES
          return         = it_return_msg
          inspectionctrl = gt_quality.

      IF it_return_msg[] IS NOT INITIAL.
        READ TABLE it_return_msg INTO ls_msg WITH KEY type = 'E'.
        IF sy-subrc = 0.
        ELSE.
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait = 'X'.
        ENDIF.
      ENDIF.
    ENDIF.

    PERFORM log.

    CLEAR: wa_final_rm,
           wa_quality,
           bapimathead,
           bapi_makt,
           bapi_mara,
           bapi_marax,
           bapi_mard,
           bapi_mardx,
           bapi_marc,
           bapi_marcx,
           bapi_mbew,
           bapi_mbewx,
           bapi1001004_qmat,
           tq34.
  ENDLOOP.

  IF gt_msg[] IS NOT INITIAL.
    WRITE :/15(31) 'Total No. of Records in Excel :' COLOR 5,v_total COLOR 7.
    SKIP.
    WRITE :/18(28) ' Number of Records Success :' COLOR 5,v_success COLOR 5.
    SKIP.
    WRITE :/18(28) 'Number of Records Failure  :' COLOR 6,v_failure COLOR 6.

    SKIP.

    LOOP AT gt_msg INTO gs_msg.
      IF gs_msg-type = 'E'.
        WRITE:/1(5) 'Line#', 7(10) gs_msg-count COLOR 6, 17(1) gs_msg-type, 20(100) gs_msg-message  COLOR 6.
      ELSEIF gs_msg-type = 'S'.
        WRITE:/1(5) 'Line#', 6(1) gs_msg-type, 7(10) gs_msg-count COLOR 5, 17(1) gs_msg-type, 20(100) gs_msg-message  COLOR 5.
      ENDIF.
      CLEAR gs_msg.
    ENDLOOP.
  ENDIF.

ENDFORM.                    " USE_BAPI
*&---------------------------------------------------------------------*
*&      Form  GET_DATA_INTERNAL_TABLE_SFM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data_internal_table_sfm .
  SORT itab BY row col.
  READ TABLE itab INDEX 1.
  gd_currentrow = itab-row.
  LOOP AT itab.
    IF itab-row NE gd_currentrow.
      APPEND wa_final_sfm TO it_final_sfm.
      CLEAR wa_final_sfm.
      gd_currentrow = itab-row.
    ENDIF.

    CASE itab-col.
      WHEN '0001'.
        wa_final_sfm-matnr = itab-value.
      WHEN '0002'.
        wa_final_sfm-ind_sector = itab-value.
      WHEN '0003'.
        wa_final_sfm-matl_type = itab-value.
      WHEN '0004'.
        wa_final_sfm-plant = itab-value.
      WHEN '0005'.
        wa_final_sfm-stge_loc = itab-value.
      WHEN '0006'.
        wa_final_sfm-sale_org = itab-value.
      WHEN '0007'.
        wa_final_sfm-dist_chan = itab-value.
      WHEN '0008'.
        wa_final_sfm-matl_desc = itab-value.
      WHEN '0009'.
        wa_final_sfm-base_uom = itab-value.
      WHEN '0010'.
        wa_final_sfm-matl_group = itab-value.
      WHEN '0011'.
        wa_final_sfm-old_mat_no = itab-value.
      WHEN '0012'.
        wa_final_sfm-gross_wt = itab-value.
      WHEN '0013'.
        wa_final_sfm-unit_of_wt = itab-value.
      WHEN '0014'.
        wa_final_sfm-net_weight = itab-value.
      WHEN '0015'.
        wa_final_sfm-cust_no = itab-value.
      WHEN '0016'.
        wa_final_sfm-taxclass_1 = itab-value.
      WHEN '0017'.
        wa_final_sfm-matl_stats = itab-value.
      WHEN '0018'.
        wa_final_sfm-gen_item_cat_g = itab-value.
      WHEN '0019'.
        wa_final_sfm-item_cat_g = itab-value.
      WHEN '0020'.
        IF itab-value IS NOT INITIAL.
          lv_availcheck = itab-value.
          wa_final_sfm-availcheck = lv_availcheck.
        ENDIF.
      WHEN '0021'.
        IF itab-value IS NOT INITIAL.
          lv_trans_grp = itab-value.
          wa_final_sfm-trans_grp = lv_trans_grp+1(3).
        ENDIF.
      WHEN '0022'.
        IF itab-value IS NOT INITIAL.
          lv_loadinggrp = itab-value.
          wa_final_sfm-loadinggrp = lv_loadinggrp.
        ENDIF.
      WHEN '0023'.
        wa_final_sfm-pur_group = itab-value.
      WHEN '0024'.
        wa_final_sfm-batch_mgmt = itab-value.
      WHEN '0025'.
        wa_final_sfm-pur_valkey = itab-value.
      WHEN '0026'.
        wa_final_sfm-gr_pr_time = itab-value.
      WHEN '0027'.
        IF itab-value IS NOT INITIAL.
          lv_mrp_grp = itab-value.
          wa_final_sfm-mrp_group = lv_mrp_grp.
        ENDIF.
      WHEN '0028'.
        wa_final_sfm-mrp_type = itab-value.
      WHEN '0029'.
        wa_final_sfm-mrp_ctrler = itab-value.
      WHEN '0030'.
        wa_final_sfm-lotsizekey = itab-value.
      WHEN '0031'.
        wa_final_sfm-proc_type = itab-value.
      WHEN '0032'.
        wa_final_sfm-spproctype = itab-value.
      WHEN '0033'.
        wa_final_sfm-iss_st_loc = itab-value.
      WHEN '0034'.
        wa_final_sfm-sloc_exprc = itab-value.
      WHEN '0035'.
        wa_final_sfm-inhseprodt = itab-value.
      WHEN '0036'.
        wa_final_sfm-plnd_delry = itab-value.
      WHEN '0037'.
        wa_final_sfm-gr_pr_time1 = itab-value.
      WHEN '0038'.
        IF itab-value IS NOT INITIAL.
          lv_sm_key = itab-value.
          wa_final_sfm-sm_key = lv_sm_key+1(3).
        ENDIF.
      WHEN '0039'.
        wa_final_sfm-plan_strgp = itab-value.
      WHEN '0040'.
        IF itab-value IS NOT INITIAL.
          CLEAR : lv_availcheck.
          lv_availcheck = itab-value.
          wa_final_sfm-availcheck1 = lv_availcheck.
        ENDIF.
      WHEN '0041'.
        wa_final_sfm-dep_req_id = itab-value.
      WHEN '0042'.
        wa_final_sfm-stge_bin = itab-value.
      WHEN '0043'.
        wa_final_sfm-minremlife = itab-value.
      WHEN '0044'.
        wa_final_sfm-shelf_life = itab-value.
      WHEN '0045'.
        wa_final_sfm-period_ind_expiration_date = itab-value.
      WHEN '0046'.
        wa_final_sfm-serno_prof1 = itab-value.
      WHEN '0047'.
        lv_profit_ctr = itab-value.
        wa_final_sfm-profit_ctr = lv_profit_ctr.
*     WHEN '0048'.
*            wa_final_sfm- = itab-value.
      WHEN '0049'.
        lv_insptype = itab-value.
        wa_final_sfm-insptype = lv_insptype.
      WHEN '0050'.
        wa_final_sfm-ind_insptype_mat_active = itab-value.
      WHEN '0051'.
        wa_final_sfm-val_cat = itab-value.
      WHEN '0052'.
        wa_final_sfm-val_class = itab-value.
      WHEN '0053'.
        wa_final_sfm-price_ctrl = itab-value.
      WHEN '0054'.
        wa_final_sfm-price_unit = itab-value.
      WHEN '0055'.
        wa_final_sfm-moving_pr = itab-value.
      WHEN '0056'.
        wa_final_sfm-std_price = itab-value.
      WHEN '0057'.
        wa_final_sfm-prod_unit = itab-value.
      WHEN '0058'.
        wa_final_sfm-production_scheduler = itab-value.
      WHEN '0059'.
        wa_final_sfm-prodprof = itab-value.
      WHEN '0060'.
        wa_final_sfm-serno_prof = itab-value.

      WHEN OTHERS.

    ENDCASE.
    CLEAR : lv_mrp_grp, lv_sm_key, lv_availcheck, lv_insptype.
  ENDLOOP.
  APPEND wa_final_sfm TO it_final_sfm.

ENDFORM.                    " GET_DATA_INTERNAL_TABLE_SFM
*&---------------------------------------------------------------------*
*&      Form  use_bapi_sfm
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM use_bapi_sfm .
  DESCRIBE TABLE it_final_sfm LINES v_total.

  LOOP AT it_final_sfm INTO wa_final_sfm.

    REFRESH : it_bapi_makt[],bapi_marm[],bapi_marmx[], bapi_mlan[], it_return_msg[].

    v_count = sy-tabix.

* Header Data
    bapimathead-ind_sector = wa_final_sfm-ind_sector.
    bapimathead-matl_type = wa_final_sfm-matl_type.

    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
      EXPORTING
        input        = wa_final_sfm-matnr
      IMPORTING
        output       = wa_final_sfm-matnr
      EXCEPTIONS
        length_error = 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.

    bapimathead-material = wa_final_sfm-matnr.
    bapimathead-basic_view = 'X'.
    bapimathead-purchase_view = 'X'.
    bapimathead-mrp_view = 'X'.
    bapimathead-account_view = 'X'.
    bapimathead-quality_view = 'X'.
    bapimathead-storage_view = 'X'.
    bapimathead-sales_view = 'X'.

* Material Description
    it_bapi_makt-matl_desc = wa_final_sfm-matl_desc.
    it_bapi_makt-langu = sy-langu.
    APPEND it_bapi_makt.

* Client Data
    CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
      EXPORTING
        input          = wa_final_sfm-base_uom
        language       = sy-langu
      IMPORTING
        output         = wa_final_sfm-base_uom
      EXCEPTIONS
        unit_not_found = 1
        OTHERS         = 2.

    bapi_mara-base_uom       = wa_final_sfm-base_uom.
    bapi_mara-matl_group     = wa_final_sfm-matl_group.
    bapi_mara-old_mat_no     = wa_final_sfm-old_mat_no.
    bapi_mara-unit_of_wt     = wa_final_sfm-unit_of_wt.
    bapi_mara-unit_of_wt_iso = wa_final_sfm-unit_of_wt.
    bapi_mara-net_weight     = wa_final_sfm-net_weight.
    bapi_mara-batch_mgmt     = wa_final_sfm-batch_mgmt.
    bapi_mara-pur_valkey     = wa_final_sfm-pur_valkey.
    bapi_mara-matl_group     = wa_final_sfm-matl_group.
    bapi_mara-minremlife     = wa_final_sfm-minremlife.
    CALL FUNCTION 'CONVERSION_EXIT_PERKZ_INPUT'
      EXPORTING
        input  = wa_final_sfm-period_ind_expiration_date
      IMPORTING
        output = wa_final_sfm-period_ind_expiration_date.
    bapi_mara-period_ind_expiration_date = wa_final_sfm-period_ind_expiration_date.
    bapi_mara-shelf_life = wa_final_sfm-shelf_life.
    bapi_mara-std_descr  = wa_final_sfm-cust_no.

    bapi_marax-base_uom   = 'X'.
    bapi_marax-matl_group = 'X'.
    bapi_marax-old_mat_no = 'X'.
    bapi_marax-unit_of_wt = 'X'.
    bapi_marax-unit_of_wt_iso = 'X'.
    bapi_marax-net_weight = 'X'.
    bapi_marax-batch_mgmt  = 'X'.
    bapi_marax-pur_valkey  = 'X'.
    bapi_marax-matl_group  = 'X'.
    bapi_marax-minremlife  = 'X'.
    bapi_marax-period_ind_expiration_date = 'X'.
    bapi_marax-shelf_life  = 'X'.
    bapi_marax-std_descr   = 'X'.

* Plant Data
    bapi_marc-availcheck = wa_final_sfm-availcheck.
    bapi_marc-loadinggrp = wa_final_sfm-loadinggrp.
    bapi_marc-pur_group = wa_final_sfm-pur_group.
    bapi_marc-gr_pr_time = wa_final_sfm-gr_pr_time.
    bapi_marc-plant = wa_final_sfm-plant.
    bapi_marc-mrp_group = wa_final_sfm-mrp_group.
    bapi_marc-mrp_type = wa_final_sfm-mrp_type.
    bapi_marc-mrp_ctrler  = wa_final_sfm-mrp_ctrler.
    bapi_marc-lotsizekey = wa_final_sfm-lotsizekey.
    bapi_marc-proc_type = wa_final_sfm-proc_type.
    bapi_marc-spproctype = wa_final_sfm-spproctype.
    bapi_marc-iss_st_loc = wa_final_sfm-iss_st_loc.
    bapi_marc-sloc_exprc = wa_final_sfm-sloc_exprc.
    bapi_marc-inhseprodt = wa_final_sfm-inhseprodt.
    bapi_marc-plnd_delry = wa_final_sfm-plnd_delry.
    bapi_marc-gr_pr_time = wa_final_sfm-gr_pr_time1.
    bapi_marc-sm_key  = wa_final_sfm-sm_key.
    bapi_marc-dep_req_id = wa_final_sfm-dep_req_id.
    bapi_marc-serno_prof = wa_final_sfm-serno_prof.
    bapi_marc-profit_ctr = wa_final_sfm-profit_ctr.
    bapi_marc-prod_unit = wa_final_sfm-prod_unit.
    bapi_marc-production_scheduler = wa_final_sfm-production_scheduler.
    bapi_marc-prodprof = wa_final_sfm-prodprof.
    bapi_marc-serno_prof = wa_final_sfm-serno_prof.
    bapi_marc-plan_strgp = wa_final_sfm-plan_strgp.

    bapi_marcx-availcheck  = 'X'.
    bapi_marcx-loadinggrp = 'X'.
    bapi_marcx-pur_group = 'X'.
    bapi_marcx-gr_pr_time = 'X'.
    bapi_marcx-plant = wa_final_sfm-plant.
    bapi_marcx-mrp_group = 'X'.
    bapi_marcx-mrp_type = 'X'.
    bapi_marcx-mrp_ctrler  = 'X'.
    bapi_marcx-lotsizekey = 'X'.
    bapi_marcx-proc_type = 'X'.
    bapi_marcx-spproctype = 'X'.
    bapi_marcx-iss_st_loc = 'X'.
    bapi_marcx-sloc_exprc = 'X'.
    bapi_marcx-inhseprodt = 'X'.
    bapi_marcx-plnd_delry = 'X'.
    bapi_marcx-gr_pr_time = 'X'.
    bapi_marcx-sm_key  = 'X'.
    bapi_marcx-dep_req_id = 'X'.
    bapi_marcx-serno_prof = 'X'.
    bapi_marcx-profit_ctr = 'X'.
    bapi_marcx-prod_unit = 'X'.
    bapi_marcx-production_scheduler = 'X'.
    bapi_marcx-prodprof = 'X'.
    bapi_marcx-serno_prof = 'X'.
    bapi_marcx-plan_strgp = 'X'.

* Storage Location Data
    bapi_mard-plant = wa_final_sfm-plant.
    bapi_mard-stge_loc = wa_final_sfm-stge_loc.
    bapi_mard-stge_bin = wa_final_sfm-stge_bin.

    bapi_mardx-plant = wa_final_sfm-plant.
    bapi_mardx-stge_loc = wa_final_sfm-stge_loc.
    bapi_mardx-stge_bin = 'X'.

* Valuation Data
    bapi_mbew-val_area   = wa_final_sfm-plant.
    bapi_mbew-val_cat    = wa_final_sfm-val_cat.
    bapi_mbew-val_class  = wa_final_sfm-val_class.
    bapi_mbew-price_ctrl = wa_final_sfm-price_ctrl.
    bapi_mbew-price_unit = wa_final_sfm-price_unit.
    bapi_mbew-moving_pr  = wa_final_sfm-moving_pr.
    bapi_mbew-std_price  = wa_final_sfm-std_price.

    bapi_mbewx-val_area   = wa_final_sfm-plant.
    bapi_mbewx-val_cat = 'X'.
    bapi_mbewx-val_class = 'X'.
    bapi_mbewx-price_ctrl = 'X'.
    bapi_mbewx-price_unit = 'X'.
    bapi_mbewx-moving_pr = 'X'.
    bapi_mbewx-std_price = 'X'.

* Sales Data
    bapi_mvke-sales_org = wa_final_sfm-sale_org.
    bapi_mvke-distr_chan = wa_final_sfm-dist_chan.
    bapi_mvke-matl_stats = wa_final_sfm-matl_stats.
    bapi_mvke-item_cat = wa_final_sfm-item_cat_g.

    bapi_mvkex-sales_org = wa_final_sfm-sale_org.
    bapi_mvkex-distr_chan = wa_final_sfm-dist_chan.
    bapi_mvkex-matl_stats = 'X'.
    bapi_mvkex-item_cat = 'X'.

* Units of Measure
    bapi_marm-alt_unit   = wa_final_sfm-base_uom.
    bapi_marm-gross_wt   = wa_final_sfm-gross_wt.
    bapi_marm-unit_of_wt = wa_final_sfm-unit_of_wt.
    APPEND bapi_marm.

    bapi_marmx-alt_unit   = wa_final_sfm-base_uom.
    bapi_marmx-gross_wt   = 'X'.
    bapi_marmx-unit_of_wt = 'X'.
    APPEND bapi_marmx.


* Tax Classifications
    bapi_mlan-taxclass_1 = wa_final_sfm-taxclass_1+0(1).
    bapi_mlan-taxclass_2 = wa_final_sfm-taxclass_1+1(1).
    bapi_mlan-taxclass_3 = wa_final_sfm-taxclass_1+2(1).
    bapi_mlan-taxclass_4 = wa_final_sfm-taxclass_1+3(1).
    bapi_mlan-taxclass_5 = wa_final_sfm-taxclass_1+4(1).
    bapi_mlan-tax_type_1 = 'JIVC'.
    bapi_mlan-tax_type_2 = 'JIVP'.
    bapi_mlan-tax_type_3 = 'JSVD'.
    bapi_mlan-tax_type_4 = 'JEC3'.
    bapi_mlan-tax_type_5 = 'JEC4'.
    bapi_mlan-depcountry = 'EE'.
    APPEND bapi_mlan.

    CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
      EXPORTING
        headdata             = bapimathead
        clientdata           = bapi_mara
        clientdatax          = bapi_marax
        plantdata            = bapi_marc
        plantdatax           = bapi_marcx
        storagelocationdata  = bapi_mard
        storagelocationdatax = bapi_mardx
        valuationdata        = bapi_mbew
        valuationdatax       = bapi_mbewx
        salesdata            = bapi_mvke
        salesdatax           = bapi_mvkex
      IMPORTING
        return               = it_return
      TABLES
        materialdescription  = it_bapi_makt
        unitsofmeasure       = bapi_marm
        unitsofmeasurex      = bapi_marmx
        taxclassifications   = bapi_mlan
        returnmessages       = it_return_msg.

    IF it_return_msg[] IS NOT INITIAL.
      READ TABLE it_return_msg INTO ls_msg WITH KEY type = 'E'.
      IF sy-subrc = 0.
      ELSE.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
      ENDIF.
    ENDIF.

    PERFORM log.

    wa_quality-material = wa_final_sfm-matnr.
    wa_quality-plant = wa_final_sfm-plant.
    wa_quality-insptype                = wa_final_sfm-insptype.
    wa_quality-ind_insptype_mat_active = wa_final_sfm-ind_insptype_mat_active.
    wa_quality-ind_auto_assign         = 'X'.
    wa_quality-ind_insp_by_charac      = 'X'.
    wa_quality-ind_skips_allowed       = 'X'.
    wa_quality-ind_automatic_ud        = 'X'.


    IF wa_final_sfm-insptype IS NOT INITIAL.
      SELECT SINGLE * FROM tq34 WHERE art = wa_quality-insptype.
      IF sy-subrc = 0.
        wa_quality-ind_insp_with_tsk_list    = tq34-ppl.
        wa_quality-ind_post_to_insp_stock    = tq34-insmk.
        wa_quality-qual_score_procedure      = tq34-qkzverf.
        wa_quality-contr_insp_lot_create     = tq34-chg.
        wa_quality-ind_single_units_possible = tq34-ein.
      ENDIF.

      APPEND wa_quality TO gt_quality.
    ENDIF.

    IF gt_quality[] IS NOT INITIAL.
      CALL FUNCTION 'BAPI_MATINSPCTRL_SAVEREPLICA'
        TABLES
          return         = it_return_msg
          inspectionctrl = gt_quality.

      IF it_return_msg[] IS NOT INITIAL.
        READ TABLE it_return_msg INTO ls_msg WITH KEY type = 'E'.
        IF sy-subrc = 0.
        ELSE.
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait = 'X'.
        ENDIF.
      ENDIF.
    ENDIF.

    PERFORM log.

    CLEAR: wa_final_sfm,
           wa_quality,
           bapimathead,
           bapi_makt,
           bapi_mara,
           bapi_marax,
           bapi_marc,
           bapi_marcx,
           bapi_mard,
           bapi_mardx,
           bapi_mbew,
           bapi_mbewx,
           bapi_mvke,
           bapi_mvkex,
           bapi1001004_qmat,
           tq34.
  ENDLOOP.

  IF gt_msg[] IS NOT INITIAL.
    WRITE :/15(31) 'Total No. of Records in Excel :' COLOR 5,v_total COLOR 7.
    SKIP.
    WRITE :/18(28) ' Number of Records Success :' COLOR 5,v_success COLOR 5.
    SKIP.
    WRITE :/18(28) 'Number of Records Failure  :' COLOR 6,v_failure COLOR 6.

    SKIP 2.

    LOOP AT gt_msg INTO gs_msg.
      IF gs_msg-type = 'E'.
        WRITE:/1(5) 'Line#', 7(10) gs_msg-count COLOR 6, 17(1) gs_msg-type, 20(100) gs_msg-message  COLOR 6.
      ELSEIF gs_msg-type = 'S'.
        WRITE:/1(5) 'Line#', 6(1) gs_msg-type, 7(10) gs_msg-count COLOR 5, 17(1) gs_msg-type, 20(100) gs_msg-message  COLOR 5.
      ENDIF.
      CLEAR gs_msg.
    ENDLOOP.
  ENDIF.


ENDFORM.              "use_bapi_sfm

*&---------------------------------------------------------------------*
*&      Form  GET_DATA_INTERNAL_TABLE_FGM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data_internal_table_fgm .
  SORT itab BY row col.
  READ TABLE itab INDEX 1.
  gd_currentrow = itab-row.
  LOOP AT itab.
    IF itab-row NE gd_currentrow.
      APPEND wa_final_fgm TO it_final_fgm.
      CLEAR wa_final_fgm.
      gd_currentrow = itab-row.
    ENDIF.

    CASE itab-col.
      WHEN '0001'.
        wa_final_fgm-matnr = itab-value.
      WHEN '0002'.
        wa_final_fgm-ind_sector = itab-value.
      WHEN '0003'.
        wa_final_fgm-matl_type = itab-value.
      WHEN '0004'.
        wa_final_fgm-plant = itab-value.
      WHEN '0005'.
        wa_final_fgm-stge_loc = itab-value.
      WHEN '0006'.
        wa_final_fgm-sale_org = itab-value.
      WHEN '0007'.
        wa_final_fgm-dist_chan = itab-value.
      WHEN '0008'.
        wa_final_fgm-matl_desc = itab-value.
      WHEN '0009'.
        wa_final_fgm-base_uom = itab-value.
      WHEN '0010'.
        wa_final_fgm-matl_group = itab-value.
      WHEN '0011'.
        wa_final_fgm-old_mat_no = itab-value.
      WHEN '0012'.
        wa_final_fgm-gross_wt = itab-value.
      WHEN '0013'.
        wa_final_fgm-unit_of_wt = itab-value.
      WHEN '0014'.
        wa_final_fgm-net_weight = itab-value.
      WHEN '0015'.
        wa_final_fgm-cust_no = itab-value.
      WHEN '0016'.
        wa_final_fgm-taxclass_1 = itab-value.
      WHEN '0017'.
        wa_final_fgm-matl_stats = itab-value.
      WHEN '0018'.
        wa_final_fgm-gen_item_cat_g = itab-value.
      WHEN '0019'.
        wa_final_fgm-item_cat_g = itab-value.
      WHEN '0020'.
        IF itab-value IS NOT INITIAL.
          lv_availcheck = itab-value.
          wa_final_fgm-availcheck = lv_availcheck.
        ENDIF.
      WHEN '0021'.
        IF itab-value IS NOT INITIAL.
          lv_trans_grp = itab-value.
          wa_final_fgm-trans_grp = lv_trans_grp+1(3).
        ENDIF.
      WHEN '0022'.
        IF itab-value IS NOT INITIAL.
          lv_loadinggrp = itab-value.
          wa_final_fgm-loadinggrp = lv_loadinggrp.
        ENDIF.
      WHEN '0023'.
        IF itab-value IS NOT INITIAL.
          lv_mrp_grp = itab-value.
          wa_final_fgm-mrp_group = lv_mrp_grp.
        ENDIF.
      WHEN '0024'.
        wa_final_fgm-mrp_type = itab-value.
      WHEN '0025'.
        wa_final_fgm-mrp_ctrler = itab-value.
      WHEN '0026'.
        wa_final_fgm-lotsizekey = itab-value.
      WHEN '0027'.
        wa_final_fgm-proc_type = itab-value.
      WHEN '0028'.
        wa_final_fgm-spproctype = itab-value.
      WHEN '0029'.
        wa_final_fgm-iss_st_loc = itab-value.
      WHEN '0030'.
        wa_final_fgm-sloc_exprc = itab-value.
      WHEN '0031'.
        wa_final_fgm-inhseprodt = itab-value.
      WHEN '0032'.
        wa_final_fgm-plnd_delry = itab-value.
      WHEN '0033'.
        wa_final_fgm-gr_pr_time1 = itab-value.
      WHEN '0034'.
        IF itab-value IS NOT INITIAL.
          lv_sm_key = itab-value.
          wa_final_fgm-sm_key = lv_sm_key+1(3).
        ENDIF.
      WHEN '0035'.
        wa_final_fgm-plan_strgp = itab-value.
      WHEN '0036'.
        IF itab-value IS NOT INITIAL.
          CLEAR : lv_availcheck.
          lv_availcheck = itab-value.
          wa_final_fgm-availcheck1 = lv_availcheck.
        ENDIF.
      WHEN '0037'.
        wa_final_fgm-dep_req_id = itab-value.
      WHEN '0038'.
        wa_final_fgm-stge_bin = itab-value.
      WHEN '0039'.
        wa_final_fgm-minremlife = itab-value.
      WHEN '0040'.
        wa_final_fgm-shelf_life = itab-value.
      WHEN '0041'.
        wa_final_fgm-period_ind_expiration_date = itab-value.
      WHEN '0042'.
        wa_final_fgm-serno_prof1 = itab-value.
      WHEN '0043'.
        lv_profit_ctr = itab-value.
        wa_final_fgm-profit_ctr = lv_profit_ctr.
*     WHEN '0044'.
*            wa_final_fgm- = itab-value.
      WHEN '0045'.
        lv_insptype = itab-value.
        wa_final_fgm-insptype = lv_insptype.
      WHEN '0046'.
        wa_final_fgm-ind_insptype_mat_active = itab-value.
      WHEN '0047'.
        wa_final_fgm-val_cat = itab-value.
      WHEN '0048'.
        wa_final_fgm-val_class = itab-value.
      WHEN '0049'.
        wa_final_fgm-price_ctrl = itab-value.
      WHEN '0050'.
        wa_final_fgm-price_unit = itab-value.
      WHEN '0051'.
        wa_final_fgm-moving_pr = itab-value.
      WHEN '0052'.
        wa_final_fgm-std_price = itab-value.
      WHEN '0053'.
        wa_final_fgm-prod_unit = itab-value.
      WHEN '0054'.
        wa_final_fgm-production_scheduler = itab-value.
      WHEN '0055'.
        wa_final_fgm-prodprof = itab-value.
      WHEN '0056'.
        wa_final_fgm-serno_prof = itab-value.
      WHEN '0057'.
        wa_final_fgm-batch_mgmt1 = itab-value.

      WHEN OTHERS.

    ENDCASE.
    CLEAR : lv_mrp_grp, lv_sm_key, lv_availcheck, lv_insptype.
  ENDLOOP.
  APPEND wa_final_fgm TO it_final_fgm.

ENDFORM.                    " GET_DATA_INTERNAL_TABLE_FGM

*&---------------------------------------------------------------------*
*&      Form  use_bapi_fgm
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM use_bapi_fgm .
  DESCRIBE TABLE it_final_fgm LINES v_total.

  LOOP AT it_final_fgm INTO wa_final_fgm.

    REFRESH : it_bapi_makt[],bapi_marm[],bapi_marmx[], bapi_mlan[], it_return_msg[].

    v_count = sy-tabix.

* Header Data
    bapimathead-ind_sector = wa_final_fgm-ind_sector.
    bapimathead-matl_type = wa_final_fgm-matl_type.

    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
      EXPORTING
        input        = wa_final_fgm-matnr
      IMPORTING
        output       = wa_final_fgm-matnr
      EXCEPTIONS
        length_error = 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.

    bapimathead-material = wa_final_fgm-matnr.
    bapimathead-basic_view = 'X'.
    bapimathead-purchase_view = 'X'.
    bapimathead-mrp_view = 'X'.
    bapimathead-account_view = 'X'.
    bapimathead-quality_view = 'X'.
    bapimathead-storage_view = 'X'.
    bapimathead-sales_view = 'X'.

* Material Description
    it_bapi_makt-matl_desc = wa_final_fgm-matl_desc.
    it_bapi_makt-langu = sy-langu.
    APPEND it_bapi_makt.

* Client Data
    CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
      EXPORTING
        input          = wa_final_fgm-base_uom
        language       = sy-langu
      IMPORTING
        output         = wa_final_fgm-base_uom
      EXCEPTIONS
        unit_not_found = 1
        OTHERS         = 2.

    bapi_mara-base_uom   = wa_final_fgm-base_uom.
    bapi_mara-matl_group = wa_final_fgm-matl_group.
    bapi_mara-old_mat_no = wa_final_fgm-old_mat_no.
    bapi_mara-unit_of_wt = wa_final_fgm-unit_of_wt.
    bapi_mara-net_weight = wa_final_fgm-net_weight.
    bapi_mara-batch_mgmt = wa_final_fgm-batch_mgmt1.
    bapi_mara-matl_group = wa_final_fgm-matl_group.
    bapi_mara-minremlife = wa_final_fgm-minremlife.
    CALL FUNCTION 'CONVERSION_EXIT_PERKZ_INPUT'
      EXPORTING
        input  = wa_final_fgm-period_ind_expiration_date
      IMPORTING
        output = wa_final_fgm-period_ind_expiration_date.
    bapi_mara-period_ind_expiration_date = wa_final_fgm-period_ind_expiration_date.
    bapi_mara-shelf_life = wa_final_fgm-shelf_life.
    bapi_mara-std_descr  = wa_final_fgm-cust_no.

    bapi_marax-base_uom   = 'X'.
    bapi_marax-matl_group = 'X'.
    bapi_marax-old_mat_no = 'X'.
    bapi_marax-unit_of_wt = 'X'.
    bapi_marax-net_weight = 'X'.
    bapi_marax-batch_mgmt  = 'X'.
    bapi_marax-matl_group  = 'X'.
    bapi_marax-minremlife  = 'X'.
    bapi_marax-period_ind_expiration_date = 'X'.
    bapi_marax-shelf_life  = 'X'.
    bapi_marax-std_descr   = 'X'.

* Plant Data
    bapi_marc-availcheck = wa_final_fgm-availcheck.
    bapi_marc-loadinggrp = wa_final_fgm-loadinggrp.
    bapi_marc-plant = wa_final_fgm-plant.
    bapi_marc-mrp_group = wa_final_fgm-mrp_group.
    bapi_marc-mrp_type = wa_final_fgm-mrp_type.
    bapi_marc-mrp_ctrler  = wa_final_fgm-mrp_ctrler.
    bapi_marc-lotsizekey = wa_final_fgm-lotsizekey.
    bapi_marc-proc_type = wa_final_fgm-proc_type.
    bapi_marc-spproctype = wa_final_fgm-spproctype.
    bapi_marc-iss_st_loc = wa_final_fgm-iss_st_loc.
    bapi_marc-sloc_exprc = wa_final_fgm-sloc_exprc.
    bapi_marc-inhseprodt = wa_final_fgm-inhseprodt.
    bapi_marc-plnd_delry = wa_final_fgm-plnd_delry.
    bapi_marc-gr_pr_time = wa_final_fgm-gr_pr_time1.
    bapi_marc-sm_key  = wa_final_fgm-sm_key.
    bapi_marc-dep_req_id = wa_final_fgm-dep_req_id.
    bapi_marc-serno_prof = wa_final_fgm-serno_prof.
    bapi_marc-profit_ctr = wa_final_fgm-profit_ctr.
    bapi_marc-prod_unit = wa_final_fgm-prod_unit.
    bapi_marc-production_scheduler = wa_final_fgm-production_scheduler.
    bapi_marc-prodprof = wa_final_fgm-prodprof.
    bapi_marc-serno_prof = wa_final_fgm-serno_prof.
    bapi_marc-plan_strgp = wa_final_fgm-plan_strgp.

    bapi_marcx-availcheck  = 'X'.
    bapi_marcx-loadinggrp = 'X'.
    bapi_marcx-plant = wa_final_fgm-plant.
    bapi_marcx-mrp_group = 'X'.
    bapi_marcx-mrp_type = 'X'.
    bapi_marcx-mrp_ctrler  = 'X'.
    bapi_marcx-lotsizekey = 'X'.
    bapi_marcx-proc_type = 'X'.
    bapi_marcx-spproctype = 'X'.
    bapi_marcx-iss_st_loc = 'X'.
    bapi_marcx-sloc_exprc = 'X'.
    bapi_marcx-inhseprodt = 'X'.
    bapi_marcx-plnd_delry = 'X'.
    bapi_marcx-gr_pr_time = 'X'.
    bapi_marcx-sm_key  = 'X'.
    bapi_marcx-dep_req_id = 'X'.
    bapi_marcx-serno_prof = 'X'.
    bapi_marcx-profit_ctr = 'X'.
    bapi_marcx-prod_unit = 'X'.
    bapi_marcx-production_scheduler = 'X'.
    bapi_marcx-prodprof = 'X'.
    bapi_marcx-serno_prof = 'X'.
    bapi_marcx-plan_strgp = 'X'.

* Storage Location Data
    bapi_mard-plant = wa_final_fgm-plant.
    bapi_mard-stge_loc = wa_final_fgm-stge_loc.
    bapi_mard-stge_bin = wa_final_fgm-stge_bin.

    bapi_mardx-plant = wa_final_fgm-plant.
    bapi_mardx-stge_loc = wa_final_fgm-stge_loc.
    bapi_mardx-stge_bin = 'X'.

* Valuation Data
    bapi_mbew-val_area   = wa_final_fgm-plant.
    bapi_mbew-val_cat = wa_final_fgm-val_cat.
    bapi_mbew-val_class = wa_final_fgm-val_class.
    bapi_mbew-price_ctrl = wa_final_fgm-price_ctrl.
    bapi_mbew-price_unit = wa_final_fgm-price_unit.
    bapi_mbew-moving_pr = wa_final_fgm-moving_pr.
    bapi_mbew-std_price = wa_final_fgm-std_price.

    bapi_mbewx-val_area   = wa_final_fgm-plant.
    bapi_mbewx-val_cat = 'X'.
    bapi_mbewx-val_class = 'X'.
    bapi_mbewx-price_ctrl = 'X'.
    bapi_mbewx-price_unit = 'X'.
    bapi_mbewx-moving_pr = 'X'.
    bapi_mbewx-std_price = 'X'.

* Sales Data
    bapi_mvke-sales_org = wa_final_fgm-sale_org.
    bapi_mvke-distr_chan = wa_final_fgm-dist_chan.
    bapi_mvke-matl_stats = wa_final_fgm-matl_stats.
    bapi_mvke-item_cat = wa_final_fgm-item_cat_g.

    bapi_mvkex-sales_org = wa_final_fgm-sale_org.
    bapi_mvkex-distr_chan = wa_final_fgm-dist_chan.
    bapi_mvkex-matl_stats = 'X'.
    bapi_mvkex-item_cat = 'X'.

* Units of Measure
    bapi_marm-alt_unit   = wa_final_fgm-base_uom.
    bapi_marm-gross_wt   = wa_final_fgm-gross_wt.
    bapi_marm-unit_of_wt = wa_final_fgm-unit_of_wt.
    APPEND bapi_marm.

    bapi_marmx-alt_unit   = wa_final_fgm-base_uom.
    bapi_marmx-gross_wt   = 'X'.
    bapi_marmx-unit_of_wt = 'X'.
    APPEND bapi_marmx.

* Tax Classifications
    bapi_mlan-taxclass_1 = wa_final_sfm-taxclass_1+0(1).
    bapi_mlan-taxclass_2 = wa_final_sfm-taxclass_1+1(1).
    bapi_mlan-taxclass_3 = wa_final_sfm-taxclass_1+2(1).
    bapi_mlan-taxclass_4 = wa_final_sfm-taxclass_1+3(1).
    bapi_mlan-taxclass_5 = wa_final_sfm-taxclass_1+4(1).
    bapi_mlan-tax_type_1 = 'JIVC'.
    bapi_mlan-tax_type_2 = 'JIVP'.
    bapi_mlan-tax_type_3 = 'JSVD'.
    bapi_mlan-tax_type_4 = 'JEC3'.
    bapi_mlan-tax_type_5 = 'JEC4'.
    bapi_mlan-depcountry = 'EE'.
    APPEND bapi_mlan.

    CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
      EXPORTING
        headdata             = bapimathead
        clientdata           = bapi_mara
        clientdatax          = bapi_marax
        plantdata            = bapi_marc
        plantdatax           = bapi_marcx
        storagelocationdata  = bapi_mard
        storagelocationdatax = bapi_mardx
        valuationdata        = bapi_mbew
        valuationdatax       = bapi_mbewx
        salesdata            = bapi_mvke
        salesdatax           = bapi_mvkex
      IMPORTING
        return               = it_return
      TABLES
        materialdescription  = it_bapi_makt
        unitsofmeasure       = bapi_marm
        unitsofmeasurex      = bapi_marmx
        taxclassifications   = bapi_mlan
        returnmessages       = it_return_msg.

    IF it_return_msg[] IS NOT INITIAL.
      READ TABLE it_return_msg INTO ls_msg WITH KEY type = 'E'.
      IF sy-subrc = 0.
      ELSE.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
      ENDIF.
    ENDIF.

    PERFORM log.

    wa_quality-material = wa_final_fgm-matnr.
    wa_quality-plant = wa_final_fgm-plant.
    wa_quality-insptype                = wa_final_fgm-insptype.
    wa_quality-ind_insptype_mat_active = wa_final_fgm-ind_insptype_mat_active.
    wa_quality-ind_auto_assign         = 'X'.
    wa_quality-ind_insp_by_charac      = 'X'.
    wa_quality-ind_skips_allowed       = 'X'.
    wa_quality-ind_automatic_ud        = 'X'.


    IF wa_final_fgm-insptype IS NOT INITIAL.
      SELECT SINGLE * FROM tq34 WHERE art = wa_quality-insptype.
      IF sy-subrc = 0.
        wa_quality-ind_insp_with_tsk_list    = tq34-ppl.
        wa_quality-ind_post_to_insp_stock    = tq34-insmk.
        wa_quality-qual_score_procedure      = tq34-qkzverf.
        wa_quality-contr_insp_lot_create     = tq34-chg.
        wa_quality-ind_single_units_possible = tq34-ein.
      ENDIF.

      APPEND wa_quality TO gt_quality.
    ENDIF.

    IF gt_quality[] IS NOT INITIAL.
      CALL FUNCTION 'BAPI_MATINSPCTRL_SAVEREPLICA'
        TABLES
          return         = it_return_msg
          inspectionctrl = gt_quality.

      IF it_return_msg[] IS NOT INITIAL.
        READ TABLE it_return_msg INTO ls_msg WITH KEY type = 'E'.
        IF sy-subrc = 0.
        ELSE.
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait = 'X'.
        ENDIF.
      ENDIF.
    ENDIF.

    PERFORM log.

    CLEAR: wa_final_sfm,
           wa_quality,
           bapimathead,
           bapi_makt,
           bapi_mara,
           bapi_marax,
           bapi_marc,
           bapi_marcx,
           bapi_mard,
           bapi_mardx,
           bapi_mbew,
           bapi_mbewx,
           bapi_mvke,
           bapi_mvkex,
           bapi1001004_qmat,
           tq34.
  ENDLOOP.

  IF gt_msg[] IS NOT INITIAL.
    WRITE :/15(31) 'Total No. of Records in Excel :' COLOR 5,v_total COLOR 7.
    SKIP.
    WRITE :/18(28) ' Number of Records Success :' COLOR 5,v_success COLOR 5.
    SKIP.
    WRITE :/18(28) 'Number of Records Failure  :' COLOR 6,v_failure COLOR 6.

    SKIP 2.

    LOOP AT gt_msg INTO gs_msg.
      IF gs_msg-type = 'E'.
        WRITE:/1(5) 'Line#', 7(10) gs_msg-count COLOR 6, 17(1) gs_msg-type, 20(100) gs_msg-message  COLOR 6.
      ELSEIF gs_msg-type = 'S'.
        WRITE:/1(5) 'Line#', 6(1) gs_msg-type, 7(10) gs_msg-count COLOR 5, 17(1) gs_msg-type, 20(100) gs_msg-message  COLOR 5.
      ENDIF.
      CLEAR gs_msg.
    ENDLOOP.
  ENDIF.

ENDFORM.              "use_bapi_fgm


*&---------------------------------------------------------------------*
*&      Form  LOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM log .
  IF it_return_msg[] IS NOT INITIAL.
*    SORT it_return_msg[] BY type id number.
*    DELETE ADJACENT DUPLICATES FROM it_return_msg[] COMPARING type id number.

    LOOP AT it_return_msg INTO ls_msg WHERE type = 'E'.
      v_failure = v_failure + 1.
      gs_msg-count = v_count.
      IF r_mat = 'X'.
        CONCATENATE wa_final_rm-matnr ls_msg-message INTO ls_msg-message SEPARATED BY ' : '.
      ELSEIF sf_mat = 'X'.
        CONCATENATE wa_final_sfm-matnr ls_msg-message INTO ls_msg-message SEPARATED BY ' : '.
      ELSEIF fg_mat = 'X'.
        CONCATENATE wa_final_fgm-matnr ls_msg-message INTO ls_msg-message SEPARATED BY ' : '.
      ENDIF.
      gs_msg-message = ls_msg-message.
      gs_msg-type  = ls_msg-type.

      APPEND gs_msg TO gt_msg.
    ENDLOOP.

    READ TABLE it_return_msg INTO ls_msg WITH KEY type = 'S'.
    IF sy-subrc = 0.
      v_success = v_success + 1.
      gs_msg-count = v_count.
      IF r_mat = 'X'.
        CONCATENATE wa_final_rm-matnr ls_msg-message INTO ls_msg-message SEPARATED BY ' : '.
      ELSEIF sf_mat = 'X'.
        CONCATENATE wa_final_sfm-matnr ls_msg-message INTO ls_msg-message SEPARATED BY ' : '.
      ELSEIF fg_mat = 'X'.
        CONCATENATE wa_final_fgm-matnr ls_msg-message INTO ls_msg-message SEPARATED BY ' : '.
      ENDIF.
      gs_msg-message = ls_msg-message.
      gs_msg-type  = ls_msg-type.
      APPEND gs_msg TO gt_msg.
    ENDIF.

  ENDIF.
  REFRESH : it_return_msg.
ENDFORM.                    " LOG




Output Selection Screen:



Share this

Related Posts