ALV Report Using Layout – Practical 2


ALV REPORT USING FIELD LAYOUT TO OPTIMIZE THE OUTPUT

Best SAP ABAP Latest Course

SAP ABAP Fundamentals

SAP ABAP Interview Questions – Real Time

Step 1: Go to SE38 Tcode. Type the program name and choose Source Code from Subojects and Click on Create button.

Step 2: Type the Title & select ‘Executable Program’ type in Attributes and then click on save.

Step 3: Now enter the Package name in the ‘Package’ Attribute and click on the button.

Step 4: A new pop-up will open, select the TR and click on .button

Now ABAP Editor will open, here write the code given below for the report.

 


REPORT zalvexample5.
*Table Declaration
TABLES : vbap.

*Type-Pools

TYPE-POOLS: slis.

*Type Declaration

TYPES: BEGIN OF ty_vbap,

vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
matkl TYPE vbap-matkl,
arktx TYPE vbap-arktx,
netwr TYPE vbap-netwr,
waerk TYPE vbap-waerk,
klmeng TYPE vbap-klmeng,
vrkme TYPE vbap-vrkme,

END OF ty_vbap.

*Data Declaration

DATA: gt_vbap TYPE STANDARD TABLE OF ty_vbap,

wa_vbap TYPE ty_vbap,
gt_fcat TYPE slis_t_fieldcat_alv,
wa_fcat LIKE LINE OF gt_fcat,
gt_layout TYPE slis_layout_alv.

*Selection Screen

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: so_vbeln FOR vbap-vbeln.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

*Data Fetching

SELECT vbeln

posnr
matnr
matkl
arktx
netwr
waerk
klmeng
vrkme

FROM vbap INTO TABLE gt_vbap
WHERE vbeln IN so_vbeln.

*Field Catalog

wa_fcat-col_pos = 1.
wa_fcat-fieldname = ‘VBELN’.
wa_fcat-seltext_m = ‘SD NO.’.
wa_fcat-key = ‘X’.
wa_fcat-hotspot = ‘X’.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos = 2.
wa_fcat-fieldname = ‘POSNR’.
wa_fcat-seltext_m = ‘ITEM NO.’.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos = 3.
wa_fcat-fieldname = ‘MATNR’.
wa_fcat-seltext_m = ‘MATERIAL NO.’.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos = 4.
wa_fcat-fieldname = ‘MATKL’.
wa_fcat-seltext_m = ‘MATERIAL GROUP’.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos = 5.
wa_fcat-fieldname = ‘ARKTX’.
wa_fcat-seltext_m = ‘DESCRIPTION’.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos = 6.
wa_fcat-fieldname = ‘NETWR’.
wa_fcat-seltext_m = ‘AMOUNT’.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos = 7.
wa_fcat-fieldname = ‘WAERK’.
wa_fcat-seltext_m = ‘CURRENCY’.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos = 8.
wa_fcat-fieldname = ‘KLMENG’.
wa_fcat-seltext_m = ‘QUANTITY’.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos = 9.
wa_fcat-fieldname = ‘VRKME’.
wa_fcat-seltext_m = ‘UNTI’.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

*LAYOUT : It is used to optimize the Column width of output.

gt_layout-zebra = ‘X’.                                         “Zebra Color on Output
gt_layout-colwidth_optimize = ‘X’.              “Optimize the Column width

*Displaying ALV Grid

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
       i_callback_program = sy-repid
       is_layout = gt_layout
       it_fieldcat = gt_fcat

TABLES
        t_outtab = gt_vbap
*EXCEPTIONS
         *PROGRAM_ERROR = 1
*OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

 


OUTPUT

Best Laptops for ABAP Programmers

Step 1: Press F8 Button in the report, Selection Screen will come as shown below.

Step 2: Press F8 Button again to see the output.