BPC Script Logic: Samples & References

[LOGIC1.LGF]

*WHEN P_ACCT
*IS "KPI1"
*REC(FACTOR=2,P_ACCT="KPI5")
*ENDWHEN
*COMMIT

[LOGIC2.LGF]

*WHEN P_ACCT
*IS KPI1, KPI2
*REC(FACTOR=1.5,P_ACCT="KPI5")
*ENDWHEN
*COMMIT

[LOGIC3.LGF]

WHEN P_ACCT.SELECTION
*IS B
*REC(FACTOR=3,P_ACCT="KPI5")
*ENDWHEN
*COMMIT

[LOGIC4.LGF]

*WHEN P_ACCT.SELECTION
*IS B
*REC(EXPRESSION=%VALUE%*3,P_ACCT="KPI5")
*ENDWHEN
*COMMIT

[LOGIC5.LGF]

*WHEN P_ACCT.SELECTION
*IS B
*REC(EXPRESSION=%VALUE%/[P_ACCT].[KPI1],P_ACCT="KPI5")
*ENDWHEN
*COMMIT

[LOGIC6.LGF]

*XDIM_MEMBERSET P_ACCT=KPI1,KPI2

*WHEN P_ACCT
*IS KPI1, KPI2
*REC(FACTOR=1.5,P_ACCT="KPI5")
*ENDWHEN
*COMMIT

[LOGIC7.LGF]

*XDIM_MEMBERSET TIME=2011.001,2011.002
*XDIM_MEMBERSET P_ACCT = KPI1

*WHEN P_ACCT
*IS *
*WHEN TIME
*IS "2011.001"

*FOR %KPI% = KPI1, KPI2, KPI3, KPI4, KPI5

*REC(EXPRESSION=%VALUE%+([P_ACCT].[%KPI%],[TIME].[2011.002]),CATEGORY=FLASH,P_ACCT=%KPI%,TIME=2011.003)
*NEXT
*ENDWHEN
*ENDWHEN
*COMMIT

[LOGIC8.LGF]

*XDIM_MEMBERSET TIME=2011.001
*XDIM_MEMBERSET CATEGORY=FLASH
*XDIM_MEMBERSET ENTITY=STORE17
*XDIM_MEMBERSET INPUTCURRENCY=EUR
*XDIM_MEMBERSET PRODUCT2=DOGDRYPUPPY
*XDIM_FILTER P_ACCT = [P_ACCT].properties("SELECTION") = "B"

*WHEN P_ACCT
*IS *

*REC(EXPRESSION=200)
*ENDWHEN
*COMMIT

[LOGIC9.LGF]

*XDIM_MEMBERSET TIME=2011.001
*XDIM_MEMBERSET CATEGORY=FLASH
*XDIM_MEMBERSET ENTITY=STORE17
*XDIM_MEMBERSET INPUTCURRENCY=EUR
*XDIM_MEMBERSET PRODUCT2=DOGDRYPUPPY

*SELECT(%SELVAR%, "[ID]",P_ACCT,"SELECTION" = "B")
*XDIM_MEMBERSET P_ACCT = %SELVAR%

*WHEN CATEGORY
*IS "FLASH"
*REC(FACTOR=1.1,TIME="2011.002")
*ENDWHEN
*COMMIT

*XDIM_MEMBERSET TIME=2011.001,2011.002
*XDIM_MEMBERSET P_ACCT = KPI1

*WHEN P_ACCT
*IS *
*WHEN TIME
*IS "2011.001"

*FOR %KPI% = %SELVAR%

*REC(EXPRESSION=%VALUE%+([P_ACCT].[%KPI%],[TIME].[2011.002]),CATEGORY=FLASH,P_ACCT=%KPI%,TIME=2011.003)
*NEXT
*ENDWHEN
*ENDWHEN
*COMMIT

[LOGIC10.LGF]

*XDIM_MEMBERSET TIME=2011.001,2011.002
*XDIM_MEMBERSET CATEGORY=FLASH
*XDIM_MEMBERSET ENTITY=STORE17
*XDIM_MEMBERSET INPUTCURRENCY=EUR
*XDIM_MEMBERSET PRODUCT2=DOGDRYPUPPY

