Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Code listing for: ZAGTESR_DISPLAY_CHAR_NEW

Description: APO CRM Interface

 

*&---------------------------------------------------------------------*
*& Report  ZAGTESR_DISPLAY_CHAR_NEW
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*


REPORT ZAGTESR_DISPLAY_CHAR_NEW MESSAGE-ID ZDEV.

*Global data declarations
*INCLUDE Zgtesn_charcomb_top.

*&---------------------------------------------------------------------*
*&  Include           ZGTESN_CHARCOMB_TOP
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&  Include           ZGTESN_CHARCOMB_TOP
*&---------------------------------------------------------------------*

TYPE-POOLS: rs, rsd, rsdw, rsddk, rsdu, slis.

CONTROLS : tbstrp TYPE TABSTRIP.

TYPES : BEGIN OF ty_salorg,
            vkorg TYPE VKORG,                     "Sales Organization
            saltext TYPE text60,
            vtweg TYPE VTWEG,                     " Description
            distext TYPE text60,
          END OF ty_salorg.

TYPES: BEGIN OF ty_matklpla_crm,
            matkl_crm TYPE char20,
            sales_org_crm TYPE VKORG,
            apopla_crm TYPE char40,
       END OF ty_matklpla_crm.

TYPES: BEGIN OF ty_matklpla_apo,
            matkl TYPE MATKL,
            vkorg TYPE VKORG,                 " Sales Organization
            parea TYPE /sapapo/ts_pareaname,  "APO Planning area
       END OF ty_matklpla_apo.

TYPES: BEGIN OF ty_salorg_input,
            vkorg TYPE VKORG ,                 " Sales Organization
       END OF ty_salorg_input.

TYPES : BEGIN OF ty_onlysales,
          vkorg TYPE VKORG,        " Sales Organization
          saltext TYPE text60,
        END OF ty_onlysales.

TYPES : BEGIN OF ty_matgrp1,
            mvgr1 TYPE MVGR1,
            bezei TYPE char40,
         END OF ty_matgrp1.


* For Material and Material Group1
TYPES : BEGIN OF ty_material,
           matnr TYPE matnr,            " Product
           vkorg TYPE vkorg,   " Sales Organization
           vtweg TYPE vtweg,   " Distribution Channel
           mvgr1 TYPE mvgr1,   " Material Group
        END OF ty_material.

* For Customer Hierarchy
TYPES : BEGIN OF ty_custhier,
            kunnr TYPE kunnr,             " Customer
            vkorg TYPE vkorg,    " Sales Organization
            vtweg TYPE vtweg,    " Distribution Channel
            END OF ty_custhier.

*** Begin of Mod-011
TYPES : BEGIN OF ty_cust_hier,
            kunnr TYPE kunnr,   " Customer
            vkorg TYPE vkorg,    " Sales Organization
            vtweg TYPE vtweg,    " Distribution Channel
            hzuor TYPE hzuor,              " Customer Level 2 or 4
        END OF ty_cust_hier.
*** End of Mod-011

* For Locations
TYPES : BEGIN OF ty_plants,
         matnr TYPE /sapapo/matnr_ex,
         werks TYPE werks_d,       " Plant
        END OF ty_plants.
*-->Begin of MOD-001
TYPES : BEGIN OF ty_output_tab,
          gtsalorg  TYPE vkorg,   "Sales Organisation
          gtnestch  TYPE VTWEG,   "Distribution Channel
          gtgroup1  TYPE mvgr1,   "Material Group 1
          gtcuslev4 TYPE CUS_HIER,  "Customer Level 4
          9amatnr   TYPE matnr,    "Product
          9alocno   TYPE /sapapo/loc-locid,    "APO - Location
          9aplobj   TYPE /SAPAPO/TS_PLOBJ,    "Planning Object
          sorg_desc TYPE rstxtlg,
          dch_desc  TYPE rstxtsh,
          clvl_desc TYPE rstxtmd,
          mgp_desc  TYPE rstxtsh,
          mat_desc  TYPE rstxtmd,
          loc_desc  TYPE rstxtmd,
        END OF ty_output_tab,
        ty_output_tab_t  TYPE STANDARD TABLE OF ty_output_tab.

*** Begin of MOD-002
TYPES: BEGIN OF ty_prod,
        sign      TYPE c,
        option(2) TYPE c,
        low       TYPE matnr,
        high      TYPE matnr,
        END OF ty_prod,
       ty_t_prod TYPE STANDARD TABLE OF ty_prod,

       BEGIN OF ty_mgrp,
        sign      TYPE c,
        option(2) TYPE c,
        low       TYPE /FRE/UI_SEL_VALUE,
        high      TYPE /FRE/UI_SEL_VALUE,
       END OF ty_mgrp,
       ty_t_mgrp TYPE STANDARD TABLE OF ty_mgrp,

       BEGIN OF ty_loc,
        sign      TYPE c,
        option(2) TYPE c,
        low       TYPE werks_d,
        high      TYPE werks_d,
       END OF ty_loc,
       ty_t_loc TYPE STANDARD TABLE OF ty_loc.
*** End of MOD-002

*DATA : i_sorg_desc   TYPE STANDARD TABLE OF /BIC/OIGTSALORG,
*       wa_sorg_desc  TYPE /BIC/OIGTSALORG,
*
*       i_dch_desc    TYPE STANDARD TABLE OF /BIC/OIGTNESTCH,
*       wa_dch_desc   TYPE /BIC/OIGTNESTCH,
*
*       i_clvl_desc   TYPE STANDARD TABLE OF /BIC/OIGTCUS4,
*       wa_clvl_desc  TYPE /BIC/OIGTCUS4,
*
*       i_mgp_desc    TYPE STANDARD TABLE OF /BIC/OIGTGROUP1,
*       wa_mgp_desc   TYPE /BIC/OIGTGROUP1,
*
*       i_mat_desc    TYPE STANDARD TABLE OF /bi0/9atmatnr,
*       wa_mat_desc   TYPE /bi0/9atmatnr,

DATA: i_loc_desc TYPE STANDARD TABLE OF /bi0/9atlocno,
       wa_loc_desc   TYPE /bi0/9atlocno.

DATA: i_field_cat TYPE lvc_t_fcat,
       wa_field_cat  TYPE lvc_s_fcat.
*<--End of MOD-001

DATA : i_sal_temp TYPE TABLE OF ty_salorg.


DATA : i_selections TYPE STANDARD TABLE OF /sapapo/ts_iobj_selection.



DATA : i_return TYPE TABLE OF ddshretval INITIAL SIZE 0,
        rec_return TYPE ddshretval.

DATA : i_dynpread TYPE STANDARD TABLE OF dynpread INITIAL SIZE 0,
       rec_dynpread TYPE dynpread.

DATA : i_group_by TYPE STANDARD TABLE OF /sapapo/ts_group_by_str .

*-->Begin of MOD-001 comment
*DATA : i_existing TYPE STANDARD TABLE OF /bic/vgtdppos32.
*DATA : rec_existing TYPE /bic/vgtdppos32.
*
*DATA : i_potential TYPE TABLE OF /bic/vgtdppos32,
*       rec_potential TYPE  /bic/vgtdppos32.
*<--End of MOD-001 comment

*-->Begin of MOD-001
DATA : i_existing TYPE STANDARD TABLE OF ty_output_tab,
       rec_existing TYPE ty_output_tab,

       i_potential TYPE STANDARD TABLE OF ty_output_tab,
       rec_potential TYPE ty_output_tab.

*<--End of MOD-001

*DATA: ty_t_vgtdppos32 TYPE STANDARD TABLE OF /BIC/EBDINFOCUBE.

DATA : v_plob_id TYPE /sapapo/ts_plobid.

DATA : i_fieldcat TYPE lvc_t_fcat.

DATA : rec_fieldcat TYPE lvc_s_fcat.
DATA : rec_layout TYPE lvc_s_layo.

DATA : i_sel_rows TYPE lvc_t_row,
        rec_sel_row TYPE lvc_s_row.

DATA : i_salorg TYPE STANDARD TABLE OF ty_salorg INITIAL SIZE 0,
       i_salorg_temp  TYPE STANDARD TABLE OF ty_salorg   INITIAL SIZE 0,
       i_plants       TYPE STANDARD TABLE OF ty_plants   INITIAL SIZE 0,
       i_plants_temp  TYPE STANDARD TABLE OF ty_plants   INITIAL SIZE 0,
       i_material     TYPE STANDARD TABLE OF ty_material INITIAL SIZE 0,
       i_mat_temp     TYPE STANDARD TABLE OF ty_material INITIAL SIZE 0,
       i_custhier     TYPE STANDARD TABLE OF ty_custhier INITIAL SIZE 0,
       i_hier_temp    TYPE STANDARD TABLE OF ty_custhier INITIAL SIZE 0,
       i_cust_heir    TYPE STANDARD TABLE OF ty_cust_hier.                "++Mod-011

DATA:
   i_matklpla_crm TYPE STANDARD TABLE OF ty_matklpla_crm INITIAL SIZE 0,
   i_matklpla_apo TYPE STANDARD TABLE OF ty_matklpla_apo INITIAL SIZE 0,
   i_salorg_input TYPE STANDARD TABLE OF ty_onlysales    INITIAL SIZE 0.

DATA: rec_matklpla_crm TYPE ty_matklpla_crm,
      rec_matklpla_apo TYPE ty_matklpla_apo,
      rec_salorg_input TYPE ty_onlysales.

DATA: v_pareaname TYPE /sapapo/ts_pareaname,
      p_mpos TYPE /sapapo/ts_plobname.

DATA : rec_salorg TYPE ty_salorg,
       rec_plants   TYPE ty_plants,
       rec_material TYPE ty_material,
       rec_custhier TYPE ty_custhier.

DATA : v_container1 TYPE scrfname VALUE 'CUST_CTRL_01',
       v_container2 TYPE scrfname VALUE 'CUST_CTRL_02',
       v_alv1 TYPE REF TO cl_gui_alv_grid  ,
       v_alv2 TYPE REF TO cl_gui_alv_grid  ,
       v_alv_container1 TYPE REF TO cl_gui_custom_container,
       v_alv_container2 TYPE REF TO cl_gui_custom_container.

CONSTANTS : c_param_salo(7) TYPE c VALUE 'P_VKORG',
            c_param_disc(7) TYPE c VALUE 'P_VTWEG',
            c_param_cusl(8) TYPE c VALUE 'P_CUSLVL',
            c_param_matg(8) TYPE c VALUE 'P_MATGRP',
            c_param_prod(6) TYPE c VALUE 'P_PROD',
            c_param_loc(5)  TYPE c VALUE 'P_LOC',
*** Begin of MOD-002
            c_param_cusl1(8)  TYPE c VALUE 'S_CUSLVL',
            c_cus_low(15)     TYPE c VALUE 'S_CUSLVL-LOW',
            c_cus_high(15)    TYPE c VALUE 'S_CUSLVL-HIGH',
            c_param_matg1(8)  TYPE c VALUE 'S_MATGRP',
            c_matg_low(15)    TYPE c VALUE 'S_MATGRP-LOW',
            c_matg_high(15)   TYPE c VALUE 'S_MATGRP-HIGH',
            c_param_prod1(15) TYPE c VALUE 'S_PROD-LOW',
            c_param_prod2(15) TYPE c VALUE 'S_PROD-HIGH',
            c_param_loc1(5)   TYPE c VALUE 'S_LOC',
            c_loc_low(15)     TYPE c VALUE 'S_LOC-LOW',
            c_loc_high(15)    TYPE c VALUE 'S_LOC-HIGH',
            c_star            TYPE c VALUE '*',
            c_option_bt(2)    TYPE c VALUE 'BT',
            c_1               TYPE i VALUE 1,
            c_2               TYPE i VALUE 2,
*** Begin of MOD-003
            c_3               TYPE i VALUE 3,
            c_4               TYPE i VALUE 4,
*** End of MOD-003
            c_dynnr           TYPE sydynnr VALUE '1000'.
*** End of MOD-002



CONSTANTS : c_mpos_loc(7) TYPE c VALUE '9ALOCNO',
            c_mpos_prod(7)  TYPE c VALUE '9AMATNR',
            c_mpos_cusl(9)  TYPE c VALUE 'GTCUSLEV4',
            c_mpos_matg(8)  TYPE c VALUE 'GTGROUP1',
            c_mpos_disc(8)  TYPE c VALUE 'GTNESTCH',
            c_mpos_salo(8)  TYPE c VALUE 'GTSALORG'.

*-->Begin of MOD-001
CONSTANTS : c_floc_desc TYPE fieldname VALUE 'LOC_DESC',
            c_fmat_desc      TYPE fieldname VALUE 'MAT_DESC',
            c_fsorg_desc     TYPE fieldname VALUE 'SORG_DESC',
            c_fdch_desc      TYPE fieldname VALUE 'DCH_DESC',
            c_fclvl_desc     TYPE fieldname VALUE 'CLVL_DESC',
            c_fmgp_desc      TYPE fieldname VALUE 'MGP_DESC',

            c_loc           TYPE scrtext_m VALUE 'APO Location',
            c_loc_desc      TYPE scrtext_m VALUE 'Locn Desc',
            c_prd           TYPE scrtext_m VALUE 'Product',
            c_prd_desc      TYPE scrtext_m VALUE 'Prod Desc',
            c_clvl          TYPE scrtext_m VALUE 'Customer Level 4',
            c_clvl_desc     TYPE scrtext_m VALUE 'Cust Lev Desc',
            c_mgp           TYPE scrtext_m VALUE 'Material Grp 1',
            c_mgp_desc      TYPE scrtext_m VALUE 'Mat Grp Desc',
            c_dch           TYPE scrtext_m VALUE 'Distr Channel',
            c_dch_desc      TYPE scrtext_m VALUE 'Distr Chan Desc',
            c_sorg          TYPE scrtext_m VALUE 'Sales Org',
            c_sorg_desc     TYPE scrtext_m VALUE 'Sales Org Desc',

            c_tabname_ex    TYPE tabname VALUE 'I_EXISTING',
            c_tabname_pt    TYPE tabname VALUE 'I_POTENTIAL'.
*<--End of MOD-001


CONSTANTS : c_fcode_back(4) TYPE c VALUE 'BACK',
            c_fcode_cancel(6) TYPE c VALUE 'CANCEL',
            c_fcode_exit(4) TYPE c VALUE 'EXIT',
            c_fcode_create(6) TYPE c VALUE 'CREATE',
            c_fcode_delete(6) TYPE c VALUE 'DELETE',
            c_fcode_tab1(5)  TYPE c VALUE 'PUSH1',
            c_fcode_tab2(5) TYPE c VALUE 'PUSH2'.


