Registration

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

Code listing for: ZAGT_DP_PROM_PLANNING

Description: Demand Planning Program

 

*&---------------------------------------------------------------------*
*& Report  ZAGT_DP_PROM_PLANNING
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZAGT_DP_PROM_PLANNING message-id /sapapo/prp.

*&---------------------------------------------------------------------*
* The report is an example to show how a promotion can be
* created from external data resources.
* The external resource data has to be read and transfered
* into internal data format defined in this report.
* The exmaple is based on the standard planning area '9ASNP02'
*  and for the version '000';
* Preconditions:
* 1. The report should be run every time only for one planning area,
*    one planning version and one base planning key figure;
* 2. TA /SAPAPO/MP33 that the promotion key figure has been defined
*    for the planning type used;
* 3. At least one promotion has been created for the planning area
*    using promotion planning/demand planning;
* 4. The charateristics combinations for the promotion should be
*    exist for the planning area and the planning version;
*&---------------------------------------------------------------------*

*****standard constants and global parameters****
*****do not change this part*********************
INCLUDE /sapapo/agc_constants.
INCLUDE /sapapo/ts_constants_iobjnm.

Include /sapapo/promotion_global.
Include /sapapo/promotion_constants.

TABLES:
  /sapapo/prominfo,
  /sapapo/promlist,
  /sapapo/promattr,
  /sapapo/promaval,
  /sapapo/prom_attrvalu,
  /sapapo/promtion,
  /sapapo/prombody,
  /sapapo/promcbgp,
  /sapapo/promcust,
  /sapapo/promcbgph,
  /sapapo/promkeyf,
  /sapapo/prom_keyf,
  /sapapo/prp_2tab,
  /sapapo/cbgphead,
  /sapapo/cbgpbody,
  /sapapo/pbmlkeyt,
  t006.

*****internal table definition******
*****do not change this part********
*  the header table should be filled
*  each promotion has only one entry in the table
data: begin of zt_promhead occurs 0,
*  the name of promotion, should be unique(!!!)
  promid      type /sapapo/promid,       "obligator/Key
*  description of promotion
  pmtext      type /sapapo/pmtext,
*  periodicity
  perkz       type /sapapo/perkz,        "obligator
  periv       type /sapapo/periv,
*  start date of the promotion
  startdate   type /sapapo/pm_startdate, "obligator
*  number of periods of the promotion
  pmlength    type /sapapo/pmlength,     "obligator
*  type of the promotion '+' absolute, '%' percentage
  pm_type     type /sapapo/pm_type,      "obligator
end of zt_promhead.

*  the characteristics combination of promotion
*  multiple entry each promotion is possible
data: begin of zt_prombody occurs 0,
*  the name of promotion, should be unique(!!!)
  promid      type /sapapo/promid,       "key
*  the position connecting charateristics together
*  the entries with the same position belong to
*  the same combination
  position    type i,                    "key
*  the level defines the hierarchy of the promotion
*  under the same promotion for different positions (combinations)
*  the level of each charateristics should alwayse be the same
*  the last level should be the Promotion Level
*  defined by TA /SAPAPO/MP33
  level       type i,                    "key
*  name of the charateristics
  iobjnm      type /sapapo/iobjnm,
*  value of the charateristics
  chavl       type /sapapo/chavl,
end of zt_prombody.

*  the data of the promotion
data: begin of zt_promts occurs 0,
*  the ID of the data should be the combination of
*  Position[3]+Promid[maximum 19 charaters]
  tsid type /sapapo/tsguid,    "key
*  the sequence of the data
  tspos type /sapapo/tspos,     "key
*  value
  tsvalue type /sapapo/tsvalue,
end of zt_promts.

data:
  lv_flg_error(1),
  lv_plan_kennz type /sapapo/iobjnm,
  lv_pareaid    type /sapapo/ts_pareaid,
  lv_vrsioid    type /sapapo/vrsioid.

*****example data*******************
****should be changed according to your own case ====>>>>
data:
  lv_testcase   type i,
  lv_promid     type /sapapo/promid,
  lv_promid_2   type /sapapo/promid,
  lv_pmtext     type /sapapo/pmtext  value 'PROMOTION EXTERN EXAMPLE',
  lv_perkz      type /sapapo/perkz        value 'W',
  lv_startdate  type /sapapo/pm_startdate value '20010101', "Y/M/D
  lv_pmlength   type /sapapo/pmlength     value '3',
  lv_pmtype     type /sapapo/pm_type      value '+',
  lv_location_1 type /sapapo/chavl        value 'PRP_CUST01',
  lv_location_3 type /sapapo/chavl        value 'PRP_CUST03',
  lv_product_1  type /sapapo/chavl        value 'PRP_PROD01',
  lv_product_3  type /sapapo/chavl        value 'PRP_PROD03'.

 data  it_plobs_in_view TYPE REF TO DATA.

 FIELD-SYMBOLS:
    <lt_plobs_in_view> TYPE STANDARD TABLE,
    <it_plobs_in_view> TYPE STANDARD TABLE.


 data:
    lv_sl_wrong_version(1),
    lv_sl_level type i,
    lv_sl_bodyguid type /sapapo/bodyguid.
  data:
    ls_sl_sdptms like /sapapo/sdptms,
*    lt_sl_level_0tab like PRP_DE6616DB14FF
*              occurs 0 with header line,
    lt_sl_1tab type /sapapo/prp_1tab_tab.

parameter: testcase type i. "input test case for testing

**the tables should be filled with your own promotion data**
**the subroutine shows you how the tables could be filled***
  perform fill_with_your_own_program.
** <<<<<===== end of the changing part ********************


************!!!!!!!!!!!!!!!!!!!!!!!!!!*********************
**Standard program begins here, do not change any more*****
  if zt_promhead[] is initial.
*  no promotion to be created
    message i018.
    exit.
  endif.

*  check planning area
  perform check_parea_do_not_change.
  check lv_flg_error is initial.

*  check version
  perform check_version_do_not_change.
  check lv_flg_error is initial.

*  check key figure settings
  perform check_keyfs_do_not_change.
  check lv_flg_error is initial.

*  check generated table
  perform check_gen_tab_do_not_change.
  check lv_flg_error is initial.

*  build promotion
  perform build_promo_do_not_change.

*&---------------------------------------------------------------------*
*&      Form  fill_with_your_own_prog
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form fill_with_your_own_program.

