Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Dyanamic Internal table

Former Member
0 Likes
554

Hi all ,

My internal table structure will be changing every time based on the input user inputs.Some times it may have 10 fields some times it may have 20 fields hope the only solution is using dynamic internal table .Can any one send me how to create dynamic internal table.

4 REPLIES 4
Read only

Former Member
0 Likes
499

Hi,

Check this Weblog by Rich.

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

Reward points if useful.

Regards,

Atish

Read only

Former Member
0 Likes
499

hi raghvendra ,

i had one report regarding dynamic itab,

just copy this code paste in your se38 report and debugg to know the functionality,

&----


*& Report ZMM_SUPP_FORE_R

*&

&----


*&

*&

&----


report zmm_supp_fore_r no standard page heading message-id zsmep.

&----


*&Purpose:

*& This report will provide a summary of the materials and their

*& associated forecast for a supplier.

*& Based upon the entered selection parameters, the report will display

*& a listing of the materials associated with the supplier for each

*& requirements exists. A single line will be provided for each material.

&----


*types declaration...

types: begin of t_tab_marc,

matnr type matnr,

werks type werks_d,

ekgrp type ekgrp.

types: end of t_tab_marc.

types: begin of t_tab_t024,

ekgrp type ekgrp,

eknam type eknam.

types: end of t_tab_t024.

types: begin of t_tab_globe,

matnr type matnr,

maktx type maktx,

ekgrp type ekgrp,

eknam type eknam,

pln_q type mng01,

sal_r type mng01,

pro_r type mng01.

types: end of t_tab_globe.

type-pools: slis.

field-symbols: <dyn_table> type standard table,

<dyn_wa>,

<fs1>.

*data statements declaration...

data: g_tab_marc type table of t_tab_marc,

g_wa_marc type t_tab_marc.

data: g_tab_t024 type table of t_tab_t024,

g_wa_t024 type t_tab_t024.

data: g_tab_globe type table of t_tab_globe,

g_wa_globe type t_tab_globe.

data: g_ven_name type lfa1-name1,

g_plant_name type t001w-name1.

data: g_tab_mt61d type table of mt61d,

g_wa_mt61d type mt61d,

g_crpes like crpes,

g_pastdue type mdps-mng01.

data: "g_wa_globe TYPE ty_final_s,

gv_vendor type lfa1-name1,

gv_plant type t001w-name1,

gv_period,

gv_perhdr type dd03p-reptext,

gv_count type i,

gv_lastwk type kweek,

gv_frstwk type kweek,

gv_frstqt type kweek,

gv_lastqt type kweek,

gv_pastdue type mdps-mng01.

data: i_fromdate type sydatum.

data: i_mdkex type table of mdke.

data: s_date type range of sy-datum,

s_date_line like line of s_date.

data: report type sy-repid,

l_pos type i,

l_tab_fieldcatlog type slis_t_fieldcat_alv,

lt_fieldcatlog type table of lvc_s_fcat,

wa_fieldcat type lvc_s_fcat,

l_list_top_of_page type slis_t_listheader,

g_variant like disvariant,

g_events type slis_t_event.

data: l_wa_fieldcatlog type slis_fieldcat_alv.

data: l_tab_mdke type table of mdke,

l_wa_mdke type mdke,

l_tab_mdpsx type table of mdps with header line,

l_wa_mdpsx type mdps.

*constants declaration...

constants: c_top_of_page type slis_formname value 'TOP_OF_PAGE',

c_formname_top_of_page type slis_formname value 'TOP_OF_PAGE'.

*selection-screen declaration...

selection-screen: begin of block b1 with frame title text-001,

begin of block b2 with frame.

parameters: p_lifnr type lfa1-lifnr obligatory,

p_werks type marc-werks obligatory.

selection-screen begin of line.

selection-screen comment 1(20) for field p_fromdt.

selection-screen position 31.

parameters : p_fromdt type sy-datum obligatory.

selection-screen position 50.

selection-screen comment 50(10) for field p_todt.

parameters : p_todt type sy-datum obligatory.

selection-screen end of line.

selection-screen:end of block b2,

begin of block b3 with frame title text-002.

parameters: p_qua radiobutton group gr,