CONSTANTS : c_no TYPE c VALUE '2',
            c_x TYPE c VALUE 'X',
            c_a TYPE c VALUE 'A',
            c_s TYPE c VALUE 'S'.

CONSTANTS : c_plob_str TYPE tabname VALUE '/BIC/GTINFOCUBE'.

CONSTANTS : c_status(7) TYPE c VALUE 'PF_9000',
            c_title(8) TYPE c VALUE 'TIT-9000'.

CONSTANTS : c_sign_i TYPE c VALUE 'I',
            c_pattern(2)   TYPE c VALUE '+*',
            c_option_cp(2) TYPE c VALUE 'CP',
            c_option_eq(2) TYPE c VALUE 'EQ'.

CONSTANTS : c_vkorg TYPE fieldname VALUE 'VKORG',
            c_vtweg TYPE fieldname VALUE 'VTWEG',
            c_kunnr TYPE fieldname VALUE 'KUNNR',
            c_mvgr1 TYPE fieldname VALUE 'MVGR1',
            c_matnr TYPE fieldname VALUE 'MATNR',
            c_werks TYPE fieldname VALUE 'WERKS'.

CONSTANTS: c_crm(1) TYPE C VALUE 'C'.

* "TYPE  zrgtcw_system_type   VALUE  'C'.

DATA: v_cuslvl TYPE CUS_HIER,
      v_prod      TYPE /BIC/OIZ9AMATNR,
      v_matgrp    TYPE /SAPAPO/MATGRPTYPE,
      v_loc       TYPE /bi0/9aoilocno.

PARAMETERS :
*            Sales Organization
             p_vkorg      TYPE vkorg,
*            Distribution Channel
             p_vtweg      TYPE vtweg.  "MOD-004

SELECT-OPTIONS:
*            Customer at level 4
             s_cuslvl    FOR v_cuslvl  NO INTERVALS ,
*            Product
             s_prod      FOR v_prod    NO INTERVALS ,
*            Material group 1
             s_matgrp     FOR v_matgrp NO INTERVALS ,
*            Location
             s_loc        FOR v_loc    NO INTERVALS .





*INITIALIZATION.
*  PERFORM rfc_get_entries_for_f4.
*
************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vkorg.
************************************************************************
  PERFORM f4_on_vkorg.

************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vtweg.
************************************************************************
  PERFORM f4_on_vtweg.

*** Begin of Mod-004
************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_cuslvl-low.
************************************************************************
  PERFORM f4_on_cuslvl USING c_cus_low.
************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_cuslvl-high.
************************************************************************
  PERFORM f4_on_cuslvl USING c_cus_high.

************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_prod-low.
************************************************************************
  PERFORM f4_on_prod USING c_param_prod1.

************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_prod-high.
************************************************************************
  PERFORM f4_on_prod USING c_param_prod2.

************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_matgrp-low.
************************************************************************
  PERFORM f4_on_matgrp USING c_matg_low.

************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_matgrp-high.
************************************************************************
  PERFORM f4_on_matgrp USING c_matg_high.

************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_loc-low.
************************************************************************
  PERFORM f4_on_loc USING c_loc_low.

************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_loc-high.
************************************************************************
  PERFORM f4_on_loc USING c_loc_high.
*** End of Mod-004.

AT SELECTION-SCREEN.
  PERFORM validate_selections.
  PERFORM pad_lead_zeroes USING : s_prod-low, s_cuslvl-low. "Mod-004

************************************************************************
START-OF-SELECTION.
************************************************************************
*** Begin of MOD-004
  IF s_cuslvl[] IS INITIAL OR s_prod[] IS INITIAL OR s_loc[] IS INITIAL.
    MESSAGE s007.
    LEAVE LIST-PROCESSING.
    LEAVE SCREEN.
  ENDIF.
*** End of MOD-004


  PERFORM prepare_selections_tables.

* Returns ID when Name is passed.
  PERFORM get_plob_id_from_name USING p_mpos
                                CHANGING v_plob_id.

*-->Begin of MOD-002
* Prepare the tables containing the descriptions for the key figures
* PERFORM get_keyfigure_desc.
*<--End of MOD-002

* Get all the existing combinations from the Infocube.
  PERFORM get_existing_comb TABLES
                                   i_selections
                                   i_group_by
                             USING v_plob_id
                             CHANGING i_existing.

* Calculate the posible Combinations
  PERFORM get_potential_comb
                             CHANGING i_potential.


END-OF-SELECTION.

* Display ALV Grid.
  PERFORM display_in_alv.


*&---------------------------------------------------------------------*
*&      Form  rfc_get_entries_for_f4
*&---------------------------------------------------------------------*
*       Get Data from R/3 system
*----------------------------------------------------------------------*
FORM rfc_get_entries_for_f4.
* For performance reasons, it is important that RFC to R/3 and CRM
* is done only the first time, not everytime the selection screen is
* re-visited. So, all the retreived internal tables are exported to
* memory and imported when selection screen is re-visited.

  DATA : l_logdes_r3 TYPE rfcdest,
         l_logdes_crm TYPE rfcdest.
  DATA : flg_no_first_call TYPE flag,
         l_mpos_old TYPE /sapapo/ts_plobname,
         l_i_parea TYPE STANDARD TABLE OF /sapapo/tsareako.

* Import the flag to check first call or not
  IMPORT flg_no_first_call FROM MEMORY ID 'INDX_FLG'.

* Import the POS from calling program
  IMPORT p_mpos FROM MEMORY ID 'INDX_POS'.

* Import the old POS from current program
  IMPORT l_mpos_old FROM MEMORY ID 'INDX_POS_OLD'.

* If not first call and same POS, import from memory
  IF flg_no_first_call = c_x AND
     p_mpos = l_mpos_old.
    IMPORT i_salorg_input FROM MEMORY ID 'INDX_SALORG_INPUT'.
    IMPORT i_salorg FROM MEMORY ID 'INDX_SALORG'.
    IMPORT i_material FROM MEMORY ID 'INDX_MATERIAL'.
    IMPORT i_custhier FROM MEMORY ID 'INDX_CUSTHIER'.
    IMPORT i_plants FROM MEMORY ID 'INDX_PLANT'.
    EXIT.
  ELSE.
* If first call, retrieve from R/3 and CRM
    flg_no_first_call = c_x.
    PERFORM get_logical_dest_crm CHANGING l_logdes_crm.

    IF l_logdes_crm IS INITIAL.
* No entry found for CRM system in table /GLB/RGT_RFCDEST
      MESSAGE i002.
      LEAVE PROGRAM.
    ENDIF.

    IF NOT l_logdes_crm IS INITIAL.
      CALL FUNCTION 'RFC_PING'
        DESTINATION l_logdes_crm
        EXCEPTIONS
          communication_failure = 1
          system_failure        = 2.
      .

      IF sy-subrc <> 0.
        MESSAGE i003 WITH l_logdes_crm.
        LEAVE PROGRAM.
      ENDIF.

* Retrieve valid sales orgs from the mapping table /GLB/CGTMATKLPLA in
* CRM
*      CALL FUNCTION 'ZAGT_DATA_TO_APO'
*        DESTINATION l_logdes_crm
*        TABLES
*          i_matklpla = i_matklpla_crm.
*
*      LOOP AT i_matklpla_crm INTO rec_matklpla_crm.
*        MOVE:
*        rec_matklpla_crm-matkl_crm TO rec_matklpla_apo-matkl,
*        rec_matklpla_crm-sales_org_crm TO rec_matklpla_apo-vkorg,
*        rec_matklpla_crm-apopla_crm TO rec_matklpla_apo-parea.
*        APPEND rec_matklpla_apo TO i_matklpla_apo.
*      ENDLOOP.

      IF l_i_parea[] IS INITIAL.
        SELECT pareaid
        FROM /sapapo/tsareako
        INTO CORRESPONDING FIELDS OF TABLE l_i_parea
        WHERE bas_plobid = p_mpos.
      ENDIF.

      LOOP AT i_matklpla_apo INTO rec_matklpla_apo.
        READ TABLE l_i_parea TRANSPORTING NO FIELDS WITH KEY
        pareaid = rec_matklpla_apo-parea.
        CHECK sy-subrc = 0.
        MOVE: rec_matklpla_apo-vkorg TO rec_salorg_input-vkorg.
        APPEND rec_salorg_input TO i_salorg_input.
      ENDLOOP.
    ENDIF.

    SORT i_salorg_input.
    DELETE ADJACENT DUPLICATES FROM i_salorg_input.

*********************************************************
*MOD-001
*********************************************************

*    IF i_salorg_input[] IS INITIAL.
*      MESSAGE i004.
*      LEAVE PROGRAM.
*    ENDIF.
*
    PERFORM get_logical_dest CHANGING l_logdes_r3 .

*    IF l_logdes_r3 IS INITIAL.
*      MESSAGE i000 WITH text-013 .
*      LEAVE PROGRAM.
*    ENDIF.

*    CALL FUNCTION 'ZAGT_DATA_TO_APO'
*      DESTINATION l_logdes_r3
*      TABLES
*        i_salorg_input = i_salorg_input
*        i_salesdis     = i_salorg
*        i_material     = i_material
*        i_custhier     = i_custhier
*        i_plants       = i_plants.
*
*    LOOP AT i_material INTO rec_material.
*      PERFORM conversion_of_product USING  rec_material-matnr.
*      MODIFY i_material FROM rec_material TRANSPORTING matnr.
*    ENDLOOP.
*
*    LOOP AT i_plants INTO rec_plants.
*      PERFORM conversion_of_product USING  rec_plants-matnr.
*      MODIFY i_plants FROM rec_plants TRANSPORTING matnr.
*    ENDLOOP.
*
** Export the retrieved data to memory
*    EXPORT i_salorg_input TO MEMORY ID 'INDX_SALORG_INPUT'.
*    EXPORT i_salorg TO MEMORY ID 'INDX_SALORG'.
*    EXPORT i_material TO MEMORY ID 'INDX_MATERIAL'.
*    EXPORT i_custhier TO MEMORY ID 'INDX_CUSTHIER'.
*    EXPORT i_plants TO MEMORY ID 'INDX_PLANT'.
*    EXPORT flg_no_first_call TO MEMORY ID 'INDX_FLG'.
*    l_mpos_old = p_mpos.
*    EXPORT l_mpos_old TO MEMORY ID 'INDX_POS_OLD'.

*********************************************************
*MOD-001
*********************************************************
 ENDIF.
ENDFORM. " rfc_get_entries_for_f4

*&---------------------------------------------------------------------*
*&      Form  f4_on_vkorg
*&---------------------------------------------------------------------*
*       When the user Hits F4 on Sales organization.
*----------------------------------------------------------------------*
FORM f4_on_vkorg.
  DATA : i_onlysales TYPE STANDARD TABLE OF ty_onlysales INITIAL SIZE 0.

  i_onlysales[] = i_salorg[].

  DELETE ADJACENT DUPLICATES FROM i_onlysales COMPARING vkorg.

* Show the F4 screen
  PERFORM show_f4help TABLES i_onlysales
                      USING  c_vkorg
                             space.                         "Mod-004

* If the user selected a value from the F4 list capture it.
*  IF NOT i_return[] IS INITIAL.
*    READ TABLE i_return  INTO rec_return INDEX 1.
*    p_vkorg = rec_return-fieldval.
*  ELSE.
*    EXIT.
*  ENDIF.

  REFRESH i_dynpread.
* Identify the screen fields that need to be refreshed.

*** Begin of MOD-004
  PERFORM prepare_dynp USING :  c_param_disc,
                                c_param_cusl1,
                                c_param_prod1,
                                c_param_matg1,
                                c_param_loc1.
*** End of MOD-004

* Refresh the screen values ( since Sales organization changed )
  PERFORM refresh_screen TABLES i_dynpread.
ENDFORM. " f4_on_vkorg
*&---------------------------------------------------------------------*
*&      Form  f4_on_vtweg
*&---------------------------------------------------------------------*
*       When the user hits F4 on Distribution channel
*----------------------------------------------------------------------*
FORM f4_on_vtweg.
* Variable to stote the on screen value of Sales Organization
  DATA : l_vkorg TYPE char4.
* Take all the values in a temporary internal table( For Manipulations )
  i_sal_temp[] = i_salorg[].

  REFRESH i_dynpread.
* Read on-screen value of sales organization
  PERFORM prepare_dynp USING : c_param_salo.
  PERFORM read_screen_values TABLES i_dynpread.

  CLEAR rec_dynpread.
  READ TABLE i_dynpread INTO rec_dynpread INDEX 1.
  IF sy-subrc = 0.
    l_vkorg = rec_dynpread-fieldvalue.
  ENDIF.

  IF l_vkorg IS INITIAL.
    MESSAGE i000 WITH text-014. " Fill the above fields first.
  ENDIF.

* Filter the no of entries based on Sales org entered on screen
  DELETE i_sal_temp WHERE vkorg NE l_vkorg.

  REFRESH i_return.
  CLEAR   rec_return.

* Show the possible Distribution channles
  PERFORM show_f4help TABLES i_sal_temp
                      USING c_vtweg
                            space.                          "Mod-004

* If user has selected a distribution channel
*  IF NOT i_return[] IS INITIAL.
*    READ TABLE i_return  INTO rec_return INDEX 1.
*    p_vtweg = rec_return-fieldval.
*  ELSE.
*    EXIT.
*  ENDIF.

  REFRESH i_dynpread.
* Refresh screen values dependent on Distribution channel

*** Begin of MOD-004
  PERFORM prepare_dynp USING :  c_param_cusl1,
                                c_param_prod1,
                                c_param_matg1,
                                c_param_loc1.
*** End of MOD-004.

  PERFORM refresh_screen TABLES i_dynpread.
