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: <LINE> TYPE STANDARD TABLE, <WA> TYPE ANY.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. … Read more