10-31-2006 2:16 PM
Hi SAPgurus,
I have been facing one issue i.e creation of internal table dynamically based on the date range entered in the selection screen. For example the date range I am giving as 06/2006 to 08/2006, it should display the Fieldcatelog dynamically, this part i have completed but the only issue I am facing is to populate the sales data into that fields.
Right now my program is displaying the ALV like this.
Ex:
<b>CSR District 06/2006 07/2006 08/2006 totals</b>
Shiva New York 10.00
Shiva new york 30.00
Shiva new york 40.00
but it should display like this
<b>CSR District 06/2006 07/2006 08/2006 totals</b>
Shiva New York 10.00 30.00 40.00
80.00
Please help me in this scenario, how to acheive like this..
Thanks & Regards,
Sivaram Kandula
10-31-2006 6:14 PM
Here is a sample program.
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.
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.
Will you be rewarding points under the "Shankar" user id, as you will not be able to do so under your newly creatly user id.
Regards,
Rich Heilman
10-31-2006 2:27 PM
I assume that you have named the columns of your internal table specific to the period, for example, column name for the first period would be like 200606, etc. So you know the names of the columns, so when filling the with data. You need to assign to a field symbol.
assign component '200606' of structure itab to <fs>.
Of course the component can be(and should be) defined dynamically in this statement. This is how you will be able to fill these fields with data.
Regards,
Rich Heilman
10-31-2006 5:20 PM
Hi Rich,
Thank you very much for your reply. What ever you said it is right, I am new to OABAP, that is why I am unable to find out where I am doing wrong, but your understanding my problem is correct. Can you please send me the code for that, so that I will analyze that and same thing I will incorporate in my code. Can you please do this favour.
Thanks & Regards,
Sivaram Kandula
10-31-2006 6:14 PM
Here is a sample program.
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.
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.
Will you be rewarding points under the "Shankar" user id, as you will not be able to do so under your newly creatly user id.
Regards,
Rich Heilman
11-01-2006 4:51 PM
Hi Rich,
Thank you very much for your immediate reply. This is a great help. Definitely I will reward the points.
Here my issue is I have to read the data from internal table (Tab_item) , my question is how to move the internal table data and fill in the dynamic table. Please suggest me how to proceed further.
Here I am pasting some of my code. Please go through that and advice me If I am going in wrong way.
SELECT-OPTIONS : s_spbup FOR s858-bup.
SELECT kunnr vkbur bzirk INTO TABLE tab_csrcust
FROM knvv
WHERE vkbur <> '' AND vkorg IN s_vkorg
AND vtweg = p_vtweg AND spart = p_spart.
SELECT pkunwe
bzirk
spbup
SUM( umnetwr )
SUM( gunetwr )
SUM( umwavwr )
SUM( guwavwr )
INTO TABLE tab_csrbydist
FROM s858
WHERE spbup IN s_spbup
GROUP BY s858~pkunwe s858~bzirk s858~spbup.
LOOP AT tab_csrcust.
SELECT SINGLE * FROM tvkbt WHERE spras = 'E' AND vkbur = tab_csrcust-vkbur.
IF sy-subrc EQ 0.
MOVE tvkbt-bezei TO tab_head-bezei.
ENDIF.
LOOP AT tab_csrbydist WHERE pkunwe = tab_csrcust-kunnr AND
bzirk = tab_csrcust-bzirk.
CLEAR : sales,cost.
SELECT SINGLE * FROM tvkbt WHERE spras = 'E' AND vkbur = tab_csrcust-vkbur.
IF sy-subrc EQ 0.
MOVE tvkbt-bezei TO tab_item-bezei.
SELECT SINGLE * FROM t171t WHERE spras = 'E' AND bzirk = tab_csrcust-bzirk.
IF sy-subrc EQ 0.
MOVE t171t-bztxt TO tab_item-bztxt.
ENDIF.
sales = tab_csrbydist-umnetwr - tab_csrbydist-gunetwr.
total = TRUNC( sales ).
MOVE tab_csrbydist-spbup TO tab_item-spbup.
MOVE total TO tab_item-total.
CLEAR total.
APPEND tab_item.
CLEAR tab_item.
ENDIF.
ENDLOOP.
ENDLOOP.
CALL METHOD grid->set_table_for_first_display
CHANGING
it_outtab = <dyn_table>
it_fieldcatalog = it_fieldcat
it_sort = gt_sort1
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
FORM fill_fieldcat.
DATA: l_repid LIKE sy-repid.
DATA : date(6) TYPE c,date1(6) TYPE c.
DATA: n(2),d(2).
DATA : n1 TYPE i.
DATA : i TYPE n VALUE 1.
* l_repid = sy-repid.
IF s_spbup-low(4) <> s_spbup-high(4).
n1 = ABS( s_spbup-low(4) - s_spbup-high(4) ).
IF n1 = 1.
d = ( 12 - s_spbup-low+4(2) ) + 1.
ELSEIF n1 = 2.
d = ( 24 - s_spbup-low+4(2) ) + 1.
ENDIF.
n = d + s_spbup-high+4(2).
MOVE s_spbup-low TO date.
ELSEIF s_spbup-low(4) = s_spbup-high(4).
n = ABS( s_spbup-low+4(2) - s_spbup-high+4(2) ) + 1.
MOVE s_spbup-low TO date.
ENDIF.
MOVE s_spbup-low TO date.
is_fieldcat-fieldname = 'BEZEI'.
is_fieldcat-scrtext_l = 'CSR'.
is_fieldcat-scrtext_m = 'CSR'.
is_fieldcat-scrtext_s = 'CSR'.
is_fieldcat-outputlen = 20.
APPEND is_fieldcat TO it_fieldcat.
is_fieldcat-fieldname = 'BZTXT'.
is_fieldcat-scrtext_l = 'District'.
is_fieldcat-scrtext_m = 'District'.
is_fieldcat-scrtext_s = 'District'.
is_fieldcat-outputlen = 20.
APPEND is_fieldcat TO it_fieldcat.
DO n TIMES.
is_fieldcat-fieldname = date.
is_fieldcat-scrtext_l = date.
is_fieldcat-scrtext_m = date.
is_fieldcat-scrtext_s = date.
is_fieldcat-outputlen = 20.
APPEND is_fieldcat TO it_fieldcat.
IF date+4(2) = 12.
date+3(1) = date+3(1) + 1.
date+4(2) = '00'.
ENDIF.
date+4(2) = date+4(2) + i.
date1+4(1) = date+4(1).
IF date+5(1) = ' '.
date+4(1) = 0.
date+5(1) = date1+4(1).
ENDIF.
ENDDO.
is_fieldcat-fieldname = 'TOTALS'.
is_fieldcat-scrtext_l = 'TOTALS'.
is_fieldcat-scrtext_m = 'TOTALS'.
is_fieldcat-scrtext_s = 'TOTALS'.
is_fieldcat-outputlen = 20.
APPEND is_fieldcat TO it_fieldcat.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
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. " fill_fieldcat
FORM populate_data .
*<dyn_table>
*tab_item.
*
LOOP AT tab_item.
ASSIGN COMPONENT 1 OF STRUCTURE <dyn_wa> TO <dyn_table>.
ASSIGN COMPONENT 2 OF STRUCTURE <dyn_wa> TO <dyn_table>.
* <dyn_wa> = tab_item-bztxt.
* <dyn_wa> = tab_item-total.
* APPEND <dyn_wa> TO <dyn_table>.
** <dyn_wa> = tab_item-total.
** ASSIGN tab_item-bezei TO <dyn_wa>.
**
* APPEND <dyn_table>.
*
ENDLOOP.
ENDFORM. " populate_data
12-22-2014 7:59 AM
Hi Sivaram,
I also got the same requirement . i saw rich and your code whatever you have uploaded.i have created dynamic internal table but i am facing the issue to populating the data to my dynamic internal table.
Sivaram, can you please explain your code after this.
*<dyn_table>
*tab_item.
*
LOOP AT tab_item.
ASSIGN COMPONENT 1 OF STRUCTURE <dyn_wa> TO <dyn_table>.
ASSIGN COMPONENT 2 OF STRUCTURE <dyn_wa> TO <dyn_table>.
* <dyn_wa> = tab_item-bztxt.
* <dyn_wa> = tab_item-total.
* APPEND <dyn_wa> TO <dyn_table>.
** <dyn_wa> = tab_item-total.
** ASSIGN tab_item-bezei TO <dyn_wa>.
**
* APPEND <dyn_table>.
*
ENDLOOP.
how you are puting the loop at tab_item. but tab_item is already commented.
can you send me the code after that.
i am sending some part of my code.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gt_fCAT1
IMPORTING
ep_table = new_table.
ASSIGN new_table->* TO <dyn_table>.
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
select vbeln
fkart
vkorg
vtweg
fkdat
spart
fksto
from vbrk
client specified
into table gt_vbrk
where mandt = sy-mandt
and fkart in ('ZF5','ZFR')
and vkorg = '1100'
and vtweg = '20'
and fkdat in s_fkdat
and spart = '06'
and fksto = ' '.
if gt_vbrk[] is not initial.
select vbeln
fkimg
prsdt
netwr
matnr
arktx
werks
mwsbp
from vbrp
client specified
into table gt_vbrp
for all entries in gt_vbrk
where vbeln = gt_vbrk-vbeln
and werks in s_werks
and matnr in s_matnr.
endif.
select mnr ltx spras from t247
into table it_t247
where spras = 'E'.
data: lv_month1 type vbrp-prsdt,
name1(3) type c,
s_month type string,
s_month1 type string,
s_month2 type string.
* lv_netwr1 type vbrp-netwr,
* lv_mwsbp1 type vbrp-mwsbp.
loop at gt_vbrp into gs_vbrp.
gs_final2-matnr = gs_vbrp-matnr.
gs_final2-arktx = gs_vbrp-arktx.
gs_final2-fkimg = gs_vbrp-fkimg.
lv_month1 = gs_vbrp-prsdt.
read table it_t247 into wa_t247 with key mnr = lv_month1+4(2).
if sy-subrc eq 0.
name1 = wa_t247-ltx.
endif.
concatenate name1
lv_month1(4) into s_month SEPARATED BY '_' .
CONCATENATE S_MONTH 'QTY' INTO S_MONTH1 SEPARATED BY ''.
CONCATENATE S_MONTH 'VALUE' INTO S_MONTH2 SEPARATED BY ''.
gs_final2-month = s_month.
lv_netwr1 = gs_vbrp-netwr.
lv_mwsbp1 = gs_vbrp-mwsbp.
gs_final2-MONTH_QTY = S_MONTH1.
GS_FINAL2-MONTH_VAL = S_MONTH2.
gs_final2-value = lv_netwr1 + lv_mwsbp1.
append gs_final2 to gt_final2.
clear: gs_final2. "lv_name2.
endloop.
if gt_final2[] is not initial.
sort gt_final2 by matnr month ascending .
loop at gt_final2 into gs_final2.
gs_final2_01 = gs_final2.
collect gs_final2_01 into gt_final2_01.
endloop.
endif.
ENDIF..
Regards
Ankur
11-03-2006 9:03 AM
Hi Rich,
Thank you very much for your support on this issue. Now I am able to fill the data dynamically. I have already assigned the points for you to solve my issue.
once again thank you very much...
regards,
Sivaram Kandula
04-11-2011 3:19 PM