Skip to Content
0
Former Member
Jul 02, 2006 at 08:13 PM

dynamic table (rich blog)

86 Views

there is a alv dynamic wrote by rich.

now i need to add mslb-lblab too.

the title will be the number of lifnr and the data is

mslb-lblab

any suggest thanks.

report zrich_0002 .

type-pools: slis.

tables: mard, t023t, marc,makt, mara, t001l,mdbs, vbup,vbfa,mvke,

vbep, vbap, vbak.

field-symbols: <dyn_table> type standard table,

<dyn_wa>.

data: alv_fldcat type slis_t_fieldcat_alv,

it_fldcat type lvc_t_fcat,

wa_it_fldcat type lvc_s_fcat.

*data: imard type table of mard with header line.

data: begin of imard occurs 0,

werks like marc-werks,

matkl like t023t-matkl,

matnr like ekpo-matnr,

lgort like mard-lgort,

labst like mard-labst,

diskz like mard-diskz,

insme like mard-insme,

wgbez like t023t-wgbez,

meins like mara-meins,

speme like mard-speme,

retme like mard-retme,

umlme like mard-umlme,

  • werks LIKE mard-werks,

maktx like makt-maktx,

eislo like marc-eislo,

end of imard.

select-options: matnr for mara-matnr matchcode object mat1,

werks for mard-werks, " MATCHCODE OBJECT t001w,

lgort for mard-lgort, " MATCHCODE OBJECT tl001,

mtart for mara-mtart, "MATCHCODE OBJECT mara,

matkl for mara-matkl." MATCHCODE OBJECT mara.

start-of-selection.

select mardeinme mardinsme mardlabst mardmatnr mard~retme

mardspeme mardumlme mardwerks maramatnr mara~meins

maktmaktx maktmatnr marceislo marcmatnr mard~lgort

mard~werks

into (mard-einme , mard-insme , mard-labst , mard-matnr , mard-retme

, mard-speme , mard-umlme , mard-werks , mara-matnr , mara-meins

, makt-maktx , makt-matnr , marc-eislo , marc-matnr , mard-lgort

, mard-werks

)

from ( mard

inner join mara

on maramatnr = mardmatnr

inner join makt

on maktmatnr = maramatnr

inner join marc

on marcmatnr = maktmatnr )

where mara~matnr in matnr

and mard~werks in werks

and mard~lgort in lgort

and mara~mtart in mtart

and mara~matkl in matkl

and makt~spras = 'B'.

if sy-subrc = 0.

move mard-einme to imard-insme.

move mard-insme to imard-insme.

move mard-labst to imard-labst.

shift mard-matnr left deleting leading '0'.

move mard-matnr to imard-matnr.

move mard-retme to imard-retme.

move mard-speme to imard-speme.

move mard-umlme to imard-umlme.

move mard-werks to imard-werks.

move mara-matnr to imard-matnr.

move mara-meins to imard-meins.

move makt-maktx to imard-maktx.

move makt-matnr to imard-matnr.

move marc-eislo to imard-eislo.

move marc-matnr to imard-matnr.

move mard-lgort to imard-lgort.

append imard.

endif.

endselect.

delete adjacent duplicates from imard.

  • select * into table imard from mard

  • where matnr = p_matnr

  • and werks = p_werks.

  • build the dynamic internal table

perform build_dyn_itab.

perform build_report.

  • call the alv grid.

perform call_alv.

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

  • Build_dyn_itab

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

form build_dyn_itab.

data: new_table type ref to data,

new_line type ref to data,

tot_lines type i.

clear wa_it_fldcat.

wa_it_fldcat-fieldname = 'MATNR'.

wa_it_fldcat-datatype = 'CHAR'.

wa_it_fldcat-seltext = 'Material Number'.

wa_it_fldcat-intlen = 25.

append wa_it_fldcat to it_fldcat .

clear wa_it_fldcat.

wa_it_fldcat-fieldname = 'WERKS'.

wa_it_fldcat-datatype = 'CHAR'.

wa_it_fldcat-seltext = 'Plant'.

wa_it_fldcat-intlen = 4.

append wa_it_fldcat to it_fldcat .

loop at imard.

  • Check that the field hasn't been already addd to the fieldcat.

concatenate 'LABST' imard-lgort into wa_it_fldcat-fieldname.

read table it_fldcat into wa_it_fldcat

with key fieldname = wa_it_fldcat-fieldname.

check sy-subrc <> 0.