ENDFORM. " f4_on_vtweg
*&---------------------------------------------------------------------*
*&      Form  f4_on_cuslvl
*&---------------------------------------------------------------------*
*       When the user hits F4 on Customer level 4.
*----------------------------------------------------------------------*
FORM f4_on_cuslvl USING fp_cus TYPE char15.

  DATA : l_vkorg TYPE char4,
         l_vtweg TYPE char2.

  CLEAR i_dynpread.
  REFRESH i_dynpread.


  i_hier_temp[] = i_custhier[].

  rec_dynpread-fieldname = c_param_salo.
  APPEND rec_dynpread TO i_dynpread.

  rec_dynpread-fieldname = c_param_disc.
  APPEND rec_dynpread TO i_dynpread.

  PERFORM read_screen_values TABLES i_dynpread.

  READ TABLE i_dynpread INTO rec_dynpread INDEX 1.
  l_vkorg = rec_dynpread-fieldvalue.

  READ TABLE i_dynpread INTO rec_dynpread INDEX 2.
  l_vtweg = rec_dynpread-fieldvalue.

  IF l_vkorg IS INITIAL OR l_vtweg IS INITIAL.
    MESSAGE i000 WITH text-015.
  ENDIF.

  DELETE i_hier_temp WHERE vkorg NE l_vkorg
                       OR vtweg NE l_vtweg.

  REFRESH i_return.
  CLEAR   rec_return.

  PERFORM show_f4help TABLES i_hier_temp
                      USING c_kunnr
                            fp_cus.                         "MOD-004

*  IF NOT i_return IS INITIAL.
*    READ TABLE i_return INTO rec_return  INDEX 1.
*    p_cuslvl = rec_return-fieldval.
*  ENDIF.

ENDFORM. " f4_on_cuslvl
*&---------------------------------------------------------------------*
*&      Form  f4_on_prod
*&---------------------------------------------------------------------*
*       When the user Hits F4 on Product
*----------------------------------------------------------------------*
FORM f4_on_prod USING fp_param_prod TYPE char15.
  DATA : l_vtweg TYPE char2,
         l_vkorg TYPE char4.
  CLEAR i_dynpread.
  REFRESH i_dynpread.
  REFRESH i_mat_temp.
  CLEAR i_mat_temp.

  i_mat_temp[] = i_material[].

  PERFORM prepare_dynp USING :  c_param_salo,
                                c_param_disc.

  PERFORM read_screen_values TABLES i_dynpread.

  READ TABLE i_dynpread INTO rec_dynpread INDEX 1.
  l_vkorg = rec_dynpread-fieldvalue.

  READ TABLE i_dynpread INTO rec_dynpread INDEX 2.
  l_vtweg = rec_dynpread-fieldvalue.

  IF l_vkorg IS INITIAL OR l_vtweg IS INITIAL.
    MESSAGE i000 WITH text-015.
    EXIT.
  ENDIF.

  DELETE i_mat_temp WHERE vkorg NE l_vkorg
                       OR vtweg NE l_vtweg.


  REFRESH i_return.
  CLEAR   rec_return.

  PERFORM show_f4help TABLES i_mat_temp
                          USING c_matnr
                                fp_param_prod.              "MOD-004

*  IF NOT i_return[] IS INITIAL.
*
*    READ TABLE i_return  INTO rec_return INDEX 1.
*    p_prod = rec_return-fieldval.
*
*  ENDIF.

* Whenever product is changed Material group on screen should be
* refreshed.
  REFRESH i_dynpread.
  PERFORM prepare_dynp USING : c_param_matg1.
  PERFORM refresh_screen TABLES i_dynpread.


ENDFORM. " f4_on_prod
*&---------------------------------------------------------------------*
*&      Form  f4_on_matgrp
*&---------------------------------------------------------------------*
*       When the user Hits F4 on Material group
*----------------------------------------------------------------------*
FORM f4_on_matgrp USING fp_matg TYPE char15.
  DATA : l_vkorg TYPE char4,  " Sales Organization
          l_vtweg TYPE char2,  " Distribution Channel
          l_matnr TYPE char18, " Product
          l_v_line TYPE i,
          l_i_prod      TYPE ty_t_prod,
          l_wa_material TYPE ty_material.

  CLEAR rec_dynpread.
  REFRESH i_dynpread.

  CLEAR i_mat_temp.
  REFRESH i_mat_temp.

  i_mat_temp[] = i_material[].

* Read onscreen values of Sales Org, Dis Chnl, Product
  PERFORM prepare_dynp USING :  c_param_salo,
                                c_param_disc,
                                c_param_prod1.              "Mod-004

  PERFORM read_screen_values TABLES i_dynpread.
  CLEAR rec_dynpread.

* Assign the values read to corresponding variables.
  READ TABLE i_dynpread INTO rec_dynpread INDEX 1.
  l_vkorg = rec_dynpread-fieldvalue.

  READ TABLE i_dynpread INTO rec_dynpread INDEX 2.
  l_vtweg = rec_dynpread-fieldvalue.

  READ TABLE i_dynpread INTO rec_dynpread INDEX 3.
  l_matnr = rec_dynpread-fieldvalue.
*** Begin of MOD-004
  IF l_vkorg IS INITIAL OR l_vtweg IS INITIAL
                OR ( l_matnr IS INITIAL AND s_prod[] IS INITIAL ).
    MESSAGE i000 WITH text-016.
    EXIT.
  ENDIF.

* Filter the F4 table depending on values selected.
  IF l_matnr = c_star.
    DELETE i_mat_temp WHERE vkorg NE l_vkorg
                         OR vtweg NE l_vtweg.
  ELSE.
    DESCRIBE TABLE s_prod LINES l_v_line.
    IF l_v_line LT 1.
      DELETE i_mat_temp WHERE vkorg NE l_vkorg
                           OR vtweg NE l_vtweg
                           OR matnr NE l_matnr.
    ELSE.
      PERFORM product_range CHANGING l_i_prod.
      DELETE i_mat_temp WHERE vkorg NE l_vkorg
                           OR vtweg NE l_vtweg
                           OR NOT matnr IN l_i_prod.
      LOOP AT i_mat_temp INTO l_wa_material.
        PERFORM conversion_of_product USING l_wa_material-matnr.
        MODIFY i_mat_temp FROM l_wa_material.
      ENDLOOP.
    ENDIF.
  ENDIF.
*** End of MOD-004
  REFRESH i_return.
  CLEAR   rec_return.

* Display F4 help for Material group.
  PERFORM show_f4help TABLES i_mat_temp
                         USING c_mvgr1
                               fp_matg.                     "Mod-004

*  IF NOT i_return[] IS INITIAL.
*
*    READ TABLE i_return  INTO rec_return INDEX 1.
*    p_matgrp = rec_return-fieldval.
*
*  ENDIF.



ENDFORM. " f4_on_matgrp

*&---------------------------------------------------------------------*
*&      Form  f4_on_loc
*&---------------------------------------------------------------------*
*       When the user hits F4 on Location
*----------------------------------------------------------------------*
FORM f4_on_loc USING fp_loc TYPE char15.

  DATA : l_matnr  TYPE char18,
           l_v_line TYPE i,
           l_i_prod TYPE ty_t_prod,
           l_wa_plants TYPE ty_plants.

  REFRESH i_dynpread.
  REFRESH i_mat_temp.
  CLEAR i_mat_temp.

  i_plants_temp[]  =  i_plants[].


  PERFORM prepare_dynp USING : c_param_prod1.               "Mod-004

  PERFORM read_screen_values TABLES i_dynpread.

  READ TABLE i_dynpread INTO rec_dynpread INDEX 1.
  IF sy-subrc = 0.
    l_matnr = rec_dynpread-fieldvalue.
  ENDIF.
*** Begin of MOD-004
  IF  l_matnr IS INITIAL AND s_prod[] IS INITIAL.
    MESSAGE i000 WITH text-017.
    EXIT.
  ENDIF.
  IF l_matnr NE c_star.
    DESCRIBE TABLE s_prod LINES l_v_line.
    IF l_v_line LT 1.
      DELETE i_plants_temp WHERE matnr NE l_matnr.
    ELSE.
*     PERFORM plant_product_range CHANGING l_i_prod.
      DELETE i_plants_temp WHERE NOT matnr IN l_i_prod.
      LOOP AT i_plants_temp INTO l_wa_plants.
        PERFORM conversion_of_product USING l_wa_plants-matnr.
        MODIFY i_plants_temp FROM l_wa_plants.
      ENDLOOP.
    ENDIF.
  ENDIF.
*** End of MOD-004

  REFRESH i_return.
  CLEAR   rec_return.

  PERFORM show_f4help TABLES i_plants_temp
                      USING c_werks
                            fp_loc.                         "Mod-004

*  IF NOT i_return[] IS INITIAL.
*
*    READ TABLE i_return  INTO rec_return INDEX 1.
*    p_loc = rec_return-fieldval.
*
*  ENDIF.


ENDFORM. " f4_on_loc
*&---------------------------------------------------------------------*
*&      Form  show_f4help
*&---------------------------------------------------------------------*
*       Pops up the standard F4 help
*----------------------------------------------------------------------*
*      -->P_I_VALTAB  Containing Values to be shown in F4.
*      -->P_FIELD     Field on which F4 is pressed.
*----------------------------------------------------------------------*
FORM show_f4help TABLES p_i_valtab
                 USING    p_field  TYPE fieldname
                          fp_field TYPE char15.

*** Begin of MOD-004

*  DATA : l_progname TYPE syrepid,
*         l_screen   TYPE sydynnr,
*         l_dynfam   TYPE dynfnam.

  DATA : l_dynfam   TYPE dynfnam,
         l_wa_return TYPE ddshretval.
*** Begin of MOD-004
*  l_progname = sy-repid.
*  l_screen = sy-dynnr
*** End of MOD-004.
  l_dynfam = p_field.

*** End of MOD-004

  REFRESH i_return.

*  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
*       EXPORTING
*            retfield        = p_field
*            value_org       = c_s
*       TABLES
*            value_tab       = p_i_valtab
*            return_tab      = i_return[]
*       EXCEPTIONS
*            parameter_error = 1
*            no_values_found = 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.
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
*   DDIC_STRUCTURE         = ' '
      retfield               = p_field
*   PVALKEY                = ' '
*** Begin of MOD-001
*      dynpprog               = l_progname
*      dynpnr                 = l_screen
*** End of MOD-001
      dynprofield            = l_dynfam
*   STEPL                  = 0
*   WINDOW_TITLE           =
*   VALUE                  = ' '
      value_org              = c_s
*   MULTIPLE_CHOICE        = ' '
*   DISPLAY                = ' '
*   CALLBACK_PROGRAM       = ' '
*   CALLBACK_FORM          = ' '
    TABLES
      value_tab             = p_i_valtab
*   FIELD_TAB              =
      return_tab            = i_return                      "MOD-004
*   DYNPFLD_MAPPING        =
* EXCEPTIONS
*   PARAMETER_ERROR        = 1
*   NO_VALUES_FOUND        = 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.
*** Begin of MOD-004
  READ TABLE i_return INTO l_wa_return INDEX 1.
  IF sy-subrc = 0.
    CASE p_field.
      WHEN  c_vkorg.
        p_vkorg      = l_wa_return-fieldval.
      WHEN  c_vtweg.
        p_vtweg      = l_wa_return-fieldval.
      WHEN  c_kunnr.
        IF fp_field = c_cus_low.
          s_cuslvl-low   = l_wa_return-fieldval.
        ELSE.
          s_cuslvl-high =  l_wa_return-fieldval.
        ENDIF.
      WHEN  c_matnr.
        IF fp_field = c_param_prod1.
          s_prod-low   = l_wa_return-fieldval.
        ELSE.
          s_prod-high =  l_wa_return-fieldval.
        ENDIF.
      WHEN c_mvgr1.
        IF fp_field = c_matg_low.
          s_matgrp-low   = l_wa_return-fieldval.
        ELSE.
          s_matgrp-high =  l_wa_return-fieldval.
        ENDIF.
      WHEN c_werks.
        IF fp_field = c_loc_low.
          s_loc-low   = l_wa_return-fieldval.
        ELSE.
          s_loc-high =  l_wa_return-fieldval.
        ENDIF.
    ENDCASE.
  ENDIF.
* End of MOD-004
ENDFORM. " show_f4help
*&---------------------------------------------------------------------*
*&      Form  read_screen_values
*&---------------------------------------------------------------------*
*       Reads the screen values
*----------------------------------------------------------------------*
*      -->P_I_DYNPREAD  text
*----------------------------------------------------------------------*
FORM read_screen_values TABLES p_i_dynpread STRUCTURE dynpread.

  DATA : l_prog TYPE sycprog,
         l_scr  TYPE sydynnr.

  l_prog = sy-cprog.
  l_scr  = c_dynnr.                                         "MOD-004

  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname               = l_prog
      dynumb               = l_scr
      translate_to_upper   = c_x
    TABLES
      dynpfields           = p_i_dynpread
    EXCEPTIONS
      invalid_abapworkarea = 1
      invalid_dynprofield  = 2
      invalid_dynproname   = 3
      invalid_dynpronummer = 4
      invalid_request      = 5
      no_fielddescription  = 6
      invalid_parameter    = 7
      undefind_error       = 8
      double_conversion    = 9
      stepl_not_found      = 10
      OTHERS               = 11.
  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. " read_screen_values
*&---------------------------------------------------------------------*
*&      Form  refresh_screen
*&---------------------------------------------------------------------*
*       update on screen values
*----------------------------------------------------------------------*
*      -->P_I_DYNPREAD  text
*----------------------------------------------------------------------*
FORM refresh_screen TABLES p_i_dynpread STRUCTURE dynpread.

  DATA : l_progname TYPE sycprog,
         l_screen   TYPE sydynnr.

  l_progname = sy-cprog.
  l_screen   = sy-dynnr.

  CALL FUNCTION 'DYNP_VALUES_UPDATE'
    EXPORTING
      dyname               = l_progname
      dynumb               = l_screen
    TABLES
      dynpfields           = p_i_dynpread
    EXCEPTIONS
      invalid_abapworkarea = 1
      invalid_dynprofield  = 2
      invalid_dynproname   = 3
      invalid_dynpronummer = 4
      invalid_request      = 5
      no_fielddescription  = 6
      undefind_error       = 7
      OTHERS               = 8.
  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. " refresh_screen
*&---------------------------------------------------------------------*
*&      Form  pad_lead_zeroes
*&---------------------------------------------------------------------*
*         Pads leading zeroes to Product and Customer
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM pad_lead_zeroes USING p_field.

  CHECK NOT p_field IS INITIAL.

  DATA : l_field TYPE /sapapo/matnr.

  CALL FUNCTION 'CONVERSION_EXIT_PRODU_INPUT'
    EXPORTING
      input        = p_field
    IMPORTING
      output       = l_field
    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.

  CASE p_field.
    WHEN c_param_prod1.                                     "Mod-004
      s_prod = l_field+22(18).
    WHEN c_param_cusl1.
      s_cuslvl = l_field+30(10).                            "Mod-004
  ENDCASE.
