SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software Kodyaz SAP and ABAP Programming Tutorials
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Vista, etc.




Win FREE BOOK
from Kodyaz



CRM Companies List
Web Based CRM Software



SAP ABAP Tutorial - ALV Grid Example with cl_gui_alv_grid and Screen Painter


This ABAP example program lists VBAK and VBAP items between given two VBELN numbers on an SAP screen in an ALV grid using cl_gui_alv_grid.

And the below SAP screenshot is showing the output of the example ABAP program that filters data from VBAK and VBAP transparent tables and displays data on an ABAP ALV grid control cl_gui_alv_grid placed in a custom container.

SAP ABAP alv grid example with vbeln range
Display data using cl_gui_alv_grid in ABAP programming

Let's begin with the source code of the example ABAP report codes.

REPORT ZLIST_VBAP LINE-SIZE 160.

DATA :
 gr_vbeln TYPE RANGE OF vbak-vbeln,
 grs_vbeln LIKE LINE OF gr_vbeln.

DATA:
 gs_fieldcatalog TYPE lvc_s_fcat OCCURS 0,
 gv_fcat LIKE LINE OF gs_fieldcatalog,
 gs_layout TYPE lvc_s_layo.

TYPES :
 BEGIN OF gty_item,
  mandt LIKE vbak-mandt,
  vbeln LIKE vbak-vbeln,
  erdat LIKE vbak-erdat,
  kunnr LIKE vbak-kunnr,
  posnr LIKE vbap-posnr,
  matnr LIKE vbap-matnr,
  arktx LIKE vbap-arktx,
  kwmeng LIKE vbap-kwmeng,
  desc_text LIKE zvbap-desc_text,
 END OF gty_item,
 BEGIN OF gty_vbak,
  mandt LIKE vbak-mandt,
  vbeln LIKE vbak-vbeln,
  erdat LIKE vbak-erdat,
  kunnr LIKE vbak-kunnr,
 END OF gty_vbak,
 BEGIN OF gty_vbap,
  vbeln LIKE vbap-vbeln,
  posnr LIKE vbap-posnr,
  matnr LIKE vbap-matnr,
  arktx LIKE vbap-arktx,
  kwmeng LIKE vbap-kwmeng,
 END OF gty_vbap.


DATA :
 gs_item TYPE gty_item,
 gt_item TYPE TABLE OF gty_item.


DATA :
 gs_vbak TYPE gty_vbak,
 gt_vbak TYPE TABLE OF gty_vbak,
 gs_vbap TYPE gty_vbap,
 gt_vbap TYPE TABLE OF gty_vbap.

DATA :
 g_Container TYPE scrfname VALUE 'CC_CONTAINER_GRID',
 g_Custom_Container TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
 g_Grid TYPE REF TO CL_GUI_ALV_GRID.

DATA :
 OK_CODE LIKE sy-ucomm,
 SAVE_OK LIKE sy-ucomm.

START-OF-SELECTION.

 CALL SCREEN 100.

Let's continue reviewing the sample ABAP program code with the screen 100 dynapro object.
In the below screenshot you can see the layout view of the screen on the SAP Screen Painter editor.
This Screen Painter example show a cl_gui_custom_container object and the grid object cl_gui_alv_grid placed in that container.

SAP ABAP screen painter screen for ABAP alv grid sample

Please pay attention to the FctCode of the Button object BTNLIST. The FctCode is set as "BTNLIST" and will be controlled in the PAI (Process After Input) module with the ABAP CASE statement controlling the value of OK_CODE.

Here is the Process Before Output (PBO) module or ABAP code block of the Screen 100.

