ALV Report with layout SAP ABAP

What is layout in SAP ALV reports ? Using layout parameter in SAP ALV using SAP ABAP

+ -

Layout:

Layout is a structure which is used to decorate or embellish the output of ALV Report.

Requirement: Display list of materials for a material type, with all fields of output is editable, no horizontal and vertical lines and hotspot on material no.

Input Screen

ALV report with layout in ABAP

Out put Screen (all rows are editable and hotspot on material no)

Making ALV editable in ABAP

Please follow previous lesson steps to create a fieldcatlog in ALV, in addition to that we will be adding additional properties hotspot, editable to output fields using layout options.

The below is the code to add layout to ALV.

DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV .
  WA_LAYOUT-ZEBRA = 'X' .
  WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X' .
  WA_LAYOUT-EDIT = 'X' .
  WA_LAYOUT-NO_VLINE = 'X' .
  WA_LAYOUT-NO_HLINE = 'X' .

We will supply remaining options through fieldcatlog also.

Full referance code for using layout in ALV

REPORT  ZSAPN_ALV_LAYOUT.
TYPE-POOLS : SLIS .
*DATA DECLARAATIONS
DATA : I_MARA TYPE TABLE OF MARA .
DATA : WA_MARA TYPE MARA .
*ALV DECLARATIONS
DATA : I_FCAT TYPE SLIS_T_FIELDCAT_ALV .
DATA : WA_FCAT TYPE SLIS_FIELDCAT_ALV .
DATA : V_POS TYPE I .
DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV .
PARAMETERS : P_MTART TYPE MARA-MTART.

START-OF-SELECTION .
  PERFORM GET_DATA .
  PERFORM CREATE_FCAT .
  PERFORM CREATE_LAYOUT.
  PERFORM DISPLAY_DATA .
END-OF-SELECTION .
FORM GET_DATA .

  SELECT * FROM MARA
      INTO TABLE I_MARA
       UP TO 100 ROWS WHERE MTART = P_MTART .
ENDFORM.                    " GET_DATA
FORM DISPLAY_DATA .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID
      IS_LAYOUT          = WA_LAYOUT
      IT_FIELDCAT        = I_FCAT
    TABLES
      T_OUTTAB           = I_MARA.
ENDFORM.                    " DISPLAY_DATA
FORM DISPLAY_DATA_LIST .
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      I_STRUCTURE_NAME = 'MARA'
    TABLES
      T_OUTTAB         = I_MARA.
  IF SY-SUBRC NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " DISPLAY_DATA_LIST
FORM CREATE_FCAT .
  V_POS = 1 .
  WA_FCAT-COL_POS = V_POS.
  WA_FCAT-FIELDNAME = 'MATNR' .
  WA_FCAT-SELTEXT_M = 'Material.NO' .
  WA_FCAT-HOTSPOT = 'X' .
  APPEND WA_FCAT TO I_FCAT .
  CLEAR WA_FCAT .

  V_POS = V_POS   1.
  WA_FCAT-COL_POS = V_POS .
  WA_FCAT-FIELDNAME = 'MTART' .
  WA_FCAT-SELTEXT_M = 'Material.Type' .
  APPEND WA_FCAT TO I_FCAT .
  CLEAR WA_FCAT .


  V_POS = V_POS   1.
  WA_FCAT-COL_POS = V_POS .
  WA_FCAT-FIELDNAME = 'MBRSH' .
  WA_FCAT-SELTEXT_M = 'Ind.Sector' .
  APPEND WA_FCAT TO I_FCAT .
  CLEAR WA_FCAT .


  V_POS = V_POS   1.
  WA_FCAT-COL_POS = V_POS .
  WA_FCAT-FIELDNAME = 'MATKL' .
  WA_FCAT-SELTEXT_M = 'Mat.Grp' .
  APPEND WA_FCAT TO I_FCAT .
  CLEAR WA_FCAT .


  V_POS = V_POS   1.
  WA_FCAT-COL_POS = V_POS .
  WA_FCAT-FIELDNAME = 'MEINS' .
  WA_FCAT-SELTEXT_M = 'Units' .
  APPEND WA_FCAT TO I_FCAT .
  CLEAR WA_FCAT .

ENDFORM.                    " CREATE_FCAT
FORM CREATE_LAYOUT .
  WA_LAYOUT-ZEBRA = 'X' .
  WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X' .
  WA_LAYOUT-EDIT = 'X' .
  WA_LAYOUT-NO_VLINE = 'X' .
  WA_LAYOUT-NO_HLINE = 'X' .

ENDFORM.                    " CREATE_LAYOUT

Please Sign in to ask a question

Was this lesson helpful to you? Yes No 33 People out of 36 think this lesson helpful


Lesson Navigation

←Previous Chapter
Next Chapter →