Category Archive ABAP code

Use statement CLIENT SPECIFIED when mandant is specified in SELECT statement

If you want to add the mandant in your where clause (to force use of an index for instance), you have to add statement CLIENT SPECIFIED.


    SELECT * FROM table_name CLIENT SPECIFIED INTO TABLE gi_table_name
      FOR ALL ENTRIES IN li_table
      WHERE mandt     = sy-mandt                 " To force Index 001
        AND field1    = li_table-field1
        AND field1    = li_table-field2.

Display messages in popup


  CALL FUNCTION 'C14ALD_BAPIRET2_SHOW'
    TABLES
      I_BAPIRET2_TAB = T_RETURN_MESSAGE. " T_RETURN with type BAPIRET2_TAB

Add message in BAPIRET2 table


FORM add_message      USING pw_type TYPE sy-msgty
                            pw_id   TYPE sy-msgid
                            pw_num  TYPE sy-msgno
                            pw_v1   "TYPE sy-msgv1
                            pw_v2   "TYPE sy-msgv2
                            pw_v3   "TYPE sy-msgv3
                            pw_v4.  "TYPE sy-msgv4.

  DATA ls_bapiret2 TYPE bapiret2.

  ls_bapiret2-type       = pw_type .
  ls_bapiret2-id         = pw_id   .
  ls_bapiret2-number     = pw_num  .
  ls_bapiret2-message_v1 = pw_v1   .
  ls_bapiret2-message_v2 = pw_v2   .
  ls_bapiret2-message_v3 = pw_v3   .
  ls_bapiret2-message_v4 = pw_v4   .

  IF ls_bapiret2-type IS INITIAL.
    ls_bapiret2-type = 'S'.
  ENDIF.

  IF ls_bapiret2-id IS INITIAL.
    ls_bapiret2-id     = '0H'.
  ENDIF.

  IF ls_bapiret2-number IS INITIAL.
    ls_bapiret2-number = '000'.
  ENDIF.


  MESSAGE    ID ls_bapiret2-id
           TYPE ls_bapiret2-type
         NUMBER ls_bapiret2-number
           WITH ls_bapiret2-message_v1
                ls_bapiret2-message_v2
                ls_bapiret2-message_v3
                ls_bapiret2-message_v4
           INTO ls_bapiret2-message.

  APPEND ls_bapiret2 TO gi_user_message.

ENDFORM.

Display transport request (TR) informations in ABAP

Use FMs :

  • STRF_READ_COFILE
  • TR_READ_GLOBAL_INFO_OF_REQUEST

Search tag: TO, Transport order, ordre de transport, OT

Protected: Abap code to call filtered BADI in enhancement

This content is password protected. To view it please enter your password below:

Open popup window to choose a diretory

Use method : cl_gui_frontend_services=>directory_browse.

Read More

Write spool in color

Create spool to display it later in SP01, SP02…

With code below, you can easily add lines in spool like that :


    ls_text-color = c_color_jaune.
    CONCATENATE 'Error on PN' lw_matnr INTO ls_text-text SEPARATED BY space.
    APPEND ls_text TO gt_text.

    CLEAR ls_text.
    ls_text-color = c_color_rouge.
    APPEND ls_text TO gt_text.

Read More

Create an ALV with custom control

You can check the SAP demo programs starting with BCALV_GRID_*

Read More

Add day/month/year to a date in ABAP

Add days to date

You can simply add integer value if your variable is typed DATUM.


  DATA : lw_date  TYPE  sy-datum.
  lw_date = '20170927'.
  lw_processed_date = lw_date + 5.
* ==> lw_processed_date = 20171002

Read More