*SELECTCASE [P_ACCT].CURRENTMEMBER.PROPERTIES("SELECTION")

*CASE "B"
[TIME].[#2011.002] = [TIME].[2011.001]+[TIME].[2011.002]

*CASE "C"
[TIME].[#2011.003] = [TIME].[2011.001]+[TIME].[2011.002]

*ENDSELECT

[LOGIC11.LGF]

*XDIM_MEMBERSET TIME=2011.001,2011.002
*XDIM_MEMBERSET CATEGORY=FLASH
*XDIM_MEMBERSET ENTITY=STORE17
*XDIM_MEMBERSET INPUTCURRENCY=EUR
*XDIM_MEMBERSET PRODUCT2=DOGDRYPUPPY

*ADD %ACC%=[KPI1],[KPI2],[KPI3],[KPI4]

[#KPI5]= %ACC%/[KPI1]

*ENDADD
*COMMIT

[LOGIC12.LGF]

*XDIM_MEMBERSET CATEGORY=FLASH
*XDIM_MEMBERSET ENTITY=STORE17
*XDIM_MEMBERSET INPUTCURRENCY=EUR
*XDIM_MEMBERSET PRODUCT2=DOGDRYPUPPY
*XDIM_MEMBERSET P_ACCT= BAS(KPI_NODE)
*XDIM_MEMBERSET TIME= TMVL(-1,2011.002),2011.002

*WHEN CATEGORY
*IS "FLASH"

*WHEN TIME
*IS TMVL(-1,2011.002)

*REC(EXPRESSION=%VALUE%+[TIME].[2011.002],TIME=TMVL(1,2011.002))

*ENDWHEN
*ENDWHEN

*COMMIT

[LOGIC13.LGF]

*XDIM_MEMBERSET CATEGORY=FLASH
*XDIM_MEMBERSET ENTITY=STORE17
*XDIM_MEMBERSET INPUTCURRENCY=EUR
*XDIM_MEMBERSET PRODUCT2=DOGDRYPUPPY
*XDIM_MEMBERSET P_ACCT= BAS(KPI_NODE)
*XDIM_MEMBERSET TIME= 2011.001

*WHEN CATEGORY
*IS "FLASH"

*REC(FACTOR=1.1, TIME=TMVL(2,2011.001))

*ENDWHEN

*COMMIT

[LOGIC14.LGF]

*XDIM_MEMBERSET CATEGORY=FLASH
*XDIM_MEMBERSET ENTITY=STORE17
*XDIM_MEMBERSET INPUTCURRENCY=EUR
*XDIM_MEMBERSET PRODUCT2=DOGDRYPUPPY
*XDIM_MEMBERSET P_ACCT= BAS(KPI_NODE)
*XDIM_MEMBERSET TIME= %TIME_SET%

*WHEN CATEGORY
*IS FLASH

*WHEN TIME
*IS %TIME_SET%

*REC(EXPRESSION=%VALUE%*2)

*ENDWHEN
*ENDWHEN

*COMMIT

[LOGIC15.LGF] – $[VAR]$ – Passing parameter from script logic package

*XDIM_MEMBERSET CATEGORY=FLASH
*XDIM_MEMBERSET ENTITY=STORE17
*XDIM_MEMBERSET P_ACCT= BAS(KPI_NODE)
*XDIM_MEMBERSET PRODUCT2=DOGDRYPUPPY
*XDIM_MEMBERSET INPUTCURRENCY=EUR
*XDIM_MEMBERSET TIME= 2011.001

[P_ACCT].[#KPI1]=[P_ACCT].[KPI1]*(1+$VAR_KPI1$/100)
[P_ACCT].[#KPI2]=[P_ACCT].[KPI2]*(1+$VAR_KPI2$/100)
[P_ACCT].[#KPI3]=[P_ACCT].[KPI3]*(1+$VAR_KPI3$/100)
[P_ACCT].[#KPI4]=[P_ACCT].[KPI4]*(1+$VAR_KPI4$/100)
[P_ACCT].[#KPI5]=[P_ACCT].[KPI5]*(1+$VAR_KPI5$/100)

[Macro to run package to execute script logic]

Application.Run "MNU_eData_SELECTPACKAGE", "PACKAGE TO EXECUTE SCRIPT LOGIC", "/CPMB/ICDATA", "", "STUDENT"

[Allocation Parameter – To execute  script logic from package]

PROMPT(SELECTINPUT,,,,"%CATEGORY_DIM%,%CURRENCY_DIM%,%ENTITY_DIM%,%ACCOUNT_DIM%,PRODUCT2,%TIME_DIM%")

TASK(/CPMB/ALLOCATION_LOGIC,SUSER,%USER%)
TASK(/CPMB/ALLOCATION_LOGIC,SAPPSET,%APPSET%)
TASK(/CPMB/ALLOCATION_LOGIC,SAPP,%APP%)
TASK(/CPMB/ALLOCATION_LOGIC,LOGICFILENAME,ALLOCATION.LGF)

[Allocation Script Logic]

*XDIM_MEMBERSET               P_ACCT=BAS(ALLOCATION_NODE)
*XDIM_MEMBERSET               ENTITY=BAS(NODE_ALLOCATION)

*RUNALLOCATION
*FACTOR=USING/TOTAL

*DIM ENTITY            WHAT=BAS(NODE_SENDER);   WHERE=BAS(NODE_RECEIVER);  USING= <<<;            TOTAL= <<<;
*DIM P_ACCT            WHAT=ORIGINAL_ACCOUNT;   WHERE= <<<;                USING=ALLOC_KEY_SQM;   TOTAL= <<<;
*DIM CATEGORY          WHAT=FORECAST;           WHERE= <<<;                USING= <<<;            TOTAL= <<<;
*DIM PRODUCT2          WHAT=NONE;               WHERE= <<<;                USING= <<<;            TOTAL= <<<;
*DIM INPUTCURRENCY     WHAT=EUR;                WHERE= <<<;                USING= <<<;            TOTAL= <<<;

*ENDALLOCATION
*COMMIT

[Dynamic script package prompt] – Refer to LOGIC15.LGF above

PROMPT(SELECTINPUT,,,,"%ENTITY_DIM%,%CATEGORY_DIM%,%CURRENCY_DIM%,%ACCOUNT_DIM%,PRODUCT2,%TIME_DIM%")

PROMPT(TEXT,%VAR_KPI1%,"INPUT VARIABLE VALUE FOR KPI1 AS ABSOLUTE VALUE",)
PROMPT(TEXT,%VAR_KPI2%,"INPUT VARIABLE VALUE FOR KPI2 AS ABSOLUTE VALUE",)
PROMPT(TEXT,%VAR_KPI3%,"INPUT VARIABLE VALUE FOR KPI3 AS ABSOLUTE VALUE",)
PROMPT(TEXT,%VAR_KPI4%,"INPUT VARIABLE VALUE FOR KPI4 AS ABSOLUTE VALUE",)
PROMPT(TEXT,%VAR_KPI5%,"INPUT VARIABLE VALUE FOR KPI5 AS ABSOLUTE VALUE",)

INFO(%EQU%,=)
INFO(%TAB%,:)

TASK(/CPMB/ICDATA_LOGIC,TAB,%TAB%)
TASK(/CPMB/ICDATA_LOGIC,EQU,%EQU%)
TASK(/CPMB/ICDATA_LOGIC,SUSER,%USER%)
TASK(/CPMB/ICDATA_LOGIC,SAPPSET,%APPSET%)
TASK(/CPMB/ICDATA_LOGIC,SAPP,%APP%)
TASK(/CPMB/ICDATA_LOGIC,SELECTION,%SELECTION%)
TASK(/CPMB/ICDATA_LOGIC,LOGICFILENAME,LOGIC_15.LGF)
TASK(/CPMB/ICDATA_LOGIC,REPLACEPARAM,VAR_KPI1%EQU%%VAR_KPI1%%TAB%VAR_KPI2%EQU%%VAR_KPI2%%TAB%VAR_KPI3%EQU%%VAR_KPI3%
%TAB%VAR_KPI4%EQU%%VAR_KPI4%%TAB%VAR_KPI5%EQU%%VAR_KPI5%)

[Dynamic script with file variable]

PROMPT(SELECTINPUT,,,,"%ENTITY_DIM%,%ACCOUNT_DIM%,%CATEGORY_DIM%,%CURRENCY_DIM%,PRODUCT2,%TIME_DIM%")

PROMPT(TEXT,%FILE_NAME%,"INPUT FILE NAME")

TASK(/CPMB/ICDATA_LOGIC,SUSER,%USER%)
TASK(/CPMB/ICDATA_LOGIC,SAPPSET,%APPSET%)
TASK(/CPMB/ICDATA_LOGIC,SAPP,%APP%)
TASK(/CPMB/ICDATA_LOGIC,SELECTION,%SELECTION%)
TASK(/CPMB/ICDATA_LOGIC,LOGICFILENAME,%FILE_NAME%)

[Function definition]

*FUNCTION QUANTITY = CE0008000
*FUNCTION PRICE = CE0008500
*FUNCTION REVENUE = CE0002100
*FUNCTION ACCOUNT = P_ACCT

*FUNCTION CALCREV(%QUANTITY%,%PRICE%)

%QUANTITY%*%PRICE%

*ENDFUNCTION

[BADI Code ABAP Script Logic]

method IF_UJ_CUSTOM_LOGIC~EXECUTE.
BREAK-POINT.

TYPES: BEGIN OF tbldimension ,
  Measures(20),
  Product(20),
  category(20),
  entity(20),
  p_acct(20),
  rptcurrency(20),
  time(20),
  signeddata TYPE p LENGTH 11 DECIMALS 7,
  END OF tbldimension.

  DATA:
        field1          TYPE fieldname value ‘p_acct’,
        field2          TYPE fieldname value ‘entity’,
        field3          TYPE fieldname value ‘time’,
        t_data          TYPE TABLE OF tbldimension,
        l_data          TYPE tbldimension,
        l_acct          TYPE string,
        l_entity        TYPE string,
        l_time          TYPE string,
        res1            TYPE p LENGTH 11 DECIMALS 7,
        res2            TYPE p LENGTH 11 DECIMALS 7,
        res3            TYPE p LENGTH 11 DECIMALS 7,
        res             TYPE p LENGTH 11 DECIMALS 7.

*  FIELD-SYMBOLS:
*                <data> TYPE any,
*                <ct_data> TYPE standard table.
  FIELD-SYMBOLS:
                <data> TYPE tbldimension,
                <ct_data> TYPE ANY.
*CREATE DATA t_data LIKE CT_DATA.
*Assign t_data->* to <ct_data>.
*
*Create data l_data like line of ct_data.
*Assign l_data->* to <data>.

 

  DEFINE get_.
    read table t_data assigning <data>
    with key p_acct      = &2
             entity       = l_entity
             time         = l_time.
    if sy-subrc = 0.
      &1 = <data>-signeddata.
    else.
      &1 = 0.
    endif.
  END-OF-DEFINITION.

  DEFINE put_.
    read table ct_data assigning <ct_data>
    with key (field1) = &2
             (field2) = l_entity
             (field3) = l_time.

    if sy-subrc = 0.
      move-corresponding <ct_data> to l_data.
      l_data-signeddata = &1.
      move-corresponding l_data to <ct_data>.
    else.
        read table ct_data assigning <ct_data> index 1.
        append <ct_data> to ct_data.
        move-corresponding <ct_data> to l_data.
        l_data-P_acct = ‘CE0004520’.
        l_data-entity = l_entity.
        l_data-time = l_time.
        l_data-signeddata = &1.
        move-corresponding l_data to <ct_data>.
    endif.

  END-OF-DEFINITION.

  CLEAR t_data.
  LOOP AT ct_data ASSIGNING <ct_data>.
    MOVE-CORRESPONDING <ct_data> TO l_data.
    APPEND l_data TO t_data.
  ENDLOOP.
  SORT t_data BY p_acct entity time.

  LOOP AT t_data INTO l_data.
    l_entity = l_data-entity.
    l_time = l_data-time.

    CASE l_data-P_acct.
      WHEN ‘CE0004010’.
*REC(EXPRESSION=(GET(ACCOUNT="CA_0008")*GET(ACCOUNT="CA_0012")*GET(ACCOUNT="CA_0015")), ACCOUNT="CA_0029a")
       get_ res1 ‘CE0004010’.
       get_ res2 ‘CE0004020’.
     res = res1 + res2.
       put_ res ‘CE0004520’.
    ENDCASE.

  ENDLOOP.

endmethod.

[BADI Code Start Routine]

method IF_UJD_ROUTINE~RUNROUTINE.
BREAK-POINT.

*————————————————-
*FORMAT1
*————————————————-
*FIELD-SYMBOLS:
*               <lt_err> TYPE STANDARD TABLE,
*               <ls_data> TYPE any.
*
*CREATE DATA er_error_data LIKE ct_data.
*ASSIGN er_error_data->* to <lt_err>.
*
* LOOP AT ct_data ASSIGNING <ls_data>.
*  APPEND <ls_data>  TO <lt_err>.
*endloop.
*————————————————-
*FORMAT2
*————————————————-

FIELD-SYMBOLS:
                 <lt_err> TYPE STANDARD TABLE,
                 <ls_data> TYPE any,
                 <l_line> type string.

  FIELD-SYMBOLS: <ls_err_data> TYPE any,
                 <lt_err_data> TYPE  any,
                 <l_amount> TYPE ANY,
                 <l_P_ACCT> TYPE ANY,
                 <l_INPUTCURRENCY> TYPE ANY,
                 <l_TIME> TYPE ANY,
                 <l_CATEGORY> TYPE ANY,
                 <l_INTCOL> TYPE ANY,
                 <l_ENTITY> TYPE ANY,
                 <l_PRODUCT2> TYPE ANY.

  DATA:          l_AMOUNT(30) TYPE c,
                 l_P_ACCT(30) TYPE c,
                 l_INPUTCURRENCY(30) TYPE c,
                 l_TIME(30) TYPE c,
                 l_CATEGORY(30) TYPE c,
                 l_INTCOL(30) TYPE c,
                 l_ENTITY(30) TYPE c,
                 l_PRODUCT2(30) TYPE c.

  DATA: BEGIN OF data_struc1,
            CATEGORY(30)    TYPE c,
            ENTITY(30)    TYPE c,
            INPUTCURRENCY(30)    TYPE c,
            TIME(30)    TYPE c,
            AMOUNT(30)    TYPE c,
            PRODUCT2(30)    TYPE c,
            P_ACCT(30)    TYPE c,
        END OF data_struc1.

  DATA: BEGIN OF data_struc2,
           CATEGORY(30)    TYPE c,
           ENTITY(30)    TYPE c,
           INPUTCURRENCY(30)    TYPE c,
           TIME(30)    TYPE c,
           SIGNEDDATA(30)    TYPE c,
           PRODUCT2(30)    TYPE c,
           P_ACCT(30)    TYPE c,
       END OF data_struc2.
  data l_amount_i type i.
  data l_tabix like sy-tabix .
  Data: ls_message_err type line of UJ0_T_Message.
  Data: ls_message type line of UJ0_T_Message.
  data: l_mode type c.

  data: BEGIN OF data_index_struc,
    tabix type i,
    END OF data_index_struc.
  data data_index_table like table of data_index_struc.

  FIELD-SYMBOLS:  <lt_data> TYPE STANDARD TABLE,
       <lv_p_acct> TYPE any,
       <lv_signeddata> type any,
       <lv_curr> type any.

  er_data = ir_data.

  ASSIGN er_data->* to <lt_data>.
  read table <lt_data> index 1 ASSIGNING <ls_data>.

  assign COMPONENT ‘LINE’ of STRUCTURE <ls_data> to <L_line>.
  if sy-subrc = 0.
    l_mode = ‘1’.
    CREATE DATA er_error_data LIKE TABLE OF data_struc1.
  else.
    l_mode = ‘2’.
    CREATE DATA er_error_data LIKE TABLE OF data_struc2.
  endif.
  ASSIGN er_error_data->* to <lt_err>.

  LOOP AT <lt_data> ASSIGNING <ls_data>.

    assign COMPONENT ‘LINE’ of STRUCTURE <ls_data> to <L_line>.

    if l_mode = ‘1’.

*      split <L_line> at ‘,’ into l_CATEGORY l_ENTITY l_INPUTCURRENCY l_TIME l_amount l_PRODUCT2 l_P_ACCT.
      split <l_line> at ‘,’ into l_CATEGORY l_ENTITY l_INPUTCURRENCY l_TIME l_P_ACCT l_PRODUCT2 l_amount.
    else.

       assign COMPONENT ‘CATEGORY’ of STRUCTURE <ls_data> to <l_CATEGORY>.
      l_CATEGORY = <l_CATEGORY>.
      assign COMPONENT ‘ENTITY’ of STRUCTURE <ls_data> to <l_ENTITY>.
      l_ENTITY = <l_ENTITY>.
      assign COMPONENT ‘INPUTCURRENCY’ of STRUCTURE <ls_data> to <l_INPUTCURRENCY>.
      l_INPUTCURRENCY = <l_INPUTCURRENCY>.
      assign COMPONENT ‘TIME’ of STRUCTURE <ls_data> to <l_TIME>.
      l_TIME = <l_TIME>.
      assign COMPONENT ‘SIGNEDDATA’ of STRUCTURE <ls_data> to <l_amount>.
      l_amount = <l_amount>.
      assign COMPONENT ‘PRODUCT2’ of STRUCTURE <ls_data> to <l_PRODUCT2>.
      l_PRODUCT2 = <l_PRODUCT2>.
      assign COMPONENT ‘P_ACCT’ of STRUCTURE <ls_data> to <l_P_ACCT>.
      l_P_ACCT = <l_P_ACCT>.
    endif.

 

    if l_amount <> ‘AMOUNT’ and l_amount <> ‘SIGNEDDATA’. "not a header
      l_amount_i = l_amount.
      if l_amount_i > 2000.
*————————————————-
*Fill rejrct data
*————————————————-
*        l_tabix = sy-tabix.
        data_index_struc-tabix = sy-tabix.
        append data_index_struc to data_index_table .
        if l_mode = ‘1’.
          data_struc1-CATEGORY = l_CATEGORY.
          data_struc1-ENTITY = l_ENTITY .
          data_struc1-INPUTCURRENCY = l_INPUTCURRENCY.
          data_struc1-TIME = l_TIME.
          data_struc1-amount = l_amount.
          data_struc1-PRODUCT2 = l_PRODUCT2.
          data_struc1-P_ACCT = l_P_ACCT.
          APPEND data_struc1  TO <lt_err>.
        else.
          data_struc2-CATEGORY = l_CATEGORY.
          data_struc2-ENTITY = l_ENTITY .
          data_struc2-INPUTCURRENCY = l_INPUTCURRENCY.
          data_struc2-TIME = l_TIME.
          data_struc2-SIGNEDDATA = l_amount.
          data_struc2-PRODUCT2 = l_PRODUCT2.
          data_struc2-P_ACCT = l_P_ACCT.
          APPEND data_struc2  TO <lt_err>.
        endif.
*————————————————-
*Fill rejrct error reason
*————————————————-
        ls_message_err-MSGID = ‘ZDAVY’.
        ls_message_err-MSGTY = ‘E’.
        ls_message_err-MSGNO = ‘001’.
        ls_message_err-MSGV1 = l_amount.
        ls_message_err-RECNO = data_index_struc-tabix.
        Append ls_message_err to ET_error_reason.

      endif.
    endif.

  endloop.

  sort data_index_table by tabix DESCENDING.

  loop at data_index_table into data_index_struc.
    delete <lt_data> index data_index_struc-tabix.
  endloop.

  if data_index_table is not initial.

*————————————————-
*Fill general error message
*————————————————-
    ls_message-MSGID = ‘ZDAVY’.
    ls_message-MSGTY = ‘E’.
    ls_message-MSGNO = ‘000’.
    ls_message-MSGV1 = l_tabix.
    ls_message-MSGV1 = ‘ At least one of data row is rejected!’.
    Append ls_message to ET_Message.
  endif.
  ENDMETHOD.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s