*******help parameters********
data:
  lv_index      type i,
  lv_n3(3)      type n,
  lv_value1     type f value '100',
  lv_value2     type f value '200',
  lv_tsid       type /sapapo/tsguid.

*  test parameters
  lv_pareaid    = '9ASNP02'.  "planning area
  lv_vrsioid    = '000'.        "planning version
  lv_plan_kennz = '9APFCST'.  "base plan key figure

  lv_testcase = testcase.   "test case
  if lv_testcase is initial.
    lv_testcase = 1.
  endif.
*  test cases
*  1. promotion 'ZZ_TEST_EXAMPLE_1' for combinations
*     Location 'PRP_CUST01' Produt 'PRP_PROD01', value '100'
*     Location 'PRP_CUST03' Produt 'PRP_PROD03', value '200'
*  2. promotion 'ZZ_TEST_EXAMPLE_2' for combinations
*     Location 'PRP_CUST01' Produt 'PRP_PROD01', value '100'
*     Location 'PRP_CUST01' Produt 'PRP_PROD03', value '200'
*  3. promotion 'ZZ_TEST_EXAMPLE_3' for combinations
*     Location 'PRP_CUST01' Produt 'PRP_PROD01', value '100'
*     Location 'PRP_CUST01' Produt 'PRP_PROD03', value '200'
*     Location 'PRP_CUST03' Produt 'PRP_PROD01', value '100'
*     Location 'PRP_CUST03' Produt 'PRP_PROD03', value '200'
*  4. promotion 'ZZ_TEST_EXAMPLE_41' for combinations
*     Location 'PRP_CUST01' Produt 'PRP_PROD01', value '100'
*     Location 'PRP_CUST03' Produt 'PRP_PROD03', value '200'
*     promotion 'ZZ_TEST_EXAMPLE_42' for combinations
*     Location 'PRP_CUST01' Produt 'PRP_PROD01', value '100'
*     Location 'PRP_CUST01' Produt 'PRP_PROD03', value '200'

  case lv_testcase.
    when 1.
*     lv_promid   = '9APFCST'.
      lv_promid   = '9AMP34'.

*    when 2.
*      lv_promid   = 'ZZ_TEST_EXAMPLE_2'.
*    when 3.
*      lv_promid   = 'ZZ_TEST_EXAMPLE_3'.
*    when 4.
*      lv_promid   = 'ZZ_TEST_EXAMPLE_41'.
*      lv_promid_2 = 'ZZ_TEST_EXAMPLE_42'.
  endcase.

*  create header for the example
  clear zt_promhead.
  zt_promhead-promid     = lv_promid.
  zt_promhead-pmtext     = lv_pmtext.
  zt_promhead-perkz      = lv_perkz.
  zt_promhead-startdate  = lv_startdate.
  zt_promhead-pmlength   = lv_pmlength.
  zt_promhead-pm_type    = lv_pmtype.
  append zt_promhead.

  if lv_testcase = 4.
*    create header for the second promotion
    clear zt_promhead.
    zt_promhead-promid     = lv_promid_2.
    zt_promhead-pmtext     = lv_pmtext.
    zt_promhead-perkz      = lv_perkz.
    zt_promhead-startdate  = lv_startdate.
    zt_promhead-pmlength   = lv_pmlength.
    zt_promhead-pm_type    = lv_pmtype.
    append zt_promhead.
  endif.

*  create the first combination for the promotion
*  for location and product
*  the product is the promotion level
*  so the product is the last level in the hierarchy
  case lv_testcase.
    when 1.
      read table zt_promhead index 1.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 1.  "first combination
      zt_prombody-level    = 1.
*      standard characteristics name for location
      zt_prombody-iobjnm   = gs_c_iobjnm-lokation.
      zt_prombody-chavl    = lv_location_1.
      append zt_prombody.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 1.
      zt_prombody-level    = 2.
*      standard characteristics name for product
      zt_prombody-iobjnm   = gs_c_iobjnm-produkt.
      zt_prombody-chavl    = lv_product_1.
      append zt_prombody.

*      create the second combination for the promotion
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 2.  "second combination
      zt_prombody-level    = 1.
*      standard characteristics name for location
      zt_prombody-iobjnm   = gs_c_iobjnm-lokation.
      zt_prombody-chavl    = lv_location_3.
      append zt_prombody.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 2.
      zt_prombody-level    = 2.
*      standard characteristics name for product
      zt_prombody-iobjnm   = gs_c_iobjnm-produkt.
      zt_prombody-chavl    = lv_product_3.
      append zt_prombody.

    when 2.
      read table zt_promhead index 1.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 1.
      zt_prombody-level    = 1.
*      standard characteristics name for location
      zt_prombody-iobjnm   = gs_c_iobjnm-lokation.
      zt_prombody-chavl    = lv_location_1.
      append zt_prombody.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 1.
      zt_prombody-level    = 2.
*      standard characteristics name for product
      zt_prombody-iobjnm   = gs_c_iobjnm-produkt.
      zt_prombody-chavl    = lv_product_1.
      append zt_prombody.

*      create the second combination for the promotion
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 2.
      zt_prombody-level    = 1.
*      standard characteristics name for location
      zt_prombody-iobjnm   = gs_c_iobjnm-lokation.
      zt_prombody-chavl    = lv_location_1.
      append zt_prombody.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 2.
      zt_prombody-level    = 2.
*      standard characteristics name for product
      zt_prombody-iobjnm   = gs_c_iobjnm-produkt.
      zt_prombody-chavl    = lv_product_3.
      append zt_prombody.

    when 3.
      read table zt_promhead index 1.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 1.
      zt_prombody-level    = 1.
*      standard characteristics name for location
      zt_prombody-iobjnm   = gs_c_iobjnm-lokation.
      zt_prombody-chavl    = lv_location_1.
      append zt_prombody.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 1.
      zt_prombody-level    = 2.
*      standard characteristics name for product
      zt_prombody-iobjnm   = gs_c_iobjnm-produkt.
      zt_prombody-chavl    = lv_product_1.
      append zt_prombody.

*      create the second combination for the promotion
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 2.
      zt_prombody-level    = 1.
*      standard characteristics name for location
      zt_prombody-iobjnm   = gs_c_iobjnm-lokation.
      zt_prombody-chavl    = lv_location_1.
      append zt_prombody.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 2.
      zt_prombody-level    = 2.
*      standard characteristics name for product
      zt_prombody-iobjnm   = gs_c_iobjnm-produkt.
      zt_prombody-chavl    = lv_product_3.
      append zt_prombody.

      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 3.
      zt_prombody-level    = 1.
