Skip to Content
avatar image
Former Member

Dynamic Internal Table

Hi Guru's

I need to develope a report to create a Internal table dynamically using the selction screen field VKBUR as select option if user gives From and To for Ex: 100 to 110 then 10 fields need to be created dynamically....

Please help me to do this.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Oct 10, 2008 at 10:38 AM

    Hi Murali,

    Here is the sample program for your reference.. Just go through the program I have develop the same logic only I am using the Fiscal year as a dynamic.

    *&---------------------------------------------------------------------*
    *& Report  ZMM_TRANSACTIONAL_HISTORY                                   *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    *& Developer: Chidanand Chauhan (Sparta Consulting)                    *
    *& Date: 09/23/2008                                                    *
    *& Description:  Transaction History for the Plant 0088
    *&                                                                     *
    *&---------------------------------------------------------------------*
    *           M O D I F I C A T I O N   L O G                            *
    *&---------------------------------------------------------------------*
    *  Version     Date          Developer            Description of change*
    *&---------------------------------------------------------------------*
    
    REPORT  ZMM_TRANSACTIONAL_HISTORY   .
    *&---------------------------------------------------------------------*
    *                    SELECTION SCREEN                                  *
    *&---------------------------------------------------------------------*
    TABLES: MARA,
            MARC,
            MSEG,
            MKPF.
    TYPES:  BEGIN OF TY_MSEG ,
            MBLNR TYPE MSEG-MBLNR,    "Doc Number
            MJAHR TYPE MSEG-MJAHR,    "Fiscal Year
            BWART TYPE MSEG-BWART,    "Movement Type
            MATNR TYPE MARA-MATNR,    "Material Number
            WERKS TYPE MARC-WERKS,    "Plant
            DMBTR TYPE MSEG-DMBTR,    "Amount in Loc Curr
          END OF TY_MSEG,
            BEGIN OF TY1_MSEG,
             MATNR TYPE MARA-MATNR,    "Material Number
            MJAHR TYPE MSEG-MJAHR,    "Fiscal Year
            DMBTR TYPE MSEG-DMBTR,    "Amount in Loc Curr
            BWART TYPE MSEG-BWART,    "Movement Type
            WERKS TYPE MARC-WERKS,    "Plant
            END OF TY1_MSEG,
           BEGIN OF TY_FYEAR,
             MJAHR TYPE MSEG-MJAHR,
           END OF TY_FYEAR.
    
    DATA: BEGIN OF IT_MARA OCCURS 0,
            MATNR TYPE MARA-MATNR,
            MATKL TYPE MARA-MATKL,
          END OF IT_MARA,
    
          BEGIN OF IT_MARC OCCURS 0,
            MATNR TYPE MARA-MATNR,
            WERKS TYPE MARC-WERKS,
          END OF IT_MARC,
          BEGIN OF IT_MARA1 OCCURS 0,
            MATNR TYPE MARA-MATNR,
          END OF IT_MARA1,
          BEGIN OF IT_MAKT OCCURS 0,
            MATNR TYPE MARA-MATNR,
            MAKTX TYPE MAKT-MAKTX,
          END OF IT_MAKT,
          BEGIN OF IT_MBEW OCCURS 0,
            MATNR TYPE MARA-MATNR,
            STPRS TYPE MBEW-STPRS,
          END OF IT_MBEW,
    
          BEGIN OF IT_FINAL OCCURS 0,
            MATNR TYPE MARA-MATNR,
            MAKTX TYPE MAKT-MAKTX,
            MATKL TYPE MARA-MATKL,
            STPRS TYPE MBEW-STPRS,
            DMBTR1 TYPE MSEG-DMBTR,
            DMBTR2 TYPE MSEG-DMBTR,
            DMBTR3 TYPE MSEG-DMBTR,
            DMBTR4 TYPE MSEG-DMBTR,
            DMBTR5 TYPE MSEG-DMBTR,
            DMBTR6 TYPE MSEG-DMBTR,
            DMBTR7 TYPE MSEG-DMBTR,
            DMBTR8 TYPE MSEG-DMBTR,
            DMBTR9 TYPE MSEG-DMBTR,
          END OF IT_FINAL.
    
    DATA: IT_MSEG TYPE STANDARD TABLE OF TY_MSEG WITH HEADER LINE.
    DATA: IT_FYEAR TYPE STANDARD TABLE OF TY_FYEAR.
    DATA: WA_FYEAR TYPE TY_FYEAR.
    
    DATA: IT1_MSEG TYPE STANDARD TABLE OF TY1_MSEG WITH HEADER LINE.
    DATA: WA1_MSEG TYPE TY1_MSEG.
    *NAME OF THE CUSTOM CONTROL ADDED ON THE SCREEN
    data: G_CONTAINER type SCRFNAME value 'CUST_CONTAINER1'.
    
    *CUSTOM CONTAINER INSTANCE REFERENE
    data: G_CUSTOM_CONTAINER type ref to CL_GUI_CUSTOM_CONTAINER.
    data: G_GRID  type ref to CL_GUI_ALV_GRID.
    data: GT_FIELDCAT type LVC_T_FCAT.
    
    data WA_FIELDCAT like line of GT_FIELDCAT.
    *LAYOUT STRUCTURE
    
    DATA: I_FIELD   TYPE SLIS_T_FIELDCAT_ALV,
          W_FIELD   TYPE SLIS_FIELDCAT_ALV.
    .
    *&---------------------------------------------------------------------*
    *                    SELECTION SCREEN                                  *
    *&---------------------------------------------------------------------*
    SELECTION-SCREEN BEGIN OF BLOCK BLK1
                     WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.            "Material Number
    SELECT-OPTIONS: S_WERKS FOR MARC-WERKS.            "Plant
    SELECT-OPTIONS: S_BLDAT FOR MKPF-BLDAT.            "Document Date
    SELECT-OPTIONS: S_BWART FOR MSEG-BWART.            "Movement Type
    SELECT-OPTIONS: S_MJAHR FOR MSEG-MJAHR NO INTERVALS Obligatory.  "Year
    SELECT-OPTIONS: S_WERKS1 FOR MARC-WERKS.            "Plant
    SELECTION-SCREEN END   OF BLOCK BLK1.
    
    *----------------------------------------------------------------------*
    *       CLASS lcl_read_materials DEFINITION
    *----------------------------------------------------------------------*
    
    CLASS LCL_READ_TRANSACTIONAL_HISTORY DEFINITION.
      PUBLIC SECTION.
        METHODS:
        GET_MATERIALS.
    
    ENDCLASS.                    "LCL_READ_TRANSACTIONAL_HISTORY DEFINITION
    *----------------------------------------------------------------------*
    *       CLASS lcl_output_detail DEFINITION
    *----------------------------------------------------------------------*
    CLASS LCL_OUTPUT_DETAIL DEFINITION.
      PUBLIC SECTION.
    
        METHODS:
    * Fill the fieldcatalog for ALV output
          DISPLAY_OUTPUT,
          FIELDCAT
            IMPORTING
              FIELDNAME TYPE LVC_FNAME
              DO_SUM    TYPE CHAR1
              FIELDTEXT TYPE LVC_TXTCOL.
    
    
      PRIVATE SECTION.
        DATA:
          L_FIELDNAME TYPE LVC_FNAME,
          L_FIELDTEXT TYPE LVC_TXTCOL.
    
    ENDCLASS.                    "lcl_output_detail DEFINITION
    
    *----------------------------------------------------------------------*
    *       CLASS lcl_output_detail IMPLEMENTATION
    *----------------------------------------------------------------------*
    CLASS LCL_READ_TRANSACTIONAL_HISTORY IMPLEMENTATION.
      METHOD GET_MATERIALS.
        PERFORM P_GET_DATA.
      ENDMETHOD.                    "GET_MATERIALS
    
    ENDCLASS.              "LCL_READ_TRANSACTIONAL_HISTORY IMPLEMENTATION
    *----------------------------------------------------------------------*
    *       CLASS lcl_output_detail IMPLEMENTATION
    *----------------------------------------------------------------------*
    CLASS LCL_OUTPUT_DETAIL IMPLEMENTATION.
      METHOD DISPLAY_OUTPUT.
        DATA: V_COUNT TYPE I.
        DATA: V_PERIOD(2) TYPE C.
        DATA: V_COUNTER1 TYPE I VALUE 0.
        DATA: COUNT TYPE I VALUE 0.
        DATA: TAB TYPE C.
        DATA: V_MONTH TYPE SY-DATUM.
    
        CALL METHOD FIELDCAT
          EXPORTING
            FIELDNAME = 'MATNR'
            DO_SUM    = 'X'
            FIELDTEXT = 'P/N'.
    
        CALL METHOD FIELDCAT
          EXPORTING
            FIELDNAME = 'MAKTX'
            DO_SUM    = 'X'
            FIELDTEXT = 'Material Description'.
    
        CALL METHOD FIELDCAT
          EXPORTING
            FIELDNAME = 'MATKL'
            DO_SUM    = 'X'
            FIELDTEXT = 'Material Group'.
    
        CALL METHOD FIELDCAT
          EXPORTING
            FIELDNAME = 'STPRS'
            DO_SUM    = 'X'
            FIELDTEXT = 'Std Cost(Plant 0088)'.
    
        LOOP AT IT_FYEAR INTO WA_FYEAR.
          TAB = SY-TABIX.
          CONCATENATE:
           'DMBTR' TAB INTO L_FIELDNAME,
           'Fiscal Year' WA_FYEAR-MJAHR INTO L_FIELDTEXT SEPARATED BY SPACE
    .
    
          CALL METHOD FIELDCAT
            EXPORTING
              FIELDNAME = L_FIELDNAME
              DO_SUM    = 'X'
              FIELDTEXT = L_FIELDTEXT.
    
        ENDLOOP.
    
        PERFORM P_SHOW_DATA.
    
      ENDMETHOD.                  "fieldcat
    
      METHOD FIELDCAT.
        CLEAR W_FIELD.
        MOVE:
          FIELDNAME   TO W_FIELD-FIELDNAME,
          FIELDTEXT   TO W_FIELD-SELTEXT_L,
          FIELDTEXT   TO W_FIELD-SELTEXT_M,
          DO_SUM      TO W_FIELD-DO_SUM.
    
    
        APPEND W_FIELD TO I_FIELD.
        CLEAR: W_FIELD.
      ENDMETHOD.                  "fieldcat
    ENDCLASS.                    "lcl_output_detail IMPLEMENTATION
    *&---------------------------------------------------------------------*
    *                   START OF SELECTION                                 *
    *&---------------------------------------------------------------------*
    START-OF-SELECTION.
      DATA: MAT1 TYPE REF TO LCL_READ_TRANSACTIONAL_HISTORY.
      DATA: MAT2 TYPE REF TO LCL_OUTPUT_DETAIL.
    
      CREATE OBJECT MAT1.
      CREATE OBJECT MAT2.
      CALL METHOD MAT1->GET_MATERIALS.
      CALL METHOD MAT2->DISPLAY_OUTPUT.
    *  PERFORM P_GET_DATA.
    *  PERFORM P_SHOW_DATA.
    
    *&---------------------------------------------------------------------*
    *&      Form  P_GET_DATA
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM P_GET_DATA .
    *&Below loop will populate the Fiscal year which will display in o/p
      LOOP AT S_MJAHR.
        WA_FYEAR-MJAHR = S_MJAHR-LOW.
        APPEND WA_FYEAR TO IT_FYEAR .
      ENDLOOP.
      SELECT MATNR MATKL FROM MARA
          INTO TABLE IT_MARA
          WHERE MATNR IN S_MATNR.
      IF SY-SUBRC = 0.
        SORT IT_MARA BY MATNR.
        IF NOT IT_MARA[] IS INITIAL.
    
          SELECT MATNR WERKS  FROM MARC
                 INTO TABLE IT_MARC
                 FOR ALL ENTRIES IN IT_MARA
                 WHERE MATNR = IT_MARA-MATNR.
          LOOP AT IT_MARC.
            IT_MARA1-MATNR = IT_MARC-MATNR.
            APPEND IT_MARA1.
            CLEAR IT_MARA1.
          ENDLOOP.
          SORT IT_MARA1 BY MATNR.
          DELETE ADJACENT DUPLICATES FROM IT_MARA1 COMPARING MATNR.
    
          IF NOT IT_MARA1[] IS INITIAL.
    *& GET Material Description
            SELECT MATNR MAKTX FROM MAKT
                  INTO TABLE IT_MAKT
                  FOR ALL ENTRIES IN IT_MARA1
                  WHERE MATNR = IT_MARA1-MATNR.
    *& Get Standard Cost
            SELECT MATNR STPRS FROM MBEW
                  INTO TABLE IT_MBEW
                  FOR ALL ENTRIES IN IT_MARA1
                  WHERE MATNR = IT_MARA1-MATNR.
    
            SORT IT_MARA1 BY MATNR.
    *Get Fiscal year Cost
            SELECT MBLNR MJAHR BWART MATNR WERKS DMBTR
                 FROM MSEG
                 INTO TABLE IT_MSEG
                 FOR ALL ENTRIES IN IT_MARA1
                 WHERE MATNR = IT_MARA1-MATNR
                   AND MJAHR IN S_MJAHR
                   AND BWART IN S_BWART
                   AND WERKS IN S_WERKS1.
    *& Populate Final Table.
            PERFORM P_POPULATE_FINAL_TABLE.
    *        PERFORM P_POPULATE_
    
    
          ENDIF.
        ENDIF.
      ENDIF.
    ENDFORM.                    " GET_DATA
    *&---------------------------------------------------------------------*
    *&      Form  P_SHOW_DATA
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM P_SHOW_DATA .
    *  CALL SCREEN 9999.
      DATA: I_LAYOUT  TYPE SLIS_LAYOUT_ALV.
    
    
      MOVE:
        'X'     TO I_LAYOUT-ZEBRA,
        'X'     TO I_LAYOUT-COLWIDTH_OPTIMIZE,
        'X'     TO I_LAYOUT-CELL_MERGE.
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM     = SY-REPID
    *        i_callback_top_of_page = 'WRITE_TOP_ALV'
          IT_FIELDCAT            = I_FIELD
          I_SAVE                 = 'A'
    *        IT_EVENTS          = IT_EVENTS[]
          I_DEFAULT              = 'X'
          IS_LAYOUT              = I_LAYOUT
        TABLES
          T_OUTTAB               = IT_FINAL.
    
    ENDFORM.                    " P_SHOW_DATA
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_9999  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE STATUS_9999 OUTPUT.
      SET PF-STATUS 'MAIN9999'.
      SET TITLEBAR 'xxx'.
    *  PERFORM P_CREATE_AND_INIT_ALV.
    *  PERFORM P_CREATE_FIELD_CATALOG.
      PERFORM P_DISPLAY_ALV.
    
    ENDMODULE.                 " STATUS_9999  OUTPUT
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_9999  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE USER_COMMAND_9999 INPUT.
      case SY-UCOMM.
        when 'BACK'.
          leave to screen 0.
        when 'EXIT'.
          leave program.
      endcase.
    ENDMODULE.                 " USER_COMMAND_9999  INPUT
    *&---------------------------------------------------------------------*
    *&      Form  CREATE_AND_INIT_ALV
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM P_CREATE_AND_INIT_ALV .
      create object G_CUSTOM_CONTAINER
        exporting
          CONTAINER_NAME = G_CONTAINER.
      create object G_GRID
        exporting
          I_PARENT = G_CUSTOM_CONTAINER.
    
    ENDFORM.                    " CREATE_AND_INIT_ALV
    
    *&---------------------------------------------------------------------*
    *&      Form  P_CREATE_FIELD_CATALOG
    *&---------------------------------------------------------------------*
    *       TO DISPLAY ALV
    *----------------------------------------------------------------------*
    *----------------------------------------------------------------------*
    form P_CREATE_FIELD_CATALOG.
      data LS_FCAT type LVC_S_FCAT.
    
      loop at GT_FIELDCAT into WA_FIELDCAT.
    
        if WA_FIELDCAT-FIELDNAME = 'MODULE'.
          WA_FIELDCAT-COLTEXT = 'MODULE'.
          WA_FIELDCAT-OUTPUTLEN = 9.
    
          modify GT_FIELDCAT index SY-TABIX from WA_FIELDCAT.
    
        endif.
      ENDLOOP.
    ENDFORM.      "P_CREATE_FIELD_CATALOG
    *&---------------------------------------------------------------------*
    *&      Form  P_DISPLAY_ALV
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM P_DISPLAY_ALV .
    *  GS_LAYOUT-GRID_TITLE = 'TRANSACTION HISTORY REPORT'.
    *  GS_LAYOUT-DETAILTITL = 'TRANSACTION HISTORY REPORT'.
    *  GS_LAYOUT-DETAILINIT = 'X'.
    *  GS_LAYOUT-ZEBRA = 'X'.
    *
    *  call method G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
    *    EXPORTING
    *      IS_LAYOUT       = GS_LAYOUT
    *    CHANGING
    *      IT_FIELDCATALOG = GT_FIELDCAT
    *      IT_OUTTAB       = IT_MARA[].
    *DATA: I_LAYOUT  TYPE SLIS_LAYOUT_ALV.
    *
    *
    *    MOVE:
    *      'X'     TO I_LAYOUT-ZEBRA,
    *      'X'     TO I_LAYOUT-COLWIDTH_OPTIMIZE,
    *      'X'     TO I_LAYOUT-CELL_MERGE.
    *
    *    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    *      EXPORTING
    *        I_CALLBACK_PROGRAM     = SY-REPID
    **        i_callback_top_of_page = 'WRITE_TOP_ALV'
    *        IT_FIELDCAT            = I_FIELD
    *        I_SAVE                 = 'A'
    **        IT_EVENTS          = IT_EVENTS[]
    *        I_DEFAULT              = 'X'
    *        IS_LAYOUT              = I_LAYOUT
    *      TABLES
    *        T_OUTTAB               = IT_FINAL.
    
    ENDFORM.                    " P_DISPLAY_ALV
    *&---------------------------------------------------------------------*
    *&      Form  P_POPULATE_FINAL_TABLE
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM P_POPULATE_FINAL_TABLE .
    
      DATA: BEGIN OF LT_MSEG OCCURS 0,
    *        MBLNR TYPE MSEG-MBLNR,    "Doc Number
              MATNR TYPE MARA-MATNR,    "Material Number
              MJAHR TYPE MSEG-MJAHR,    "Fiscal Year
              DMBTR TYPE MSEG-DMBTR,    "Amount in Loc Curr
              BWART TYPE MSEG-BWART,    "Movement Type
              WERKS TYPE MARC-WERKS,    "Plant
      END OF LT_MSEG.
      DATA: SUM TYPE P DECIMALS 2.
      DATA: L_FIELD_QTY TYPE LVC_FNAME.
      DATA: L_TABIX(1) TYPE C.
      FIELD-SYMBOLS :
        <FS>  TYPE ANY,
        <FS1> TYPE ANY.
    
    *DATA: LT_MSEG TYPE STANDARD TABLE OF MSEG WITH HEADER LINE.
    *LT_MSEG[] = IT_MSEG[].
      LOOP AT IT_MSEG.
        LT_MSEG-MJAHR = IT_MSEG-MJAHR.
        LT_MSEG-MATNR = IT_MSEG-MATNR.
        LT_MSEG-DMBTR = IT_MSEG-DMBTR.
        APPEND LT_MSEG.
        CLEAR LT_MSEG.
      ENDLOOP.
      SORT LT_MSEG BY MATNR MJAHR.
      LOOP AT LT_MSEG.
        SUM = SUM + LT_MSEG-DMBTR.
        IT1_MSEG = LT_MSEG.
        AT END OF MJAHR.
    *    IT1_MSEG = LT_MSEG.
          IT1_MSEG-DMBTR = SUM.
          APPEND IT1_MSEG.
          CLEAR IT1_MSEG.
          SUM = 0.
        ENDAT.
      ENDLOOP.
    
      LOOP AT IT1_MSEG .
        READ TABLE S_MJAHR WITH KEY LOW = IT1_MSEG-MJAHR.
        IF SY-SUBRC = 0.
          L_TABIX = SY-TABIX.
          CONCATENATE 'IT_FINAL-DMBTR' L_TABIX INTO L_FIELD_QTY.
          ASSIGN: COMPONENT 'DMBTR' OF STRUCTURE IT1_MSEG TO <FS>.
          ASSIGN:  L_FIELD_QTY TO <FS1>.
          ASSIGN TABLE FIELD (L_FIELD_QTY) TO <FS1>.
          <FS1> = IT1_MSEG-DMBTR.
          IF SY-TABIX = 1.
            IT_FINAL-DMBTR1 = IT1_MSEG-DMBTR.
          ENDIF.
          IF SY-TABIX = 2.
            IT_FINAL-DMBTR2 = IT1_MSEG-DMBTR.
          ENDIF.
          IF SY-TABIX = 3.
            IT_FINAL-DMBTR3 = IT1_MSEG-DMBTR.
          ENDIF.
          IF SY-TABIX = 4.
            IT_FINAL-DMBTR4 = IT1_MSEG-DMBTR.
          ENDIF.
          IF SY-TABIX = 5.
            IT_FINAL-DMBTR5 = IT1_MSEG-DMBTR.
          ENDIF.
    
    
        ENDIF.
        AT END OF MATNR.
          READ TABLE IT_MARA WITH KEY MATNR = IT1_MSEG-MATNR.
          IF SY-SUBRC = 0.
            IT_FINAL-MATNR = IT_MARA-MATNR.
            IT_FINAL-MATKL = IT_MARA-MATKL.
          ENDIF.
          READ TABLE IT_MAKT WITH KEY MATNR = IT1_MSEG-MATNR.
          IF SY-SUBRC = 0.
            IT_FINAL-MAKTX = IT_MAKT-MAKTX.
          ENDIF.
          READ TABLE IT_MBEW WITH KEY MATNR = IT1_MSEG-MATNR.
          IF SY-SUBRC = 0.
            IT_FINAL-STPRS = IT_MBEW-STPRS.
          ENDIF.
    
          APPEND IT_FINAL.
          CLEAR IT_FINAL.
        ENDAT.
      ENDLOOP.
    
    *LOOP AT IT_MSEG.
    *  READ TABLE IT_MARA WITH KEY MATNR = IT_MSEG-MATNR.
    *  IF SY-SUBRC = 0.
    *    IT_FINAL-MATNR = IT_MARA-MATNR.
    *    IT_FINAL-MATKL = IT_MARA-MATKL.
    *  ENDIF.
    *  READ TABLE IT_MAKT WITH KEY MATNR = IT_MSEG-MATNR.
    *  IF SY-SUBRC = 0.
    *    IT_FINAL-MAKTX = IT_MAKT-MAKTX.
    *  ENDIF.
    *  READ TABLE IT_MBEW WITH KEY MATNR = IT_MSEG-MATNR.
    *  IF SY-SUBRC = 0.
    *    IT_FINAL-STPRS = IT_MBEW-STPRS.
    *  ENDIF.
    *  READ TABLE LT_MSEG WITH KEY MATNR = IT_MSEG-MATNR
    *                              MJAHR = '2006'.
    *  IF SY-SUBRC = 0.
    *    IT_FINAL-DMBTR1 = LT_MSEG-DMBTR.
    **    DELETE TABLE LT_MSEG INDEX SY-TABIX.
    *  ENDIF.
    *  READ TABLE LT_MSEG WITH KEY MATNR = IT_MSEG-MATNR
    *                              MJAHR = '2004'.
    *  IF SY-SUBRC = 0.
    *    IT_FINAL-DMBTR2 = LT_MSEG-DMBTR.
    **    DELETE TABLE LT_MSEG INDEX SY-TABIX.
    *  ENDIF.
    *  READ TABLE LT_MSEG WITH KEY MATNR = IT_MSEG-MATNR
    *                              MJAHR = '2008'.
    *  IF SY-SUBRC = 0.
    *    IT_FINAL-DMBTR3 = LT_MSEG-DMBTR.
    **    DELETE TABLE LT_MSEG INDEX SY-TABIX.
    *  ENDIF.
    *
    *  APPEND IT_FINAL.
    *  CLEAR IT_FINAL.
    *ENDLOOP.
    ENDFORM.                    " P_POPULATE_FINAL_TABLE
    

    Thanks,

    Chidanand

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 10, 2008 at 10:38 AM

    Hi,

    try the below code..

    PARAMETER : p_table LIKE dd02l-tabname.FIELD-SYMBOLS: <table> TYPE table.FIELD-SYMBOLS : <fname> TYPE ANY.DATA : it_fieldcat TYPE lvc_t_fcat.DATA : wa_fieldcat TYPE lvc_s_fcat.DATA : i_program_name LIKE sy-repid.DATA : i_structure_name LIKE dd02l-tabname.DATA : v_ref TYPE REF TO data.i_structure_name = p_table.i_program_name = sy-repid. break-point.CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING i_structure_name = i_structure_name CHANGING ct_fieldcat = it_fieldcat EXCEPTIONS inconsistent_interface = 1 program_error = 2 OTHERS = 3. CALL METHOD cl_alv_table_create=>create_dynamic_table EXPORTING it_fieldcatalog = it_fieldcat IMPORTING ep_table = v_ref. ASSIGN v_ref->* TO <table>. SELECT * INTO corresponding fields of TABLE <table> FROM (p_table).

    thanks & regards

    Kishore M

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 10, 2008 at 10:46 AM

    Hi,

    Try this Example code......

      DATA: struct_type TYPE REF TO cl_abap_structdescr,
            comp_tab    TYPE cl_abap_structdescr=>component_table,
            dref        TYPE REF TO data,
            itab_type   TYPE REF TO cl_abap_tabledescr,
            wa_comp     LIKE LINE OF comp_tab,
            index1      TYPE char10,
            gr_table      TYPE REF TO cl_salv_table.
     
    FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
                   <dyn_wa>.
     
    PARAMETERS:  p TYPE i.
     
    DO p TIMES
          index1 = sy-index.
    "Preparing the Column names
          CONCATENATE 'COL' '_' index1 INTO wa_comp-name.
          CONDENSE wa_comp-name NO-GAPS.
    "Preparing the Column Data type
          wa_comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
          APPEND  wa_comp TO comp_tab.
    ENDDO.
     
    "Creating the Structure...
      struct_type = cl_abap_structdescr=>create( comp_tab ).
    "Creating the Table...
      itab_type   = cl_abap_tabledescr=>create( struct_type ).
      CREATE DATA dref TYPE HANDLE itab_type.
      ASSIGN dref->* TO <dyn_table>.         "Table
      CREATE DATA dref TYPE HANDLE struct_type.
      ASSIGN dref->* TO <dyn_wa>.             "Workarea
     
    *&--Display the ALV
        cl_salv_table=>factory( IMPORTING r_salv_table = gr_table CHANGING t_table = <dyn_table> ).
        gr_table->display( ).
    
    

    I think this will solve ur problem....

    Add comment
    10|10000 characters needed characters exceeded