cancel
Showing results for 
Search instead for 
Did you mean: 

program to update material in DP\SNP selection profile

former_member209252
Participant
0 Kudos

hi,

does anyone know how to build a program to update the selection profile periodically, for example selection profile with only materials which have open sales order.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello,

For the benefits of the others consultants, please indicate the good or the helpful answer!

Thanks, Marius

marianoc
Active Contributor
0 Kudos

Hi,

Do you want to update the selection profile of your planning books, with the list of materials?

So you know what is the selection profile ID and the program should update the profile with those materials. Is this what you want?

Kind Regards,

Mariano

former_member209252
Participant
0 Kudos

yes i want to update the material list in specific selection profile.

marianoc
Active Contributor
0 Kudos

Hi,

You will need to make a routine to get the list of open orders and the corresponding materials. This can be done in your R/3 system.
Maybe you can extract the list into the application server or a ftp.

Then in APO you will collect this list into an internal table: it_matnr

Then make a program similar to this..

REPORT ZSELECTION NO STANDARD PAGE HEADING MESSAGE-ID AQ.


************************************************************************
* TYPES and TYPE-POOLS                                                 *
************************************************************************
*TYPES: ty_selection TYPE STANDARD TABLE OF bapi10030pbselection.
TYPES: BEGIN OF ty_matnr,
*        ZMATNR LIKE ZDP_FCSTLV_MAT-ZMATNR,      " Material
        ZMATNR(60) TYPE C,      " Material
       END OF ty_matnr.
TYPES: tb_matnr type standard table of ty_matnr.

************************************************************************
* DATAS                                                                *
************************************************************************
DATA: iv_selection_id TYPE /sapapo/ts_sel_descr,
      lv_selection_id TYPE /sapapo/selectionid,
      es_sel_head TYPE /sapapo/ts_selko,
      it_selection TYPE /SAPAPO/TS_IOBJ_SELECTION_TAB,
      it2_selection TYPE /SAPAPO/TS_IOBJ_SELECTION_TAB,
      wa_selection LIKE LINE OF it_selection.
DATA: it_matnr type tb_matnr WITH HEADER LINE.
DATA: wa_matnr LIKE LINE OF it_matnr.
DATA: x_sel TYPE /SAPAPO/TS_SELKO-SEL_DESRCIPTION.
DATA: ymatnr TYPE ZDP_FCSTLV_MAT-ZMATNR.
DATA: GW_PAREAID TYPE /SAPAPO/TS_PAREAID.

************************************************************************
* SELECT-OPTIONS / PARAMETERS                                          *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK TB1 WITH FRAME TITLE TEXT-TB1.
PARAMETERS:
P_PBOOK LIKE /SAPAPO/TSPLB-MVIEW,
P_SELDI LIKE /SAPAPO/TSPLBSEL-SELID.
SELECTION-SCREEN END OF BLOCK TB1.

************************************************************************
* INITIALIZATION Event                                                 *
************************************************************************
INITIALIZATION.

************************************************************************
* START-OF-SELECTION Event                                             *
************************************************************************
START-OF-SELECTION.

  IF NOT p_seldi IS INITIAL.
    PERFORM get_material.
    IF NOT it_matnr[] IS INITIAL.
      PERFORM read_sel_profile.
      PERFORM update_sel_profile.
    ELSE.
      MESSAGE I001 WITH text-E03.
    ENDIF.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  get_material
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_material.

Here put the code to collect the materials into it_matnr

ENDFORM.              " get_material_fcstlevel

*&---------------------------------------------------------------------*
*&      Form  read_sel_profile
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM read_sel_profile.

  CLEAR: lv_selection_id, es_sel_head, it_selection.
  REFRESH: it_selection.

* -> get id for given selection
  CALL FUNCTION 'CONVERSION_EXIT_SELID_INPUT'
      EXPORTING
          input  = x_sel
      IMPORTING
          output = lv_selection_id.

  IF lv_selection_id = x_sel.
    EXIT.
  ENDIF.

* -> get selection data for selection id
  CALL FUNCTION '/SAPAPO/MCPSH_SELECTION_GET'
      EXPORTING
          iv_selid     = lv_selection_id
      IMPORTING
          es_sel_head  = es_sel_head
          et_selection = it_selection[]
      EXCEPTIONS
          id_not_exist = 1
      OTHERS       = 2.

  IF sy-subrc <> 0.
    EXIT.
  ENDIF.