clear wa_it_fldcat.

  • concatenate 'LGORT' imard-lgort into

  • wa_it_fldcat-fieldname.

  • wa_it_fldcat-datatype = 'CHAR'.

  • wa_it_fldcat-seltext = wa_it_fldcat-fieldname.

  • wa_it_fldcat-intlen = 4.

  • append wa_it_fldcat to it_fldcat .

clear wa_it_fldcat.

concatenate 'LABST' imard-lgort into

wa_it_fldcat-fieldname.

wa_it_fldcat-datatype = 'QUAN'.

wa_it_fldcat-seltext = wa_it_fldcat-fieldname.

wa_it_fldcat-intlen = 15.

append wa_it_fldcat to it_fldcat .

clear wa_it_fldcat.

concatenate 'INSME' imard-lgort into

wa_it_fldcat-fieldname.

wa_it_fldcat-datatype = 'QUAN'.

wa_it_fldcat-seltext = wa_it_fldcat-fieldname.

wa_it_fldcat-intlen = 15.

append wa_it_fldcat to it_fldcat .

clear wa_it_fldcat.

concatenate 'RETME' imard-lgort into

wa_it_fldcat-fieldname.

wa_it_fldcat-datatype = 'QUAN'.

wa_it_fldcat-seltext = wa_it_fldcat-fieldname.

wa_it_fldcat-intlen = 15.

append wa_it_fldcat to it_fldcat .

clear wa_it_fldcat.

concatenate 'UMLME' imard-lgort into

wa_it_fldcat-fieldname.

wa_it_fldcat-datatype = 'QUAN'.

wa_it_fldcat-seltext = wa_it_fldcat-fieldname.

wa_it_fldcat-intlen = 15.

append wa_it_fldcat to it_fldcat .

clear wa_it_fldcat.

concatenate 'SPEME' imard-lgort into

wa_it_fldcat-fieldname.

wa_it_fldcat-datatype = 'QUAN'.

wa_it_fldcat-seltext = wa_it_fldcat-fieldname.

wa_it_fldcat-intlen = 15.

append wa_it_fldcat to it_fldcat .

endloop.

  • 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.

data: fieldname(20) type c.

data: fieldvalue(5) type c.

data: index(3) type c.

field-symbols: <fs1>.

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

  • call function 'CONVERSION_EXIT_MATN1_OUTPUT'

  • exporting

  • input = matnr

  • importing

  • output = matnr.

  • shift matnr-low left deleting leading '0'.

  • <fs1> = matnr-low.

*

  • assign component 'WERKS' of structure <dyn_wa> to <fs1>.

  • <fs1> = werks.

loop at imard.

index = sy-index.

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

<fs1> = imard-matnr.

call function 'CONVERSION_EXIT_MATN1_OUTPUT'

exporting

input = <fs1>

importing

output = <fs1>.

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

<fs1> = imard-werks.

  • Set the LGORT

  • concatenate 'LGORT' imard-lgort into

  • fieldname.

  • condense fieldname no-gaps.

  • assign component fieldname of structure <dyn_wa> to <fs1>.

  • <fs1> = imard-lgort.

  • Set the LABST

concatenate 'LABST' imard-lgort into

fieldname.

condense fieldname no-gaps.

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

<fs1> = imard-labst.

  • INSME

concatenate 'INSME' imard-lgort into

fieldname.

condense fieldname no-gaps.

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

<fs1> = imard-insme .

*******RETEME

concatenate 'RETME' imard-lgort into

fieldname.

condense fieldname no-gaps.

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

<fs1> = imard-retme.

******UMLME

concatenate 'UMLME' imard-lgort into

fieldname.

condense fieldname no-gaps.

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

<fs1> = imard-umlme.

****SPEME

concatenate 'SPEME' imard-lgort into

fieldname.

condense fieldname no-gaps.

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

<fs1> = imard-speme.

at end of matnr.

  • Append to the dynamic internal table

append <dyn_wa> to <dyn_table>.

clear <dyn_wa>.

endat.

endloop.

endform.

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

  • CALL_ALV

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

form call_alv.

data: wa_cat like line of alv_fldcat.

loop at it_fldcat into wa_it_fldcat.

wa_cat-fieldname = wa_it_fldcat-fieldname.

wa_cat-seltext_s = wa_it_fldcat-seltext.

wa_cat-outputlen = wa_it_fldcat-outputlen.

append wa_cat to alv_fldcat.

endloop.

  • Call ABAP List Viewer (ALV)

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

it_fieldcat = alv_fldcat

tables

t_outtab = <dyn_table>.

endform.