Skip to Content
avatar image
Former Member

having the fields dynamic in internal table......

hello friends

i have got an issue where i have to display all the months based on the month and year inselection criteria which has range and is mandatory.the problem i have got is,if i want to display material group and one more field (say total) including all the months.

i wanted the output like this

MAKTL | All months in the given range..... | Total ( these all fields must be | | printed horizontally)

I have typed the COde as given below but i don know how to print all the months horizontally in dynamic way since i wanted to have the structure as an internal table.

REPORT ZBHAVANI NO STANDARD PAGE HEADING LINE-SIZE 275.

tables : mara, itob .

DATA: MN LIKE T247-MNR,

S(4) TYPE C,

N TYPE I,

T(6) TYPE C,

T1(4) TYPE C,

TEMP TYPE I,

C(6) TYPE C,

L(6) TYPE C,

COUNT TYPE I,

  • moyr(6) type c,

  • P(6) TYPE C,

H(6) TYPE C.

DATA: BEGIN OF T_DATA OCCURS 0,

MATKL LIKE MARA-MATKL,

moyr(6) type c,

tot type i,

end of t_data.

******************************

*DATA: L_TABIX LIKE SY-TABIX.

*DATA ALV_PROG_NAME LIKE SY-REPID.

*ALV_PROG_NAME = SY-REPID.

*DATA : GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

  • LS_FIELDCAT LIKE GT_FIELDCAT,

  • WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

*DATA : IMPORT_VARIANT LIKE DISVARIANT.

*

*DATA : EVENTS TYPE SLIS_T_EVENT WITH HEADER LINE.

**********************************

DATA: ITAB TYPE TABLE OF T247 WITH HEADER LINE.

**********************************

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

PARAMETERS: P_WERKS LIKE VBAP-WERKS,

P_TPLNR LIKE RIWOL-TPLNR,

P_MATK LIKE MARA-MATKL.

SELECT-OPTIONS: S_YEAR FOR SY-DATUM+0(4),

S_MONTH FOR SY-DATUM+4(2) OBLIGATORY.

SELECTION-SCREEN END OF BLOCK B1.

IF S_YEAR-LOW <> 0 AND S_YEAR-HIGH = 0 .

S_YEAR-HIGH = S_YEAR-LOW.

ELSEIF S_YEAR-LOW = 0 AND S_YEAR-HIGH <> 0.

S_YEAR-LOW = S_YEAR-HIGH .

ENDIF.

IF S_MONTH-LOW <> 0 AND S_MONTH-HIGH = 0 .

S_MONTH-HIGH = S_MONTH-LOW.

ELSEIF S_MONTH-LOW = 0 AND S_MONTH-HIGH <> 0.

S_MONTH-LOW = S_MONTH-HIGH .

ENDIF.

CONCATENATE S_YEAR-LOW S_MONTH-LOW INTO L.

CONCATENATE S_YEAR-HIGH S_MONTH-HIGH INTO H.

C = L.

CONCATENATE S_YEAR-HIGH '00' INTO T.

  • WRITE T.

IF T > L.

TEMP = H - T .

S = S_YEAR-HIGH - 1.

CONCATENATE S '12' INTO T.

IF T > L.

  • s = YOURDATE-HIGH - 1.

CONCATENATE S '00' INTO T.

IF T > L.

TEMP = TEMP + 12 .

S = S - 1.

CONCATENATE S '12' INTO T.

IF T > L.

CONCATENATE S '00' INTO T.

IF T > L.

TEMP = TEMP + 12 .

ELSE.

TEMP = TEMP + ( 12 - S_MONTH-LOW ).

ENDIF.

ENDIF.

ELSE.

TEMP = TEMP + ( 12 - S_MONTH-LOW ).

ENDIF.

ENDIF.

ELSE.

TEMP = H - L.

ENDIF.

  • WRITE TEMP.

N = TEMP + 1.

DO N TIMES.

  • count = count + 1.

IF C GE L AND C LE H.

IF C+4(2) LE 12.

  • c = c + 1.

ELSE.

C0(4) = C0(4) + 1.

C+4(2) = '01'.

  • write c+2(2).

  • c = c + 1.

ENDIF.

CASE C+4(2).