*      standard characteristics name for location
      zt_prombody-iobjnm   = gs_c_iobjnm-lokation.
      zt_prombody-chavl    = lv_location_3.
      append zt_prombody.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 3.
      zt_prombody-level    = 2.
*      standard characteristics name for product
      zt_prombody-iobjnm   = gs_c_iobjnm-produkt.
      zt_prombody-chavl    = lv_product_1.
      append zt_prombody.

*      create the second combination for the promotion
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 4.
      zt_prombody-level    = 1.
*      standard characteristics name for location
      zt_prombody-iobjnm   = gs_c_iobjnm-lokation.
      zt_prombody-chavl    = lv_location_3.
      append zt_prombody.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 4.
      zt_prombody-level    = 2.
*      standard characteristics name for product
      zt_prombody-iobjnm   = gs_c_iobjnm-produkt.
      zt_prombody-chavl    = lv_product_3.
      append zt_prombody.

    when 4.
      read table zt_promhead index 1.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 1.
      zt_prombody-level    = 1.
*      standard characteristics name for location
      zt_prombody-iobjnm   = gs_c_iobjnm-lokation.
      zt_prombody-chavl    = lv_location_1.
      append zt_prombody.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 1.
      zt_prombody-level    = 2.
*      standard characteristics name for product
      zt_prombody-iobjnm   = gs_c_iobjnm-produkt.
      zt_prombody-chavl    = lv_product_1.
      append zt_prombody.

*      create the second combination for the promotion
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 2.
      zt_prombody-level    = 1.
*      standard characteristics name for location
      zt_prombody-iobjnm   = gs_c_iobjnm-lokation.
      zt_prombody-chavl    = lv_location_3.
      append zt_prombody.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 2.
      zt_prombody-level    = 2.
*      standard characteristics name for product
      zt_prombody-iobjnm   = gs_c_iobjnm-produkt.
      zt_prombody-chavl    = lv_product_3.
      append zt_prombody.

      read table zt_promhead index 2.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 1.
      zt_prombody-level    = 1.
*      standard characteristics name for location
      zt_prombody-iobjnm   = gs_c_iobjnm-lokation.
      zt_prombody-chavl    = lv_location_1.
      append zt_prombody.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 1.
      zt_prombody-level    = 2.
*      standard characteristics name for product
      zt_prombody-iobjnm   = gs_c_iobjnm-produkt.
      zt_prombody-chavl    = lv_product_1.
      append zt_prombody.

*      create the second combination for the promotion
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 2.
      zt_prombody-level    = 1.
*      standard characteristics name for location
      zt_prombody-iobjnm   = gs_c_iobjnm-lokation.
      zt_prombody-chavl    = lv_location_1.
      append zt_prombody.
      clear zt_prombody.
      zt_prombody-promid = zt_promhead-promid.
      zt_prombody-position = 2.
      zt_prombody-level    = 2.
*      standard characteristics name for product
      zt_prombody-iobjnm   = gs_c_iobjnm-produkt.
      zt_prombody-chavl    = lv_product_3.
      append zt_prombody.

  endcase.

*  get the promotion data for the combination
*  the TSID for the first combination
  read table zt_promhead index 1.
  lv_index = 1.
  lv_n3 = lv_index.
  lv_tsid(3) = lv_n3.
  lv_tsid+3(19) = zt_promhead-promid.
  clear lv_index.
  do zt_promhead-pmlength times.
    add 1 to lv_index.
    clear zt_promts.
    zt_promts-tsid = lv_tsid.
    zt_promts-tspos = lv_index.
    zt_promts-tsvalue = lv_value1.
    append zt_promts.
  enddo.

*  the TSID for the second combination
  lv_index = 2.
  lv_n3 = lv_index.
  lv_tsid(3) = lv_n3.
  lv_tsid+3(19) = zt_promhead-promid.
  clear lv_index.
  do zt_promhead-pmlength times.
    add 1 to lv_index.
    clear zt_promts.
    zt_promts-tsid = lv_tsid.
    zt_promts-tspos = lv_index.
    zt_promts-tsvalue = lv_value2.
    append zt_promts.
  enddo.

  if lv_testcase = 3.
*  data for the 3rd and 4th combinations
    lv_index = 3.
    lv_n3 = lv_index.
    lv_tsid(3) = lv_n3.
    lv_tsid+3(19) = zt_promhead-promid.
    clear lv_index.
    do zt_promhead-pmlength times.
      add 1 to lv_index.
      clear zt_promts.
      zt_promts-tsid = lv_tsid.
      zt_promts-tspos = lv_index.
      zt_promts-tsvalue = lv_value1.
      append zt_promts.
    enddo.

*    the TSID for the second combination
    lv_index = 4.
    lv_n3 = lv_index.
    lv_tsid(3) = lv_n3.
    lv_tsid+3(19) = zt_promhead-promid.
    clear lv_index.
    do zt_promhead-pmlength times.
      add 1 to lv_index.
      clear zt_promts.
      zt_promts-tsid = lv_tsid.
      zt_promts-tspos = lv_index.
      zt_promts-tsvalue = lv_value2.
      append zt_promts.
    enddo.
  endif.

  if lv_testcase = 4.
*  data for the second promotion
    read table zt_promhead index 2.
    lv_index = 1.
    lv_n3 = lv_index.
    lv_tsid(3) = lv_n3.
    lv_tsid+3(19) = zt_promhead-promid.
    clear lv_index.
    do zt_promhead-pmlength times.
      add 1 to lv_index.
      clear zt_promts.
      zt_promts-tsid = lv_tsid.
      zt_promts-tspos = lv_index.
      zt_promts-tsvalue = lv_value1.
      append zt_promts.
    enddo.

*    the TSID for the second combination
    lv_index = 2.
    lv_n3 = lv_index.
    lv_tsid(3) = lv_n3.
    lv_tsid+3(19) = zt_promhead-promid.
    clear lv_index.
    do zt_promhead-pmlength times.
      add 1 to lv_index.
      clear zt_promts.
      zt_promts-tsid = lv_tsid.
      zt_promts-tspos = lv_index.
      zt_promts-tsvalue = lv_value2.
      append zt_promts.
    enddo.
  endif.

endform. " fill_with_your_own_prog
*&---------------------------------------------------------------------*
*&      Form  check_parea_do_not_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_LV_FLG_ERROR  text
*----------------------------------------------------------------------*
form check_parea_do_not_change.

  clear lv_flg_error.
  call function '/SAPAPO/TS_PAREA_SINGLE_GET'
    exporting
      iv_pareaid       = lv_pareaid
    IMPORTING
      ES_AREAKO        = GS_AREAKO
      ES_TSTR          = gs_sdptstr
