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

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 'ZRGT_RFC_DESTINATION'

EXPORTING

DESTSYSTTYPE = C_CRM

CHARACT_FIELD = ' '

CHARACT_VALUE = ' '

IMPORTING

RFCDEST = PO_LOGDES_CRM

EXCEPTIONS

NO_DESTINATION_FOUND = 1

OWN_LOGICAL_SYSTEM_NOT_FOUND = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

PO_LOGDES_CRM = 'SD3CLNT100'.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " get_logical_dest_crm

*-->Begin of MOD-002

*&---------------------------------------------------------------------*

*& Form fill_catalog

*&---------------------------------------------------------------------*

* Build up the field catalog

*----------------------------------------------------------------------*

* -->FP_FIELDNAME text

* -->FP_TABNAME text

* -->FP_FLD_DESC text

* -->FP_OPLEN text

*----------------------------------------------------------------------*

FORM FILL_CATALOG USING FP_FIELDNAME TYPE C

FP_TABNAME TYPE TABNAME

FP_FLD_DESC TYPE SCRTEXT_M

FP_OPLEN TYPE I

FP_REF_FIELD TYPE LVC_RFNAME

FP_REF_TABLE TYPE LVC_RTNAME.

WA_FIELD_CAT-FIELDNAME = FP_FIELDNAME.

WA_FIELD_CAT-TABNAME = FP_TABNAME.

WA_FIELD_CAT-SCRTEXT_M = FP_FLD_DESC.

WA_FIELD_CAT-OUTPUTLEN = FP_OPLEN.

WA_FIELD_CAT-REF_FIELD = FP_REF_FIELD.

WA_FIELD_CAT-REF_TABLE = FP_REF_TABLE.

APPEND WA_FIELD_CAT TO I_FIELD_CAT.

ENDFORM. " fill_catalog

*&---------------------------------------------------------------------*

*& 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: &

  • No labels