Skip to Content
Technical Articles

Get All Your BW Customer-Exit Variables with One ABAP Statement

How BW Customer-Exit Variables are programmed? Usually it is a bunch of nested CASE, IF statements and lots I_T_VAR_RANGE parameter APPEND statements / assignments. Why you need to have tons of I_T_VAR_RANGE parameter APPEND / assignments all over your program code?

In my sample code below I assign I_T_VAR_RANGE parameter only once and code all logic in nested COND statements

METHOD if_rsroa_variables_exit_badi~process.

  TRY.
    c_t_range = COND #( WHEN i_iobjnm = '1TEXT' AND LINES( c_t_range ) > 0 THEN c_t_range
                        WHEN i_step = 1
                        THEN COND #( WHEN i_vnam = 'AR_FY'
                                     THEN VALUE #( ( sign = 'I'
                                                     opt  = 'EQ'
                                                     low  = COND #( WHEN sy-datum+4(2) BETWEEN '01' AND '03' THEN CONV num4( sy-datum+0(4) - 1 )
                                                                    ELSE sy-datum+0(4) ) ) )
                                     WHEN i_vnam = 'AR_CLERK_HIER'
                                     THEN VALUE #( ( sign = 'I'
                                                     opt  = 'EQ'
                                                     low  = 'PCI' ) ) )
                       WHEN i_step = 2
                       THEN COND #( WHEN i_vnam = 'AR_CLERK'
                                    THEN get_ar_clerk( i_t_var_range )
                                    WHEN i_vnam = 'AR_PSTNG' OR i_vnam = 'AR_DUE'
                                    THEN VALUE #( ( sign = 'I'
                                                    opt  = 'EQ'
                                                    low  = |{ i_t_var_range[ vnam = 'AR_FY' ]-low+0(4) }04| ) )
                                    WHEN i_vnam CP 'AR_CLEAR_0_++'
                                    THEN VALUE #( ( sign = 'I'
                                                    opt  = 'EQ'
                                                    low  =  COND dats( WHEN i_vnam+11(2) BETWEEN '00' AND '09' THEN |{ i_t_var_range[ vnam = 'AR_FY' ]-low+0(4) - 1 }{ CONV num2( i_vnam+11(2) + 3 ) }01|
                                                                       WHEN i_vnam+11(2) BETWEEN '10' AND '13' THEN |{ i_t_var_range[ vnam = 'AR_FY' ]-low+0(4) }{ CONV num2( i_vnam+11(2) - 9 ) }01| ) ) )