MODULE STATUS_0100 OUTPUT.

 SET PF-STATUS 'MAINSTATUS'.
 SET TITLEBAR 'TITLE'.

 IF g_Custom_Container IS INITIAL.

  " Create CONTAINER object with reference to container name in the screen
  CREATE OBJECT g_Custom_Container EXPORTING CONTAINER_NAME = g_Container.
  " Create GRID object with reference to parent name
  CREATE OBJECT g_Grid EXPORTING I_PARENT = g_Custom_Container.

  PERFORM u_prepare_fieldcatalog.
  gs_layout-ZEBRA = 'X'.
  "gs_layout-edit = 'X'. " Makes all Grid editable

  " SET_TABLE_FOR_FIRST_DISPLAY
  CALL METHOD g_Grid->SET_TABLE_FOR_FIRST_DISPLAY
   EXPORTING
    is_layout = gs_layout
   CHANGING
    it_fieldcatalog = gs_fieldcatalog
    IT_OUTTAB = gt_item. " Data

 ELSE.
  CALL METHOD g_Grid->REFRESH_TABLE_DISPLAY.
 ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

And you can find the Process After Input (PAI) module or ABAP code block of the Screen 100.

MODULE USER_COMMAND_0100 INPUT.

 SAVE_OK = OK_CODE.
 CLEAR OK_CODE.

 CASE SAVE_OK.
  WHEN 'EXIT' OR 'BACK' OR 'CNCL'.
   LEAVE PROGRAM.
  WHEN 'BTNLIST'.
   PERFORM u_filter_vbak.
  WHEN OTHERS.
 ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

In U_FILTER_VBAK, the required ABAP code to select data from related data dictionary objects, tables according to the given criteria takes place.
Within this ABAP code block, the necessary internal tables are populated with data from database.

FORM U_FILTER_VBAK .

 REFRESH gt_vbak.

 " Define Range Criteria
 grs_vbeln-SIGN = 'I'.
 grs_vbeln-OPTION = 'BT'.
 APPEND grs_vbeln to gr_vbeln.

 CHECK gr_vbeln[] IS NOT INITIAL.
 SELECT mandt vbeln erdat kunnr
  FROM vbak INTO TABLE gt_vbak
  WHERE vbeln IN gr_vbeln.

 CHECK gt_vbak[] IS NOT INITIAL.
 SELECT vbeln posnr matnr arktx kwmeng
  FROM vbap INTO TABLE gt_vbap
  FOR ALL ENTRIES IN gt_vbak
  WHERE vbeln EQ gt_vbak-vbeln.

 IF gt_vbak[] IS NOT INITIAL.

  LOOP AT gt_vbap INTO gs_vbap.

   READ TABLE gt_vbak INTO gs_vbak WITH KEY vbeln = gs_vbap-vbeln.

   gs_item-mandt = gs_vbak-mandt.
   gs_item-vbeln = gs_vbak-vbeln.
   gs_item-erdat = gs_vbak-erdat.
   gs_item-kunnr = gs_vbak-kunnr.
   gs_item-posnr = gs_vbap-posnr.
   gs_item-matnr = gs_vbap-matnr.
   gs_item-arktx = gs_vbap-arktx.
   gs_item-kwmeng = gs_vbap-kwmeng.

   APPEND gs_item TO gt_item.

   CLEAR gs_item.
   CLEAR gs_vbak.
   CLEAR gs_vbap.
  ENDLOOP.

 ENDIF.

ENDFORM. " U_FILTER_VBAK

And below ABAP developers can see how I build the field catalog required for displaying data on ALV grid.