WHEN '01'.

WRITE: 'jan', C+2(2).

concatenate 'jan' c+2(2) into t_data-moyr.

WHEN '02'.

WRITE: 'feb', C+2(2) .

WHEN '03'.

WRITE : 'mar', C+2(2) .

WHEN '04'.

WRITE : 'apr', C+2(2).

WHEN '05'.

WRITE : 'may', C+2(2).

WHEN '06'.

WRITE : 'jun', C+2(2).

WHEN '07'.

WRITE : 'jul', C+2(2).

WHEN '08'.

WRITE : 'aug', C+2(2).

WHEN '09'.

WRITE : 'sep', C+2(2).

WHEN '10'.

WRITE : 'oct', C+2(2).

WHEN '11'.

WRITE : 'nov', C+2(2).

WHEN '12'.

WRITE : 'dec', C+2(2).

ENDCASE.

*write count.

  • WRITE C+2(2).

C = C + 1.

ENDIF.

append t_data.

ENDDO.

Please Help me....

Thanks & regards

Nigesh

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Aug 17, 2007 at 02:49 PM

    Hello Migesh,

    you can get months b/w two dates using 'MM_ARRANG_SPMON_RANGE'...

    coming to your problem...

    refer the following code...

    report zssr_multi_cols.
     
    type-pools: slis.
     
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>.
     
    data: it_alvfc type slis_t_fieldcat_alv,
          wa_alvfc type slis_fieldcat_alv,
          it_fldcat type lvc_t_fcat,
          wa_fldcat type lvc_s_fcat.
     
    selection-screen begin of block b1 with frame title text-001.
    parameters: p_flds(5) type c.
    selection-screen end of block b1.
     
    start-of-selection.
     
    * build the dynamic internal table
      perform build_dyn_itab.
     
    * write 5 records to the alv grid
      do 5 times.
        perform build_report.
      enddo.
     
    * call the alv grid.
      perform call_alv.
     
     
    ************************************************************************
    *  Build_dyn_itab
    ************************************************************************
    form build_dyn_itab.
     
    * Create the dynamic internal table
      data: new_table type ref to data,
            new_line  type ref to data.
     
    * Create fields .
      do p_flds times.
        clear wa_fldcat.
        wa_fldcat-fieldname = sy-index.
        wa_fldcat-datatype  = 'CHAR'.
        wa_fldcat-intlen    = 5.
        append wa_fldcat to it_fldcat .
      enddo.
     
    * Create dynamic internal table and assign to FS
      call method cl_alv_table_create=>create_dynamic_table
                   exporting
                      it_fieldcatalog = it_fldcat
                   importing
                      ep_table        = new_table.
     
      assign new_table->* to <dyn_table>.
     
    * Create dynamic work area and assign to FS
      create data new_line like line of <dyn_table>.
      assign new_line->* to <dyn_wa>.
     
    endform.
     
    *********************************************************************
    *      Form  build_report
    *********************************************************************
    form build_report.
     
    * Fill some values into the dynamic internal table
     
      data: fieldname(20) type c.
      data: fieldvalue(5) type c.
      data: index(3) type c.
      field-symbols: <fs1>.
     
      do p_flds times.
     
        index = sy-index.
     
    * Set up fieldvalue
        concatenate 'FLD' index into
                 fieldvalue.
        condense   fieldvalue no-gaps.
     
        assign component  index  of structure <dyn_wa> to <fs1>.
        <fs1> =  fieldvalue.
     
      enddo.
     
    * Append to the dynamic internal table
      append <dyn_wa> to <dyn_table>.
     
     
    endform.
     
    ************************************************************************
    *  CALL_ALV
    ************************************************************************
    form call_alv.
     
    * Build FC for ALV
      loop at  it_fldcat into wa_fldcat.
        wa_alvfc-fieldname = wa_fldcat-fieldname.
        wa_alvfc-seltext_s = sy-tabix.
        wa_alvfc-outputlen = wa_fldcat-intlen.
        append wa_alvfc to it_alvfc.
      endloop.
     
    * Call ABAP List Viewer (ALV)
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                it_fieldcat = it_alvfc
           tables
                t_outtab    = <dyn_table>.
     
    endform.

    Reward If Useful.

    Regards

    --

    Sasidhar Reddy Matli.

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 17, 2007 at 03:01 PM

    You may want to look into using a dynamic internal table. Here is any example. Run this program and enter in the range 05/2006 - 07/2007 in the selection screen, the output will be an ALV which uses a dynamic internal table with the columns for all of the months within the range.

    
    report zrich_0001.
    
    type-pools: slis.
    
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>.
    
    data: it_alvfc type slis_t_fieldcat_alv,
          wa_alvfc type slis_fieldcat_alv,
          it_fldcat type lvc_t_fcat,
          wa_fldcat type lvc_s_fcat.
    
    data: xspbup type s001-spbup.
    
    selection-screen begin of block b1 with frame title text-001.
    select-options s_spbup for xspbup no-extension.
    selection-screen end of block b1.
    
    start-of-selection.
    
    * build the dynamic internal table
      perform build_dyn_itab.
    
    * Put some data into the table.
      perform build_report.
    
    * call the alv grid.
      perform call_alv.
    
    
    ************************************************************************
    *  Build_dyn_itab
    ************************************************************************
    form build_dyn_itab.
    
    * Create the dynamic internal table
      data: new_table type ref to data,
            new_line  type ref to data.
    
      clear wa_fldcat.
      wa_fldcat-fieldname = 'MATKL'.
      wa_fldcat-datatype  = 'CHAR'.
      wa_fldcat-intlen    = '9'.
      wa_fldcat-seltext  = 'Material Group'.
      append wa_fldcat to it_fldcat .
    
    * Create fields .
      do.
        if s_spbup-low > s_spbup-high.
          exit.
        endif.
    
        clear wa_fldcat.
        wa_fldcat-fieldname =  s_spbup-low.  " For formatting
        wa_fldcat-datatype  = 'INT4'.
        wa_fldcat-intlen    = '10'.
        write s_spbup-low to wa_fldcat-seltext.
        append wa_fldcat to it_fldcat .
    
    
        s_spbup-low = s_spbup-low + 1.
        if s_spbup-low+4(2) = '13'.
          s_spbup-low(4) = s_spbup-low(4) + 1.
          s_spbup-low+4(2) = '01'.
        endif.
    
    
      enddo.
    
    * Create dynamic internal table and assign to FS
      call method cl_alv_table_create=>create_dynamic_table
                   exporting
                      it_fieldcatalog = it_fldcat
                   importing
                      ep_table        = new_table.
    
      assign new_table->* to <dyn_table>.
    
    * Create dynamic work area and assign to FS
      create data new_line like line of <dyn_table>.
      assign new_line->* to <dyn_wa>.
    
    endform.
    
    *********************************************************************
    *      Form  build_report
    *********************************************************************
    form build_report.
    
    * Fill some values into the dynamic internal table
      field-symbols: <fs1>.
    
      do.
    * Do not do for first field.
        if sy-index = 1.
          continue.
        endif.
        assign component  sy-index  of structure <dyn_wa> to <fs1>.
        if sy-subrc <> 0.
          exit.
        endif.
        <fs1> = sy-index * 10..
      enddo.
    
    * Append to the dynamic internal table
      append <dyn_wa> to <dyn_table>.
    
    
    endform.
    
    ************************************************************************
    *  CALL_ALV
    ************************************************************************
    form call_alv.
    
    * Build FC for ALV
      loop at  it_fldcat into wa_fldcat.
        wa_alvfc-fieldname = wa_fldcat-fieldname.
        wa_alvfc-seltext_s = wa_fldcat-seltext.
        wa_alvfc-outputlen = wa_fldcat-intlen.
        append wa_alvfc to it_alvfc.
      endloop.
    
    * Call ABAP List Viewer (ALV)
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                it_fieldcat = it_alvfc
           tables
                t_outtab    = <dyn_table>.
    
    endform.
    
    
    
    

    Regards,

    Rich Heilman

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 17, 2007 at 02:52 PM

    Hello,

    Refer to this link...it shows how to create dynamic internal tables easily.

    http://www.saptechnical.com/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm

    Bye

    Gabriel

    Add comment
    10|10000 characters needed characters exceeded