Skip to end of metadata
Go to start of metadata
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
************************************************************************
* Y_BW_BPS_FOX_CHECKER
* --------------------
* Display list of BPS formulas and perform a syntax check
*
* (c) SAP AG 2009
* created: 2009-04-08                                MFB, SAP Labs, LLC
* last update: 2009-04-08
************************************************************************
* Apply SAP notes 635244 and 934618 (or BW 3.5 SP 18)
************************************************************************

REPORT y_bw_bps_fox_checker.

TYPE-POOLS: rs, icon.

TABLES:
  upc_area, upc_plevel, upf_planf.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
SELECT-OPTIONS:
  so_area FOR upc_area-area,
  so_plvl FOR upc_plevel-plevel,
  so_func FOR upf_planf-method.
SELECTION-SCREEN END   OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t02.
PARAMETERS:
  p_gen  AS CHECKBOX DEFAULT rs_c_false.
SELECTION-SCREEN END   OF BLOCK b2.

* FOX
DATA:
  gs_fox      TYPE upf_planf,
  gt_fox      TYPE TABLE OF upf_planf WITH DEFAULT KEY.

* Planning area settings
DATA:
  g_area      TYPE upc_y_area,
  gs_chapro   TYPE upc_ys_chapro,
  gs_kyfpro   TYPE upc_ys_kyfpro,
  gs_chacmp   TYPE upc_ys_chacmp,
  gto_chapro  TYPE upc_yto_chapro,
  gto_kyfpro  TYPE upc_yto_kyfpro,
  gto_chacmp  TYPE upc_yto_chacmp.

* Planning level settings
DATA:
  g_plevela   TYPE upc_y_area,
  g_plevell   TYPE upc_y_plevel,
  gs_cha      TYPE upc_ys_cha,
  gto_cha     TYPE upc_yto_cha,
  gs_kyf      TYPE upc_ys_kyf,
  gto_kyf     TYPE upc_yto_kyf,
  gs_plevels  TYPE upc_ys_charsel,
  gto_plevels TYPE upc_yto_charsel,
  gs_plevelv  TYPE upc_ys_varsel,
  gto_plevelv TYPE upc_yto_varsel,
  gs_charng   TYPE upc_ys_charng,
  gs_chasel   TYPE upc_ys_chasel,
  gto_chasel  TYPE upc_yto_chasel.

* Planning function and parameter groups
DATA:
  gs_text     TYPE textpool,
  gt_text     TYPE TABLE OF textpool,
  gt_text_old TYPE TABLE OF textpool,
  g_dummy     TYPE string,
  g_comma     TYPE c,
  g_len       TYPE i,
  g_fields    TYPE i,
  g_count     TYPE i,
  g_condi     TYPE i,
  g_condt     TYPE c,
  g_subrc     TYPE sy-subrc,
  g_function  TYPE string,
  g_error      TYPE rs_bool,
  g_error_area TYPE rs_bool,
  g_error_pos  TYPE i,
  g_error_line TYPE i,
  g_semkey    TYPE upc_grepcat-semkey,
  g_report    TYPE upc_grepcat-reportname,
  g_hash      TYPE char32,
  g_generate  TYPE char1,
  gs_planf    TYPE upf_planf,
  gt_planf    TYPE TABLE OF upf_planf,
  gs_pflds    TYPE upf_pflds,
  gt_pflds    TYPE TABLE OF upf_pflds,
  gs_param    TYPE upf_param,
  gt_param    TYPE TABLE OF upf_param,
  gs_pargd    TYPE upf_pargd,
  gs_pargd2   TYPE upf_pargd,
  gt_pargd    TYPE TABLE OF upf_pargd,
  gs_optios   TYPE upc_ys_optios,
  gt_optios   TYPE upc_yt_optios,
  gs_forml    TYPE upc_forml,
  gt_forml    TYPE TABLE OF upc_forml,
  gs_neval    TYPE upc_neval,
  gt_neval    TYPE TABLE OF upc_neval,
  gs_calcf    TYPE upc_ys_cha,
  gt_calcf    TYPE upc_yto_cha,
  gs_cline    TYPE upf_ys_cline,
  gt_cline    TYPE upf_yt_cline,
  gs_formla   TYPE upc_ys_forml,
  gt_formla   TYPE upc_yt_forml,
  gt_formlb   TYPE upc_yt_formlb.

* Optimizer
TYPES:
  BEGIN OF ys_replin,
    line     TYPE c LENGTH 132,
  END OF ys_replin.

