Application Development 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: 

dynamic table (rich blog)

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

rich PLs can you help me

11 REPLIES 11

Former Member
0 Kudos

Hi

You have to update:

- Internal table definition:

data: begin of imard occurs 0,

werks like marc-werks,

.......................

eislo like marc-eislo,

lblab like mslb-lblab, <----


end of imard.

- The join

select mardeinme mardinsme mardlabst mardmatnr

..................................................

mardwerks mslblblab

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

..................................................

, mard-werks, mslb~lblab)

from ( mard

...........................

inner join marc

on marcmatnr = maktmatnr

inner join mslb

on mslbmatnr = marcmatnr

and mslbwerks = marcwerks )

............................

  • The catalog definition

loop at imard.

clear wa_it_fldcat.

wa_it_fldcat-fieldname = 'LBLAB'.

wa_it_fldcat-datatype = 'QUAN'.

wa_it_fldcat-seltext = imard-lifnr.

wa_it_fldcat-intlen = 15.

append wa_it_fldcat to it_fldcat .

Max

0 Kudos

max hi.

i made it but he give me at aby lgort the lblab, this is not what i need .

i need at the end of all the lgort i will have a dynamic

column the title will be : <b>lifnr</b> and data <b>lblab</b>

Former Member
0 Kudos

rich PLs can you help me

0 Kudos

Hi

I can't really understand your code, anyway you need to import the value of LIFNR from MSLB.

Append the field for LBLAB at the last position of catalog table and transfer it the vendor code as label.

Max

0 Kudos

max hi

i have 4 lgort and 2 lifnr with data lblab

i want it give me all the 4 lgort ( all lgort have the 6 items) and in the end the 2 lifnr(title) and lblab (data)

0 Kudos

you can take my prog (help of rich) and see what i get

and form this i need to add at the last row lifnr-->lblab

0 Kudos

Ok, I made some modifications to the program. It will add a column for each vendor and give the qty.



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.

<b>types: begin of tmslb,
       lifnr type mslb-lifnr,
       lblab type mslb-lblab,
       end of tmslb.

data: xmslb type tmslb.</b>

*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,
<b>imslb type table of tmslb ,</b>
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 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
  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 mara~matnr = mard~matnr
  inner join makt
  on makt~matnr = mara~matnr
  inner join marc
  on marc~matnr = makt~matnr )
  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 = 'E'.
    if sy-subrc = 0.
      clear imard.
      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.

<b>* Get special stock and number of vendors.
      data: jmslb type table of mslb with header line.
      clear jmslb.  refresh jmslb.
      select * into table jmslb from mslb
               where matnr = imard-matnr
                 and werks = imard-werks.
      loop at jmslb.
        xmslb-lifnr = jmslb-lifnr.
        xmslb-lblab = jmslb-lblab.
        collect xmslb into imard-imslb.
      endloop.</b>
      append imard.
    endif.
  endselect.
  sort imard ascending by matnr werks lgort.
  delete adjacent duplicates from imard comparing matnr werks lgort.


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


<b>* Add the colum for ss
loop at imard.
  loop at imard-imslb into xmslb.
    clear wa_it_fldcat.
    concatenate xmslb-lifnr 'LBLAB' 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.
endloop.</b>

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

<b>    loop at imard-imslb into xmslb.
      concatenate xmslb-lifnr 'LBLAB' into
                   fieldname.
      condense fieldname no-gaps.
      assign component fieldname of structure <dyn_wa> to <fs1>.
      <fs1> = xmslb-LBLAB.
    endloop.</b>

    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.

Regards,

Rich Heilman

0 Kudos

why when i copy it

i get all the word in 1 line???

0 Kudos

i copy well thanks.

now when i running in 1 matnr it's good

and in lgort only it's dump why????

0 Kudos

rich do you know whY??

0 Kudos

rich it doesnt work why???

PLS