*                                                                       WHEN i_vnam+11(2) = '12' THEN || ) ) )
                                    WHEN i_vnam CP 'AR_CLEAR_1_++'
                                    THEN VALUE #( ( sign = 'I'
                                                    opt  = 'EQ'
                                                    low  =  COND dats( WHEN i_vnam+11(2) BETWEEN '00' AND '09' THEN |{ i_t_var_range[ vnam = 'AR_FY' ]-low+0(4) }{ CONV num2( i_vnam+11(2) + 3 ) }01|
                                                                       WHEN i_vnam+11(2) BETWEEN '10' AND '13' THEN |{ i_t_var_range[ vnam = 'AR_FY' ]-low+0(4) + 1 }{ CONV num2( i_vnam+11(2) - 9 ) }01| ) ) )
                                    WHEN i_vnam CP 'AR_DUE_0_++++++++'
                                    THEN VALUE #( ( sign = 'I'
                                                    opt  = 'BT'
                                                    low  = COND dats( WHEN i_vnam+14(3) = '999' THEN '00010101'
                                                                      ELSE CONV dats( COND d( WHEN i_vnam+9(2) BETWEEN '09' AND '12' THEN |{ i_t_var_range[ vnam = 'AR_FY' ]-low+0(4) }{ CONV num2( i_vnam+9(2) - 8 ) }01|
                                                                                      WHEN i_vnam+9(2) BETWEEN '00' AND '08' THEN |{ i_t_var_range[ vnam = 'AR_FY' ]-low+0(4) - 1 }{ CONV num2( i_vnam+9(2) + 4 ) }01| ) - i_vnam+14(3) ) )
                                                    high = CONV dats( COND d( WHEN i_vnam+9(2) BETWEEN '09' AND '12' THEN |{ i_t_var_range[ vnam = 'AR_FY' ]-low+0(4) }{ CONV num2( i_vnam+9(2) - 8 ) }01|
                                                                      WHEN i_vnam+9(2) BETWEEN '00' AND '08' THEN |{ i_t_var_range[ vnam = 'AR_FY' ]-low+0(4) - 1 }{ CONV num2( i_vnam+9(2) + 4 ) }01| ) - i_vnam+11(3) ) ) )
                                    WHEN i_vnam CP 'AR_DUE_1_++++++++'
                                    THEN VALUE #( ( sign = 'I'
                                                    opt  = 'BT'
                                                    low  = COND dats( WHEN i_vnam+14(3) = '999' THEN '00010101'
                                                                      ELSE CONV dats( COND d( WHEN i_vnam+9(2) BETWEEN '09' AND '12' THEN |{ i_t_var_range[ vnam = 'AR_FY' ]-low+0(4) + 1 }{ CONV num2( i_vnam+9(2) - 8 ) }01|
                                                                                      WHEN i_vnam+9(2) BETWEEN '00' AND '08' THEN |{ i_t_var_range[ vnam = 'AR_FY' ]-low+0(4) }{ CONV num2( i_vnam+9(2) + 4 ) }01| ) - i_vnam+14(3) ) )
                                                    high = CONV dats( COND d( WHEN i_vnam+9(2) BETWEEN '09' AND '12' THEN |{ i_t_var_range[ vnam = 'AR_FY' ]-low+0(4) + 1 }{ CONV num2( i_vnam+9(2) - 8 ) }01|
                                                                      WHEN i_vnam+9(2) BETWEEN '00' AND '08' THEN |{ i_t_var_range[ vnam = 'AR_FY' ]-low+0(4) }{ CONV num2( i_vnam+9(2) + 4 ) }01| ) - i_vnam+11(3) ) ) )
                                    WHEN i_vnam CP 'AR_MON_++'
                                    THEN VALUE #( ( sign = 'I'
                                                    opt  = 'EQ'
                                                    low =  |{ COND text( WHEN i_vnam+7(2) = '00' THEN 'Mar'
                                                                         WHEN i_vnam+7(2) = '01' THEN 'Apr'
                                                                         WHEN i_vnam+7(2) = '02' THEN 'May'
                                                                         WHEN i_vnam+7(2) = '03' THEN 'Jun'
                                                                         WHEN i_vnam+7(2) = '04' THEN 'Jul'
                                                                         WHEN i_vnam+7(2) = '05' THEN 'Aug'
                                                                         WHEN i_vnam+7(2) = '06' THEN 'Sep'
                                                                         WHEN i_vnam+7(2) = '07' THEN 'Oct'
                                                                         WHEN i_vnam+7(2) = '08' THEN 'Nov'
                                                                         WHEN i_vnam+7(2) = '09' THEN 'Dec'
                                                                         WHEN i_vnam+7(2) = '10' THEN 'Jan'
                                                                         WHEN i_vnam+7(2) = '11' THEN 'Feb'
                                                                         WHEN i_vnam+7(2) = '12' THEN 'Mar' ) } {
                                                              COND text( WHEN i_vnam+7(2) BETWEEN '00' AND '09' THEN |{ i_t_var_range[ vnam = 'AR_FY' ]-low }|
                                                                         ELSE |{ i_t_var_range[ vnam = 'AR_FY' ]-low + 1 }| ) }| ) ) ) ).
  CATCH cx_sy_itab_line_not_found.
  ENDTRY.


ENDMETHOD.


METHOD get_ar_clerk.

  ...
  TRY.
    ...
       APPEND VALUE #( sign = 'I'
                       opt  = 'EQ'
                       low  = wa_hier-0accntclrk ) TO rt_range.
    ENDLOOP.
  CATCH cx_sy_itab_line_not_found.
  ENDTRY.

ENDMETHOD.

Disclaimer: your ultimate goal is to make BW Customer-Exit Variable code more readable and maintainable. Getting all your BW Customer-exit Variables in one statement is secondary. Do not overdo with new ABAP expression syntax, but rather wrap complex logic into functional method (see get_ar_clerk for example).

4 Comments
You must be Logged on to comment or reply to a post.
  • Hi Uladzislau,

     

    Nice Blog.

     

    one question, i believe while creating customer exists using BADI, filter value is mandatory.

    so if you are embedding all variable code in one place, what you are using as your filter?

     

    Thanks.

    • Hi Akash,

      using InfoObject filter with BW Variable BADI is optional, but highly recommend. I have multiple BW Variable BADI implementations (common variables and per specific application area) and limit a scope of each implementation using InfoObject filter.

      Regards, Uladzislau

  • Hi Mr. Uladzislau,

     

    If you said that ” your ultimate goal is to make BW Customer-Exit Variable code more readable and maintainable”.

    Why don’t’ you use a table as a tool to replace case or if statement more readable?

     

    Regards,

    Hendra Mahadina