ENDFORM. " pad_lead_zeroes
*&---------------------------------------------------------------------*
*&      Form  PREPARE_DYNP
*&---------------------------------------------------------------------*
*       Prepare Itab to be passed to Dynp_values_read and Update
*----------------------------------------------------------------------*
*      -->p_paramname    Parameter name
*----------------------------------------------------------------------*
FORM prepare_dynp USING p_paramname.

  rec_dynpread-fieldname = p_paramname.
  rec_dynpread-fieldvalue = space.
  APPEND rec_dynpread TO i_dynpread.

ENDFORM. " PREPARE_DYNP

*&---------------------------------------------------------------------*
*&      Form  prepare_selections_tables
*&---------------------------------------------------------------------*
* Prepare Internal table containing selections to retrieve Combinations
*----------------------------------------------------------------------*
FORM prepare_selections_tables .

  DATA : l_matnr TYPE /sapapo/matnr,
         l_matnr_h TYPE /sapapo/matnr.

* Prepares group by internal table
  PERFORM append_group_by TABLES i_group_by.

*** Begin of MOD-004
  IF NOT s_loc[] IS INITIAL.
    LOOP AT s_loc.
      PERFORM append_selections USING c_mpos_loc
                                        s_loc-sign
                                        s_loc-option
                                        s_loc-low
                                        s_loc-high.
    ENDLOOP.
  ENDIF.

  IF NOT s_prod[] IS INITIAL.

    LOOP AT s_prod.
      CALL FUNCTION 'CONVERSION_EXIT_PRODU_INPUT'
        EXPORTING
          input  = s_prod-low
        IMPORTING
          output = l_matnr.

      CALL FUNCTION 'CONVERSION_EXIT_PRODU_INPUT'
        EXPORTING
          input  = s_prod-high
        IMPORTING
          output = l_matnr_h.

      PERFORM append_selections USING c_mpos_prod
                                      s_prod-sign
                                      s_prod-option
                                      l_matnr
                                      l_matnr_h.
    ENDLOOP.
  ENDIF.

  IF NOT s_cuslvl[] IS INITIAL.
    LOOP AT s_cuslvl.
      PERFORM append_selections USING c_mpos_cusl
                                      s_cuslvl-sign
                                      s_cuslvl-option
                                      s_cuslvl-low
                                      s_cuslvl-high.
    ENDLOOP.
  ENDIF.

  IF NOT s_matgrp[] IS INITIAL.
    LOOP AT s_matgrp.
      PERFORM append_selections USING c_mpos_matg
                                      s_matgrp-sign
                                      s_matgrp-option
                                      s_matgrp-low
                                      s_matgrp-high.
    ENDLOOP.
  ENDIF.


  IF NOT p_vtweg IS INITIAL.
    PERFORM append_selections USING c_mpos_disc
                                    c_sign_i
                                    c_option_eq
                                    p_vtweg
                                    space.
  ENDIF.

  IF NOT p_vkorg IS INITIAL.
    PERFORM append_selections USING c_mpos_salo
                                    c_sign_i
                                    c_option_eq
                                    p_vkorg
                                    space.
  ENDIF.

*End of MOD-004
ENDFORM. " prepare_selections_tables
*&---------------------------------------------------------------------*
*&      Form  get_plob_id_from_name
*&---------------------------------------------------------------------*
*       Return ID when Name is passed.
*----------------------------------------------------------------------*
FORM get_plob_id_from_name USING p_mpos TYPE /sapapo/ts_plobname
                           CHANGING p_plob_id TYPE /sapapo/ts_plobid.

  CALL FUNCTION '/SAPAPO/TS_PSTRU_PLOBID_GET'
    EXPORTING
      iv_plobname      = p_mpos
    IMPORTING
      ev_plobid        = p_plob_id
    EXCEPTIONS
      plobname_invalid = 1
      OTHERS           = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


ENDFORM. " get_plob_id_from_name
*&---------------------------------------------------------------------*
*&      Form  get_existing_combinations
*&---------------------------------------------------------------------*
*      Get all the existing characteristing combinations
*----------------------------------------------------------------------*
*      -->P_I_EXISTING    Table containing Existing values
*      -->P_I_SELECTIONS  Table containing Selections from sel screen
*      -->P_I_GROUP_BY    Table containing Group by criteria
*      -->P_PLOB_ID       ID of the planning Object
*----------------------------------------------------------------------*
FORM get_existing_comb
              TABLES
                      p_i_selections STRUCTURE /sapapo/ts_iobj_selection
                      p_i_group_by   STRUCTURE /sapapo/ts_group_by_str
              USING   p_plob_id TYPE /sapapo/ts_plobid
              CHANGING p_i_existing TYPE ty_output_tab_t.

  DATA:
    l_i_existing    TYPE STANDARD TABLE OF /BIC/GTINFOCUBE,
    l_rec_existing  TYPE /BIC/GTINFOCUBE.

* FM Retrieves all the existing combinations for the Planning Object
  CALL FUNCTION '/SAPAPO/TS_PLOB_LIST_GET'
    EXPORTING
      iv_bas_plobid            = p_plob_id
      it_selection             = p_i_selections[]
      it_group_by              = p_i_group_by[]
    IMPORTING
      et_plobs_in_view         = l_i_existing
    EXCEPTIONS
      invalid_selection        = 1
      no_bas_plobid            = 2
      inherited_error          = 3
      coding_generation_failed = 4
      OTHERS                   = 5.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  LOOP AT l_i_existing INTO l_rec_existing.

* Getting the keyfigure descriptions from the relevent tables
* Getting the location description
    CLEAR rec_existing.
    rec_existing-gtsalorg = l_rec_existing-Zgtsalorg.
    rec_existing-gtnestch = l_rec_existing-Zgtnestch.
    rec_existing-gtgroup1 = l_rec_existing-Zgtgroup1.
    rec_existing-gtcuslev4 = l_rec_existing-Zgtcuslev4.
    rec_existing-9amatnr = l_rec_existing-z9amatnr.
    rec_existing-9alocno = l_rec_existing-z9alocno.

    READ TABLE i_loc_desc INTO wa_loc_desc
      WITH KEY /bi0/9alocno = l_rec_existing-z9alocno
      BINARY SEARCH.
    IF sy-subrc = 0.

**Begin Of Mod-009**
*      rec_existing-loc_desc = wa_loc_desc-txtmd.
      rec_existing-loc_desc = wa_loc_desc-TXTSH.
**End Of Mod-009**

    ENDIF.

* Getting the material description

*    READ TABLE i_mat_desc INTO wa_mat_desc
*      WITH KEY /bi0/9amatnr = l_rec_existing-z9amatnr
*      BINARY SEARCH.
*    IF sy-subrc = 0.
*
***Begin Of Mod-009**
**      rec_existing-mat_desc = wa_mat_desc-txtmd.
*      rec_existing-mat_desc = wa_mat_desc-TXTSH.
*
***End Of Mod-009**
*
*    ENDIF.

** Getting the material group description
*    READ TABLE i_mgp_desc INTO wa_mgp_desc
*      WITH KEY /bic/gtgroup1 = l_rec_existing-gtgroup1
*      BINARY SEARCH.
*    IF sy-subrc = 0.
*      rec_existing-mgp_desc = wa_mgp_desc-txtsh.
*    ENDIF.
*
** Getting the customer level description
*    READ TABLE i_clvl_desc INTO wa_clvl_desc
*      WITH KEY /bic/gtcuslev4 = l_rec_existing-gtcuslev4
*      BINARY SEARCH.
*    IF sy-subrc = 0.
*      rec_existing-clvl_desc = wa_clvl_desc-txtmd.
*    ENDIF.
*
** Getting the distribution channel description
*    READ TABLE i_dch_desc INTO wa_dch_desc
*      WITH KEY /bic/gtnestch = l_rec_existing-gtnestch
*      BINARY SEARCH.
*    IF sy-subrc = 0.
*      rec_existing-dch_desc = wa_dch_desc-txtsh.
*    ENDIF.
*
** Getting the sales organisation description
*    READ TABLE i_sorg_desc INTO wa_sorg_desc
*      WITH KEY /bic/gtsalorg = l_rec_existing-gtsalorg
*      BINARY SEARCH.
*    IF sy-subrc = 0.
*      rec_existing-sorg_desc = wa_sorg_desc-txtlg.
*    ENDIF.
     APPEND rec_existing TO p_i_existing.
  ENDLOOP.
**<--End of MOD-002
*
*** Begin of MOD-004
  SORT p_i_existing BY 9alocno    9amatnr
                      gtcuslev4  gtgroup1
                      gtnestch   gtsalorg.
***End of MOD-004

ENDFORM. " get_existing_combinations
*&---------------------------------------------------------------------*
*&      Form  get_potential_comb
*&---------------------------------------------------------------------*
*       Get all the potential combinations
*----------------------------------------------------------------------*
*  --> P_I_POTENTIAL     TABLE containing potential values .
*----------------------------------------------------------------------*
FORM get_potential_comb
*-->Begin of MOD-002 comment
*                        TABLES p_i_potential STRUCTURE /bic/vgtdppos32.
*<--End of MOD-002 comment
*-->Begin of MOD-002
                         CHANGING p_i_potential  TYPE ty_output_tab_t.
*<--End of MOD-002


* Mod-001
  DATA : l_matnr TYPE /bi0/9aoimatnr.
* end of mod 001

*-->Begin of MOD-002
  DATA : l_v_matnr  TYPE /bi0/9aoimatnr,
         l_v_locno  TYPE /bi0/9aoilocno.
*<--End of MOD-002

* Store data retrieved from R/3 system in temp internal tables for
* manipulations
  i_salorg_temp[] = i_salorg[].
  i_mat_temp[]    = i_material[].
  i_hier_temp[]   = i_custhier[].
  i_plants_temp[] = i_plants[].

* Filter entries based on selection criterion.
  IF NOT p_vtweg IS INITIAL.
    DELETE i_salorg_temp WHERE vkorg NE p_vkorg
                            OR vtweg NE p_vtweg.

    DELETE i_mat_temp WHERE vkorg NE p_vkorg
                         OR vtweg NE p_vtweg.
    DELETE i_hier_temp WHERE vkorg NE p_vkorg
                          OR vtweg NE p_vtweg.

*** Begin of MOD-004
    IF NOT s_cuslvl[] IS INITIAL.
      DELETE i_hier_temp WHERE NOT kunnr IN s_cuslvl.
    ENDIF.

    IF NOT s_prod[] IS INITIAL.
      DELETE i_mat_temp WHERE NOT matnr IN s_prod.
      DELETE i_plants_temp WHERE NOT matnr IN s_prod.
    ENDIF.

    IF NOT s_matgrp[] IS INITIAL.
      DELETE i_mat_temp WHERE NOT mvgr1 IN s_matgrp.
    ENDIF.

    IF NOT s_loc[] IS INITIAL.
      DELETE i_plants_temp WHERE NOT werks IN s_loc.
    ENDIF.
*** End of MOD-004
  ELSE.
    DELETE i_salorg_temp WHERE vkorg NE p_vkorg.
    DELETE i_mat_temp WHERE vkorg NE p_vkorg.
    DELETE i_hier_temp WHERE vkorg NE p_vkorg.
  ENDIF.

  LOOP AT i_salorg_temp INTO rec_salorg.

    LOOP AT i_mat_temp INTO rec_material WHERE
               vkorg EQ rec_salorg-vkorg AND vtweg EQ rec_salorg-vtweg.


      LOOP AT i_hier_temp INTO rec_custhier WHERE
               vkorg EQ rec_salorg-vkorg AND vtweg EQ rec_salorg-vtweg.

        LOOP AT i_plants_temp INTO rec_plants WHERE
                   matnr EQ  rec_material-matnr.

          CLEAR rec_potential.
          rec_potential-gtsalorg  = rec_salorg-vkorg.
          rec_potential-gtnestch  = rec_salorg-vtweg.
          rec_potential-gtcuslev4 = rec_custhier-kunnr.
          rec_potential-gtgroup1  = rec_material-mvgr1.
          l_v_matnr = rec_material-matnr.
          CALL FUNCTION 'CONVERSION_EXIT_PRODU_INPUT'
            EXPORTING
              input  = l_v_matnr
            IMPORTING
              output = l_v_matnr.
          rec_potential-9amatnr   = l_v_matnr.
          rec_potential-9alocno   = rec_plants-werks.

*---------Begin of MOD-003
          IF rec_potential-gtsalorg  IS INITIAL
          OR rec_potential-gtnestch  IS INITIAL
          OR rec_potential-gtcuslev4 IS INITIAL
          OR rec_potential-gtgroup1  IS INITIAL
          OR rec_potential-9amatnr   IS INITIAL
          OR rec_potential-9alocno   IS INITIAL.

            CONTINUE.
          ENDIF.
*--------End of MOD-003.


*-->Begin of MOD-002
* Getting the keyfigure descriptions from the relevent tables
* Getting the location description
          l_v_locno = rec_plants-werks.
          READ TABLE i_loc_desc INTO wa_loc_desc
            WITH KEY /bi0/9alocno = l_v_locno
            BINARY SEARCH.
          IF sy-subrc = 0.
**Begin Of Mod-009**
*            rec_potential-loc_desc = wa_loc_desc-txtmd.
            rec_potential-loc_desc = wa_loc_desc-TXTSH.

**Begin Of Mod-009**

          ENDIF.

** Getting the material description
*          READ TABLE i_mat_desc INTO wa_mat_desc
*            WITH KEY /bi0/9amatnr = l_v_matnr
*            BINARY SEARCH.
*          IF sy-subrc = 0.
***Begin of Mod-009*
**            rec_potential-mat_desc = wa_mat_desc-txtmd.
*            rec_potential-mat_desc = wa_mat_desc-TXTSH.
*****End Of Mod-009
*          ENDIF.
*
** Getting the material group description
*          READ TABLE i_mgp_desc INTO wa_mgp_desc
*            WITH KEY /bic/gtgroup1 = rec_material-mvgr1
*            BINARY SEARCH.
*          IF sy-subrc = 0.
*            rec_potential-mgp_desc = wa_mgp_desc-txtsh.
*          ENDIF.
*
** Getting the customer level description
*          READ TABLE i_clvl_desc INTO wa_clvl_desc
*            WITH KEY /bic/gtcuslev4 = rec_custhier-kunnr
*            BINARY SEARCH.
*          IF sy-subrc = 0.
*            rec_potential-clvl_desc = wa_clvl_desc-txtmd.
*          ENDIF.
*
** Getting the distribution channel description
*          READ TABLE i_dch_desc INTO wa_dch_desc
*            WITH KEY /bic/gtnestch = rec_salorg-vtweg
*            BINARY SEARCH.
*          IF sy-subrc = 0.
*            rec_potential-dch_desc = wa_dch_desc-txtsh.
*          ENDIF.
*
** Getting the sales organisation description
*          READ TABLE i_sorg_desc INTO wa_sorg_desc
*            WITH KEY /bic/gtsalorg = rec_salorg-vkorg
*            BINARY SEARCH.
*          IF sy-subrc = 0.
*            rec_potential-sorg_desc = wa_sorg_desc-txtlg.
*          ENDIF.

