- Creating dynamic ALV with dynamic editable columns and dynamic colors to the columns based on condition
- Adding PF-Status, Header and Footer in ALV using class CL_SALV
- Hiding the print info of the ALV list in the spool
- Create, Modify and Delete entries dynamically from any custom table by using Object Oriented ALV
- Coloring of the cells in the F4 help of ALV
- Printing a line after every subtotaling in ALV
- Increasing the width of the spool when using ALV List
- Simple interactive ALV Tree calling ALV list display
- Display text 'Total' in ALV using Object Oriented Programming
- ALV with user-defined menu on toolbar
- Simple ALV Tree report (6-levels)
- Interactive ALV report using OOPS
- ALV with editable F4
- ALV Styles in Field catalogue using OOPS
- ALV drag and drop functionality on its rows
- ALV with user-defined buttons on toolbar
- Add custom sub-menu in ALV Context menu
- Editable Field catalogue for ALV display
- ALV code for simple hierarchical sequential list display (single child)
- ALV with EDIT and SAVE functionality
- Display subtotal text in ALV grid
- Demo program on interactive ALV using REUSE_ALV_GRID_DISPLAY
- Dropdown list in ALV
- ALV in a Pop up window and ALV in a dialog box
- ALV Interface Check
- Displaying ALV on the Selection Screen
- Changing Font style in ALV
- Dynamic ALV List generation
- Simple ALV report with its output transposed (rows as columns and columns as rows)
- Problem with ALV Grid Top-of-Page - How to print more than 60 characters?
- Printing ALV list with Page Numbers
- Printing Subtotals at the end of an ALV List
- Highlighting only a particular cell instead of entire row in ALV Grid
- Demo program on ALV Blocked list display
- Displaying Lights (Red, Green, Yellow) in ALV
- Working with ALV Layout variant
- Sample ALV Grid program using the function module REUSE_ALV_GRID_DISPLAY
- Displaying Logo in ALV
- Building Interactive ALV list using 'REUSE_ALV_LIST_DISPLAY'.
- Demo program to color particular row or column or cell of an ALV list using 'REUSE_ALV_LIST_DISPLAY'
- Demo program to color the contents of a field based on a condition using 'REUSE_ALV_LIST_DISPLAY'
- Highlighting the visited record on the basic list (ALV) on pressing BACK button in the secondary list using 'REUSE_ALV_LIST_DISPLAY'.
- Colored Excel output (Multiple Colors, Bold and others) using ALV
- Achieving Page Breaks using ALV Grid
- Demo program on ALV Tree Control
- Excluding a column from ALV Display using CL_SALV_TABLE Class.
- Displaying the data in various languages using ALV
- Working with Multiple dynamic internal tables
Tuesday, November 16, 2010
ALV Programs
Creating dynamic ALV with dynamic editable columns and dynamic colors to the columns based on condition
This Program will help to create dynamic ALV with dynamic editable columns and dynamic colors to the columns based on condition.
*&---------------------------------------------------------------------*
*& Report YSHU_SAI_ALV_DYNAMIC
*&---------------------------------------------------------------------*
REPORT YSHU_SAI_ALV_DYNAMIC.
TYPE-POOLS : ABAP.
FIELD-SYMBOLS:
DATA: DYN_TABLE TYPE REF TO DATA,
DYN_LINE TYPE REF TO DATA,
WA_FIELDCAT TYPE LVC_S_FCAT,
IT_FIELDCAT TYPE LVC_T_FCAT,
IT_FIELDCAT_1 TYPE LVC_T_FCAT,
OK_CODE TYPE SY-UCOMM.
TYPES: BEGIN OF TY_1,
TIME TYPE T,
REMARKS TYPE CHAR50,
END OF TY_1.
DATA: LV_FLD_1 TYPE TY_1.
START-OF-SELECTION.
* Create dynamic table stricture..
PERFORM GET_TABLE_STRUCTURE.
*Create dynamic internale table..
PERFORM CREATE_ITAB_DYNAMICALLY.
* filling the data into dynamic internal table..
PERFORM GET_DATA.
END-OF-SELECTION.
* display dynamic interal data.
PERFORM DISPLAY_ALV_REPORT.
CALL SCREEN 2000.
*&---------------------------------------------------------------------*
*& Form get_table_structure
*&---------------------------------------------------------------------*
* Get structure of an SAP table
*----------------------------------------------------------------------*
FORM GET_TABLE_STRUCTURE.
DATA : REF_TABLE_DESCR TYPE REF TO CL_ABAP_STRUCTDESCR,
IT_TABDESCR TYPE ABAP_COMPDESCR_TAB,
WA_TABDESCR TYPE ABAP_COMPDESCR,
LV_NO_DAYS TYPE P,
LV_DATE TYPE SY-DATUM,
LV_DATUM TYPE SY-DATUM,
LV_DAY TYPE TEXT40,
LV_WEEK_DAY TYPE TEXT10,
LIN TYPE SY-TFILL,
C_REM TYPE STRING VALUE 'Remarks' .
* fill the data into fieldcatlog of static field
PERFORM BUILD_FIELDCATALOG USING IT_FIELDCAT.
* Return structure of the table.
REF_TABLE_DESCR ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( LV_FLD_1 ).
IT_TABDESCR[] = REF_TABLE_DESCR->COMPONENTS[].
* Get no of days in a month..
CALL FUNCTION 'HR_E_NUM_OF_DAYS_OF_MONTH'
EXPORTING
P_FECHA = SY-DATUM
IMPORTING
NUMBER_OF_DAYS = LV_NO_DAYS.
* get no of lines..
DESCRIBE TABLE IT_FIELDCAT LINES LIN .
LV_DATUM = SY-DATUM.
LV_DATUM+6(2) = 1.
WA_FIELDCAT-COL_POS = LIN.
* fill dynamic field into fields cate..
DO LV_NO_DAYS TIMES.
LV_DATE = LV_DATUM + SY-INDEX - 1.
CALL FUNCTION 'DATE_TO_DAY'
EXPORTING
DATE = LV_DATE
IMPORTING
WEEKDAY = LV_WEEK_DAY.
CONCATENATE LV_DATE+6(2) ',' LV_WEEK_DAY INTO LV_DAY.
LOOP AT IT_TABDESCR INTO WA_TABDESCR.
WA_FIELDCAT-COL_POS = WA_FIELDCAT-COL_POS + 1 .
IF SY-TABIX = 1.
WA_FIELDCAT-FIELDNAME = LV_DATE .
WA_FIELDCAT-COLTEXT = LV_DAY.
ELSE.
CONCATENATE LV_DATE '_R' INTO WA_FIELDCAT-FIELDNAME.
WA_FIELDCAT-COLTEXT = C_REM."'Remarks'.
ENDIF.
WA_FIELDCAT-INTTYPE = WA_TABDESCR-TYPE_KIND.
WA_FIELDCAT-INTLEN = WA_TABDESCR-LENGTH / 2.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
ENDLOOP.
ENDDO.
ENDFORM. "get_table_structure
*&---------------------------------------------------------------------*
*& Form create_itab_dynamically
*&---------------------------------------------------------------------*
* Create internal table dynamically
*----------------------------------------------------------------------*
FORM CREATE_ITAB_DYNAMICALLY.
* Create dynamic internal table and assign to Field-Symbol
CLEAR WA_FIELDCAT.
*move fields from IT_FIELDCAT into IT_FIELDCAT_1.
IT_FIELDCAT_1 = IT_FIELDCAT.
* Use ref table CALENDAR_TYPE and ref field 'COLTAB'
WA_FIELDCAT-FIELDNAME = 'CELLCOLOR'.
WA_FIELDCAT-REF_TABLE = 'CALENDAR_TYPE'.
WA_FIELDCAT-REF_FIELD = 'COLTAB'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
* create a table type 'ZCELLSTYL' with field 'CELLSTYLE' of type LVC_T_STYL
WA_FIELDCAT-FIELDNAME = 'CELLSTYLE'.
WA_FIELDCAT-REF_TABLE = 'ZCELLSTYL'.
WA_FIELDCAT-REF_FIELD = 'CELLSTYLE'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
*Create a dynamic table with IT_FIELDCAT.
* and Use IT_FIELDCAT_1 to display ALV.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FIELDCAT
IMPORTING
EP_TABLE = DYN_TABLE.
ASSIGN DYN_TABLE->* TO
CREATE DATA DYN_LINE LIKE LINE OF
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* Populate dynamic itab
*----------------------------------------------------------------------*
FORM GET_DATA.
FIELD-SYMBOLS:
DATA: IT_CELLCOLOR TYPE LVC_T_SCOL,
IT_CELLSTYLE TYPE LVC_T_STYL,
L_DAY_P TYPE P,
LV_MOD_DATE TYPE DATUM,
C_HOL TYPE CHAR10 VALUE '
ASSIGN COMPONENT 'PERNR' OF STRUCTURE
* adde color to dynamci fields..
ASSIGN COMPONENT 'CELLCOLOR' OF STRUCTURE
PERFORM MODIFY_CELL_COLOR USING
IF
LV_MOD_DATE =
L_DAY_P = LV_MOD_DATE MOD 7.
IF L_DAY_P > 1.
L_DAY_P = L_DAY_P - 1.
ELSE.
L_DAY_P = L_DAY_P + 6.
ENDIF.
IF L_DAY_P = 6 OR L_DAY_P = 7.
PERFORM MODIFY_CELL_COLOR USING
ENDIF.
ENDIF.
ENDIF.
*Dynamic editable
IF
ASSIGN COMPONENT 'CELLSTYLE' OF STRUCTURE
ENDLOOP.
APPEND
*&---------------------------------------------------------------------*
*& Form modify_cell_color
*&---------------------------------------------------------------------*
* -->P_FIELDNAME text
* -->PT_CELLCOLOR text
*----------------------------------------------------------------------*
FORM MODIFY_CELL_COLOR USING P_FIELDNAME TYPE LVC_FNAME
CHANGING PT_CELLCOLOR TYPE TABLE.
DATA L_CELLCOLOR TYPE LVC_S_SCOL.
DATA : LV_DATE TYPE DATUM.
DATA: DAY_P TYPE P.
CLEAR L_CELLCOLOR.
IF P_FIELDNAME+8(2) = '_R'.
LV_DATE = P_FIELDNAME+8(2).
ELSE.
LV_DATE = P_FIELDNAME.
ENDIF.
DAY_P = LV_DATE MOD 7.
IF DAY_P > 1.
DAY_P = DAY_P - 1.
ELSE.
DAY_P = DAY_P + 6.
ENDIF.
IF DAY_P = 6 OR DAY_P = 7.
IF P_FIELDNAME+8(2) = '_R'.
L_CELLCOLOR-COLOR-COL = 7. " Red.
L_CELLCOLOR-COLOR-INT = 0.
L_CELLCOLOR-COLOR-INV = 0.
ELSE.
L_CELLCOLOR-COLOR-COL = 7. " Red.
L_CELLCOLOR-COLOR-INT = 1.
L_CELLCOLOR-COLOR-INV = 1.
ENDIF.
L_CELLCOLOR-FNAME = P_FIELDNAME.
APPEND L_CELLCOLOR TO PT_CELLCOLOR.
ELSE.
CLEAR L_CELLCOLOR.
ENDIF.
IF P_FIELDNAME+0(8) = SY-DATUM.
L_CELLCOLOR-FNAME = P_FIELDNAME.
L_CELLCOLOR-COLOR-COL = 3. " Red.
L_CELLCOLOR-COLOR-INT = 1.
L_CELLCOLOR-COLOR-INV = 1.
APPEND L_CELLCOLOR TO PT_CELLCOLOR.
CONCATENATE P_FIELDNAME '_R' INTO L_CELLCOLOR-FNAME .
L_CELLCOLOR-COLOR-COL = 3. " Red.
L_CELLCOLOR-COLOR-INT = 1.
L_CELLCOLOR-COLOR-INV = 1.
APPEND L_CELLCOLOR TO PT_CELLCOLOR.
ENDIF.
ENDFORM. " MODIFY_CELL_COLOR
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report, using SAP table structure
*----------------------------------------------------------------------*
FORM BUILD_FIELDCATALOG USING P_IT_FIELDCAT TYPE LVC_T_FCAT."SLIS_T_FIELDCAT_ALV .
** ALV Function module to build field catalog from SAP table structure
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
I_STRUCTURE_NAME = 'ZDYNAMIC_ALV_STR'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
CT_FIELDCAT = P_IT_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
FORM DISPLAY_ALV_REPORT.
DATA :G_GRID_I TYPE REF TO CL_GUI_ALV_GRID,
G_CUSTOM_CONTAINER_I TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
I_CONTAINER TYPE SCRFNAME VALUE 'ALV',
GS_LAYOUT TYPE LVC_S_LAYO.
CREATE OBJECT G_CUSTOM_CONTAINER_I
EXPORTING
CONTAINER_NAME = I_CONTAINER.
CREATE OBJECT G_GRID_I
EXPORTING
I_PARENT = G_CUSTOM_CONTAINER_I.
GS_LAYOUT-COL_OPT = 'X'.
GS_LAYOUT-CWIDTH_OPT = 'X'.
GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.
GS_LAYOUT-STYLEFNAME = 'CELLSTYLE'.
CALL METHOD G_GRID_I->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = GS_LAYOUT
* IT_TOOLBAR_EXCLUDING = LT_EXCLUDE[]
CHANGING
IT_FIELDCATALOG = IT_FIELDCAT_1
IT_OUTTAB =
CALL METHOD G_GRID_I->SET_READY_FOR_INPUT
EXPORTING
I_READY_FOR_INPUT = 1.
ENDFORM. " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_2000 INPUT.
CASE OK_CODE.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_2000 OUTPUT.
SET PF-STATUS 'STATUS_2000'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
*& Form EDITABLE_CELL
*&---------------------------------------------------------------------** -->P_IT_CELLSTYLE text
*----------------------------------------------------------------------*
FORM EDITABLE_CELL USING P_FIELDNAME TYPE LVC_FNAME
CHANGING P_IT_CELLSTYLE TYPE LVC_T_STYL.
DATA : WA_CELLSTYLE TYPE LVC_S_STYL.
WA_CELLSTYLE-FIELDNAME = P_FIELDNAME .
WA_CELLSTYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.
INSERT WA_CELLSTYLE INTO TABLE P_IT_CELLSTYLE.
ENDFORM. " EDITABLE_CELL
Output:
The output shows current month calendar with all the Saturday and Sundays dynamically red color will apply and for the current date yellow color with Editable fields.