FORM U_PREPARE_FIELDCATALOG .

 CLEAR gv_fcat.
 gv_fcat-fieldname = 'MANDT'.
 gv_fcat-tabname = 'VBAP'.
 gv_fcat-col_pos = 0.
 gv_fcat-coltext = 'MANDT'.
 gv_fcat-no_out = 'X'. " Do not Display Column
 INSERT gv_fcat INTO TABLE gs_fieldcatalog.

 CLEAR gv_fcat.
 gv_fcat-fieldname = 'VBELN'.
 gv_fcat-tabname = 'VBAP'.
 gv_fcat-col_pos = 1.
 gv_fcat-coltext = 'VBELN'.
 INSERT gv_fcat INTO TABLE gs_fieldcatalog.

 CLEAR gv_fcat.
 gv_fcat-fieldname = 'ERDAT'.
 gv_fcat-tabname = 'VBAP'.
 gv_fcat-col_pos = 2.
 gv_fcat-coltext = 'ERDAT'.
 INSERT gv_fcat INTO TABLE gs_fieldcatalog.

 CLEAR gv_fcat.
 gv_fcat-fieldname = 'KUNNR'.
 gv_fcat-tabname = 'VBAP'.
 gv_fcat-col_pos = 3.
 gv_fcat-coltext = 'KUNNR'.
 INSERT gv_fcat INTO TABLE gs_fieldcatalog.

 CLEAR gv_fcat.
 gv_fcat-fieldname = 'POSNR'.  gv_fcat-tabname = 'VBAP'.
 gv_fcat-col_pos = 4.
 gv_fcat-coltext = 'POSNR'.
 INSERT gv_fcat INTO TABLE gs_fieldcatalog.

 CLEAR gv_fcat.
 gv_fcat-fieldname = 'MATNR'.
 gv_fcat-tabname = 'VBAP'.
 gv_fcat-col_pos = 5.
 gv_fcat-coltext = 'MATNR'.
 INSERT gv_fcat INTO TABLE gs_fieldcatalog.

 CLEAR gv_fcat.
 gv_fcat-fieldname = 'ARKTX'.
 gv_fcat-tabname = 'VBAP'.
 gv_fcat-col_pos = 6.
 gv_fcat-coltext = 'ARKTX'.
 INSERT gv_fcat INTO TABLE gs_fieldcatalog.

 CLEAR gv_fcat.
 gv_fcat-fieldname = 'KWMENG'.
 gv_fcat-tabname = 'VBAP'.
 gv_fcat-col_pos = 7.
 gv_fcat-coltext = 'KWMENG'.
 gv_fcat-EDIT = 'X'. " Makes field editable in Grid
 INSERT gv_fcat INTO TABLE gs_fieldcatalog.

 CLEAR gv_fcat.
 gv_fcat-fieldname = 'DESC_TEXT'.
 gv_fcat-tabname = 'VBAP'.
 gv_fcat-col_pos = 7.
 gv_fcat-coltext = 'DESC_TEXT'.
 gv_fcat-no_out = 'X'.
 INSERT gv_fcat INTO TABLE gs_fieldcatalog.

ENDFORM. " U_PREPARE_FIELDCATALOG






SAP Resources

SAP Tutorial

SAP Forums

SAP Tools

SAP Transaction Codes Table






SAP Tutorial and ABAP Tutorials (including Web Dynpro and Smartforms)

