SALV-Table mit “Grafik”

Heute kam mir die Idee, Daten in einem ALV-Grid einmal grafisch darzustellen. Ich hatte eigentlich vor, die grafischen Zeichen aus dem DOS-Zeichensatz zu verwenden:

Bild_2014_06_26_210631

 

Leider war das nicht möglich. Ich habe mich dann für ein anderes Sonderzeichen entschieden:

Bild_2014_06_26_200626 (2)

Die Länge des “Balkens” wird anhand der verwenden Feldgröße von 20 Zeichen berechnet.

Das Pipe-Symbol | sieht auch gut aus. Nimmt nicht so viel Platz weg…

Bild_2014_06_26_210606

Coding

REPORT z.

*== global data
DATA:
  BEGIN OF gs_data,
    matnr   TYPE char10,
    descr   TYPE text20,
    amount  TYPE i,
    camount TYPE char20,
  END OF gs_data,
  gt_data LIKE TABLE OF gs_data,
  hex TYPE x VALUE 7.

FIELD-SYMBOLS  TYPE c.

*== start of program
START-OF-SELECTION.
  PERFORM main.

*&---------------------------------------------------------------------*
*&      Form  main
*&---------------------------------------------------------------------*
FORM main.

*== local data
  DATA lo_grid      TYPE REF TO cl_salv_table.
  FIELD-SYMBOLS  LIKE LINE OF gt_data.

*== assign special Character
  ASSIGN hex TO  CASTING.

*== Fill testdata
  gs_data-matnr = '1000'. gs_data-descr = 'Screw'.      gs_data-amount = 120. APPEND gs_data TO gt_data.
  gs_data-matnr = '1300'. gs_data-descr = 'Nut 1"'.     gs_data-amount = 030. APPEND gs_data TO gt_data.
  gs_data-matnr = '1506'. gs_data-descr = 'Driver'.     gs_data-amount = 222. APPEND gs_data TO gt_data.
  gs_data-matnr = '1660'. gs_data-descr = 'Tool '.      gs_data-amount = 180. APPEND gs_data TO gt_data.
  gs_data-matnr = '2040'. gs_data-descr = 'Screw 0.4"'. gs_data-amount = 178. APPEND gs_data TO gt_data.
  gs_data-matnr = '2220'. gs_data-descr = 'Screw 0.6"'. gs_data-amount = 660. APPEND gs_data TO gt_data.
  gs_data-matnr = '2456'. gs_data-descr = 'Gripper'.    gs_data-amount = 066. APPEND gs_data TO gt_data.
  gs_data-matnr = '2660'. gs_data-descr = 'Nipper'.     gs_data-amount = 510. APPEND gs_data TO gt_data.
  gs_data-matnr = '2807'. gs_data-descr = 'Pincer'.     gs_data-amount = 790. APPEND gs_data TO gt_data.

*== calc amount
  LOOP AT gt_data ASSIGNING .
    PERFORM calc CHANGING .
  ENDLOOP.

*== call SALV
  TRY.
      CALL METHOD cl_salv_table=>factory
        IMPORTING
          r_salv_table = lo_grid
        CHANGING
          t_table      = gt_data.
      lo_grid->display( ).

    CATCH cx_salv_msg.
      WRITE: / 'Error: ALV exception CX_SALV_MSG'.
  ENDTRY.

ENDFORM.                    "main

*&---------------------------------------------------------------------*
*&      Form  calc
*&---------------------------------------------------------------------*
FORM calc CHANGING cs_data LIKE gs_data.

*== local data
  DATA number TYPE i.
  DATA max TYPE i VALUE 1000.

*== calculate bar
  number = cs_data-amount * 100 / 1000 / 5.

*== Fill bar
  DO number TIMES.
     CONCATENATE cs_data-camount  INTO cs_data-camount.
  ENDDO.

ENDFORM.                    "calc
Enno Wulff
Letzte Artikel von Enno Wulff (Alle anzeigen)