*     ET_PAPLOB        =
*     ET_PAREL         =
      ET_CHARS         = gt_chars
      ET_KEYFS         = gt_keyfs
    EXCEPTIONS
      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.
    lv_flg_error = true.
    exit.
  endif.
  gv_fabkl = gs_sdptstr-fabkl.
  gv_unit  = GS_AREAKO-basme.

  CALL FUNCTION '/SAPAPO/PROMOTION_ADD_CHARS'
    CHANGING
      ct_chars       = gt_chars.

endform. " check_parea_do_not_change
*&---------------------------------------------------------------------*
*&      Form  check_version_do_not_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form check_version_do_not_change.

  data:
    lt_version_tab type  /sapapo/ts_vers_tab with header line.

  call function '/SAPAPO/TS_PAREA_VERSIO_GET'
       exporting
            iv_pareaid       = lv_pareaid
       importing
            et_version_tab   = lt_version_tab[]
       exceptions
            no_version_found = 1
            others           = 2.

  read table lt_version_tab
      with key vrsioid = lv_vrsioid.
  if sy-subrc ne 0.
    message i062 with lv_vrsioid.
    lv_flg_error = true.
    exit.
  endif.

endform. " check_version_do_not_change
*&---------------------------------------------------------------------*
*&      Form  check_keyfs_do_not_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form check_keyfs_do_not_change.

*  check promotion level
  read table gt_promkeyf
        with key pareaid = lv_pareaid.
  if sy-subrc ne 0.
    SELECT SINGLE * FROM /sapapo/promkeyf
        WHERE pareaid   = lv_pareaid.
    IF sy-subrc NE 0.
      MESSAGE i069 WITH lv_pareaid.
*    Bitte pflegen Sie die Promotionsebene für & (siehe Langtext)
      lv_flg_error = true.
      EXIT.
    ENDIF.
    move-corresponding /sapapo/promkeyf to gt_promkeyf.
    append gt_promkeyf.
  endif.
  if gt_promkeyf-pm_iobjnm is initial.
    MESSAGE i069 WITH lv_pareaid.
*  Bitte pflegen Sie die Promotionsebene für & (siehe Langtext)
    lv_flg_error = true.
    EXIT.
  endif.

endform. " check_keyfs_do_not_change
*&---------------------------------------------------------------------*
*&      Form  check_gen_tab_do_not_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form check_gen_tab_do_not_change.

  CALL FUNCTION '/SAPAPO/PROMOTION_TAB_GENER'
    EXPORTING
      i_pareaid                 = lv_pareaid
    EXCEPTIONS
      NO_TABLE_CREATE           = 1
      NO_TABLE_ACTIVATE         = 2
      NO_TECHNIC_CREATE         = 3
      NO_TECHNIC_ACTIVATE       = 4
      PAREAID_INVALID           = 5
      OTHERS                    = 6.

  IF sy-subrc <> 0.
    message e016 with lv_pareaid.
    lv_flg_error = true.
    exit.
  ENDIF.

  CALL FUNCTION '/SAPAPO/TS_GENER_CODING'
    EXPORTING
      i_plobid                = GS_AREAKO-bas_plobid
      I_PROGCLASS             = 'PSTRU_PROMOTION'
    IMPORTING
      E_GEN_REPID             = GV_REPID_promotion
    EXCEPTIONS
      GENERATION_FAILED       = 1
      OTHERS                  = 2.

  IF sy-subrc <> 0.
    message e017 with lv_pareaid.
    lv_flg_error = true.
    exit.
  ENDIF.

endform. " check_gen_tab_do_not_change
*&---------------------------------------------------------------------*
*&      Form  build_promo_do_not_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form build_promo_do_not_change.


  loop at zt_promhead.

*  refresh global data for the new promotion
    perform refresh_data_do_no_change.

*  check promid unique
    perform check_promid_do_not_change.
    check lv_flg_error is initial.

*  build the promtion
    perform build_promtion_do_not_change.

*  periodicity correct?
    perform check_perkz_do_not_change.
    check lv_flg_error is initial.

*  period and dates are correct?
    perform check_dates_do_not_change.
    check lv_flg_error is initial.

*  fill the promtion tab
    insert gs_promtion into table gt_promtion.

*  promotion body correct defined?
*  build drill path
    perform check_body_do_not_change.
    check lv_flg_error is initial.

*  build prp_1tab
    perform build_1tab_do_not_change.
    check lv_flg_error is initial.

*  get TS and aggregation
    perform get_ts_do_not_change.

*  now the promotion can be saved
    perform save_promotion_do_not_change.

  endloop.

endform. " build_promo_do_not_change
*&---------------------------------------------------------------------*
*&      Form  check_perkz_do_not_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form check_perkz_do_not_change.

  clear lv_flg_error.
  if gs_promtion-perkz is initial.
    message i005 with gs_promtion-promid.
    lv_flg_error = true.
  endif.
  case gs_promtion-perkz.
    when con_perkz_m.
      if gs_sdptstr-perm is initial.
        message i002 with gs_promtion-perkz.
        lv_flg_error = true.
      endif.
    when con_perkz_w.
      if gs_sdptstr-perw is initial.
        message i002 with gs_promtion-perkz.
        lv_flg_error = true.
      endif.
    when con_perkz_q.
      if gs_sdptstr-perq is initial.
        message i002 with gs_promtion-perkz.
        lv_flg_error = true.
      endif.
    when con_perkz_y.
      if gs_sdptstr-pery is initial.
        message i002 with gs_promtion-perkz.
        lv_flg_error = true.
      endif.
    when con_perkz_p.
      if gs_sdptstr-perp  is initial           or
         gs_sdptstr-periv ne gs_promtion-periv.
        message i002 with gs_promtion-perkz.
        lv_flg_error = true.
      endif.
    when others.
      message i002 with gs_promtion-perkz.
      lv_flg_error = true.
  endcase.

