Category Archive ABAP code

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'

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

Generate a random number in ABAP

Use class CL_ABAP_RANDOM_INT to generate a random integer number :


DATA(lv_random_num) = cl_abap_random_int=>create( seed = cl_abap_random=>seed( )
                                                  min  = 1
                                                  max  = 100 )->get_next( ).
* lv_random_num will be type i

Read More

Create ALV with class CL_SALV_TABLE

Example of implementation in SE38 : SALV_DEMO_TABLE_SELECTIONS.

Simply display ALV table


  DATA : go_alv_table TYPE REF TO CL_SALV_TABLE.

  TRY.
      cl_salv_table=>factory(
        IMPORTING
          r_salv_table = go_alv_table
        CHANGING
          t_table      = gt_table_to_display ).
    CATCH cx_salv_msg.
  ENDTRY.

  " Optimize columns width
  DATA(lo_columns) = go_alv_table->get_columns( ).
  lo_columns->set_optimize( ).

  " Apply zebra style to lv_rows
  DATA(lo_display) = go_alv_table->get_display_settings( ).
  lo_display->set_striped_pattern( cl_salv_display_settings=>true ).

  " Display ALV
  go_alv_table->display( ).

Read More