*<--End of MOD-002

          APPEND rec_potential TO p_i_potential.

        ENDLOOP.

      ENDLOOP.

    ENDLOOP.

  ENDLOOP.

  SORT i_potential BY 9alocno    9amatnr
                      gtcuslev4  gtgroup1
                      gtnestch   gtsalorg.

* After getting potential combinations, delete already existing ones.

*MOD-001 - read i_potential matnr by Last 18 Char of i_existing-9amatnr

  LOOP AT i_existing INTO rec_existing.
*** Begin of MOD-004
*    l_matnr = rec_existing-9amatnr.
*    PERFORM conversion_of_product USING  l_matnr.
*** End of MOD-004


    READ TABLE p_i_potential INTO rec_potential
                           WITH KEY 9alocno    = rec_existing-9alocno
                               9amatnr    = rec_existing-9amatnr"MOD-004
                               gtcuslev4  = rec_existing-gtcuslev4
                               gtgroup1   = rec_existing-gtgroup1
                               gtnestch   = rec_existing-gtnestch
                               gtsalorg   = rec_existing-gtsalorg
                               BINARY SEARCH.
    IF sy-subrc = 0.
      DELETE p_i_potential INDEX sy-tabix.
    ENDIF.
  ENDLOOP.


*-MOD-003
  IF p_i_potential[] IS INITIAL.
    MESSAGE s005. " No Potential combinations Determined "MOD-005
  ENDIF.
*-MOD-003
ENDFORM. " get_potential_comb
*&---------------------------------------------------------------------*
*&      Form  build_fieldcat
*&---------------------------------------------------------------------*
*       Build field catalogue for ALV Display.
*----------------------------------------------------------------------*
FORM build_fieldcat
*-->Begin of MOD-002
        USING fp_tabname TYPE tabname.
*<--End of MOD-002

  FIELD-SYMBOLS : <l_fs_fieldcat> TYPE lvc_s_fcat.

  rec_layout-sel_mode   = c_a.

*-->Begin of MOD-002 comment

*  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
*       EXPORTING
*            i_structure_name       = c_plob_str
*       CHANGING
*            ct_fieldcat            = i_fieldcat
*       EXCEPTIONS
*            inconsistent_interface = 1
*            program_error          = 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.
*
*  LOOP AT i_fieldcat INTO rec_fieldcat.
**   columns should not be fixed.
*    CLEAR rec_fieldcat-key.
*
**  no F4
*    CLEAR rec_fieldcat-ref_table.
*    rec_fieldcat-outputlen = 17.
*    MODIFY i_fieldcat FROM rec_fieldcat.
*
*
*    IF
*       rec_fieldcat-fieldname NE c_mpos_loc   AND
*       rec_fieldcat-fieldname NE c_mpos_prod  AND
*       rec_fieldcat-fieldname NE c_mpos_cusl  AND
*       rec_fieldcat-fieldname NE c_mpos_matg  AND
*       rec_fieldcat-fieldname NE c_mpos_disc  AND
*       rec_fieldcat-fieldname NE c_mpos_salo  .
*
*      DELETE i_fieldcat INDEX sy-tabix.
*
*    ENDIF.
*
*  ENDLOOP.

*<--End of MOD-002 comment
*-->Begin of MOD-002
  PERFORM fill_catalog USING :
   c_mpos_loc fp_tabname c_loc 17 '/BIC/GTWERKS' '/BIC/TGTWERKS',
   c_floc_desc fp_tabname c_loc_desc 17 'TXTSH' '/BIC/TGTWERKS',
   c_mpos_prod fp_tabname c_prd 17 '/BIC/GTSRP021C' '/BIC/TGTSRP021C',
   c_fmat_desc fp_tabname c_prd_desc 17 'TXTSH' '/BIC/TGTSRP021C',
   c_mpos_cusl fp_tabname c_clvl 17 '/BIC/GTCUSLEV4' '/BIC/PGTCUSLEV4',
   c_fclvl_desc fp_tabname c_clvl_desc 17 'TXTMD' '/BIC/TGTCUSLEV4',
   c_mpos_matg fp_tabname c_mgp 17 '/BIC/GTGROUP1' '/BIC/TGTGROUP1',
   c_fmgp_desc fp_tabname c_mgp_desc 17 'TXTSH' '/BIC/TGTGROUP1',
   c_mpos_disc fp_tabname c_dch 17 '/BIC/GTNESTCH' '/BIC/TGTNESTCH',
   c_fdch_desc fp_tabname c_dch_desc 17 'TXTSH' '/BIC/TGTNESTCH',
   c_mpos_salo fp_tabname c_sorg 17 '/BIC/GTSALORG' '/BIC/TGTSALORG',
   c_fsorg_desc fp_tabname c_sorg_desc 17 'TXTLG' '/BIC/TGTSALORG'.

*<--End of MOD-002

  READ TABLE i_field_cat ASSIGNING <l_fs_fieldcat>
             WITH KEY fieldname = c_mpos_cusl.

  IF sy-subrc = 0.
    <l_fs_fieldcat>-ref_field = '/BIC/GTCUSLEV4'.
    <l_fs_fieldcat>-ref_table = '/BIC/PGTCUSLEV4'.
  ENDIF.


ENDFORM. " build_fieldcat
*&---------------------------------------------------------------------*
*&      Form  display_in_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_in_alv.
  tbstrp-activetab = c_fcode_tab1.
  CALL SCREEN 9000.
ENDFORM. " display_in_alv
*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.


  IF tbstrp-activetab = c_fcode_tab1.
    SET PF-STATUS c_status EXCLUDING c_fcode_create.
  ELSE.
    SET PF-STATUS c_status.
  ENDIF.
  SET TITLEBAR c_title.

ENDMODULE. " STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.

  DATA : l_answer TYPE c.

  CASE sy-ucomm.
    WHEN c_fcode_back OR c_fcode_cancel .
      LEAVE TO SCREEN 0.

    WHEN c_fcode_exit.
      LEAVE PROGRAM.

    WHEN c_fcode_create.

      IF NOT i_sel_rows IS INITIAL.

* Start of change by Sudhakar
*         PERFORM p_index_check using v_plob_id.
* End of Change
        PERFORM create_comb TABLES i_sel_rows
                                   i_potential.
        CALL METHOD v_alv2->refresh_table_display.

      ENDIF.

    WHEN  c_fcode_tab1.
      IF i_sel_rows[] IS INITIAL.
        tbstrp-activetab = c_fcode_tab1.
      ELSE.
        PERFORM popup_to_confirm USING text-005
                                 CHANGING l_answer.
        IF l_answer NE c_no.
          CALL METHOD v_alv2->refresh_table_display.
          tbstrp-activetab = c_fcode_tab1.
        ENDIF.
        CLEAR l_answer.
      ENDIF.

    WHEN c_fcode_tab2.

      IF i_sel_rows[] IS INITIAL.
        tbstrp-activetab = c_fcode_tab2.
      ELSE.
        PERFORM popup_to_confirm USING text-005
                                 CHANGING l_answer.
        IF l_answer NE c_no.
          CALL METHOD v_alv1->refresh_table_display.
          tbstrp-activetab = c_fcode_tab2.
        ENDIF.
        CLEAR l_answer.
      ENDIF.

  ENDCASE.
ENDMODULE. " USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
*&      Form  init_alv1
*&---------------------------------------------------------------------*
*   Initialize ALV showing Existing combinations.
*----------------------------------------------------------------------*
FORM init_alv1.

  CHECK v_alv_container1 IS INITIAL.
  CALL METHOD cl_gui_cfw=>flush.

* Create Container
  CREATE OBJECT v_alv_container1
    EXPORTING
      container_name = v_container1.

** Create ALV Grid
  CREATE OBJECT v_alv1
    EXPORTING
      i_parent = v_alv_container1.

*-->Begin of MOD-002
  REFRESH i_field_cat.
  PERFORM build_fieldcat USING c_tabname_ex.
*<--End of MOD-002

  CALL METHOD v_alv1->set_table_for_first_display
      EXPORTING
                   i_save = 'X'
                   is_layout        = rec_layout
      CHANGING
*-->Begin of MOD-002 comment
*                 it_fieldcatalog  = i_fieldcat
*<--End of MOD-002 comment
*-->Begin of MOD-002
                  it_fieldcatalog  = i_field_cat
*<--End of MOD-002

                 it_outtab        = i_existing[].


ENDFORM. " init_alv1
*&---------------------------------------------------------------------*
*&      Form  init_alv2
*&---------------------------------------------------------------------*
*  Initialize the ALV showing Potential Combinations
*----------------------------------------------------------------------*
FORM init_alv2.
  CHECK v_alv_container2 IS INITIAL.

  CALL METHOD cl_gui_cfw=>flush.

* Create Container
  CREATE OBJECT v_alv_container2
    EXPORTING
      container_name = v_container2.

** Create ALV Grid
  CREATE OBJECT v_alv2
    EXPORTING
      i_parent = v_alv_container2.

*-->Begin of MOD-002
  REFRESH i_field_cat.
  PERFORM build_fieldcat USING c_tabname_pt.
*<--End of MOD-002

  CALL METHOD v_alv2->set_table_for_first_display
       EXPORTING
                    is_layout        = rec_layout
       CHANGING
*-->Begin of MOD-002 comment
*                 it_fieldcatalog  = i_fieldcat
*<--End of MOD-002 comment
*-->Begin of MOD-002
                  it_fieldcatalog  = i_field_cat
*<--End of MOD-002

                  it_outtab        = i_potential[].

ENDFORM. " init_alv2
*&---------------------------------------------------------------------*
*&      Module  init_9001  OUTPUT
*&---------------------------------------------------------------------*
*       Initialize ALV showing Existing Combinations
*----------------------------------------------------------------------*
MODULE init_9001 OUTPUT.

  PERFORM init_alv1.

ENDMODULE. " init_9001 OUTPUT
*&---------------------------------------------------------------------*
*&      Module  init_9002  OUTPUT
*&---------------------------------------------------------------------*
*       Initialize ALV showing Potential Combinations
*----------------------------------------------------------------------*
MODULE init_9002 OUTPUT.

  PERFORM init_alv2.

ENDMODULE. " init_9002 OUTPUT
*&---------------------------------------------------------------------*
*&      Module  get_selected_records  INPUT
*&---------------------------------------------------------------------*
*       Get the records selected by the user on ALV
*----------------------------------------------------------------------*
MODULE get_selected_rows INPUT.

  CASE tbstrp-activetab.

    WHEN c_fcode_tab1.
      PERFORM get_selected_rows USING c_x.

    WHEN c_fcode_tab2.
      PERFORM get_selected_rows USING space.

  ENDCASE.


ENDMODULE. " get_selected_records INPUT
*&---------------------------------------------------------------------*
*&      Form  get_selected_rows
*&---------------------------------------------------------------------*
*       Get the selected rows
*----------------------------------------------------------------------*
*      -->P_flag   Flag to distinguish between Existing or potential
*----------------------------------------------------------------------*
FORM get_selected_rows USING p_flag.

  CONSTANTS: l_c_20 TYPE i VALUE 20.                        " MOD-011

*** Beging of MOD-004
  DATA: l_v_sel_len TYPE i.
  CLEAR l_v_sel_len.
*** End of MOD-004

  REFRESH i_sel_rows.

  IF p_flag = c_x.

    CALL METHOD v_alv1->get_selected_rows
      IMPORTING
        et_index_rows = i_sel_rows[].
  ELSE.

    CALL METHOD v_alv2->get_selected_rows
      IMPORTING
        et_index_rows = i_sel_rows[].

*** Begin of MOD-004
* Check whether the selected rows greater than 10 or not
    DESCRIBE TABLE i_sel_rows LINES l_v_sel_len.
* Begin of MOD-011
*    IF l_v_sel_len > 10.
* Increasing the restriction from 10 to 20
    IF l_v_sel_len > l_c_20.
* End of MOD-011
      MESSAGE e006.
*** end of MOD-004.
    ENDIF.

  ENDIF.
ENDFORM. " get_selected_rows
*&---------------------------------------------------------------------*
*&      Form  popup_to_confirm
*&---------------------------------------------------------------------*
*       Warn the user about loss of data.
*----------------------------------------------------------------------*
FORM popup_to_confirm USING p_text1
                        CHANGING pi_answer.

  CALL FUNCTION 'POPUP_TO_CONFIRM'
    EXPORTING
      text_question         = p_text1
      text_button_1         = text-002
      text_button_2         = text-003
      display_cancel_button = space
    IMPORTING
      answer                = pi_answer
    EXCEPTIONS
      text_not_found        = 1
      OTHERS                = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


ENDFORM. " popup_to_confirm
*&---------------------------------------------------------------------*
*&      Form  DELETE_COMB
*&---------------------------------------------------------------------*
*      Delete existing combnations from the infocube
*----------------------------------------------------------------------*
*      -->P_I_SEL_ROWS  User selected rows on screen
*      -->P_I_EXISTING  All existing combuinations
*----------------------------------------------------------------------*
FORM delete_comb TABLES p_i_sel_rows TYPE lvc_t_row
**begin Of Mod-009**
*                          p_i_existing STRUCTURE /bic/vgtdppos32
                           p_i_existing type ty_output_tab_t.
**End Of Mod-009**
*-->Begin of MOD-002 comment
*  DATA : i_combination TYPE TABLE OF /bic/vgtdppos32.
*  DATA : rec_combination TYPE /bic/vgtdppos32.
*<--End of MOD-002 comment

*-->Begin of MOD-002
  DATA : i_combination TYPE TABLE OF ty_output_tab.
  DATA : rec_combination TYPE ty_output_tab.