endform. " check_perkz_do_not_change
*&---------------------------------------------------------------------*
*&      Form  check_dates_do_not_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form check_dates_do_not_change.

  data:
    lv_cd_length     type i.

  clear lv_flg_error.
  lv_cd_length = gs_promtion-pmlength.
  IF gs_promtion-pmlength IS INITIAL.
    MESSAGE i006 with gs_promtion-promid.
    lv_flg_error = true.
    EXIT.
  ENDIF.
  call function '/SAPAPO/PERIOD_GET_DATE_RANGE'
    exporting
      I_FABKL           = gv_fabkl
      i_perkz           = gs_promtion-perkz
      I_PERIV           = gs_promtion-periv
    changing
      ie_fromdate       = gs_promtion-startdate
      ie_todate         = gs_promtion-lastdate
      ie_length         = lv_cd_length
    EXCEPTIONS
      WRONG_DATE        = 1
      WRONG_PERKZ       = 2
      WRONG_PERIV       = 3
      WRONG_FABKL       = 4
      OTHERS            = 5.
  if sy-subrc <> 0.
    MESSAGE i006 with gs_promtion-promid.
    lv_flg_error = true.
  endif.

endform. " check_dates_do_not_change
*&---------------------------------------------------------------------*
*&      Form  check_body_do_not_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form check_body_do_not_change.

  data:
    lv_cb_position   type i,
    lt_cb_group_by   type /SAPAPO/TS_GROUP_BY_TAB,
    lt_cb_selection  type /sapapo/ts_iobj_selection_tab.


  clear lv_flg_error.
  read table zt_prombody
        with key promid = gs_promtion-promid.
  if sy-subrc ne 0.
*  no charateristics combination
    message i037 with gs_promtion-promid.
    lv_flg_error = true.
    exit.
  endif.

*  build the drill path
  clear gt_prom_drillpath.
  clear gt_drillpath_total.
  loop at zt_prombody where promid = gs_promtion-promid.
*  check whether the char is correct
    read table gt_chars into gs_chars
          with key iobjnm = zt_prombody-iobjnm.
    if sy-subrc ne 0.
      message i022 with zt_prombody-iobjnm.
      lv_flg_error = true.
      exit.
    endif.
*  check whether the level correct
    read table gt_prom_drillpath into gs_drillpath
          with key drill_level = zt_prombody-level.
    if sy-subrc = 0.
      read table gt_prom_drillpath into gs_drillpath
                with key drill_level  = zt_prombody-level
                         level_iobjnm = zt_prombody-iobjnm.
      if sy-subrc ne 0.
*  mixed level iobjnm
        message i050 with zt_prombody-iobjnm.
        lv_flg_error = true.
        exit.
      else.
        read table gt_prom_drillpath into gs_drillpath
                  with key drill_level  = zt_prombody-level
                           level_iobjnm = zt_prombody-iobjnm
                           level_chavl  = zt_prombody-chavl.
        check sy-subrc ne 0.
      endif.
    endif.

*  add the level
    clear gs_drillpath.
    gs_drillpath-promguid     = gs_promtion-promguid.
    gs_drillpath-drill_level  = zt_prombody-level.
    gs_drillpath-level_iobjnm = zt_prombody-iobjnm.
    gs_drillpath-level_chavl  = zt_prombody-chavl.
    insert gs_drillpath into table gt_prom_drillpath.
  endloop.

  check lv_flg_error is initial.

*  adjust the level
  loop at gt_prom_drillpath into gs_drillpath.
    add 1 to gs_drillpath-drill_level.
    insert gs_drillpath into table gt_drillpath_total.
  endloop.

*  add the promotion level
  gs_drillpath-promguid     = gs_promtion-promguid.
  gs_drillpath-drill_level  = con_level_promotion.
  gs_drillpath-level_iobjnm = con_iobjnm_promotion.
  gs_drillpath-level_chavl  = gs_promtion-promid.
  insert gs_drillpath into table gt_drillpath_total.

  gt_prom_drillpath = gt_drillpath_total.

*  combination exists?
  lv_cb_position = 0.
  do.
    add 1 to lv_cb_position.
    read table zt_prombody
          with key promid = gs_promtion-promid
                   position = lv_cb_position.
    if sy-subrc ne 0.
      exit.
    endif.
    clear lt_cb_selection.
    loop at zt_prombody
          where promid = gs_promtion-promid and
                position = lv_cb_position.
      gs_selection-iobjnm  = zt_prombody-iobjnm.
      gs_selection-low     = zt_prombody-chavl.
      gs_selection-sign    = 'I'.
      gs_selection-option  = 'EQ'.
      append gs_selection to lt_cb_selection.
    endloop.
    gs_selection-iobjnm  = gs_c_iobjnm-version.
    gs_selection-low     = lv_vrsioid.
    gs_selection-sign    = 'I'.
    gs_selection-option  = 'EQ'.
    append gs_selection to lt_cb_selection.
    call function '/SAPAPO/TS_PLOB_LIST_GET'
      exporting
        iv_bas_plobid           = gs_areako-bas_plobid
        it_selection            = lt_cb_selection
        it_group_by             = lt_cb_group_by
*       IS_READ_OPTIONS         =
*     IMPORTING
*       ET_PLOB_VALUES          =
*       ET_PLOBS_IN_VIEW        =
*       ET_CHAR_VALUES          =
*       ET_TMP_PLOB_REL         =
*       EV_USED_PSTRU           =
      EXCEPTIONS
        INVALID_SELECTION       = 1
        NO_BAS_PLOBID           = 2
        INHERITED_ERROR         = 3
        OTHERS                  = 4.
    if sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      lv_flg_error = true.
      exit.
    endif.

  enddo.

  check lv_flg_error is initial.

*  so for all positions the combinations exist
*  check hierarchy and promotion level
*  get the last level
  describe table gt_prom_drillpath lines gv_drillpath_level.
  read table gt_prom_drillpath into gs_drillpath
          index gv_drillpath_level.
  gv_drillpath_level = gs_drillpath-drill_level.
*    the last promotion level should be the promotion characteristics
  if gs_promtion-pm_iobjnm ne gs_drillpath-LEVEL_IOBJNM.
    message i072 with gs_promtion-promid gs_promtion-pm_iobjnm.
    lv_flg_error = true.
    exit.
  endif.

endform. " check_body_do_not_change
*&---------------------------------------------------------------------*
*&      Form  build_promtion_do_not_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form build_promtion_do_not_change.