ENDFORM.                 " read_sel_profile

*&---------------------------------------------------------------------*
*&      Form  update_sel_profile
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM update_sel_profile.

  REFRESH: it2_selection.
  CLEAR: wa_selection.

  LOOP AT it_selection INTO wa_selection WHERE iobjnm NE 'ZMATNR'.
    APPEND wa_selection TO it2_selection.
  ENDLOOP.

* Check for all the materials that already exist in the Selection Profile
* if they also exist in the assignment table. If the material exist in both
* it will be included in the new selection profile, if the material exist in
* the selection profile but does not exist in the assignment table, then it
* will not be included in the new selection profile and will be removed from
* the assignemnt table
  SORT it_selection by iobjnm sign option low.
  DELETE ADJACENT DUPLICATES FROM it_selection COMPARING iobjnm sign option low.
  LOOP AT it_selection INTO wa_selection WHERE iobjnm EQ 'ZMATNR'.
*    ymatnr = wa_selection-low.
    READ TABLE it_matnr INTO wa_matnr WITH KEY zmatnr = wa_selection-low.
    IF sy-subrc = 0.
      APPEND wa_selection TO it2_selection.
    ENDIF.
    DELETE it_matnr WHERE zmatnr = wa_selection-low.
  ENDLOOP.

* Add Materials that are included in the assignment table and were not in the
* Selection Profile
  LOOP AT it_matnr INTO wa_matnr.
    wa_selection-iobjnm = 'ZMATNR'.
    wa_selection-sign = 'I'.
    wa_selection-option = 'EQ'.
    wa_selection-low = wa_matnr-zmatnr.
    APPEND wa_selection TO it2_selection.
  ENDLOOP.


  SELECT SINGLE PAREAID
      FROM /SAPAPO/TSAREAKO
      INTO GW_PAREAID
      WHERE PAREAID = P_PBOOK.


  CALL FUNCTION '/SAPAPO/MCPSH_SELECTION_CHANGE'
      EXPORTING
          IV_SELID                  = lv_selection_id
          IV_PAREAID                = GW_PAREAID
          IT_SELECTION              = it2_selection
      EXCEPTIONS
          DUPLICATE_SELECTION       = 1
          MULTIPLE_SELECTION        = 2
          NO_PERMISSION             = 3
          SELECTIONID_INVALID       = 4
          INVALID_DESCRIPTION       = 5
          OTHERS                    = 6
            .
*  IF SY-SUBRC <> 0.
*    GW_ALV-STATUS = 'FAILED'.
*  ELSE."IF sy-subrc = 0.
*    GW_ALV-STATUS = 'SAVED'.


ENDFORM.                 " read_sel_profile

Kind Regards,

Mariano

Former Member
0 Kudos

Hi Mariano,

Thanks a lot for the reply above.

I was also looking for the similar requirement and I was just wandering,

Is it possible to update my Selection ID without using the

FM '/SAPAPO/MCPSH_SELECTION_GET'.

I mean, is it possible to append New Selection Condition in my existing Selection ID.

I tried to append the new Selection Condition using the FM '/SAPAPO/MCPSH_SELECTION_CHANGE',

but it overrides the Old selection condition.

The solution provided by you will work but I do not want to unnecessarily fetch all the existing selection conditions.

Any idea ?

Thanking You All..!!

Former Member
0 Kudos

Hi Ankit,

I think that you can do this more easy. You could use the Extra attribute to update your selection profile. The extra attributes can be populated through the CIF user exit.

Based on attributes you will be able to update your selection profile automatically.

So, for example for the new SKUs (attribute SKU = NEW), in selection profile with the object selection attribute SKU = NEW you will take in consideration automatically the new SKUs and the SNP Heuristic or DP forecast future jobs will take those new SKUs in consideration.

Hope that can help!

Thanks.

Regards, Marius   

marianoc
Active Contributor
0 Kudos

Hi Ankit,

I am not aware of any other function module to update the selection profiles (only adding the new values).

Try the idea proposed by Marius.

Kind Regards,

Mariano