*<--End of MOD-002

  DATA :  i_selection        TYPE /sapapo/ts_iobj_selection_tab,
          rec_selection        TYPE /sapapo/ts_iobj_selection.

  DATA: l_infocube TYPE rsdcubev-infocube.

  LOOP AT p_i_sel_rows INTO rec_sel_row.

    READ TABLE p_i_existing  INTO rec_existing INDEX rec_sel_row-index.

    IF sy-subrc = 0.

      APPEND rec_existing TO i_combination.

    ENDIF.


  ENDLOOP.

  LOOP AT i_combination INTO rec_combination.

    CLEAR:
      rec_selection.

    rec_selection-sign    = c_sign_i.

    IF NOT rec_combination-9alocno IS INITIAL.

      IF rec_combination-9alocno CA c_pattern.
        rec_selection-option  = c_option_cp.
      ELSE.
        rec_selection-option  = c_option_eq.
      ENDIF.
      rec_selection-iobjnm = c_mpos_loc.
      rec_selection-low    = rec_combination-9alocno.
      APPEND rec_selection TO i_selection.

    ENDIF.

    IF NOT rec_combination-9amatnr IS INITIAL .


      IF rec_combination-9amatnr CA c_pattern.
        rec_selection-option  = c_option_cp.
      ELSE.
        rec_selection-option  = c_option_eq.
      ENDIF.
      rec_selection-iobjnm = c_mpos_prod.
      rec_selection-low    = rec_combination-9amatnr.
      APPEND rec_selection TO i_selection.

    ENDIF.

    IF NOT rec_combination-gtcuslev4 IS INITIAL .


      IF rec_combination-gtcuslev4 CA c_pattern.
        rec_selection-option  = c_option_cp.
      ELSE.
        rec_selection-option  = c_option_eq.
      ENDIF.
      rec_selection-iobjnm = c_mpos_cusl.
      rec_selection-low    = rec_combination-gtcuslev4.
      APPEND rec_selection TO i_selection.

    ENDIF.

    IF NOT rec_combination-gtgroup1 IS INITIAL.


      IF rec_combination-gtgroup1 CA c_pattern.
        rec_selection-option  = c_option_cp.
      ELSE.
        rec_selection-option  = c_option_eq.
      ENDIF.
      rec_selection-iobjnm = c_mpos_matg.
      rec_selection-low    = rec_combination-gtgroup1.
      APPEND rec_selection TO i_selection.

    ENDIF.

    IF NOT rec_combination-gtnestch IS INITIAL .

      IF rec_combination-gtnestch CA c_pattern.
        rec_selection-option  = c_option_cp.
      ELSE.
        rec_selection-option  = c_option_eq.
      ENDIF.
      rec_selection-iobjnm = c_mpos_disc.
      rec_selection-low    = rec_combination-gtnestch.
      APPEND rec_selection TO i_selection.

    ENDIF.

    IF NOT rec_combination-gtsalorg IS INITIAL .


      IF rec_combination-gtsalorg CA c_pattern.
        rec_selection-option  = c_option_cp.
      ELSE.
        rec_selection-option  = c_option_eq.
      ENDIF.
      rec_selection-iobjnm = c_mpos_salo.
      rec_selection-low    = rec_combination-gtsalorg.
      APPEND rec_selection TO i_selection.

    ENDIF.


    CHECK NOT i_selections[] IS INITIAL.

    CALL FUNCTION '/SAPAPO/TS_PLOB_DELETE'
      EXPORTING
        iv_bas_plobid   = v_plob_id
        it_selection    = i_selection
      EXCEPTIONS
        no_bas_plobid   = 1
        inherited_error = 2
        OTHERS          = 3.

    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      CONTINUE.

    ELSE.

      DELETE TABLE i_existing FROM rec_combination.
      APPEND rec_combination TO i_potential.
      MESSAGE s000 WITH text-006. "Selected Combinations Deleted
      "Successfully'.

    ENDIF.
    REFRESH i_selection.

  ENDLOOP.

  l_infocube = v_plob_id.

  CALL FUNCTION 'RSDRD_DIM_REMOVE_UNUSED'
    EXPORTING
      i_infocube = l_infocube
    EXCEPTIONS
      x_message  = 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.

  CALL METHOD v_alv2->refresh_table_display.
  CALL METHOD v_alv1->refresh_table_display.


ENDFORM. " DELETE_COMB
*&---------------------------------------------------------------------*
*&      Form  CREATE_COMB
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_SEL_ROWS  text
*      -->P_I_POTENTIAL  text
*----------------------------------------------------------------------*
FORM create_comb TABLES p_i_sel_rows
                          p_i_potential.

  DATA: l_infocube TYPE rsdcubev-infocube.

*-->Begin of MOD-002 comment
*  DATA : i_combination TYPE TABLE OF /bic/vgtdppos32.
*  DATA : rec_combination TYPE /bic/vgtdppos32.
*<--End of MOD-002 comment

*-->Begin of MOD-002
  DATA : i_combination TYPE TABLE OF ty_output_tab.
  DATA : rec_combination TYPE ty_output_tab.
*<--End of MOD-002


  DATA : rec_plob_values_stru   TYPE /sapapo/ts_plob_values_tabstru,
         i_plob_values_tab    TYPE /sapapo/ts_plob_values_tables,
         rec_plob_values        TYPE /sapapo/ts_plob_values_ext,
         i_plob_values        TYPE /sapapo/ts_plob_values_tab.



  LOOP AT p_i_sel_rows INTO rec_sel_row.

    READ TABLE p_i_potential INTO rec_potential INDEX rec_sel_row-index.
    IF sy-subrc = 0.
      APPEND rec_potential TO i_combination.
    ENDIF.
  ENDLOOP.


  l_infocube = v_plob_id.
  CALL FUNCTION 'RSDDCVER_DIM_NUMBER_RANGE'
    EXPORTING
      i_infocube = l_infocube
    EXCEPTIONS
      comments   = 1
      warnings   = 2
      errors     = 3
      OTHERS     = 4.

*** Begin of MOD-006
  IF sy-subrc GT c_2.
    CASE sy-subrc.
      WHEN c_3.
        MESSAGE  e012 WITH l_infocube.
      WHEN c_4.
        MESSAGE  e009.
    ENDCASE.
  ENDIF.

*  IF sy-subrc > 2.
*    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*  ENDIF.
** End of MOD-006

  LOOP AT i_combination INTO rec_combination.

    CLEAR: rec_plob_values_stru, rec_plob_values.
    CLEAR rec_plob_values.

    rec_plob_values-iobjnm   = c_mpos_loc.
    rec_plob_values-chavl    = rec_combination-9alocno.

    IF NOT rec_combination-9aplobj IS INITIAL.
      rec_plob_values-plobj = rec_combination-9aplobj.
    ENDIF.

    APPEND rec_plob_values TO i_plob_values.
    rec_plob_values-iobjnm   = c_mpos_prod.

** Begin of TPR 5175
    CALL FUNCTION 'CONVERSION_EXIT_PRODU_INPUT'
      EXPORTING
        input        = rec_combination-9amatnr
      IMPORTING
        output       = rec_plob_values-chavl
      EXCEPTIONS
        length_error = 1
        OTHERS       = 2.
    IF sy-subrc <> 0.
      rec_plob_values-chavl    = rec_combination-9amatnr.
    ENDIF.
** End of TPR 5175

    IF NOT rec_combination-9aplobj IS INITIAL.
      rec_plob_values-plobj = rec_combination-9aplobj.
    ENDIF.

    APPEND rec_plob_values TO i_plob_values.
    rec_plob_values-iobjnm   = c_mpos_cusl.

    rec_plob_values-chavl    = rec_combination-gtcuslev4.

    IF NOT rec_combination-9aplobj IS INITIAL.
      rec_plob_values-plobj = rec_combination-9aplobj.
    ENDIF.

    APPEND rec_plob_values TO i_plob_values.
    rec_plob_values-iobjnm   = c_mpos_matg.
    rec_plob_values-chavl    = rec_combination-gtgroup1.

    IF NOT rec_combination-9aplobj IS INITIAL.
      rec_plob_values-plobj = rec_combination-9aplobj.
    ENDIF.

    APPEND rec_plob_values TO i_plob_values.
    rec_plob_values-iobjnm   = c_mpos_disc.
    rec_plob_values-chavl    = rec_combination-gtnestch.

    IF NOT rec_combination-9aplobj IS INITIAL.
      rec_plob_values-plobj = rec_combination-9aplobj.
    ENDIF.

    APPEND rec_plob_values TO i_plob_values.
    rec_plob_values-iobjnm   = c_mpos_salo.
    rec_plob_values-chavl    = rec_combination-gtsalorg.

    IF NOT rec_combination-9aplobj IS INITIAL.
      rec_plob_values-plobj = rec_combination-9aplobj.
    ENDIF.

    APPEND rec_plob_values TO i_plob_values.
    rec_plob_values_stru-plobtab = i_plob_values.
    APPEND rec_plob_values_stru TO i_plob_values_tab.
  ENDLOOP.

  CALL FUNCTION '/SAPAPO/TS_PLOB_CREATE'
    EXPORTING
      iv_bas_plobid      = v_plob_id
    CHANGING                                                "ins 570422
      ct_plob_values_tab = i_plob_values_tab                "ins 570422
    EXCEPTIONS
      no_bas_plobid      = 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.

  ELSE.

*  Start of change by Sudhakar

    CALL FUNCTION '/SAPAPO/TS_LCM_PLOB_DELTA_SYNC'
      EXPORTING
        iv_bas_plobid  = v_plob_id
        iv_start_job   = c_x
      EXCEPTIONS
        plobid_invalid = 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.

*  End of Change by Sudhakar

    LOOP AT i_combination INTO rec_combination.
      DELETE TABLE i_potential FROM rec_combination.
      APPEND rec_combination TO i_existing.
    ENDLOOP.

    CALL METHOD v_alv1->refresh_table_display.
    CALL METHOD v_alv2->refresh_table_display.

  ENDIF.


ENDFORM. " CREATE_COMB
*&---------------------------------------------------------------------*
*&      Form  append_selections
*&---------------------------------------------------------------------*
*       Prepare selections table
*----------------------------------------------------------------------*
*      -->P_field  selections field
*      -->p_param  Parameter name
*----------------------------------------------------------------------*
*** Begin of MOD-004
FORM append_selections USING p_field
                              fp_sign
                              fp_option
                              p_param
                              fp_high.


  DATA : rec_selections  TYPE /sapapo/ts_iobj_selection.


  rec_selections-iobjnm = p_field.
  rec_selections-sign = fp_sign.
  rec_selections-option = fp_option.
  rec_selections-low = p_param.
  rec_selections-high = fp_high.
*** End of MOD-004

  APPEND  rec_selections TO i_selections.
ENDFORM. " append_selections
*&---------------------------------------------------------------------*
*&      Form  append_group_by
*&---------------------------------------------------------------------*
*       Prepare group by table
*----------------------------------------------------------------------*
*      -->P_I_GROUP_BY  Group by table
*----------------------------------------------------------------------*
FORM append_group_by TABLES p_i_group_by STRUCTURE
                              /sapapo/ts_group_by_str.

  DATA : rec_group_by  TYPE /sapapo/ts_group_by_str.

  rec_group_by-iobjnm = c_mpos_loc .
  APPEND rec_group_by TO p_i_group_by.

  rec_group_by-iobjnm = c_mpos_prod .
  APPEND rec_group_by TO p_i_group_by.

  rec_group_by-iobjnm = c_mpos_cusl .
  APPEND rec_group_by TO p_i_group_by.

  rec_group_by-iobjnm = c_mpos_matg .
  APPEND rec_group_by TO p_i_group_by.

  rec_group_by-iobjnm = c_mpos_disc .
  APPEND rec_group_by TO p_i_group_by.

  rec_group_by-iobjnm = c_mpos_salo .
  APPEND rec_group_by TO p_i_group_by.


ENDFORM. " append_group_by
*&---------------------------------------------------------------------*
*&      Form  get_logocal_dest
*&---------------------------------------------------------------------*
*       Get the logical R/3 Destination
*----------------------------------------------------------------------*
*      <--P_L_LOGDES  Logical R/3 destination
*----------------------------------------------------------------------*
FORM get_logical_dest CHANGING p_logdes TYPE rfcdest.

  DATA : l_logsys TYPE logsys,
         l_apoclient TYPE mandt.


  CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
    IMPORTING
      own_logical_system             = l_logsys
    EXCEPTIONS
      own_logical_system_not_defined = 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.

  SELECT mandt FROM t000
  INTO l_apoclient
  UP TO 1 ROWS
  WHERE logsys = l_logsys.

  ENDSELECT.
  IF sy-subrc = 0.

    SELECT logdes_r3
    FROM   zagtt_rfctab
    INTO  p_logdes
    UP TO 1 ROWS
    WHERE logdes_apo = l_logsys.

    ENDSELECT  .
  ENDIF.



ENDFORM. " get_logocal_dest
*&---------------------------------------------------------------------*
*&      Form  validate_selections
*&---------------------------------------------------------------------*
*      Validate selections
*----------------------------------------------------------------------*
FORM validate_selections.
  REFRESH : i_sal_temp,
            i_hier_temp,
            i_mat_temp,
            i_plants_temp.
  DATA: l_wa_material TYPE ty_material,
        l_wa_prod     TYPE ty_prod,
        l_wa_product  TYPE ty_prod,
        l_i_product   TYPE ty_t_prod,
        l_i_prod      TYPE ty_t_prod,
        l_wa_matgrp   TYPE ty_mgrp,
        l_wa_mgrp     TYPE ty_mgrp,
        l_i_matgrp    TYPE ty_t_mgrp,
        l_i_mgrp      TYPE ty_t_mgrp,
        l_i_loc       TYPE ty_t_loc,
        l_i_loct      TYPE ty_t_loc,
        l_wa_loc      TYPE ty_loc,
        l_wa_loct     TYPE ty_loc,
        l_wa_plant    TYPE ty_plants.
  REFRESH: l_i_product, l_i_prod, l_i_matgrp, l_i_mgrp ,
           l_i_loc, l_i_loct.

* Validate Sales organization
  READ TABLE i_salorg INTO rec_salorg WITH KEY vkorg = p_vkorg
                                           BINARY SEARCH.
  IF sy-subrc <> 0.
    MESSAGE e000 WITH text-007.
*>>>>MOD-010++
  ELSE.
* Authorization check on Sales.Org
    AUTHORITY-CHECK OBJECT 'YDPSALEORG'
                ID '9GTSALORG' FIELD P_VKORG.
    IF SY-SUBRC <> 0.
      MESSAGE e025 WITH SY-UNAME
                        P_VKORG.
    ENDIF.
*<<<<MOD-010++

  ENDIF.