*  genereate the promguid
  clear gs_promtion.
  move-corresponding zt_promhead to gs_promtion.
  call function 'GUID_CREATE'
       importing
            ev_guid_22 = gs_promtion-promguid.
  gs_flags-which_promotion = gs_promtion-promguid.
  gs_promtion-pareaid    = lv_pareaid.
  gs_promtion-vrsioid    = lv_vrsioid.
  gs_promtion-pm_unit    = gv_unit.
  read table gt_promkeyf index 1.
  gs_promtion-pm_iobjnm  = gt_promkeyf-pm_iobjnm.
  gs_promtion-KENNZ      = gt_promkeyf-kennz.
  gs_promtion-plan_KENNZ = lv_plan_kennz.
  gs_promtion-pm_status  = con_pmstatus_draft.

*  generate TS for the promotion
  move-corresponding gs_promtion to gs_prominfo.
  call function '/SAPAPO/PROMOTION_GENERATE_TS'
       exporting
            is_prominfo = gs_prominfo
       importing
            es_sdptms   = gs_sdptms.
  gs_promtion-ts_prom_total = gs_sdptms-tsid.
  insert gs_sdptms into table gt_sdptms.
  call function '/SAPAPO/PROMOTION_GENERATE_TS'
       exporting
            is_prominfo = gs_prominfo
       importing
            es_sdptms   = gs_sdptms.
  gs_promtion-ts_plan_total = gs_sdptms-tsid.
  insert gs_sdptms into table gt_sdptms.
  call function '/SAPAPO/PROMOTION_GENERATE_TS'
       exporting
            is_prominfo = gs_prominfo
       importing
            es_sdptms   = gs_sdptms.
  gs_promtion-ts_net_profit = gs_sdptms-tsid.
  insert gs_sdptms into table gt_sdptms.
  call function '/SAPAPO/PROMOTION_GENERATE_TS'
       exporting
            is_prominfo = gs_prominfo
       importing
            es_sdptms   = gs_sdptms.
  gs_promtion-ts_total_cost = gs_sdptms-tsid.
  insert gs_sdptms into table gt_sdptms.

  call function 'GUID_CREATE'
       importing
            ev_guid_22 = gs_promtion-docuguid.

endform. " build_promtion_do_not_change
*&---------------------------------------------------------------------*
*&      Form  build_1tab_do_not_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form build_1tab_do_not_change.

  data:
    lv_bt_flg.

  clear gt_prombody.
  clear gt_prp_1tab.
  clear gt_1tab_not.

*  set the generated tab content
*  gt_prp_1tab will be filled
  perform build_0tab_do_not_change
          changing gt_prom_drillpath
                   gs_promtion
                   gt_prombody.

*  excluding prp_1tab
  perform excluding_1tab_do_not_change.

*  transfer global data to /SAPAPO/SAPLPROMOTION
  lv_bt_flg = 'I'.
  perform promotion_transfer_ext_data
            in program /SAPAPO/SAPLPROMOTION
            using     lv_bt_flg
            changing  gv_repid_promotion
                      gv_drillpath_level
                      gs_flags
                      gt_promtion
                      gt_prombody
                      gt_prp_1tab
                      gt_1tab_not
                      gt_drillpath_total
                      gt_prom_drillpath
                      gt_sdptms
                      gt_sdp_tmsv.

*  check hierarchy
  perform promotion_exame_hierarchy
                  in program /SAPAPO/SAPLPROMOTION
                  using    gs_promtion
                  changing lv_flg_error.
  if not lv_flg_error is initial.
    MESSAGE i084 with gs_promtion-promid.
    lv_flg_error = true.
    exit.
  endif.

endform. " build_1tab_do_not_change
*&---------------------------------------------------------------------*
*&      Form  get_ts_do_not_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_ts_do_not_change.

  data:
    lv_td_flg,
    lv_td_level      type i,
    lv_td_tspos      type i,
    lt_td_1tab       type /sapapo/prp_1tab_tab,
    lv_td_tsid       type /sapapo/tsguid,
    lv_td_n3(3)      type n,
    lv_td_position   type i,
    lt_td_group_by   type /SAPAPO/TS_GROUP_BY_TAB,
    lt_td_selection  type /sapapo/ts_iobj_selection_tab.

*  transfer global data to /SAPAPO/SAPLPROMOTION
  lv_td_flg = 'I'.
  perform promotion_transfer_ext_data
            in program /SAPAPO/SAPLPROMOTION
            using     lv_td_flg
            changing  gv_repid_promotion
                      gv_drillpath_level
                      gs_flags
                      gt_promtion
                      gt_prombody
                      gt_prp_1tab
                      gt_1tab_not
                      gt_drillpath_total
                      gt_prom_drillpath
                      gt_sdptms
                      gt_sdp_tmsv.

  do.
    add 1 to lv_td_position.
    read table zt_prombody
          with key promid   = gs_promtion-promid
                   position = lv_td_position.
    if sy-subrc ne 0.
      exit.
    endif.
*  get the TSID for the position/combination
    lv_td_n3 = lv_td_position.
    lv_td_tsid(3) = lv_td_n3.
    lv_td_tsid+3(19) = gs_promtion-promid.
    read table zt_promts with key tsid = lv_td_tsid.
    check sy-subrc = 0.
*  builld the selection
    clear lt_td_selection.
    loop at zt_prombody
          where promid   = gs_promtion-promid and
                position = lv_td_position.
      gs_selection-iobjnm  = zt_prombody-iobjnm.
      gs_selection-low     = zt_prombody-chavl.
      gs_selection-sign    = 'I'.
      gs_selection-option  = 'EQ'.
      append gs_selection to lt_td_selection.
    endloop.
    gs_selection-iobjnm  = gs_c_iobjnm-version.
    gs_selection-low     = lv_vrsioid.
    gs_selection-sign    = 'I'.
    gs_selection-option  = 'EQ'.
    append gs_selection to lt_td_selection.

*  get the TS for the combination
    perform promotion_get_1tab_for_select
            in program (gv_repid_promotion)
            using
               lt_td_selection
               gv_drillpath_level
               gs_promtion-promguid
            changing
               lt_td_1tab.

    read table lt_td_1tab into gs_prp_1tab index 1.
    if sy-subrc ne 0.
*  should not happen
      message i023.
      continue.
    endif.
    loop at zt_promts where tsid = lv_td_tsid.
*  set data
      clear gs_sdp_tmsv.
      gs_sdp_tmsv-tsid = gs_prp_1tab-ts_prom.
      gs_sdp_tmsv-tspos = zt_promts-tspos.
      gs_sdp_tmsv-tsvalue = zt_promts-tsvalue.
      insert gs_sdp_tmsv into table gt_sdp_tmsv.