p_mon radiobutton group gr,

p_wee radiobutton group gr.

selection-screen:end of block b3,

end of block b1.

at selection-screen.

if p_fromdt gt p_todt.

message e123(zsmep).

endif.

*start-of-selection event...

start-of-selection.

*call function module md_selection_mdkp...

perform call_fm_mdkp.

*get the header details...

perform head_dtls.

*move to the GLOBE table...

perform move_globe_itab.

*calculating quantity and requirements...

  • PERFORM calc_quan.

*END-OF-SELECTION.

*header details of the alv grid....

  • PERFORM build_eventcatalog USING g_events[].

perform build_comment using l_list_top_of_page[].

*display the output in alv grid...

perform alv_grid.

&----


*& Form call_fm_mdkp

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form call_fm_mdkp .

call function 'MD_SELECTION_MDKP'

exporting

iwerks = p_werks

  • IBERID =

  • IDISPO =

ilifnr = p_lifnr

  • IMPOBJ =

  • IMAOBJ =

  • DISPLAY_LIST_MDKEX =

tables

mdkex = l_tab_mdke .

if not l_tab_mdke[] is initial.

  • fetch the data from marc....

select matnr

werks

ekgrp

from marc

into table g_tab_marc

for all entries in l_tab_mdke

where

matnr = l_tab_mdke-matnr

and

werks = p_werks.

  • fetch the data from t024....

select ekgrp

eknam

from t024

into table g_tab_t024

for all entries in g_tab_marc

where

ekgrp = g_tab_marc-ekgrp.

endif.

endform. " call_fm_mdkp

&----


*& Form head_dtls

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form head_dtls .

select single name1 from lfa1

into g_ven_name

where

lifnr = p_lifnr.

select single name1 from t001w

into g_plant_name

where

werks = p_werks.

endform. " head_dtls

&----


*& Form move_globe_itab

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form move_globe_itab .

loop at l_tab_mdke into l_wa_mdke .

move: l_wa_mdke-matnr to g_wa_globe-matnr,

l_wa_mdke-maktx to g_wa_globe-maktx.

read table g_tab_marc into g_wa_marc with key matnr = l_wa_mdke-matnr.

if sy-subrc eq 0.

move g_wa_marc-ekgrp to g_wa_globe-ekgrp.

endif.

read table g_tab_t024 into g_wa_t024 with key ekgrp = g_wa_globe-ekgrp.

if sy-subrc eq 0.

move g_wa_t024-eknam to g_wa_globe-eknam.

endif.

append g_wa_globe to g_tab_globe.

clear: g_wa_t024,g_wa_mt61d,g_wa_globe.

endloop.

endform. " move_globe_itab

&----


*& Form alv_grid

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form alv_grid .

perform call_fieldcat.

  • calculating quantity and requirements...

perform calc_quan.

perform call_alv_grid.

endform. " alv_grid

&----


*& Form build_fieldcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form call_fieldcat .

perform build_catlog using l_pos 'G_TAB_GLOBE' 'MATNR' '18' text-010.

perform build_catlog using l_pos 'G_TAB_GLOBE' 'MAKTX' '40' text-011.

perform build_catlog using l_pos 'G_TAB_GLOBE' 'EKGRP' '10' text-012.

perform build_catlog using l_pos 'G_TAB_GLOBE' 'EKNAM' '20' text-013.

perform build_catlog using l_pos 'G_TAB_GLOBE' 'PLN_Q' '10' text-014.

perform dyn_column.

perform build_report.

loop at lt_fieldcatlog into wa_fieldcat .

move-corresponding wa_fieldcat to l_wa_fieldcatlog.

move wa_fieldcat-reptext to l_wa_fieldcatlog-reptext_ddic.

append l_wa_fieldcatlog to l_tab_fieldcatlog.

endloop.

endform. " build_fieldcat

&----


*& Form build_catlog

&----


  • text

----


  • -->P_L_POS text

  • -->P_0439 text

  • -->P_0440 text

  • -->P_0441 text

  • -->P_TEXT_010 text

----


form build_catlog using u_pos type any

value(u_0439) type any

value(u_0440) type any

value(u_0441) type any

u_text type any.