* Validate Distribution Channel.
  IF NOT p_vtweg IS INITIAL.
    i_sal_temp[] = i_salorg[].
    DELETE i_sal_temp WHERE vkorg NE p_vkorg.
    SORT i_sal_temp BY vtweg.
    READ TABLE i_sal_temp INTO rec_salorg WITH KEY vtweg = p_vtweg BINARY
                                                                   SEARCH.
    IF sy-subrc <> 0.
      MESSAGE e000 WITH text-008.
    ENDIF.
  ENDIF.
*** Begin of MOD-004
*  Validate Customer Level 4.
  IF NOT s_cuslvl[] IS INITIAL.
    i_hier_temp[] = i_custhier[].
    IF s_cuslvl-low NE c_star.
      DELETE i_hier_temp WHERE vkorg NE p_vkorg
                            OR vtweg NE p_vtweg.
      SORT i_hier_temp BY kunnr.
      LOOP AT s_cuslvl ."into wa_cuslvl.

        READ TABLE i_hier_temp INTO rec_custhier
                   WITH KEY kunnr = s_cuslvl-low
                   BINARY SEARCH.
        IF sy-subrc <> 0.
          MESSAGE e000 WITH text-009.
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDIF.
*  Validate Product.
  IF NOT s_prod[] IS INITIAL .
    i_mat_temp[] = i_material[].
    IF s_prod-low NE c_star.
      DELETE i_mat_temp WHERE vkorg NE p_vkorg
                           OR vtweg NE p_vtweg.
      SORT i_mat_temp BY matnr.

      l_i_product[] = s_prod[].
      LOOP AT l_i_product INTO l_wa_product.
        IF l_wa_product-option EQ c_option_bt.
          LOOP AT i_mat_temp INTO l_wa_material WHERE
               matnr GE l_wa_product-low AND matnr LE l_wa_product-high.
            l_wa_prod-sign   = l_wa_product-sign.
            l_wa_prod-option = c_option_eq.
            l_wa_prod-low    = l_wa_material-matnr.
            APPEND l_wa_prod TO l_i_prod.
            CLEAR: l_wa_prod, l_wa_material.
          ENDLOOP.
        ELSE.
          l_wa_prod-sign   = l_wa_product-sign.
          l_wa_prod-option = l_wa_product-option.
          l_wa_prod-low    = l_wa_product-low.
          APPEND l_wa_prod TO l_i_prod.
          CLEAR: l_wa_prod.
        ENDIF.
        CLEAR: l_wa_prod.
      ENDLOOP.

      LOOP AT l_i_prod INTO l_wa_prod.
        READ TABLE i_mat_temp INTO rec_material
                   WITH KEY matnr = l_wa_prod-low.
        IF sy-subrc <> 0.
          MESSAGE e000 WITH text-010.
        ENDIF.
        CLEAR: l_wa_prod, rec_material.
      ENDLOOP.
    ENDIF.
  ENDIF.
*   Validate Material Group
  IF NOT s_matgrp[] IS INITIAL AND s_matgrp-low NE c_star.
    IF s_prod-low NE c_star.
      DELETE i_mat_temp WHERE NOT matnr IN l_i_prod.
    ENDIF.
    SORT i_mat_temp BY mvgr1.
    l_i_matgrp[] = s_matgrp[].
    LOOP AT l_i_matgrp INTO l_wa_matgrp.
      IF l_wa_matgrp-option EQ c_option_bt.
        LOOP AT i_mat_temp INTO l_wa_material WHERE
             mvgr1 GE l_wa_matgrp-low AND mvgr1 LE l_wa_matgrp-high.
          l_wa_mgrp-sign   = l_wa_matgrp-sign.
          l_wa_mgrp-option = c_option_eq.
          l_wa_mgrp-low    = l_wa_material-mvgr1.
          APPEND l_wa_mgrp TO l_i_mgrp.
          CLEAR: l_wa_mgrp, l_wa_material.
        ENDLOOP.
      ELSE.
        l_wa_mgrp-sign   = l_wa_matgrp-sign.
        l_wa_mgrp-option = l_wa_matgrp-option.
        l_wa_mgrp-low    = l_wa_matgrp-low.
        APPEND l_wa_mgrp TO l_i_mgrp.
        CLEAR: l_wa_mgrp.
      ENDIF.
      CLEAR: l_wa_matgrp.
    ENDLOOP.
    LOOP AT l_i_mgrp INTO l_wa_mgrp.
      READ TABLE i_mat_temp INTO rec_material
                 WITH KEY mvgr1 = l_wa_mgrp-low.
      IF sy-subrc <> 0.
        MESSAGE e000 WITH text-011.
      ENDIF.
    ENDLOOP.
  ENDIF.
*   Validate Location.
  IF NOT s_loc[] IS INITIAL AND s_loc-low NE c_star.
*psk
    i_plants_temp[] = i_plants[].
*psk
    IF s_prod-low NE c_star.
      DELETE i_plants_temp WHERE NOT matnr IN l_i_prod.
    ENDIF.
    SORT i_plants_temp BY werks .
    l_i_loc[] = s_loc[].
    LOOP AT l_i_loc INTO l_wa_loc.
      IF l_wa_loc-option EQ c_option_bt.
        LOOP AT i_plants_temp INTO l_wa_plant WHERE
              werks GE l_wa_loc-low AND werks LE l_wa_loc-high.
          l_wa_loct-sign   = l_wa_loc-sign.
          l_wa_loct-option = c_option_eq.
          l_wa_loct-low    = l_wa_plant-werks.
          APPEND l_wa_loct TO l_i_loct.
          CLEAR: l_wa_loct, l_wa_plant.
        ENDLOOP.
      ELSE.
        l_wa_loct-sign   = l_wa_loc-sign.
        l_wa_loct-option = l_wa_loc-option.
        l_wa_loct-low    = l_wa_loc-low.
        APPEND  l_wa_loct TO l_i_loct.
        CLEAR:  l_wa_loct.
      ENDIF.
      CLEAR: l_wa_loc.
    ENDLOOP.
    LOOP AT l_i_loct INTO l_wa_loct.
      READ TABLE i_plants_temp INTO rec_plants
                           WITH KEY werks =  l_wa_loct-low.
      IF sy-subrc <> 0.
        MESSAGE e000 WITH text-012.
      ENDIF.
      CLEAR: l_wa_loct, rec_plants.
    ENDLOOP.
*** End of MOD-004
  ENDIF.
ENDFORM. " validate_selections

*&---------------------------------------------------------------------*
*&      Form  p_index_check
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_V_PLOB_ID  text
*----------------------------------------------------------------------*
FORM p_index_check USING p_plob_id.

  DATA:
      lt_dbindex     LIKE dbindex OCCURS 0,
      lv_p_indx_name TYPE rsdu_index,
      lv_tab_name    TYPE ddobjname,
      lv_ftab_indx   TYPE rs_bool,
      lv_infocube    TYPE rsd_s_cube-infocube,
      lv_facttab     TYPE rsd_s_cube-facttab,
      ls_dd12v       TYPE dd12v,
      ls_tsplobko    TYPE /sapapo/tsplobko,
      lt_tsplobko    TYPE /sapapo/tsplobko_tab.

  FIELD-SYMBOLS:
    <ls_dbindex>  TYPE dbindex,
    <ls_tsplobko> TYPE /sapapo/tsplobko.

* Check basis planning object structure
  CALL FUNCTION '/SAPAPO/TS_PSTRU_SINGLE_GET'
    EXPORTING
      iv_plobid      = p_plob_id
    IMPORTING
      es_tsplobko    = ls_tsplobko
    EXCEPTIONS
      plobid_invalid = 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.

  CHECK ls_tsplobko-objstat = ''.

* Get the all active aggregates
  CALL FUNCTION '/SAPAPO/TS_PSTRU_LIST_GET'
    EXPORTING
      iv_bas_plobid      = p_plob_id
      iv_flg_active_only = 'X'
    IMPORTING
      et_tsplobko        = lt_tsplobko
    EXCEPTIONS
      no_values          = 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.

*(1) Check basis planning object structure
  lv_infocube = p_plob_id.
  CALL FUNCTION 'RSDU_INFOCUBE_PRIMIDX_CHECK'
    EXPORTING
      i_infocube       = lv_infocube
    IMPORTING
      e_ftab_indx_type = lv_ftab_indx
    EXCEPTIONS
      inherited_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.

  IF lv_ftab_indx <> 'P'.
* Create a new P-index
    PERFORM p_index_bw_create USING lv_infocube.
  ELSE.
* Get the fact table name
    CALL FUNCTION 'RSD_FACTTAB_GET_FOR_CUBE'
      EXPORTING
        i_infocube = lv_infocube
      IMPORTING
        e_facttab  = lv_facttab
      EXCEPTIONS
        name_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.
* Get all Indexes
    lv_tab_name = lv_facttab.
    CALL FUNCTION 'DB_GET_INDEXES'
      EXPORTING
        tabname   = lv_tab_name
      TABLES
        dbindexes = lt_dbindex.
* Get the name of P-Index
    CALL FUNCTION 'RSDU_GET_INDEX_NAME'
      EXPORTING
        i_tablnm        = lv_tab_name
        i_indexnumber   = 'P'
      IMPORTING
        e_index         = lv_p_indx_name
      EXCEPTIONS
        inherited_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.

    READ TABLE lt_dbindex ASSIGNING <ls_dbindex>
               WITH KEY name = lv_p_indx_name.
    IF sy-subrc = 0.
      IF <ls_dbindex>-unique IS INITIAL.
* P-Index von ist ein non-unique Index => Repair
        PERFORM p_index_bw_create USING lv_infocube.
      ELSE.
* No error found
        MESSAGE s133(/sapapo/tsm) WITH lv_infocube.
*   P-Index von & wurde erfolgreich geprüft
      ENDIF.
    ENDIF.
  ENDIF.

*(2) Check aggregates
  CHECK NOT lt_tsplobko[] IS INITIAL.

  LOOP AT lt_tsplobko ASSIGNING <ls_tsplobko>.
* Get the fact table name
    lv_infocube = <ls_tsplobko>-ancid.
* Get the fact table name
    CALL FUNCTION 'RSD_FACTTAB_GET_FOR_CUBE'
      EXPORTING
        i_infocube = lv_infocube
      IMPORTING
        e_facttab  = lv_facttab
      EXCEPTIONS
        name_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.
* Get all Indexes
    lv_tab_name = lv_facttab.
    CALL FUNCTION 'DB_GET_INDEXES'
      EXPORTING
        tabname   = lv_tab_name
      TABLES
        dbindexes = lt_dbindex.
* Get the name of P-Index
    CALL FUNCTION 'RSDU_GET_INDEX_NAME'
      EXPORTING
        i_tablnm        = lv_tab_name
        i_indexnumber   = 'P'
      IMPORTING
        e_index         = lv_p_indx_name
      EXCEPTIONS
        inherited_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.

    READ TABLE lt_dbindex ASSIGNING <ls_dbindex>
               WITH KEY name = lv_p_indx_name.
    IF sy-subrc <> 0.
* Create a new P-index
      PERFORM p_index_create USING lv_infocube
                                   lv_tab_name.
    ELSE.
      IF <ls_dbindex>-unique IS INITIAL.
* P-Index ist ein non-unique Index => Repair
        PERFORM p_index_repair USING lv_infocube
                                     lv_tab_name.
      ELSE.
        MESSAGE s133(/sapapo/tsm) WITH <ls_tsplobko>-plobid.
* P-Index von & wurde erfolgreich geprüft
      ENDIF.
    ENDIF.
  ENDLOOP.


ENDFORM. " p_index_check
*&---------------------------------------------------------------------*
*&      Form  p_index_bw_create
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LV_INFOCUBE  text
*----------------------------------------------------------------------*
FORM p_index_bw_create USING iv_infocube TYPE rsd_s_cube-infocube.

  DATA:
     lv_ftab_indx TYPE rs_bool.

* Create the P Index
  CALL FUNCTION 'RSDU_INFOCUBE_PRIMIDX_CREATE'
    EXPORTING
      i_infocube             = iv_infocube
*     I_FACTTAB              =
      i_facttabtp            = 'F'
*     I_DOUBLE_FACTTAB       = RS_C_TRUE
    EXCEPTIONS
      inherited_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.

* Check it again
  CALL FUNCTION 'RSDU_INFOCUBE_PRIMIDX_CHECK'
    EXPORTING
      i_infocube       = iv_infocube
    IMPORTING
      e_ftab_indx_type = lv_ftab_indx
    EXCEPTIONS
      inherited_error  = 1
      OTHERS           = 2.

  IF sy-subrc <> 0 OR lv_ftab_indx <> 'P'.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    MESSAGE s134(/sapapo/tsm) WITH iv_infocube.
*   P-Index von & wurde repariert
  ENDIF.


ENDFORM. " p_index_bw_create
*&---------------------------------------------------------------------*
*&      Form  p_index_create
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LV_INFOCUBE  text
*      -->P_LV_TAB_NAME  text
*----------------------------------------------------------------------*
FORM p_index_create USING iv_infocube TYPE rsd_s_cube-infocube
                          iv_tab_name TYPE ddobjname.

  DATA:
    lt_dbindex     LIKE dbindex OCCURS 0,
    lv_p_indx_name TYPE rsdu_index,
    ls_dd12v    TYPE dd12v,
    lt_dd03p    LIKE dd03p OCCURS 0,
    ls_dd17v    TYPE dd17v,
    lt_dd17v    LIKE dd17v OCCURS 0.

  FIELD-SYMBOLS:
    <ls_dbindex>  TYPE dbindex,
    <ls_dd03p>    LIKE dd03p.

* Get ls_dd12v
  ls_dd12v-sqltab     = iv_tab_name.
  ls_dd12v-indexname  = 'P'.
  ls_dd12v-as4local   = 'A'.
  ls_dd12v-as4vers    = '0000'.
  ls_dd12v-ddlanguage = sy-langu.
  ls_dd12v-authclass  = '00'.
  ls_dd12v-uniqueflag = 'X'.
  ls_dd12v-as4user    = sy-uname.
  ls_dd12v-as4date    = sy-datum.
  ls_dd12v-as4time    = sy-uzeit.
  CONCATENATE text-100 iv_tab_name
    INTO ls_dd12v-ddtext SEPARATED BY space.

