Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

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

Tags:
Former Member
Former Member replied

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.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question