add 1 to u_pos.

if u_0440 eq 'MATNR' .

wa_fieldcat-hotspot = 'X' .

wa_fieldcat-key = 'X' .

else.

clear: wa_fieldcat-hotspot, wa_fieldcat-key .

endif.

  • wa_fieldcat-col_pos = u_pos.

wa_fieldcat-tabname = u_0439.

wa_fieldcat-fieldname = u_0440.

wa_fieldcat-outputlen = u_0441.

wa_fieldcat-reptext = u_text.

append wa_fieldcat to lt_fieldcatlog.

endform. " build_catlog

&----


*& Form call_alv_grid

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form call_alv_grid .

  • DATA: l_wa_events LIKE LINE OF g_events.

  • CLEAR: g_events.

  • l_wa_events-name = slis_ev_top_of_page.

  • l_wa_events-form = 'TOP_OF_PAGE'.

  • APPEND l_wa_events TO g_events.

report = sy-repid.

if <dyn_table>[] is initial.

message i024(zsmep).

else.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

i_callback_program = report

  • I_CALLBACK_PF_STATUS_SET = ' '

i_callback_user_command = 'USER_COMMAND'

i_callback_top_of_page = 'TOP_OF_PAGE'

  • i_callback_html_top_of_page = 'TOP_OF_PAGE'

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

  • IS_LAYOUT =