DATA:
  gt_ugly    TYPE TABLE OF ys_replin WITH HEADER LINE,
  gt_pretty  TYPE TABLE OF ys_replin WITH HEADER LINE.

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

DEFINE write_title.
  write: at /5 &1 color col_group.
  if not &2 is initial.
    write &2 color col_group intensified off no-gap.
  endif.
  if not &3 is initial.
    write &3 color col_group intensified off no-gap.
  endif.
  skip.
END-OF-DEFINITION.

DEFINE write_header.
  write: at /3 &1 color col_key.
  if not &2 is initial.
    write &2 color col_key intensified off no-gap.
  endif.
  if not &3 is initial.
    write &3 color col_key intensified off no-gap.
  endif.
  skip.
END-OF-DEFINITION.

DEFINE write_value.
  write: at /5 &1 color col_normal.
  if not &2 is initial.
    write &2 color col_normal intensified off no-gap.
  endif.
  skip.
END-OF-DEFINITION.

DEFINE write_hotspot.
  write: at /5 &1 color col_normal.
  if not &2 is initial.
    write &2 color col_normal intensified off no-gap hotspot on.
    hide &2.
  endif.
  skip.
END-OF-DEFINITION.

DEFINE write_field.
  read table gto_chapro into gs_chapro
    with key chanm = &1.
  if sy-subrc = 0.
    g_len = strlen( gs_chapro-txtlg ).
    write: gs_chapro-txtlg(g_len) no-gap.
  else.
    write: 'Key figure' no-gap.
  endif.
END-OF-DEFINITION.

DEFINE addtextpool.
  read table gt_text into gs_text with key id = &1 key = &2.
  if sy-subrc = 0.
    delete gt_text where id = &1 and key = &2.
  endif.
  clear gs_text.
  gs_text-id    = &1.
  gs_text-key   = &2.
  if &1 = 'S'.
    gs_text-entry+8 = &3.
  else.
    gs_text-entry = &3.
  endif.
  append gs_text to gt_text.
END-OF-DEFINITION.

*-----------------------------------------------------------------------
INITIALIZATION.

  READ TEXTPOOL sy-repid INTO gt_text LANGUAGE sy-langu.

  gt_text_old = gt_text.

  addtextpool 'R' '' 'BW-BPS: FOX Checker'.

  addtextpool 'S' 'P_TECH'   'Display technical names'.
  addtextpool 'S' 'P_GEN'    'Generated ABAP (if necessary)'.
  addtextpool 'S' 'SO_AREA'  'Planning area'.
  addtextpool 'S' 'SO_LVL'   'Planning level'.
  addtextpool 'S' 'SO_FUNC'  'Planning function'.

  addtextpool 'I' 'T01'	'To be checked...'.
  addtextpool 'I' 'T02'	'Options'.

  IF gt_text <> gt_text_old.
    INSERT textpool sy-repid FROM gt_text LANGUAGE sy-langu.
  ENDIF.

*-----------------------------------------------------------------------
* Value help for planning level
AT SELECTION-SCREEN ON VALUE-REQUEST FOR so_plvl-low.

  CALL FUNCTION 'UPC_DISP_F4'
    EXPORTING
      i_node_type = 'PLEVEL'
      i_area      = so_area-low
    IMPORTING
      e_plevel    = so_plvl-low.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR so_plvl-high.

  CALL FUNCTION 'UPC_DISP_F4'
    EXPORTING
      i_node_type = 'PLEVEL'
      i_area      = so_area-low
    IMPORTING
      e_plevel    = so_plvl-high.

AT LINE-SELECTION.

  IF NOT g_report IS INITIAL.
    EDITOR-CALL FOR REPORT g_report DISPLAY-MODE.
  ENDIF.
  CLEAR g_report.

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

* Select all planning functions of type "formula"
  SELECT * FROM upf_planf INTO TABLE gt_fox
    WHERE area   IN so_area
      AND plevel IN so_plvl
      AND method IN so_func
      AND plntp  =  '07'
    ORDER BY PRIMARY KEY.

  LOOP AT gt_fox INTO gs_fox.
    MOVE-CORRESPONDING gs_fox TO upf_planf.

