Category Archive ABAP code

Table type for VTWEG field

This post just to save time, instead of doing where-used on VTWEG field…

Type table of VTWEG : TDT_VTWEG => line type VTWEG

Type table of VTWEG : TMS_T_VTWEG_RANGE => line type TABLE_LINE

Type range of VTWEG : RANGE_VTWEG_TAB
Warning, this uses structure in package not maintained, it generates ATC check errors, see note 2469385 ❗.

Search tag : type de table

Link check boxes and label in selection screen

You add a check box in your selection screen, want to display long text close to your check box (text longer than the standard selection text), use the synthax below, with FOR FIELD to link the added text to your check box :


SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS p_chkbx  TYPE abap_bool AS CHECKBOX DEFAULT abap_true.
SELECTION-SCREEN COMMENT 02(77) text-001 FOR FIELD p_chkbx.
SELECTION-SCREEN END OF LINE.

Read More

Popup to select a range of date

Use FM RSPC_POPUP_DATE_SELECTION :

Constants for range management

Instead of declaring constants in reports to manage ranges, save time and use attributes of interface IF_FSBP_CONST_RANGE :


IF_FSBP_CONST_RANGE=>OPTION_BETWEEN.              " Type DDOPTION    'BT'
IF_FSBP_CONST_RANGE=>OPTION_CONTAINS_PATTERN.     " Type DDOPTION    'CP'
IF_FSBP_CONST_RANGE=>OPTION_EQUAL.                " Type DDOPTION    'EQ'
IF_FSBP_CONST_RANGE=>OPTION_GREATER.              " Type DDOPTION    'GT'
IF_FSBP_CONST_RANGE=>OPTION_GREATER_EQUAL.        " Type DDOPTION    'GE'
IF_FSBP_CONST_RANGE=>OPTION_LESS.                 " Type DDOPTION    'LT'
IF_FSBP_CONST_RANGE=>OPTION_LESS_EQUAL.           " Type DDOPTION    'LE'
IF_FSBP_CONST_RANGE=>OPTION_NOT_BETWEEN.          " Type DDOPTION    'NB'
IF_FSBP_CONST_RANGE=>OPTION_NOT_CONTAINS_PATTERN. " Type DDOPTION    'NP'
IF_FSBP_CONST_RANGE=>OPTION_NOT_EQUAL.            " Type DDOPTION    'NE'
IF_FSBP_CONST_RANGE=>SIGN_EXCLUDE.                " Type DDSIGN      'E'
IF_FSBP_CONST_RANGE=>SIGN_INCLUDE.                " Type DDSIGN      'I'

Round number in ABAP

Use ceil( ) or floor( ) to round decimal to integer, respectively to upper or lower integer value.


  DATA(lv_upper_value) = ceil( '0.333' ). " ==> 1

  DATA(lv_lower_value) = floor( '1.66' ). " ==> 1

Use the round( ) method to have more possibilities :


  DATA : lv_percentage TYPE numc3.
  " [...]

  " In this case, the percentage calc is round to lower integer value :
  lv_percentage =  = CONV #( round( val  = lv_num / lv_total * 100
                                    dec  = 0
                                    mode = cl_abap_math=>round_down )  ).

You can specify in wich mode you want to round number with :

CL_ABAP_MATH=>ROUND_HALF_UP	|	Round away from zero if value is exactly half
CL_ABAP_MATH=>ROUND_HALF_DOWN	|	Round to zero if value is exactly half
CL_ABAP_MATH=>ROUND_HALF_EVEN	|	Round so last digit is an even no. if value is exactly half
CL_ABAP_MATH=>ROUND_UP		|	Round away from zero
CL_ABAP_MATH=>ROUND_DOWN	|	Round to Zero
CL_ABAP_MATH=>ROUND_CEILING	|	Round to Positive Infinity
CL_ABAP_MATH=>ROUND_FLOOR	|	Round to Negative Infinity

Search tag : arrondi, arrondir, entier, valeur supérieure, inférieure

Quicky manage SLG1 messages in ABAP

This post provides methods or macro for logging SLG1 message.
It is shortcuts for calling standard methods :
– BAL_LOG_CREATE
– BAL_LOG_MSG_ADD
– BAL_DB_SAVE

Read More

Template for ABAP local ALV event class

Local ALV event class template (to be completed with missing events) :

Read More

Adobe form: set field color dynamically with javascript

To specify with javascript the color for a text field in adobe form, use the code below.


// data.MAIN.SUBFORM.FIELD_TO_CHANGE_COLOR::initialize - (JavaScript, client)
this.font.fill.color.value = "255,0,0"; // Color Red in RGB Color

The color has to be specified in 🔗 RGB format.

Read More

Reverse sorting of an internal table

Use method CL_RS_DATA=>SWITCH_ORDER( ) :


  cl_rs_data=>switch_order( CHANGING c_t_data = lt_my_table ).

Technically, the method loops on table entries and insert each of them with INDEX 1.

Read More