Category Archive ABAP code

Simply display internal table into ALV grid

To display content of internal table into ALV grid, use this method :


  DATA : lo_table     TYPE REF TO cl_salv_table.

* Create ALV
  TRY.
      cl_salv_table=>factory(
        IMPORTING
          r_salv_table = lo_table
        CHANGING
          t_table      = gi_data_to_display ).
    CATCH cx_salv_msg.
  ENDTRY.

* Display ALV grid
  lo_table->display( ).

Example of use in SAP demo program : SALV_DEMO_TABLE_REAL_SIMPLE.

Read More

Add leading ZERO with ABAP


DATA : lw_char10 TYPE char10,
       lw_vbeln  TYPE vbeln.

lw_char10 = '300841'.

UNPACK lw_char10 TO lw_vbeln.  " ==> LW_VBELN = 0000300841

Read More

Delete leading ZERO with ABAP


SHIFT lw_char LEFT DELETING LEADING '0'.

Several synthax below to do the same thing :
(Notice that you have to work with a field type CHAR to remove the ZERO, will not work with a NUMC variable)

Read More

Write selections parameter in spool of report


  DATA : li_tab TYPE TABLE OF trdir-name,
         infotab TYPE t_varinfo OCCURS 0 WITH HEADER LINE.

  CALL FUNCTION 'PRINT_SELECTIONS'
    EXPORTING
      mode      = li_tab
      rname     = sy-repid   "program name
      rvariante = ''         "variant name
    TABLES
      infotab   = infotab.

  LOOP AT infotab.
    WRITE / infotab-line.
  ENDLOOP.

My Selection-screen macros for reports

Macros that I’m using for formatting reports quicker.

Theses are declared in the TOP of report.

Read More

READ TEXT – Code for mass extract

When needed to perform standart text mass retrieve, you can use the following code :
Read More

Submit a program and write its report in your program

This post explain how to call another report in your report and how to print it SPOOL in your program.
Read More

Show progress indicator


* Show progress indicator
  lw_percentage = ( sy-tabix * 100 ) / gw_nb_total.
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      percentage = lw_percentage
      text       = 'Message to display in SAP GUI progress bar'.

Manage Parameter ID

Get parameter in selection screen :


  IF  p_matnr IS INITIAL.
    GET PARAMETER ID 'MAT' FIELD p_matnr.
  ENDIF.

To set the entered value to parameter ID :


  IF  p_matnr IS NOT INITIAL.
    SET PARAMETER ID 'MAT' FIELD p_matnr.
  ENDIF.

Parameter ID table : TPARA (editable via SM30 transaction).
User parameter ID table : USR05.

Check if function exists

You can check if a Function Module exists into table TFDIR (field FUNCNAME).

You can also use code :


CALL FUNCTION 'FUNCTION_EXISTS'
  EXPORTING
    funcname           = 'Function_name'
  EXCEPTIONS
    function_not_exist = 1.