* Get meta info if this is a new area
    IF g_area <> upf_planf-area.
      g_error_area = rs_c_false.

      g_area = upf_planf-area.

      CALL FUNCTION 'UPC_META_INFO'
        EXPORTING
          i_area     = g_area
          i_time     = '0'
        IMPORTING
          eto_chapro = gto_chapro
          eto_kyfpro = gto_kyfpro
          eto_chacmp = gto_chacmp
        EXCEPTIONS
          failed     = 1
          rfc_error  = 2
          OTHERS     = 3.
      IF sy-subrc <> 0.
        WRITE: 'Error in area!' COLOR COL_NEGATIVE, g_area.
        g_error_area = rs_c_true.
        ULINE.
        CONTINUE.
      ENDIF.
    ENDIF.

    CHECK g_error_area = rs_c_false.

* Initialize the function, otherwise the following calls will fail
    CALL FUNCTION 'UPF_METHOD_INIT'
      EXPORTING
        i_fcode    = 'INIT'
        i_area     = upf_planf-area
        i_plevel   = upf_planf-plevel
        i_method   = upf_planf-method
      EXCEPTIONS
        error_init = 1
        OTHERS     = 2.
    IF sy-subrc <> 0.
      WRITE: 'Error in function' COLOR COL_NEGATIVE,
        upf_planf-area, upf_planf-plevel, upf_planf-method.
      CONTINUE.
    ENDIF.

* Get parameter groups (the actual formulas)
    CALL FUNCTION 'UPF_PARAM_INFO_GET'
      EXPORTING
        i_area    = upf_planf-area
        i_plevel  = upf_planf-plevel
        i_method  = upf_planf-method
      TABLES
        et_planf  = gt_planf
        et_pflds  = gt_pflds
        et_param  = gt_param
        et_pargd  = gt_pargd
        et_optios = gt_optios
        et_forml  = gt_forml
        et_neval  = gt_neval.

*   Print formula definition
    WRITE:
      / 'Planning area    :' COLOR COL_HEADING,
         upf_planf-area COLOR COL_HEADING INTENSIFIED OFF,
      / 'Planning level   :' COLOR COL_HEADING,
         upf_planf-plevel COLOR COL_HEADING INTENSIFIED OFF,
      / 'Planning function:' COLOR COL_HEADING,
         upf_planf-method COLOR COL_HEADING INTENSIFIED OFF.
    SKIP.

* Print "fields to be changed"
    WRITE: / 'Fields to be changed: {'.

    REFRESH gt_calcf.
    CLEAR g_comma.
    LOOP AT gt_pflds INTO gs_pflds WHERE pftyp = 2.
      IF g_comma = 'X'.
        WRITE: ','.
      ENDIF.

      CLEAR gs_calcf.
      gs_calcf-chanm = gs_pflds-fieldname.
      COLLECT gs_calcf INTO gt_calcf.

      write_field gs_pflds-fieldname.

      g_comma = 'X'.
    ENDLOOP.

    WRITE: ' }'.
    SKIP.

* Check fomula coding (translates it into tags)
    REFRESH gt_formla.
    LOOP AT gt_forml INTO gs_forml.
      CLEAR gs_formla.
      MOVE-CORRESPONDING gs_forml TO gs_formla.
      APPEND gs_formla TO gt_formla.
    ENDLOOP.

    CALL FUNCTION 'UPF_FORMULA_CHECK'
      EXPORTING
        i_area       = upf_planf-area
        i_plevel     = upf_planf-plevel
        it_forml     = gt_formla
        it_calcf     = gt_calcf
      IMPORTING
        et_cline     = gt_cline
        et_forml     = gt_formlb
      EXCEPTIONS
        syntax_error = 1
        OTHERS       = 2.
    IF sy-subrc = 0.
      g_error = rs_c_false.
    ELSE.
      g_error = rs_c_true.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO g_dummy.
      CONCATENATE g_dummy '(' sy-msgid sy-msgno ')' INTO g_dummy
        SEPARATED BY space.
    ENDIF.

*   For each parameter group...
    LOOP AT gt_pargd INTO gs_pargd.

*     Are there fields for conditions?
      CLEAR g_condt.
      READ TABLE gt_pflds TRANSPORTING NO FIELDS WITH KEY
        area   = gs_pargd-area
        plevel = gs_pargd-plevel
        method = gs_pargd-method
        pftyp  = '1'.
      IF sy-subrc = 0.
        g_condt = 'X'.
      ENDIF.