* Get lt_dd17v
  CALL FUNCTION 'DDIF_TABL_GET'
    EXPORTING
      name          = iv_tab_name
    TABLES
      dd03p_tab     = lt_dd03p
    EXCEPTIONS
      illegal_input = 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.

  LOOP AT lt_dd03p ASSIGNING <ls_dd03p>
                   WHERE keyflag = 'X'.
    ls_dd17v-position  = ls_dd17v-position + 1.
    ls_dd17v-sqltab    = <ls_dd03p>-tabname.
    ls_dd17v-indexname = 'P'.
    ls_dd17v-position  = ls_dd17v-position.
    ls_dd17v-as4local  = 'A'.
    ls_dd17v-as4vers   = '0000'.
    ls_dd17v-fieldname = <ls_dd03p>-fieldname.
    APPEND ls_dd17v TO lt_dd17v.
  ENDLOOP.

  CALL FUNCTION 'DDIF_INDX_PUT'
    EXPORTING
      name              = iv_tab_name
      id                = 'P'
      dd12v_wa          = ls_dd12v
    TABLES
      dd17v_tab         = lt_dd17v
    EXCEPTIONS
      indx_not_found    = 1
      name_inconsistent = 2
      indx_inconsistent = 3
      put_failure       = 4
      put_refused       = 5
      OTHERS            = 6.

  IF sy-subrc = 0.
    COMMIT WORK.
    CALL FUNCTION 'DDIF_INDX_ACTIVATE'
      EXPORTING
        name        = iv_tab_name
        id          = 'P'
      EXCEPTIONS
        not_found   = 1
        put_failure = 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.
  ELSE.
    ROLLBACK WORK.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

* Check it again
  CALL FUNCTION 'DB_GET_INDEXES'
    EXPORTING
      tabname   = iv_tab_name
    TABLES
      dbindexes = lt_dbindex.
* Get the name of P-Index
  CALL FUNCTION 'RSDU_GET_INDEX_NAME'
    EXPORTING
      i_tablnm        = iv_tab_name
      i_indexnumber   = 'P'
    IMPORTING
      e_index         = lv_p_indx_name
    EXCEPTIONS
      inherited_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.

  READ TABLE lt_dbindex ASSIGNING <ls_dbindex>
             WITH KEY name = lv_p_indx_name.
  IF sy-subrc <> 0.
    MESSAGE e137(/sapapo/tsm) WITH iv_infocube.
*   Fehler beim Reparieren von P-Index: &
  ELSE.
    IF <ls_dbindex>-unique IS INITIAL.
      MESSAGE e137(/sapapo/tsm) WITH iv_infocube.
*   Fehler beim Reparieren von P-Index: &
    ELSE.
      MESSAGE s133(/sapapo/tsm) WITH iv_infocube.
* P-Index von & wurde erfolgreich geprüft
    ENDIF.
  ENDIF.
ENDFORM. " p_index_create
*&---------------------------------------------------------------------*
*&      Form  p_index_repair
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LV_INFOCUBE  text
*      -->P_LV_TAB_NAME  text
*----------------------------------------------------------------------*
FORM p_index_repair USING iv_infocube TYPE rsd_s_cube-infocube
                             iv_tab_name TYPE ddobjname.

  DATA:
     lt_dbindex     LIKE dbindex OCCURS 0,
     lv_p_indx_name TYPE rsdu_index,
     ls_dd12v       TYPE dd12v.

  FIELD-SYMBOLS:
    <ls_dbindex>  TYPE dbindex.

  CALL FUNCTION 'DDIF_INDX_GET'
    EXPORTING
      name          = iv_tab_name
      id            = 'P'
    IMPORTING
      dd12v_wa      = ls_dd12v
    EXCEPTIONS
      illegal_input = 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.

  IF ls_dd12v IS INITIAL.
* Create a new P-index
    PERFORM p_index_create USING iv_infocube
                                 iv_tab_name.
  ELSE.
    CALL FUNCTION 'RSDU_GET_INDEX_NAME'
      EXPORTING
        i_tablnm        = iv_tab_name
        i_indexnumber   = 'P'
      IMPORTING
        e_index         = lv_p_indx_name
      EXCEPTIONS
        inherited_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.
    ls_dd12v-dbindex    = lv_p_indx_name.
    ls_dd12v-uniqueflag = 'X'.
    ls_dd12v-as4user    = sy-uname.
    ls_dd12v-as4date    = sy-datum.
    ls_dd12v-as4time    = sy-uzeit.
  ENDIF.

* Add the P-Index
  CALL FUNCTION 'DDIF_INDX_PUT'
    EXPORTING
      name              = iv_tab_name
      id                = 'P'
      dd12v_wa          = ls_dd12v
    EXCEPTIONS
      indx_not_found    = 1
      name_inconsistent = 2
      indx_inconsistent = 3
      put_failure       = 4
      put_refused       = 5
      OTHERS            = 6.

  IF sy-subrc = 0.
* Activate the P-Index again
    COMMIT WORK.
    CALL FUNCTION 'DDIF_INDX_ACTIVATE'
      EXPORTING
        name        = iv_tab_name
        id          = 'P'
      EXCEPTIONS
        not_found   = 1
        put_failure = 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.
  ELSE.
    ROLLBACK WORK.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

* Check it again
  CALL FUNCTION 'DB_GET_INDEXES'
    EXPORTING
      tabname   = iv_tab_name
    TABLES
      dbindexes = lt_dbindex.
* Get the name of P-Index
  CALL FUNCTION 'RSDU_GET_INDEX_NAME'
    EXPORTING
      i_tablnm        = iv_tab_name
      i_indexnumber   = 'P'
    IMPORTING
      e_index         = lv_p_indx_name
    EXCEPTIONS
      inherited_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.

  READ TABLE lt_dbindex ASSIGNING <ls_dbindex>
             WITH KEY name = lv_p_indx_name.
  IF sy-subrc <> 0.
    MESSAGE e137(/sapapo/tsm) WITH iv_infocube.
*   Fehler beim Reparieren von P-Index: &
  ELSE.
    IF <ls_dbindex>-unique IS INITIAL.
      MESSAGE e137(/sapapo/tsm) WITH iv_infocube.
*   Fehler beim Reparieren von P-Index: &
    ELSE.
      MESSAGE s133(/sapapo/tsm) WITH iv_infocube.
* P-Index von & wurde erfolgreich geprüft
    ENDIF.
  ENDIF.


ENDFORM. " p_index_repair
*&---------------------------------------------------------------------*
*&      Form  conversion_of_product
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_REC_MATERIAL_MATNR  text
*----------------------------------------------------------------------*
FORM conversion_of_product USING p_matnr.

  CALL FUNCTION 'CONVERSION_EXIT_PRODU_OUTPUT'
    EXPORTING
      input  = p_matnr
    IMPORTING
      output = p_matnr.


ENDFORM. " conversion_of_product

*&---------------------------------------------------------------------*
*&      Form  get_logical_dest_crm
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_L_LOGDES_CRM  text
*----------------------------------------------------------------------*
FORM get_logical_dest_crm CHANGING po_logdes_crm.

  CONSTANTS: c_crm(1) TYPE c VALUE  'R'.


  call function 
*&---------------------------------------------------------------------*
*&      Form  get_keyfigure_desc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*FORM get_keyfigure_desc.
*
** Get the descriptions for the key figures into tables
*
*  SELECT *
*    INTO TABLE i_loc_desc
*    FROM /bi0/9atlocno
*    WHERE langu = sy-langu.
** sy-subrc check is not required
*
*  SELECT *
*    INTO TABLE i_mat_desc
*    FROM /bi0/9atmatnr
*    WHERE langu = sy-langu.
** sy-subrc check is not required
*
*  SELECT *
*    INTO TABLE i_mgp_desc
*    FROM /bic/tgtgroup1
*    WHERE langu    = sy-langu.
** sy-subrc check is not required
*
*  SELECT *
*    INTO TABLE i_clvl_desc
*    FROM /bic/tgtcuslev4
*    WHERE /bic/gtcuslev4 IN s_cuslvl.                       "MOD-007
**    AND   langu     = sy-langu.                             "MOD-008
** sy-subrc check is not required
*
*  SELECT *
*    INTO TABLE i_dch_desc
*    FROM /bic/tgtnestch
*    WHERE langu     = sy-langu.
** sy-subrc check is not required
*
*  SELECT *
*    INTO TABLE i_sorg_desc
*    FROM /bic/tgtsalorg
*    WHERE langu     = sy-langu.
** sy-subrc check is not required
*
*  SORT : i_loc_desc BY /bi0/9alocno,
*         i_mat_desc BY /bi0/9amatnr,
*         i_mgp_desc BY /bic/gtgroup1,
*         i_clvl_desc BY /bic/gtcuslev4,
*         i_dch_desc BY /bic/gtnestch,
*         i_sorg_desc BY /bic/gtsalorg.
*
*
*ENDFORM.                    " get_keyfigure_desc
**<--End of MOD-002

*** Begin of MOD-004.
*&---------------------------------------------------------------------*
*&      Form  product_conversion
*&---------------------------------------------------------------------*
*      Input product conversion
*----------------------------------------------------------------------*
FORM product_conversion CHANGING fp_matnr TYPE matnr.

  DATA: l_v_matnr TYPE /sapapo/matnr.

  CALL FUNCTION 'CONVERSION_EXIT_PRODU_INPUT'
    EXPORTING
      input        = fp_matnr
    IMPORTING
      output       = l_v_matnr
    EXCEPTIONS
      length_error = 1
      OTHERS       = 2.

  IF sy-subrc <> 0.
    CASE sy-subrc.
      WHEN c_1.
        MESSAGE e008.
      WHEN c_2.
        MESSAGE e009.
    ENDCASE.

  ENDIF.

  fp_matnr = l_v_matnr+22(18).

ENDFORM. " product_conversion
*&---------------------------------------------------------------------*
*&      Form  product_range
*&---------------------------------------------------------------------*
*       PRoduct Range
*----------------------------------------------------------------------*
FORM product_range CHANGING fp_i_prod TYPE ty_t_prod.

  DATA: l_wa_prod      TYPE ty_prod,
        l_wa_material  TYPE ty_material,
        l_i_product    TYPE ty_t_prod,
        l_wa_product   TYPE ty_prod.

  REFRESH l_i_product.
  SORT i_mat_temp BY matnr.

  LOOP AT i_mat_temp INTO l_wa_material.
    PERFORM product_conversion CHANGING l_wa_material-matnr.
    MODIFY i_mat_temp FROM l_wa_material.
    CLEAR: l_wa_material.
  ENDLOOP.


  l_i_product[] = s_prod[].
  LOOP AT l_i_product INTO l_wa_product.

    PERFORM product_conversion CHANGING l_wa_product-low.
    IF l_wa_product-option EQ c_option_bt.
      PERFORM product_conversion CHANGING l_wa_product-high.
      LOOP AT i_mat_temp INTO l_wa_material
         WHERE matnr GE l_wa_product-low AND matnr LE l_wa_product-high.
        l_wa_prod-sign   = l_wa_product-sign.
        l_wa_prod-option = c_option_eq.
        l_wa_prod-low     = l_wa_material-matnr.
        APPEND l_wa_prod TO fp_i_prod.
        CLEAR: l_wa_prod, l_wa_material.
      ENDLOOP.
    ELSE.
      l_wa_prod-sign   = l_wa_product-sign.
      l_wa_prod-option = l_wa_product-option.
      l_wa_prod-low    = l_wa_product-low.
      APPEND l_wa_prod TO fp_i_prod.
      CLEAR: l_wa_prod, l_wa_material.
    ENDIF.
    CLEAR: l_wa_product.
  ENDLOOP.

ENDFORM. " product_range
*&---------------------------------------------------------------------*
*&      Form  plant_product_range
*&---------------------------------------------------------------------*
*      Plant Product Range
*----------------------------------------------------------------------*
*FORM plant_product_range CHANGING fp_i_prod TYPE ty_t_prod.
*
*  DATA: l_wa_prod     TYPE ty_prod,
*        l_wa_plants   TYPE ty_plants,
*        l_wa_product   TYPE ty_prod,
*        l_i_product    TYPE ty_t_prod.
*
*  REFRESH l_i_product.
*
*  SORT i_plants_temp BY matnr werks.
*
*  LOOP AT i_plants_temp INTO l_wa_plants.
*    PERFORM product_conversion  CHANGING l_wa_plants-matnr.
*    MODIFY i_plants_temp FROM l_wa_plants.
*    CLEAR: l_wa_plants.
*  ENDLOOP.
*
*  l_i_product[] = s_prod[].
*  LOOP AT l_i_product INTO l_wa_product.
*    PERFORM product_conversion  CHANGING l_wa_product-low.
*    IF l_wa_product-option EQ c_option_bt.
*      PERFORM product_conversion CHANGING l_wa_product-high.
*      LOOP AT i_plants_temp INTO l_wa_plants
*         WHERE matnr GE l_wa_product-low AND matnr LE l_wa_product-high.
*        l_wa_prod-sign   = l_wa_product-sign.
*        l_wa_prod-option = c_option_eq.
*        l_wa_prod-low     = l_wa_plants-matnr.
*        APPEND l_wa_prod TO fp_i_prod.
*        CLEAR: l_wa_prod, l_wa_plants.
*      ENDLOOP.
*    ELSE.
*      l_wa_prod-sign   = l_wa_product-sign.
*      l_wa_prod-option = l_wa_product-option.
*      l_wa_prod-low    = l_wa_product-low.
*      APPEND l_wa_prod TO fp_i_prod.
*      CLEAR: l_wa_prod.
*    ENDIF.
*    CLEAR: l_wa_product.
*  ENDLOOP.
*ENDFORM.                    " plant_product_range
**** END OF MOD-004.


*Selection texts
*----------------------------------------------------------
* P_VKORG         Sales Organisation
* P_VTWEG         Distribution Channel
* S_CUSLVL         Customer Hierachy Level
* S_LOC         Location
* S_MATGRP         Material Group
* S_PROD         Product


*Messages
*----------------------------------------------------------
*
* Message class: /SAPAPO/TSM
*133   & P index checked successfully
*134   & P index repaired
*137   Error repairing P index: &
*
* Message class: ZDEV
*000   & & & &.
*002
*003
*005
*006
*007
*008
*009
*012
*025


*Selection texts
*----------------------------------------------------------
* P_VKORG         Sales Organisation
* P_VTWEG         Distribution Channel
* S_CUSLVL         Customer Hierachy
* S_LOC         Location
* S_MATGRP         Material Group
* S_PROD         Product


*Messages
*----------------------------------------------------------
*
* Message class: /SAPAPO/TSM
*133   & P index checked successfully
*134   & P index repaired
*137   Error repairing P index: & | |

Extracted by Mass Download version 1.4.6 - E.G.Mellodew. 1998-2010. Sap Release 700

  • No labels