*  send the TS to /SAPAPO/SAPLPROMOTION
      lv_td_flg = 'S'.
      perform promotion_transfer_ext_data
                in program /SAPAPO/SAPLPROMOTION
                using     lv_td_flg
                changing  gv_repid_promotion
                          gv_drillpath_level
                          gs_flags
                          gt_promtion
                          gt_prombody
                          gt_prp_1tab
                          gt_1tab_not
                          gt_drillpath_total
                          gt_prom_drillpath
                          gt_sdptms
                          gt_sdp_tmsv.
*  aggregate
      lv_td_level = gv_drillpath_level - 1.
      lv_td_tspos = zt_promts-tspos.
      perform promotion_aggregation
                in program /SAPAPO/SAPLPROMOTION
                using  lv_td_level
                       lv_td_tspos
                       gs_prp_1tab-bodyguid
                       zt_promts-tsvalue.
*      get back the TS
      lv_td_flg = 'T'.
      perform promotion_transfer_ext_data
                in program /SAPAPO/SAPLPROMOTION
                using     lv_td_flg
                changing  gv_repid_promotion
                          gv_drillpath_level
                          gs_flags
                          gt_promtion
                          gt_prombody
                          gt_prp_1tab
                          gt_1tab_not
                          gt_drillpath_total
                          gt_prom_drillpath
                          gt_sdptms
                          gt_sdp_tmsv.

    endloop.

  enddo.


endform. " get_ts_do_not_change
*&---------------------------------------------------------------------*
*&      Form  excluding_1tab_do_not_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form excluding_1tab_do_not_change.

  data:
    lv_et_level      type i,
    lv_et_level_1    type i,
    ls_et_1tab       type /sapapo/prp_1tab,
    lt_et_1tab       type /sapapo/prp_1tab_tab,
    lt_et_1tab_ok    type /sapapo/prp_1tab_tab,
    lv_et_tsid       type /sapapo/tsguid,
    lv_et_n3(3)      type n,
    lv_et_position   type i,
    lt_et_selection  type /sapapo/ts_iobj_selection_tab.

  clear gt_1tab_not.

  do.  "for position
    add 1 to lv_et_position.
    read table zt_prombody
          with key promid   = gs_promtion-promid
                   position = lv_et_position.
    if sy-subrc ne 0.
      exit.
    endif.
*  get the TSID for the position/combination
    lv_et_n3 = lv_et_position.
    lv_et_tsid(3) = lv_et_n3.
    lv_et_tsid+3(19) = gs_promtion-promid.
    read table zt_promts with key tsid = lv_et_tsid.
    check sy-subrc = 0.
    lv_et_level = 0.
    do.    "for level
      add 1 to lv_et_level.
      if lv_et_level >= gv_drillpath_level.
        exit.
      endif.
*    builld the selection
      clear lt_et_selection.
      loop at zt_prombody
            where promid   =  gs_promtion-promid and
                  position =  lv_et_position     and
                  level    <= lv_et_level.
        gs_selection-iobjnm  = zt_prombody-iobjnm.
        gs_selection-low     = zt_prombody-chavl.
        gs_selection-sign    = 'I'.
        gs_selection-option  = 'EQ'.
        append gs_selection to lt_et_selection.
      endloop.
      gs_selection-iobjnm  = gs_c_iobjnm-version.
      gs_selection-low     = lv_vrsioid.
      gs_selection-sign    = 'I'.
      gs_selection-option  = 'EQ'.
      append gs_selection to lt_et_selection.

*    get the TS for the combination
      lv_et_level_1 = lv_et_level + 1.
      perform promotion_get_1tab_for_select
              in program (gv_repid_promotion)
              using
                 lt_et_selection
                 lv_et_level_1
                 gs_promtion-promguid
              changing
                 lt_et_1tab.

      loop at lt_et_1tab into ls_et_1tab.
        read table lt_et_1tab_ok into gs_prp_1tab
              with table key promguid    = ls_et_1tab-promguid
                             drill_level = ls_et_1tab-drill_level
                             bodyguid    = ls_et_1tab-bodyguid.
        if sy-subrc ne 0.
          insert ls_et_1tab into table lt_et_1tab_ok.
        endif.
      endloop.
    enddo.
  enddo.

  loop at gt_prp_1tab into gs_prp_1tab.
    read table lt_et_1tab_ok into ls_et_1tab
            with table key promguid    = gs_prp_1tab-promguid
                           drill_level = gs_prp_1tab-drill_level
                           bodyguid    = gs_prp_1tab-bodyguid.
    if sy-subrc ne 0.
      insert gs_prp_1tab into table gt_1tab_not.
    endif.
  endloop.

endform. " excluding_1tab_do_not_change
*&---------------------------------------------------------------------*
*&      Form  build_gen_0tab
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_PROM_DRILLPATH  text
*      <--P_GS_PROMTION  text
*      <--P_GT_PROMBODY  text
*----------------------------------------------------------------------*
form build_0tab_do_not_change
      changing ct_bg_drillpath type /sapapo/prom_drillpath_tab
               cs_bg_promtion  type /sapapo/promtion
               ct_bg_prombody  type /sapapo/prombody_tab.

*  build levle_0tab for each drillpath level

  DATA: iv_bas_plobid                TYPE /sapapo/ts_plobid,
        ls_gener_info            TYPE /sapapo/ts_gener_info,
        ref_plobs_in_view        TYPE REF TO data.


  data:
    ls_bg_prominfo   like /sapapo/prominfo,
    ls_bg_drillpath  like /sapapo/prom_drillpath,
    lt_bg_1tab       type /sapapo/prp_1tab_tab,
    lv_bg_level      type i.

*  total level of the promotion
  describe table ct_bg_drillpath lines lv_bg_level.
  read table ct_bg_drillpath into ls_bg_drillpath index lv_bg_level.
  gv_drillpath_level = ls_bg_drillpath-drill_level.

  check gv_drillpath_level > con_level_promotion.

  clear gs_prp_1tab.
  gs_prp_1tab-promguid     = gs_promtion-promguid.
  gs_prp_1tab-bodyguid     = gs_promtion-promguid.
  gs_prp_1tab-bodytsid     = gs_promtion-ts_prom_total.
  gs_prp_1tab-ts_prom      = gs_promtion-ts_prom_total.
  gs_prp_1tab-ts_plan      = gs_promtion-ts_plan_total.
  gs_prp_1tab-ts_prof      = gs_promtion-ts_net_profit.
  gs_prp_1tab-ts_cost      = gs_promtion-ts_total_cost.
  gs_prp_1tab-pm_unit_show = gs_promtion-pm_unit.
  gs_prp_1tab-unit_rate    = 1.
  gs_prp_1tab-drill_level = con_level_promotion.
  insert gs_prp_1tab into table gt_prp_1tab.

  lv_bg_level = con_level_promotion + 1.
  move-corresponding cs_bg_promtion to ls_bg_prominfo.