*     New parameter group?
      IF gs_pargd-area   <> gs_pargd2-area   OR
         gs_pargd-plevel <> gs_pargd2-plevel OR
         gs_pargd-method <> gs_pargd2-method OR
         gs_pargd-param  <> gs_pargd2-param.
        g_condi = 1.
        gs_pargd2 = gs_pargd.
      ELSE.
        g_condi = g_condi + 1.
      ENDIF.

      write_header 'Parameter group:' gs_pargd-param ''.

      IF g_condt = 'X'.
        write_header 'Condition Number:' g_condi ''.
      ENDIF.

*     Formula definition
      write_title 'Formula Definition:' '' ''.

      PERFORM fox_print_definition.

      IF g_error = rs_c_false.
        WRITE: AT /5 'Formula syntax checked successfully' COLOR COL_POSITIVE.
      ELSE.
        WRITE: AT /5 g_dummy COLOR COL_NEGATIVE.
        SKIP.

        IF sy-saprl >= '700'.
          g_function = 'RSPLSF_FORMULA_ERROR_POS'.
          CALL FUNCTION g_function
            IMPORTING
              e_error_pos  = g_error_pos
              e_error_line = g_error_line.

          MESSAGE i108(rsplf) WITH g_error_line g_error_pos INTO g_dummy.

          WRITE: AT /5 g_dummy COLOR COL_NEGATIVE.
        ENDIF.
      ENDIF.

      SKIP.

*     Statistics
      write_title 'Statistics:' '' ''.

      g_count = 0.
      LOOP AT gt_formla INTO gs_formla WHERE guid = gs_pargd-guid.
        g_count = g_count + 1.
      ENDLOOP.

      write_value 'Lines of FOX.........:' g_count.

*     ABAP-Program
      CONCATENATE gs_pargd-area   gs_pargd-plevel
                  gs_pargd-method gs_pargd-param
                  INTO g_semkey SEPARATED BY '-'.

      CALL FUNCTION 'UPC_GENREP_READ_CHECK_CATALOG'
        EXPORTING
          i_planarea   = gs_pargd-area
          i_applclass  = 'UPF'
          i_subclass   = '  '
          i_vern       = sy-saprl
          i_semkey     = g_semkey
        IMPORTING
          e_reportname = g_report
          e_hash       = g_hash
          e_generate   = g_generate.

*     Generate ABAP
      IF p_gen = rs_c_true AND g_error = rs_c_false.
        CALL FUNCTION 'UPF_PLAN_FUNC_GENERATE'
          EXPORTING
            i_area        = gs_pargd-area
            i_plevel      = gs_pargd-plevel
            i_method      = gs_pargd-method
            i_param       = gs_pargd-param
          IMPORTING
            e_genpr       = g_report
          EXCEPTIONS
            param_invalid = 0
            gen_error     = 0
            OTHERS        = 0.
      ENDIF.

      IF g_generate IS INITIAL AND NOT g_report IS INITIAL.
        write_hotspot 'ABAP Program.........:' g_report.
      ELSE.
        write_value 'ABAP Program.........:' '( needs to be generated )'.
      ENDIF.


      SKIP.
    ENDLOOP.

    ULINE.

  ENDLOOP.

  CLEAR g_report.

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

*&--------------------------------------------------------------------*
*&      Form  fox_print_definition
*&--------------------------------------------------------------------*
*       Write formula definition
*---------------------------------------------------------------------*
FORM fox_print_definition.

  DATA: l_line TYPE n LENGTH 5.

  REFRESH gt_ugly.
  LOOP AT gt_forml INTO gs_forml WHERE guid = gs_pargd-guid.
    gt_ugly-line = gs_forml-fline.
    REPLACE 'FOREACH' IN gt_ugly-line WITH 'FOR EACH'.
    APPEND gt_ugly.
  ENDLOOP.

  CALL FUNCTION 'PRETTY_PRINTER'
    EXPORTING
      inctoo             = space
    TABLES
      ntext              = gt_pretty[]
      otext              = gt_ugly[]
    EXCEPTIONS
      enqueue_table_full = 1
      include_enqueued   = 2
      include_readerror  = 3
      include_writeerror = 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.
    EXIT.
  ENDIF.

  l_line = 1.
  LOOP AT gt_pretty.
    REPLACE 'FOR EACH' IN gt_pretty-line WITH 'FOREACH'.
    WRITE: AT /5 l_line NO-GAP, ':', gt_pretty.
    ADD 1 TO l_line.
  ENDLOOP.

  SKIP.

ENDFORM.                    "fox_print_definition