Read Pricing Condition Text using ABAP in SAP Sales Document Output
Export SAP Data to Fixed Length Text File
Export Table Contents into Text File and Download File
Business Document Service Error: Error when accessing graphic (BDS), RC = 5
Get Proforma Invoice from Commercial Invoice in ABAP
Convert Sales Unit into Text using Function Module in Target Language
Get Fullname of SAP user using Function Module in ABAP Program
ABAP Submit Report to Run Another ABAP Program within Code
Message no XS826: Cannot process message; no node determined for 76550052
SE63 Smartform Translation and Export using SLXT Program
VF31 SAP Transaction to Reprocess Billing Output Messages
Import and Export SO10 Standard Text using RSTXSCRP ABAP Program
CALL_FUNCTION_NOT_FOUND ABAP Run Time Error
SAP Output Management - Create New SAP Output Type
SAP Purchase Order Tables, Transaction Codes and Output
Assign SAP Item Category to Sales Document Type using SPRO
Window MAIN does not fit onto page PAGE (height)
SAP Invoice Output ZZZZ is not Defined
Invoice Output fail because of missing Billing Type text in TVFKT table
Read Integer and Decimals of a Numeric Value in ABAP Programming
SAP Smartforms Table Parameter in Form Routine
Complex Conditions in SAP Smartform with AND/OR
Free Adobe LiveCycle Designer Download
Create SAP Dynamic Variant using Date Calculation
Translate Web Dynpro Header Title displayed on Web Browser
ABAP RegEx for ABAP Regular Expression to fetch Date from String
Change Output Condition Records
Web Dynpro Text Translation using Assistance Class
Move Minus Sign from Right to Left of Negative Number in SAP Smartform
Read Address Data using FM ADDR_GET instead of Querying ADRC Table
Add Value Help to Web Dynpro Select Options
Add Web Dynpro Applications to SAP Favorites Menu
Component Usage ALV Does Not Have an Active Component
Web Dynpro Component Service Syntax Error in Program /1BCWDY/O3EC1AX6A3OVKK9L5FXO==CP
Web DynPro Tutorial - Display Spool Requests using Web DynPro Table
Web DynPro Tutorial - How to create Web Dynpro Application (Web Dynpro Component)
Display Data on Web DynPro Table Element
Test Web Dynpro ABAP Component by Creating Web Dynpro Application
Graphics White Background Displayed Grey on SAP Smartform Output
Get SAP Document Flow using SD_DOCUMENT_FLOW_GET ABAP Function Module
How to Spell Numbers using ABAP Spell_Amount Function Module
How to Transport SAP Graphics using SE78 Transaction
How to Delete Standard Text using SO10 SAP Transaction
Dynamic Programming using Field Symbols in ABAP Reports
How to Disable Word Editor in SAP Smartform Text
How to Debug Popup Screen in ABAP
TVAP Item Category and SAP Table TVAPT for Text Translations
ABAP Runtime Error ST22 Transaction using Short Dump Analysis
Create Transport Request for Text Translations using RS_LXE_RECORD_TORDER
SAP Invoice Output Determination Analysis for Not Created Output Message
Set Default Single Values List for SAP Selection Screen Parameter
SAP Payment Terms Table and ZTERM Texts Table for ABAP Developers
How to Create SAPScript Text using SO10 Transaction Code
SAP Smartforms Tutorial - Table Calculations using Sum Total
SAP Smartforms Tutorial - Table Calculations using Count
SAP Smartforms Tutorial - How to Create Smartform
SAP NetWeaver Installation Guide using installshield wizard
SAP Smartforms Table for Sales Order and Invoice Outputs
Email Spool Request using SAPOffice - Spool to PDF
How to Display SAP Graphics using SE78 Transaction Code
SAPScript Transaction Codes
ABAP Tutorial - ABAP String Split Example Code
Sales Tables among ABAP Tables (SAP Sales and Distribution SD Tables)
How to Upload Data to SAP from Excel File using alsm_excel_to_internal_table Function Module
ALV Grid Color - Table Row Background Color in ALV List
Multi Color ALV Grid Color Alternate using ALV Layout info_fname Property
How to Debug SmartForms - Debugging SAP SmartForm in ABAP ?
ABAP - Create Hierarchy Tree List using rs_tree_construct, rs_tree_list_display and snodetext
Create CL_GUI_ALV_GRID ALV Grid Column Header using ABAP Data Element
ABAP Tutorial - SAP Split and ABAP Split String Function
Upload Data from Excel File in ABAP using TEXT_CONVERT_XLS_TO_SAP
SAP Tutorial - Convert Spool Request to PDF File using RSTXPDFT4 ABAP Report
SAP ABAP Tutorial - ALV Grid Example with cl_gui_alv_grid and Screen Painter
Convert Smartform to PDF in Print Preview Mode
SAP Smartforms Tutorial - Create Smartforms Example
SAP Smartforms - How to Call Smartform within ABAP Program
Complete List of SAP Modules






Copyright © 2004 - 2013 Eralper Yilmaz. All rights reserved.
Community Server by Telligent Systems