**************************************************************
*MOD-001
**************************************************************
    iv_bas_plobid = '9ASNPBAS'.

*   Generate Internal Table
    CALL FUNCTION '/SAPAPO/TS_GEN_INFO_GET'
      EXPORTING
        i_plobid      = iv_bas_plobid
      IMPORTING
        es_alles_drin = ls_gener_info.

    IF ls_gener_info-view2 IS INITIAL.
      MESSAGE e005 RAISING no_bas_plobid.
    ENDIF.

    CREATE DATA ref_plobs_in_view TYPE STANDARD TABLE
      OF (ls_gener_info-view2).
    ASSIGN ref_plobs_in_view->* TO <lt_plobs_in_view>.

* Gibt es vielleicht einen Fehler ? ...
  IF NOT <lt_plobs_in_view> IS ASSIGNED.
    MESSAGE x011.
  ENDIF.

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

  while lv_bg_level <= gv_drillpath_level.
*    create combination for the new drill down
    perform promotion_set_level_0tab
      in program (gv_repid_promotion)
      using
         lv_bg_level
         ls_bg_prominfo
         <lt_plobs_in_view>
      changing
         ct_bg_drillpath
         gt_sdptms
         lt_sl_1tab
         lt_bg_1tab.


**************************************************************
* MOD-001
**************************************************************
*form promotion_set_level_0tab
*        using
*           iv_sl_level     type i
*           is_sl_prominfo  structure /sapapo/prominfo
*           it_plobs_in_view TYPE ANY TABLE
*        changing
*           it_drillpath type /sapapo/prom_drillpath_tab
*           et_sl_sdptms type /sapapo/sdptms_tab
*           et_sl_1tab   type /sapapo/prp_1tab_tab
*           et_prp_1tab   type /sapapo/prp_1tab_tab
*
**************************************************************
* MOD-001
**************************************************************

*    keep in buffer
    insert lines of lt_bg_1tab into table gt_prp_1tab.

    loop at lt_bg_1tab
              into gs_prp_1tab.
      clear gs_prombody.
      move-corresponding gs_prp_1tab to gs_prombody.
      insert gs_prombody into table ct_bg_prombody.
    endloop.

    add 1 to lv_bg_level.
  endwhile.

endform. " build_gen_0tab
*&---------------------------------------------------------------------*
*&      Form  save_promotion_do_not_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form save_promotion_do_not_change.

  data:
    lv_sp_flg.

*  transfer global data to /SAPAPO/SAPLPROMOTION
  lv_sp_flg = 'I'.
  perform promotion_transfer_ext_data
            in program /SAPAPO/SAPLPROMOTION
            using     lv_sp_flg
            changing  gv_repid_promotion
                      gv_drillpath_level
                      gs_flags
                      gt_promtion
                      gt_prombody
                      gt_prp_1tab
                      gt_1tab_not
                      gt_drillpath_total
                      gt_prom_drillpath
                      gt_sdptms
                      gt_sdp_tmsv.

  call function '/SAPAPO/PROMOTION_SAVE'
    exporting
*     IV_DRILL_LEVEL       = '0'
      iv_promguid          = gs_promtion-promguid
    EXCEPTIONS
      PAREA_ERROR          = 1
      WRONG_SETTINGS       = 2
      LOCK_ERROR           = 3
      OTHERS               = 4.
  if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    exit.
  endif.
  message s008 with gs_promtion-promid.

endform. " save_promotion_do_not_change
*&---------------------------------------------------------------------*
*&      Form  refresh_data_do_no_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form refresh_data_do_no_change.

  clear gv_drillpath_level.
  clear gs_flags.
  clear gt_promtion.
  clear gt_prombody.
  clear gt_prp_1tab.
  clear gt_1tab_not.
  clear gt_drillpath_total.
  clear gt_prom_drillpath.
  clear gt_sdptms.
  clear gt_sdp_tmsv.

endform. " refresh_data_do_no_change
*&---------------------------------------------------------------------*
*&      Form  check_promid_do_not_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form check_promid_do_not_change.

  clear lv_flg_error.
  select single * from /sapapo/promtion
          where promid = zt_promhead-promid.
  if sy-subrc = 0.
    message i055 with zt_promhead-promid.
    lv_flg_error = true.
    exit.
  endif.

endform. " check_promid_do_not_change


*Selection texts
*----------------------------------------------------------
* TESTCASE         Promo Planning Test Scenario


*Messages
*----------------------------------------------------------
*
* Message class: /SAPAPO/PRP
*002   Periodicity & not defined in planning area
*005   Specify the periodicity of promotion &
*006   Specify the period information of promotion &
*008   Promotion & stored successfully
*011   Key figure of promotion & is not specified
*016   Error during generation of characteristics table for planning area &
*017   Error during generation for planning area &
*018   You have not selected a promotion that fulfills all conditions
*022   Object & is no standard characteristic
*023   Internal error message in promotion planning
*037   No characteristics combination was assigned for promotion &
*050   Characteristic & cannot be assigned to a promotion
*055   Promotion & already exists
*062   Planning version & does not exist
*069   Maintain the promotion level for planning area & (see long text)
*072   Promotion & has no characteristic values of promotion level &
*084   Data from promotion & not completely maintained (see long text)


*Selection texts
*----------------------------------------------------------
* TESTCASE         Input Data


*Messages
*----------------------------------------------------------
*
* Message class: /SAPAPO/PRP
*002   Periodicity & not defined in planning area
*005   Specify the periodicity of promotion &
*006   Specify the period information of promotion &
*008   Promotion & stored successfully
*011   Key figure of promotion & is not specified
*016   Error during generation of characteristics table for planning area &
*017   Error during generation for planning area &
*018   You have not selected a promotion that fulfills all conditions
*022   Object & is no standard characteristic
*023   Internal error message in promotion planning
*037   No characteristics combination was assigned for promotion &
*050   Characteristic & cannot be assigned to a promotion
*055   Promotion & already exists
*062   Planning version & does not exist
*069   Maintain the promotion level for planning area & (see long text)
*072   Promotion & has no characteristic values of promotion level &
*084   Data from promotion & not completely maintained (see long text) | |

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

  • No labels