it_fieldcat = l_tab_fieldcatlog[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

i_save = 'X'

is_variant = g_variant

  • it_events = g_events[]

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • I_HTML_HEIGHT_TOP = 0

  • I_HTML_HEIGHT_END = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • IR_SALV_FULLSCREEN_ADAPTER =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

tables

t_outtab = <dyn_table>

exceptions

program_error = 1

others = 2

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

endif.

endform. " call_alv_grid

&----


*& Form TOP_OF_PAGE

&----


  • text

----


form top_of_page .

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

i_logo = 'ENJOYSAP_LOGO'

it_list_commentary = l_list_top_of_page.

endform. "TOP_OF_PAGE

&----


*& Form build_comment

&----


  • text

----


  • -->P_G_LIST_TOP_OF_PAGE[] text

----


form build_comment using pc_top_of_page type slis_t_listheader.

data: l_line type slis_listheader,

l_vendornum type string,

l_vendorname type string,

l_plant type string.

refresh pc_top_of_page.

clear l_line.

concatenate 'Vendor:' p_lifnr into l_vendornum

separated by space.

l_line-typ = 'S'.

l_line-info = l_vendornum.

append l_line to pc_top_of_page.

concatenate 'Name:' g_ven_name into l_vendorname

separated by space.

clear l_line.

l_line-typ = 'S'.

l_line-info = l_vendorname.

append l_line to pc_top_of_page.

concatenate 'Plant:' p_werks l_plant into l_plant

separated by space.

clear l_line.

l_line-typ = 'S'.

l_line-info = l_plant.

append l_line to pc_top_of_page.

clear l_line.

l_line-typ = 'S'.

l_line-info = 'S.R: Sales Requirements'.

append l_line to pc_top_of_page.

clear l_line.

l_line-typ = 'S'.

l_line-info = 'P.R: Production Requirements'.

append l_line to pc_top_of_page.

endform. " build_comment

&----


*& Form build_eventcatalog

&----


  • text

----


  • -->P_G_EVENTS[] text

----


form build_eventcatalog using pc_events type slis_t_event.

data: l_events type slis_alv_event.

call function 'REUSE_ALV_EVENTS_GET'

exporting

i_list_type = 0

importing

et_events = pc_events.

read table pc_events with key name = c_top_of_page

into l_events.

if sy-subrc = 0.

move c_formname_top_of_page to l_events-form.

  • MODIFY pc_events FROM l_events INDEX sy-tabix.

append l_events to pc_events.

endif.

endform. " build_eventcatalog

&----


*& Form user_command

&----


  • text

----


  • -->UCOMM text

  • -->SELFIELD text

----


form user_command using ucomm like sy-ucomm

selfield type slis_selfield.

data: p_prreg type t158-prreg,

l_matnr type matnr.

p_prreg = 'ZN'.

read table <dyn_table> into <dyn_wa> index selfield-tabindex.

l_matnr = <dyn_wa>.

  • HIDE p_werks.

check sy-subrc = 0.

case ucomm.

when '&IC1'.

if selfield-fieldname = 'MATNR'.

set parameter id 'MAT' field l_matnr.

set parameter id 'WRK' field p_werks.

call transaction 'MD04' and skip first screen.

endif.

endcase.

endform. "USER_COMMAND

&----


*& Form dyn_column

&----


  • text

----


form dyn_column.

data: lv_monate type f,

lv_month(2),

lv_year(4),

lv_quart(2).

if not p_wee is initial.

call function 'DATE_GET_WEEK'

exporting

  • date = p_enddat

date = p_todt

importing

week = gv_lastwk.

call function 'DATE_GET_WEEK'

exporting

  • date = i_fromdate

date = p_fromdt

importing

week = gv_frstwk.

elseif not p_mon is initial.

call function 'MONTHS_BETWEEN_TWO_DATES'

exporting

    • i_datum_bis = p_enddat

    • i_datum_von = i_fromdate

i_datum_bis = p_todt

i_datum_von = p_fromdt

i_kz_incl_bis = ' '

importing

e_monate = lv_monate.

gv_count = lv_monate.

else.

    • lv_month = i_fromdate+4(2).

    • lv_year = i_fromdate+0(4).

lv_month = p_fromdt+4(2).

lv_year = p_fromdt+0(4).

case lv_month.

when '01' or '02' or '03'.

lv_quart = '01'.

when '04' or '05' or '06'.

lv_quart = '02'.

when '07' or '08' or '09'.

lv_quart = '03'.

when others.

lv_quart = '04'.

endcase.

concatenate lv_year lv_quart into gv_frstqt.

    • lv_month = p_enddat+4(2).

    • lv_year = p_enddat+0(4).

lv_month = p_todt+4(2).

lv_year = p_todt+0(4).

case lv_month.

when '01' or '02' or '03'.

lv_quart = '01'.

when '04' or '05' or '06'.

lv_quart = '02'.

when '07' or '08' or '09'.

lv_quart = '03'.

when others.

lv_quart = '04'.

endcase.

concatenate lv_year lv_quart into gv_lastqt.

endif.

if not p_qua is initial.

gv_period = 'Q'.

elseif not p_mon is initial.

gv_period = 'M'.

else.

gv_period = 'W'.

endif.

i_fromdate = p_fromdt.

endform. " dyn_column

&----


*& Form build_report

&----


  • text

----


form build_report .

data: index(3) type c.

data: lv_fromdate type sy-datum,

lv_todate type sy-datum.

data: lv_strtper(2) type c.

data: lv_strtyear(4) type c,

lv_count type i,

lv_frstwk type kweek,

lv_frstqt type kweek,

l_wa_fieldcatlog type lvc_s_fcat,

new_line type ref to data,

new_table type ref to data.

  • CLEAR g_wa_globe.

clear lv_fromdate.

move i_fromdate to lv_fromdate.

if not p_mon is initial.

call function 'RP_CALC_DATE_IN_INTERVAL'

exporting

date = lv_fromdate

days = '00'

months = '01'

signum = '-'

years = '00'

importing

calc_date = lv_fromdate.

add 1 to gv_count.

do gv_count times.

call function 'RP_CALC_DATE_IN_INTERVAL'

exporting

date = lv_fromdate

days = '00'

months = '01'

signum = '+'

years = '00'

importing

calc_date = lv_fromdate.

move lv_fromdate+4(2) to lv_strtper.

move lv_fromdate+0(4) to lv_strtyear.

do 2 times.

index = sy-index.

clear l_wa_fieldcatlog.

lv_count = index mod 2.

if lv_count = 1.

concatenate 'SR' '_' gv_period lv_strtper '_' lv_strtyear into l_wa_fieldcatlog-fieldname .

concatenate lv_strtper '/' lv_strtyear into l_wa_fieldcatlog-reptext.

concatenate 'S.R' gv_period l_wa_fieldcatlog-reptext

into l_wa_fieldcatlog-reptext separated by space.

else.

concatenate 'PR' '_' gv_period lv_strtper '_' lv_strtyear into l_wa_fieldcatlog-fieldname .

concatenate lv_strtper '/' lv_strtyear into l_wa_fieldcatlog-reptext.

concatenate 'P.R' gv_period l_wa_fieldcatlog-reptext

into l_wa_fieldcatlog-reptext separated by space.

endif.

condense l_wa_fieldcatlog-fieldname no-gaps.

l_wa_fieldcatlog-datatype = 'CHAR'.

l_wa_fieldcatlog-intlen = 16.

l_wa_fieldcatlog-outputlen = 14.

append l_wa_fieldcatlog to lt_fieldcatlog.

enddo.

enddo.

elseif not p_wee is initial.

clear gv_count.

lv_frstwk = gv_frstwk.

  • lv_frstwk = lv_frstwk - 1.

do.

add 1 to gv_count.

move lv_frstwk+4(2) to lv_strtper.

move lv_frstwk+0(4) to lv_strtyear.

do 2 times.

index = sy-index.

clear l_wa_fieldcatlog.

lv_count = index mod 2.

if lv_count = 1.

concatenate 'SR' '_' gv_period lv_strtper '_' lv_strtyear into l_wa_fieldcatlog-fieldname .

concatenate lv_strtper '/' lv_strtyear into l_wa_fieldcatlog-reptext.

concatenate 'S.R' gv_period l_wa_fieldcatlog-reptext

into l_wa_fieldcatlog-reptext separated by space.

else.

concatenate 'PR' '_' gv_period lv_strtper '_' lv_strtyear into l_wa_fieldcatlog-fieldname .

concatenate lv_strtper '/' lv_strtyear into l_wa_fieldcatlog-reptext.

concatenate 'P.R' gv_period l_wa_fieldcatlog-reptext

into l_wa_fieldcatlog-reptext separated by space.

endif.

condense l_wa_fieldcatlog-fieldname no-gaps.

l_wa_fieldcatlog-datatype = 'CHAR'.

l_wa_fieldcatlog-intlen = 16.

l_wa_fieldcatlog-outputlen = 14.

append l_wa_fieldcatlog to lt_fieldcatlog.

enddo.

if lv_frstwk = gv_lastwk.

exit.

endif.

call function 'NEXT_WEEK'

exporting

current_week = lv_frstwk

importing

next_week = lv_frstwk

monday = lv_fromdate

sunday = lv_todate.

enddo.

else.

clear gv_count.

lv_frstqt = gv_frstqt - 1.

do.

add 1 to gv_count.

add 1 to lv_frstqt.

if lv_frstqt+4(2) > 4.

lv_frstqt0(4) = lv_frstqt0(4) + 1.

lv_frstqt+4(2) = 1.

endif.

move lv_frstqt+4(2) to lv_strtper.

move lv_frstqt+0(4) to lv_strtyear.

do 2 times.

index = sy-index.

clear l_wa_fieldcatlog.

lv_count = index mod 2.

if lv_count = 1.

concatenate 'SR' '_' gv_period lv_strtper '_' lv_strtyear into l_wa_fieldcatlog-fieldname .

concatenate lv_strtper '/' lv_strtyear into l_wa_fieldcatlog-reptext.

concatenate 'S.R' gv_period l_wa_fieldcatlog-reptext

into l_wa_fieldcatlog-reptext separated by space.

else.

concatenate 'PR' '_' gv_period lv_strtper '_' lv_strtyear into l_wa_fieldcatlog-fieldname .

concatenate lv_strtper '/' lv_strtyear into l_wa_fieldcatlog-reptext.

concatenate 'P.R' gv_period l_wa_fieldcatlog-reptext

into l_wa_fieldcatlog-reptext separated by space.

endif.

condense l_wa_fieldcatlog-fieldname no-gaps.

l_wa_fieldcatlog-datatype = 'CHAR'.

l_wa_fieldcatlog-intlen = 16.

l_wa_fieldcatlog-outputlen = 14.

append l_wa_fieldcatlog to lt_fieldcatlog.

enddo.

if lv_frstqt = gv_lastqt.

exit.

endif.

enddo.

endif.

  • Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = lt_fieldcatlog

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. " build_report

&----


*& Form calc_quan

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form calc_quan .

data: e_matnr type rm61r-matnr,

e_werks type rm61r-werks,

e_crpes type crpes,

i_mt61d type mt61d,

t_mdpsx type standard table of mdps with header line,

lv_begdt type sy-datum,

lv_enddt type sy-datum,

lv_curyr(4),

lv_currper(2),

lv_fname1 type lvc_fname,

lv_fname2 type lvc_fname,

index type sy-index,

lv_count type i,

lv_fromdate type sy-datum,

lv_frstwk type kweek,

lv_frstqt type kweek.

data: l_index type i.

loop at g_tab_globe into g_wa_globe.

clear lv_fromdate.

call function 'RP_CALC_DATE_IN_INTERVAL'

exporting

date = i_fromdate

days = '00'

months = '01'

signum = '-'

years = '00'

importing

calc_date = lv_fromdate.

lv_frstwk = gv_frstwk.

*BEGIN OF KKUMAR 01.17.2007

call function 'LAST_WEEK'

exporting

current_week = lv_frstwk

importing

last_week = lv_frstwk.

*END OF KKUMAR 01.17.2007

lv_frstqt = gv_frstqt - 1.

clear l_index.

l_index = sy-tabix.

clear: e_matnr,

e_werks,

i_mt61d,

t_mdpsx.

refresh: t_mdpsx.

e_matnr = g_wa_globe-matnr.

e_werks = p_werks.

call function 'MD_ABBL_REPORTING'

exporting

ematnr = e_matnr

ewerks = e_werks

ecrpes = e_crpes

importing

imt61d = i_mt61d

tables

mdpsx = t_mdpsx

exceptions

error_matmaster = 1

others = 2.

if sy-subrc <> 0.

endif.

loop at t_mdpsx where dat00 < sy-datum.

case t_mdpsx-delkz.

when 'AR'.

if t_mdpsx-plumi = '-'.

gv_pastdue = gv_pastdue - t_mdpsx-mng01.

else.

gv_pastdue = gv_pastdue + t_mdpsx-mng01.

endif.

when 'VC' or 'VE' or 'VI' or 'VJ'.

if t_mdpsx-plumi = '-'.

gv_pastdue = gv_pastdue - t_mdpsx-mng01.

else.

gv_pastdue = gv_pastdue + t_mdpsx-mng01.

endif.

endcase.

endloop.

clear: t_mdpsx, g_wa_globe-pln_q.

loop at t_mdpsx where dat00 le p_todt and delkz = 'WB'.

if t_mdpsx-plumi = '-'.

g_wa_globe-pln_q = g_wa_globe-pln_q - t_mdpsx-mng01.

else.

g_wa_globe-pln_q = g_wa_globe-pln_q + t_mdpsx-mng01.

endif.

endloop.

assign component 'MATNR' of structure <dyn_wa> to <fs1>.

<fs1> = g_wa_globe-matnr.

assign component 'MAKTX' of structure <dyn_wa> to <fs1>.

<fs1> = g_wa_globe-maktx.

assign component 'EKGRP' of structure <dyn_wa> to <fs1>.

<fs1> = g_wa_globe-ekgrp.

assign component 'EKNAM' of structure <dyn_wa> to <fs1>.

<fs1> = g_wa_globe-eknam.

  • ASSIGN COMPONENT 'PAST_DUE' OF STRUCTURE <dyn_wa> TO <fs1>.

  • <fs1> = gv_pastdue.

  • CLEAR gv_pastdue.

assign component 'PLN_Q' of structure <dyn_wa> to <fs1>.

<fs1> = g_wa_globe-pln_q.

do gv_count times.

if not p_mon is initial.

call function 'RP_CALC_DATE_IN_INTERVAL'

exporting

date = lv_fromdate

days = '00'

months = '01'

signum = '+'

years = '00'

importing

calc_date = lv_fromdate.

move lv_fromdate+4(2) to lv_currper.

move lv_fromdate+0(4) to lv_curyr.

concatenate lv_curyr lv_currper '01' into lv_begdt.

concatenate lv_curyr lv_currper '31' into lv_enddt.

elseif not p_wee is initial.

call function 'NEXT_WEEK'

exporting

current_week = lv_frstwk

importing

next_week = lv_frstwk

monday = lv_begdt

sunday = lv_enddt.

move lv_frstwk+4(2) to lv_currper.

move lv_frstwk+0(4) to lv_curyr.

else.

add 1 to lv_frstqt.

if lv_frstqt+4(2) > 4.

lv_frstqt0(4) = lv_frstqt0(4) + 1.

lv_frstqt+4(2) = 1.

endif.

move lv_frstqt+4(2) to lv_currper.

move lv_frstqt+0(4) to lv_curyr.

case lv_currper.

when '01'.

concatenate lv_curyr '01' '01' into lv_begdt.

concatenate lv_curyr '03' '31' into lv_enddt.

when '02'.

concatenate lv_curyr '04' '01' into lv_begdt.

concatenate lv_curyr '06' '31' into lv_enddt.

when '03'.

concatenate lv_curyr '07' '01' into lv_begdt.

concatenate lv_curyr '09' '31' into lv_enddt.

when others.

concatenate lv_curyr '10' '01' into lv_begdt.

concatenate lv_curyr '12' '31' into lv_enddt.

endcase.

endif.

clear: lv_fname1, lv_fname2.

clear t_mdpsx.

loop at t_mdpsx where

dat00 <= lv_enddt and dat00 >= lv_begdt.

***Need to write logic for summarizing the quantity totals

case t_mdpsx-delkz.

***Production Orders

when 'AR'.

if t_mdpsx-plumi = '-'.

g_wa_globe-pro_r = g_wa_globe-pro_r - t_mdpsx-mng01.

else.

g_wa_globe-pro_r = g_wa_globe-pro_r + t_mdpsx-mng01.

endif.

***Sales Order

when 'VC' or 'VE' or 'VI' or 'VJ'.

if t_mdpsx-plumi = '-'.

g_wa_globe-sal_r = g_wa_globe-sal_r - t_mdpsx-mng01.

else.

g_wa_globe-sal_r = g_wa_globe-sal_r + t_mdpsx-mng01.

endif.

endcase.

endloop.

do 2 times.

index = sy-index.

lv_count = index mod 2.

if lv_count = 1.

concatenate 'SR' '_' gv_period lv_currper '_' lv_curyr into lv_fname1 .

else.

concatenate 'PR' '_' gv_period lv_currper '_' lv_curyr into lv_fname2 .

endif.

condense lv_fname1 no-gaps.

condense lv_fname2 no-gaps.

enddo.

assign component lv_fname1 of structure <dyn_wa> to <fs1>.

<fs1> = g_wa_globe-sal_r.

assign component lv_fname2 of structure <dyn_wa> to <fs1>.

<fs1> = g_wa_globe-pro_r.

clear: g_wa_globe-pln_q, g_wa_globe-sal_r, g_wa_globe-pro_r.

enddo.

append <dyn_wa> to <dyn_table>.

clear g_wa_globe.

endloop.

endform. " calc_quan

reward points if helpful,

regards,

seshu.

Read only

Former Member
0 Likes
499

Hi,

  type-pools : abap. 
  field-symbols: <dyn_table> type standard table, 
               <dyn_wa>, 
               <dyn_field>. 
  data: dy_table type ref to data, 
      dy_line  type ref to data, 
      xfc type lvc_s_fcat, 
      ifc type lvc_t_fcat. 
  selection-screen begin of block b1 with frame. 
parameters: p_table(30) type c default 'T001'. 
selection-screen end of block b1. 
  start-of-selection. 
    perform get_structure. 
  perform create_dynamic_itab.      **********Creates a dyanamic internal table********** 
  perform get_data. 
  perform write_out. 
  form get_structure. 
  data : idetails type abap_compdescr_tab, 
       xdetails type abap_compdescr. 
  data : ref_table_des type ref to cl_abap_structdescr. 
  * Get the structure of the table. 
  ref_table_des ?=  
      cl_abap_typedescr=>describe_by_name( p_table ). 
  idetails[] = ref_table_des->components[]. 
    loop at idetails into xdetails. 
    clear xfc. 
    xfc-fieldname = xdetails-name . 
    xfc-datatype = xdetails-type_kind. 
    xfc-inttype = xdetails-type_kind. 
    xfc-intlen = xdetails-length. 
    xfc-decimals = xdetails-decimals. 
    append xfc to ifc. 
  endloop. 
  endform. 
  form create_dynamic_itab. 
  * Create dynamic internal table and assign to FS 
  call method cl_alv_table_create=>create_dynamic_table 
               exporting 
                  it_fieldcatalog = ifc 
               importing 
                  ep_table        = dy_table. 
    assign dy_table->* to <dyn_table>. 
  * Create dynamic work area and assign to FS 
  create data dy_line like line of <dyn_table>. 
  assign dy_line->* to <dyn_wa>. 
  endform. 
    
  form get_data. 
  * Select Data from table. 
  select * into table <dyn_table> 
             from (p_table). 
  endform. 
   Write out data from table. 
  loop at <dyn_table> into <dyn_wa>. 
    do. 
      assign component  sy-index   
         of structure <dyn_wa> to <dyn_field>. 
      if sy-subrc <> 0. 
        exit. 
      endif. 
      if sy-index = 1. 
        write:/ <dyn_field>. 
      else. 
        write: <dyn_field>. 
      endif. 
    enddo. 
  endloop.

Regards

Sudheer

Read only

Former Member
0 Likes
499

Show you an example:

*****DATA DECLARATION****************************

FIELD-SYMBOLS : <it_final> TYPE STANDARD TABLE,

<wa_final> TYPE ANY,

<w_field> TYPE ANY.

**DYNAMIC CREATION OF FIELDCATALOG***************

*FIRST 2 FIELDS FIELDS FIELD1 AND FIELD2 ARE CONSTANT, FIELDS OBTAINED IN THE LOOP ENDLOOP ARE DYNAMIC,

*LIKEWISE DYNAMIC FIELDCATALOG IS CREATED

wa_fieldcatalog-fieldname = 'FIELD1'.

wa_fieldcatalog-ref_table = 'E070'.

wa_fieldcatalog-outputlen = '13'.

wa_fieldcatalog-reptext = 'Created On'.

wa_fieldcatalog-seltext = 'Created On'.

APPEND wa_fieldcatalog TO it_fieldcatalog.

CLEAR wa_fieldcatalog.

wa_fieldcatalog-fieldname = 'FIELD1'.

wa_fieldcatalog-ref_table = 'E070'.

wa_fieldcatalog-outputlen = '13'.

wa_fieldcatalog-reptext = 'Created On'.

wa_fieldcatalog-seltext = 'Created On'.

APPEND wa_fieldcatalog TO it_fieldcatalog.

CLEAR wa_fieldcatalog.

LOOP AT it_mandt WHERE mandt IN s_mandt.

CONCATENATE 'CLNT' it_mandt INTO wa_fieldcatalog-fieldname.

wa_fieldcatalog-inttype = 'NUMC'. wa_fieldcatalog-DECIMALS = 3. " <-----THIS IS IMPORTANT!!!

wa_fieldcatalog-outputlen = '14'.

wa_fieldcatalog-reptext = it_mandt.

wa_fieldcatalog-seltext = it_mandt.

APPEND wa_fieldcatalog TO it_fieldcatalog.

CLEAR :wa_fieldcatalog ,it_mandt.

ENDLOOP.

*******CREATE DYNAMIC TABLE***********************

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcatalog

IMPORTING

ep_table = new_table

EXCEPTIONS

generate_subpool_dir_full = 1

OTHERS = 2.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ASSIGN new_table->* TO <it_final>.

********CREATE WORK AREA***************************

CREATE DATA new_line LIKE LINE OF <it_final>.

ASSIGN new_line->* TO <wa_final>.

********INSERTTING WORK AREAR TO INTERNAL TABLE*****

INSERT <wa_final> INTO TABLE <it_final>.

******POPULATING DATA******************************

LOOP.

ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_final> TO <w_field>.

<w_field> = '12345'.

ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_final> TO <w_field>.

<w_field> = '21453DD'.

FIELD1 AND FIELD2 ARE COMPONENTS OF FIELDCATALOG.

ENDLOOP.

regards,

huch.