Dynamic creation of internal tables
Hi all,
i very urgently need a sample code which will help me to create an internal table dynamically at the click of a pushbutton using alv.Awaiting reply shortly .
thank you.
Regards,
Lailu Philip
Hi,
Check this.I got it from SDN.
REPORT zmaschl_create_data_dynamic .
TYPE-POOLS: slis.
DATA: it_fcat TYPE slis_t_fieldcat_alv,
is_fcat LIKE LINE OF it_fcat.
DATA: it_fieldcat TYPE lvc_t_fcat,
is_fieldcat LIKE LINE OF it_fieldcat.
DATA: new_table TYPE REF TO data.
DATA: new_line TYPE REF TO data.
FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
Build fieldcat
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SYST'
CHANGING
ct_fieldcat = it_fcat[].
LOOP AT it_fcat INTO is_fcat WHERE NOT reptext_ddic IS initial.
MOVE-CORRESPONDING is_fcat TO is_fieldcat.
is_fieldcat-fieldname = is_fcat-fieldname.
is_fieldcat-ref_field = is_fcat-fieldname.
is_fieldcat-ref_table = is_fcat-ref_tabname.
APPEND is_fieldcat TO it_fieldcat.
ENDLOOP.
Create a new Table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = new_table.
Create a new Line with the same structure of the table.
ASSIGN new_table->* TO <l_table>.
CREATE DATA new_line LIKE LINE OF <l_table>.
ASSIGN new_line->* TO <l_line>.
Test it...
DO 30 TIMES.
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
<l_field> = sy-index.
INSERT <l_line> INTO TABLE <l_table>.
ENDDO.
LOOP AT <l_table> ASSIGNING <l_line>.
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
WRITE <l_field>.
ENDLOOP.
Similar Messages
-
Dynamic creation of internal table based on alv layout
Hi experts!!
I have the following request from my client:
I am displaying an alv report and i need to download it in txt format based on the columns showed in the current layout (i.e. if the user chooses to hide some columns, then they should not appear in the txt file ). In the alv i am using the Function Modules of the alv and not ABAP Objects.
I thought of dynamically creating the internal table, but i am not sure how to do it.
I also thaught of creating an internal table with only one field with the maximum length, but how can i check which fields are diplayed, and how can i get their values??
Please Help!!
Thank u in advance!!!
Please - no duplicate posts
Edited by: Rob Burbank on Feb 24, 2009 2:16 PMAfter call the above said function module you will get the exporting table for field catalog ie
call function 'REUSE_ALV_GRID_LAYOUT_INFO_GET'
importing
es_layout = ls_slis_layo
et_fieldcat = lt_slis_fcat
if you check the lt_slis_fcat internal table if the field are hide in the layout by the user then in this internal table check for field NO_OUT will X.
Take the fields where NO_OUT ne X
then for creating dynamic internal table
field-symbols : <ptab> type standard table.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = lt_slis_fcat
importing
ep_table = i_content.
if sy-subrc = 0.
assign i_content->* to <ptab>.
else.
write: 'Error creating internal table'.
stop.
endif.
Here is the dynamic internal table
a® -
Dynamic Creation of Internal table WITH HEADER LINE
Dear,
Please show me the way of creating Internal table WITH HEADER LINE dynamically..
Thanks,
Nirav<font color='blue'>Hi Parekh,
Have a look at the sample program for Dynamic internal table
This program has been developed to update any table data in the dictionary. We give table name and File name as Input fields.
<pre>
REPORT znpmmm0201.
*Types
TYPES:
BEGIN OF ty_file,
data(4096) TYPE c,
END OF ty_file.
*Type-pools
TYPE-POOLS:
truxs.
*Work areas
DATA:
wa_file TYPE ty_file.
*Internal tables
DATA:
it_file TYPE STANDARD TABLE OF ty_file,
it_data TYPE truxs_t_text_data.
DATA:
gv_dref TYPE REF TO data,
file_name TYPE string.
*FIELD-SYMBOLS
FIELD-SYMBOLS:
<gf_itab> TYPE STANDARD TABLE,
<wa> TYPE ANY.
*& Selection-screen
PARAMETERS:
p_table TYPE rsrd1-tbma_val,
p_file TYPE ibipparms-path.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM f4_for_p_file CHANGING file_name .
*& START-OF-SELECTION
START-OF-SELECTION.
CREATE DATA gv_dref TYPE TABLE OF (p_table).
ASSIGN gv_dref->* TO <gf_itab>.
PERFORM upload_data USING file_name.
MODIFY (p_table) FROM TABLE <gf_itab>.
*& Form UPLOAD_DATA
FORM upload_data USING file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = file
filetype = 'ASC'
TABLES
data_tab = it_file.
APPEND LINES OF it_file TO it_data.
CLASS cl_abap_char_utilities DEFINITION LOAD.
DATA: l_field_seperator.
l_field_seperator = cl_abap_char_utilities=>horizontal_tab.
REPLACE ALL OCCURRENCES OF '|' IN TABLE it_data WITH l_field_seperator.
CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
EXPORTING
i_field_seperator = l_field_seperator
i_tab_raw_data = it_data
TABLES
i_tab_converted_data = <gf_itab>.
ENDFORM. " UPLOAD_DATA
*& Form F4_FOR_p_file
FORM f4_for_p_file CHANGING file.
DATA:
l_field_name LIKE dynpread-fieldname VALUE 'P_FILE'.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = l_field_name
IMPORTING
file_name = p_file.
file = p_file.
ENDFORM. " F4_FOR_p_file </pre>
Thanks,
Venkat.O</font> -
Creation of internal table dynamically based on the Date Range entered
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 KandulaHi 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 -
Dynamicly creating an internal table with header line
Hi experts,
I am trying to do a read on an internal table using field symbols of type any table. To be able to read more than one row at once, I'd like to read it into another internal table (instead of just one line and instead of looping through them one by one).
So far the following line rendered an error that the target internal table doesn't have a header line
read table <fs_v_tab> WITH KEY (<fs_comp>) = <fs_param>-low INTO <fs_v_tab>.
(also attempted using "<fs_v_tab>->*" & "<fs_v_tab>[]" to be silly)
Based on the following article, I was wondering if it were possible to dynamicly create an internal table with header line.
[http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.html|http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.html]
Any help or tips on how to dynamicly filter an internal table field-symbol is greatly appreciated!Just read the online help:
This statement reads a row from internal table itab.
Or more exact:
This statement reads one row from internal table itab.
Therefore you can not read multiple lines into another table. The header line is needed to put the result in. And this is not what you intended, the result will be in the header line, not in the table itself.
If the row to be read is not uniquely specified, the first suitable row is read. In the case of index tables, this row has the lowest table index of all matching rows.
At least you have to do what you dont wanna do: looping. -
Dynamic ALV and internal table.
Hi all,
I have a requirement of creating a dynamic field catelog based on input values in selection screen.
Example:
1) When I enter date range, say 20/03/2008 to 25/03/2008 I should have 6 columns in the output for each date with column heading as date itself.
2) For entering values for these date columns, i need to create an dynamic internal table.(values in the column will be some numbers like 10 on 20/03/2008, 15 on 21/03/2008 etc)
A rough output format would look like this:
Component | 20/03/2008 | 21/03/2008 | ..... |25/03/2008
comp1 | 10 | 15 | | 5
comp2 | 20 | 10 | | 10
Please let me know how can i achieve this...
Need it very urgently..
Regards,
DhareppaHi Dhareppa,
Refer the code below. Its almost on the same line as your requirments.
REPORT zglo2fr_master_planing_sedul NO STANDARD PAGE HEADING.
P R O G R A M H E A D E R *
ArthroCare Corporation *
Program : ZGLO2FR_MASTER_PLANING_SEDUL *
Author : Munvar Basha *
Creation Date : 11Mar08 *
Release : SAP ECC 6.0 *
Request : D01K904032 *
Description : Master Schedule Planning *
Change log (Revisions) *
Author Date Request Description *
P R O G R A M *
DATA DECLARATION *
**--Structure to hold matrial & plant combination records.
TYPES : BEGIN OF ty_marc,
matnr TYPE matnr,
werks TYPE werks_d,
dispo TYPE dispo,
beskz TYPE beskz,
mtart TYPE mtart,
END OF ty_marc.
**--structure to hold MRP LIST Data.
TYPES : BEGIN OF ty_mrp_list,
matnr TYPE matnr,
werks TYPE werks_d,
maktx TYPE maktx,
meins TYPE meins,
mtart TYPE mtart,
week TYPE kweek,
mng01 TYPE mng01,
delkz TYPE delkz,
END OF ty_mrp_list.
**--structure to hold no of weeks.
TYPES: BEGIN OF ty_week,
week TYPE kweek,
END OF ty_week.
**--structure to hold output data.
TYPES : BEGIN OF ty_final,
matnr TYPE matnr,
werks TYPE werks_d,
maktx TYPE maktx,
meins TYPE meins,
mtart TYPE mtart,
week TYPE kweek,
mng01 TYPE mng01,
END OF ty_final.
TYPES : BEGIN OF ty_range,
sign TYPE sign,
option TYPE option,
low TYPE sy-datum,
high TYPE sy-datum,
END OF ty_range.
Definitions of Table types. *
TYPES : ty_marctab TYPE STANDARD TABLE OF ty_marc.
Definitions of Ranges *
*RANGES ran_delkz FOR mdez-delkz.
DATA : i_ran_delkz TYPE RANGE OF mdez-delkz,
wa_ran_delkz LIKE LINE OF i_ran_delkz,
wa_date type ty_range.
Definitions of internal tables. *
data : i_marc type standard table of ty_marc,
i_mrp_list type standard table of ty_mrp_list,
i_week type standard table of ty_week,
i_final type standard table of ty_final,
i_mdps type standard table of mdps,
i_mdez type standard table of mdez,
i_mdsu type standard table of mdsu.
Definitions of work areas for internal tables *
DATA : wa_marc TYPE ty_marc,
wa_mrp_list TYPE ty_mrp_list,
wa_week TYPE ty_week,
wa_final TYPE ty_final,
wa_mt61d TYPE mt61d,
wa_mdez TYPE mdez.
Definitiions of General variables *
DATA : v_matnr TYPE mara-matnr, " Material Number
v_mtart TYPE mara-mtart, " Material Type
v_beskz TYPE marc-beskz, " Procurement Type
v_werks TYPE marc-werks, " Plant
v_dispo TYPE marc-dispo. " MRP Controller (Materials Planner)
DATA : v_mng01 TYPE mng01. "Requirement Quantity
DATA : v_year TYPE char4,
v_week TYPE char2,
v_ok_code TYPE sy-ucomm.
Definitiions of Constants *
CONSTANTS : k_slash TYPE c VALUE '/',
k_6 TYPE char8 VALUE '6',
k_x TYPE c VALUE 'X'.
Definitiions of Field Catlog *
DATA : wa_fieldcat TYPE lvc_s_fcat,
i_fieldcat TYPE lvc_t_fcat,
v_container TYPE scrfname VALUE 'CONTAINER_OUTPUT',
v_custom_container TYPE REF TO cl_gui_custom_container,
v_grid TYPE REF TO cl_gui_alv_grid,
i_gp_table TYPE REF TO data,
wa_gp_line TYPE REF TO data.
FIELD-SYMBOLS: <gt_table> TYPE STANDARD TABLE,
<gwa_table> TYPE ANY,
<l_field> TYPE ANY,
<l_matnr> TYPE ANY,
<l_werks> TYPE ANY,
<l_maktx> TYPE ANY,
<l_meins> TYPE ANY,
<l_mtart> TYPE ANY.
DECLERATIONS FOR SELECTION SCREEN *
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_matnr FOR v_matnr,
s_mtart FOR v_mtart NO INTERVALS,
s_beskz FOR v_beskz NO INTERVALS NO-EXTENSION,
s_werks FOR v_werks NO INTERVALS NO-EXTENSION
OBLIGATORY,
s_dispo FOR v_dispo,
s_date FOR sy-datum OBLIGATORY.
PARAMETERS : p_dattp TYPE dattp OBLIGATORY DEFAULT '1'.
SELECTION-SCREEN END OF BLOCK b1.
INITIALIZATION EVENT *
INITIALIZATION.
CALL FUNCTION '/BEV4/PLPS__ADD_MONTH_TO_DATE'
EXPORTING
months = k_6
olddate = sy-datum
IMPORTING
newdate = wa_date-high.
wa_date-low = sy-datum.
wa_date-option = 'EQ'.
wa_date-sign = 'I'.
APPEND wa_date to s_date.
SELECTION SCREEN EVENT *
**--Validation for Material
AT SELECTION-SCREEN ON s_matnr.
PERFORM validate_material.
**--Validation for Plant
AT SELECTION-SCREEN ON s_werks.
PERFORM validate_plant.
AT SELECTION-SCREEN ENENT *
AT SELECTION-SCREEN.
IF s_matnr IS INITIAL AND s_dispo IS INITIAL.
MESSAGE text-002 TYPE 'E'.
ENDIF.
IF s_date-low LT sy-datum.
MESSAGE text-003 TYPE 'E'.
ENDIF.
START-OF-SELECTION EVENT *
START-OF-SELECTION.
**--refreshing the internal tables
REFRESH : i_marc,
i_mrp_list,
i_week,
i_final,
i_mdps,
i_mdez,
i_mdsu.
**--clearing the work areas of internal tables.
CLEAR : wa_marc,
wa_mrp_list,
wa_week,
wa_final,
wa_mt61d,
wa_mdez.
To get all the matrial(s) and plant combination records
SELECT a~matnr
a~werks
a~dispo
a~beskz
b~mtart
INTO TABLE i_marc
FROM marc AS a INNER JOIN
mara AS b
ON a~matnr = b~matnr
WHERE a~werks IN s_werks AND
a~matnr IN s_matnr AND
a~dispo IN s_dispo AND
a~beskz IN s_beskz AND
b~mtart IN s_mtart.
IF sy-subrc <> 0.
MESSAGE text-005 TYPE 'S'.
LEAVE LIST-PROCESSING.
ENDIF.
SORT i_marc BY matnr werks.
Ranges to Filter the MRP list only for the following MRP Elements.
MRP Elements are : BA, BE, FE, LE and PA
wa_ran_delkz-sign = 'I'.
wa_ran_delkz-option = 'EQ'.
wa_ran_delkz-low = 'BA'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
wa_ran_delkz-low = 'BE'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
wa_ran_delkz-low = 'FE'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
wa_ran_delkz-low = 'LE'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
wa_ran_delkz-low = 'PA'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
LOOP AT i_marc INTO wa_marc.
CALL FUNCTION 'MD_MRP_LIST_API'
EXPORTING
matnr = wa_marc-matnr
werks = wa_marc-werks
sinfg = k_x
inper = p_dattp
IMPORTING
e_mt61d = wa_mt61d
TABLES
mdpsx = i_mdps
mdezx = i_mdez
mdsux = i_mdsu
EXCEPTIONS
mrp_list_not_found = 1
material_plant_not_found = 2
error = 3
OTHERS = 4.
IF sy-subrc = 0.
LOOP AT i_mdez INTO wa_mdez WHERE dat00 IN s_date AND
delkz IN i_ran_delkz.
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
date = wa_mdez-dat00
IMPORTING
week = wa_mrp_list-week
EXCEPTIONS
date_invalid = 1
OTHERS = 2.
IF sy-subrc = 0.
wa_mrp_list-matnr = wa_mt61d-matnr.
wa_mrp_list-werks = wa_mt61d-werks.
wa_mrp_list-maktx = wa_mt61d-maktx.
wa_mrp_list-meins = wa_mt61d-meins.
wa_mrp_list-mtart = wa_mt61d-mtart.
wa_mrp_list-delkz = wa_mdez-delkz.
wa_mrp_list-mng01 = wa_mdez-mng01.
APPEND wa_mrp_list TO i_mrp_list.
CLEAR : wa_mrp_list,
wa_mdez.
ENDIF.
ENDLOOP.
ENDIF.
CLEAR: wa_marc.
ENDLOOP.
IF i_mrp_list IS INITIAL.
MESSAGE text-006 TYPE 'S'.
LEAVE LIST-PROCESSING.
ENDIF.
CLEAR : v_mng01.
LOOP AT i_mrp_list INTO wa_mrp_list.
v_mng01 = v_mng01 + wa_mrp_list-mng01.
AT END OF week.
wa_final-matnr = wa_mrp_list-matnr.
wa_final-werks = wa_mrp_list-werks.
wa_final-maktx = wa_mrp_list-maktx.
wa_final-meins = wa_mrp_list-meins.
wa_final-mtart = wa_mrp_list-mtart.
wa_final-week = wa_mrp_list-week.
wa_final-mng01 = v_mng01.
wa_week-week = wa_mrp_list-week.
APPEND : wa_final TO i_final,
wa_week TO i_week.
CLEAR : v_mng01,
wa_final,
wa_week.
ENDAT.
CLEAR : wa_mrp_list.
ENDLOOP.
**-- Populate the Field catalog
PERFORM populate_fieldcat.
**--Create table dynamically
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_fieldcat
IMPORTING
ep_table = i_gp_table.
ASSIGN i_gp_table->* TO <gt_table>.
**--fill table with final output data
PERFORM fill_table.
CALL SCREEN 100.
SUB ROUTINES *
*& Form validate_material *
Validating Material Number(s) *
FORM validate_material .
TYPES : BEGIN OF l_ty_matnr,
matnr TYPE matnr,
END OF l_ty_matnr.
DATA : l_i_matnr TYPE STANDARD TABLE OF l_ty_matnr.
SELECT matnr
FROM mara
INTO TABLE l_i_matnr
WHERE matnr IN s_matnr.
IF sy-subrc <> 0.
MESSAGE text-004 TYPE 'E'.
ENDIF.
ENDFORM. " validate_material
*& Form validate_plant *
Validating Plant Number *
FORM validate_plant .
DATA : l_v_werks TYPE werks_d.
SELECT SINGLE werks
FROM t001w
INTO l_v_werks
WHERE werks = s_werks-low.
IF sy-subrc <> 0.
MESSAGE e019(zartc) WITH s_werks-low.
ENDIF.
ENDFORM. " validate_plant
*& Form populate_fieldcat
text
--> p1 text
<-- p2 text
FORM populate_fieldcat .
DATA : l_v_colname TYPE char7.
SORT i_week BY week.
DELETE ADJACENT DUPLICATES FROM i_week COMPARING week.
LOOP AT i_week INTO wa_week.
AT FIRST.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-scrtext_l = text-007.
wa_fieldcat-scrtext_m = text-007.
wa_fieldcat-scrtext_s = text-007.
wa_fieldcat-fix_column = 'X'.
wa_fieldcat-outputlen = 18.
wa_fieldcat-tooltip = text-007.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 2.
wa_fieldcat-fieldname = 'WERKS'.
wa_fieldcat-scrtext_l = text-008.
wa_fieldcat-scrtext_m = text-008.
wa_fieldcat-scrtext_s = text-008.
wa_fieldcat-fix_column = 'X'.
wa_fieldcat-outputlen = 4.
wa_fieldcat-tooltip = text-008.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 3.
wa_fieldcat-fieldname = 'MAKTX'.
wa_fieldcat-scrtext_l = text-009.
wa_fieldcat-scrtext_m = text-010.
wa_fieldcat-scrtext_s = text-011.
wa_fieldcat-tooltip = text-009.
wa_fieldcat-outputlen = 40.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 4.
wa_fieldcat-fieldname = 'MEINS'.
wa_fieldcat-scrtext_l = text-012.
wa_fieldcat-scrtext_m = text-013.
wa_fieldcat-scrtext_s = text-014.
wa_fieldcat-outputlen = 4.
wa_fieldcat-tooltip = text-012.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 5.
wa_fieldcat-fieldname = 'MTART'.
wa_fieldcat-scrtext_l = text-015.
wa_fieldcat-scrtext_m = text-015.
wa_fieldcat-scrtext_s = text-016.
wa_fieldcat-tooltip = text-015.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
ENDAT.
v_year = wa_week-week+0(4).
v_week = wa_week-week+4(2).
CONCATENATE v_week k_slash v_year INTO l_v_colname.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 6 + sy-index.
wa_fieldcat-fieldname = wa_week-week.
wa_fieldcat-quantity = 'X'.
wa_fieldcat-outputlen = 18.
wa_fieldcat-scrtext_l = l_v_colname.
wa_fieldcat-tooltip = l_v_colname.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR : wa_fieldcat,
l_v_colname,
wa_week.
ENDLOOP.
ENDFORM. " populate_fieldcat
*& Form fill_table
text
--> p1 text
<-- p2 text
FORM fill_table .
**--Create Work Area Dynamically
CREATE DATA wa_gp_line LIKE LINE OF <gt_table>.
ASSIGN wa_gp_line->* TO <gwa_table>.
DATA : l_v_col TYPE char25,
l_v_val TYPE char25.
LOOP AT i_final INTO wa_final.
l_v_col = wa_final-week.
ASSIGN COMPONENT l_v_col OF STRUCTURE <gwa_table>
TO <l_field>.
IF <l_field> IS ASSIGNED.
l_v_val = wa_final-mng01.
CONDENSE l_v_val.
<l_field> = l_v_val.
clear : l_v_val,
l_v_col.
ENDIF.
AT END OF matnr.
READ TABLE i_final INTO wa_final WITH KEY matnr = wa_final-matnr
BINARY SEARCH.
IF sy-subrc = 0.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <gwa_table>
TO <l_matnr>.
IF <l_matnr> IS ASSIGNED.
<l_matnr> = wa_final-matnr.
ENDIF.
ASSIGN COMPONENT 'WERKS' OF STRUCTURE <gwa_table>
TO <l_werks>.
IF <l_werks> IS ASSIGNED.
<l_werks> = wa_final-werks.
ENDIF.
ASSIGN COMPONENT 'MAKTX' OF STRUCTURE <gwa_table>
TO <l_maktx>.
IF <l_maktx> IS ASSIGNED.
<l_maktx> = wa_final-maktx.
ENDIF.
ASSIGN COMPONENT 'MEINS' OF STRUCTURE <gwa_table>
TO <l_meins>.
IF <l_meins> IS ASSIGNED.
<l_meins> = wa_final-meins.
ENDIF.
ASSIGN COMPONENT 'MTART' OF STRUCTURE <gwa_table>
TO <l_mtart>.
IF <l_mtart> IS ASSIGNED.
<l_mtart> = wa_final-mtart.
ENDIF.
APPEND <gwa_table> TO <gt_table>.
CLEAR <gwa_table>.
ENDIF.
ENDAT.
ENDLOOP.
ENDFORM. " fill_table
*& Module STATUS_0100 OUTPUT
text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'ZMUNNA'.
SET TITLEBAR 'MRP'.
IF v_custom_container IS INITIAL.
CREATE OBJECT v_custom_container
EXPORTING
container_name = v_container.
CREATE OBJECT v_grid
EXPORTING
i_parent = v_custom_container.
CALL METHOD v_grid->set_table_for_first_display
CHANGING
it_outtab = <gt_table>
it_fieldcatalog = i_fieldcat.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
text
MODULE user_command_0100 INPUT.
v_ok_code = sy-ucomm.
CLEAR sy-ucomm.
CASE v_ok_code.
WHEN 'EXIT'.
PERFORM exit_program.
SET SCREEN 000.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form exit_program
text
--> p1 text
<-- p2 text
FORM exit_program .
CALL METHOD v_custom_container->free.
CALL METHOD cl_gui_cfw=>flush.
ENDFORM. " exit_program
Reward points if that helps.
Manish -
Dynamic Structures and Internal Tables
Hi All,
I am doing a report to create condition records based on the condition type and condition table. Assume the condition type as PR00 and it as condition table of 304,305,306.Each condition table as its own header and item fields.Based on the condition table that the user specifies in the selection screen
the header and item structures of my report should change dynamically and these should be moved to the dynamic internal table that contains both header and item fields.Can anyone give an idea how to achieve it. Thanks in advance.
Regards,
Chakradhar.Hi All,
Thanks for your replies.
SPLIT i_string_line-input_str AT cl_abap_char_utilities=>horizontal_tab
INTO i_header_line-header
i_header_line-vkorg
i_header_line-vtweg
i_header_line-pltyp
i_header_line-waerk.
In the above syntax based on the condition table I selected on selection screen my flat file is as below.
case 1: If condition table given is 304
H SalesOrganization DistributionChannel Customer
I Material Releasestatus Amount Currency ValidFrom ValidTo
case 2: If condition table given is 305
H SalesOrganization DistributionChannel
I Material Releasestatus Amount Currency ValidFrom ValidTo
case 3: If condition table given is 306
H SalesOrganization DistributionChannel PriceListType DocumentCurrency
I Material Releasestatus Amount Currency ValidFrom ValidTo
In the above code i_string_line-input_str contains the following heading of fields based on the condition table we select in selection screen.when I want to split them into respective fields
using INTO clause my structure should change dynamically.How can I achieve it and my entire program is in OOPS ALV.Thanks in Advance.
Regards,
Chakradhar. -
How to add particluar column dynamically to an internal table
Hi
How can I add particluar column(s) to an internal table dynamically and then display in an alv.
for eg:
There are 5 columns and the 4th column is the <b>period (1 to 12)</b> that has been declared as select-options in the selection screen.
col1 = bukrs
col2 = lifnr
col3 = akont
<b>col4 = period</b>
col5 = waers
so my question is
if period is in the range from 1 to 3 then the internal table should be
bukrs lifnr akont <b>period1 period2 period 3</b> waers.
likewise if the period is in the range from 1 to n then internal table should be
Bukrs lifnr akont <b> period1 period2 period3 period4 ..... periodn </b> waers.
ThanksHi,
First create a global field catalog with all 12 periods ie period1, period2, ....period12.
Once you have fieldcatalog with all 12 periods
Then use this code arrive the dynamic field in the fieldcatalog
data : begin of i_period occurs 0.
data : period type i.
data : end of i_period.
data : v_no type i value 1.
do.
i_period-period = v_no.
v_no = v_no +1.
if v_no eq 12.
exit.
endif.
enddo.
" Here arrive the periods that are not belong to selection option period
delete i_period where period in s_period.
data : v_fldname like dd03l-fieldname.
loop at i_period.
concatenate 'PERIOD' i_period-period into v_fldname.
condense v_fldname no-gaps.
read table i_fieldcat with key fieldname = v_fldname.
if sy-subrc eq 0.
delete i_fieldcat index sy-tabix.
endif.
endloop.
After this loop your field catalog contains only valid period that equal to selection option period
aRs -
Dynamic columns in Internal Table
Hi Experts,
We have client requirments where clients want to see the report of certain no of wage types.
The no. of wage types is variable, they can select any no. of wage type (30-50). Is there any way of dynamically declaring the no of fields in internal table?
Thanks & Regards
Manas NayakHi,
use this..
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_month.
ASSIGN dy_month->* TO <dyn_month>.
CREATE DATA dy_wa LIKE LINE OF <dyn_month>.
ASSIGN dy_wa->* TO <wa_month>.
use this in one loop.....in every loop passing you just create the field catalog ifc... i think your prob will be solved.
Arunima -
Dynamical columns in internal table
Hi all.
I need to make an internal table with dynamical columns(i have 3 static columns and the rest depends on the number of clients that i have in a month). If it's possible, how can i do it?
Can anyone please help.
Thanks & RegardsHi,
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. <b> *Creates a dyanamic internal table **</b>
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.
<b>* Create dynamic internal table and assign to FS</b>
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 -
Dynamically fill the internal table with new fileds
Hi Friends,
I have the internal table like
Data:begin of i_data occurs 0,
a(60),
b(60),
c(60),
d(60),
e(60),
end of i_data.
I need to fill the internal table dynamically like
Data:begin of i_data occurs 0,
a(60),
b(60),
c(60),
c1(60), "new filed dynamically
c2(60), "new field dynamically
d(60),
e(60),
end of i_data.
Please suggest me how to do this.
Regards,
Sunny.
Code Formatted by: Alvaro Tejada Galindo on Jan 8, 2009 1:55 PMYou can not add new fields to a statically defined internal table, instead you must create the entrie internal table at runtime.
Search this forum for Dynamic Internal tables, you will get a lot of example programs.
Regards,
Rich Heilman -
Creation of Internal Table from Object created by OOPS
HI All,
go_obj_ref = cl_abap_typedescr=>describe_by_data( go_drvr ).
I have got the data in go_drvr object. From that I want to create an internal table. So that I can display output using ALV Grid. Please help me.Hi athul,
data : idetails type abap_compdescr_tab.
As i know go_obj_ref is a work area.
idetails[] = go_obj_ref->components[].
now loop this and teh data to u r internal table and you can assign it to ur alv.
Thanks -
Enhancement Point Creation in Internal table
Hi,
I want to create a Enhancement Point in Internal table declared in Customize Program.
This is more related to clarification of concept related to Enhancment Point.
But when i am putting the cursor inside the internal table and right click and Enhancment -> create ,it is giving me a message
that "Position of enhancement section/point statement is not allowed".
This means that we can't create Enhancement point or Enhancement Section inside the Internal table and solution is we can use
only Implicit Enhancement point.
But the doubt is that i had seen SAP programs where they have created the Enhancement point in the internal table declarations.
How that is possible then?
Please provide your helpful answers to get me more clarification on Enhancement Point/
Thanks,
ManishHi Afzal,
Below is the code from standard program :-
DATA: BEGIN OF lbbes OCCURS 10, "Tabelle für LB-Bestände
lifnr LIKE ekko-lifnr,
matnr LIKE mdpm-matnr,
werks LIKE mdpm-werks,
charg LIKE lifbe-charg, " SC-batch: Key-Feld
lgort LIKE resb-lgort, " SC-batch
lbmng LIKE lifbe-lblab, "LB-Bestandsmenge
erfmg LIKE mdpm-bdmng, "Verfügbare Menge
erfme LIKE mdpm-lagme, "Basismengeneinheit
wamng LIKE mdpm-bdmng,
waame LIKE mdpm-lagme,
vstel LIKE tvstz-vstel,
ladgr LIKE marc-ladgr,
sernp LIKE marc-sernp,
lblfa LIKE t161v-lblfa,
bdmng LIKE mdpm-bdmng, "sum of dep. requirements from SC POs
bdbam LIKE mdpm-bdmng, "sum of dep. requirements from SC req's
rsmng LIKE mdpm-bdmng, "sum of transfer reservations
slbbm LIKE mdpm-bdmng, "sum of third-party SC requisitions
slbmg LIKE mdpm-bdmng, "sum of third-party SC POs
lfimg LIKE komdlgn-lfimg, "sum of open deliveries
maktx LIKE mdpm-maktx,
selkz LIKE sy-calld.
ENHANCEMENT-POINT rm06ellb_03 SPOTS es_rm06ellb STATIC.
$$-Start: RM06ELLB_03----
$$
ENHANCEMENT 3 /CWM/APPL_MM_RM06ELLB. "active version
DATA: /cwm/waame LIKE mdpm-lagme,
/cwm/lbmng LIKE lifbe-lblab, "LB-Bestandsmenge in ParallelME
/cwm/erfmg LIKE mdpm-bdmng, "Verfügbare Menge in ParallelME
/cwm/erfme LIKE mdpm-lagme, "ParallelME
/cwm/meins LIKE mdpm-lagme, "CW-BasisME
/cwm/bdmng LIKE mdpm-bdmng, "sum of dep.req.< SC POs in PME
/cwm/lfimg LIKE komdlgn-lfimg, "sum of open deliveries in PME
/cwm/rsmng LIKE mdpm-bdmng, "sum of transfer reservations
/cwm/slbbm LIKE mdpm-bdmng, "sum of third-party SC requisitions
/cwm/slbmg LIKE mdpm-bdmng, "sum of third-party SC POs
/cwm/bdbam LIKE mdpm-bdmng. "sum of dep. req´s from SC req's
ENDENHANCEMENT.
$$-End: RM06ELLB_03----
$$
DATA:
END OF lbbes.
Now in the internal table lbbes they have created the enhancement point and in implementation of enhancement point they have declare some extra fields.This is not a implicit enhancement but it is a explicit enhancment implementation with the help of enhancement point.
Similarly if i have to do in my customize program then how to go ahead?
I knew that it is possible with Implicit Enhancement point and i can implement that also.
Let me know your views about this.
Thanks,
Manish -
Dynamic Creation of Data Tables and Fields
Hello all. I am currently working with a system that contains a bunch of windows. These windows are divided into two groups that represent their presentation style: Columns (such as a table) and Free (such as in a form). I created two tables in database to describe each and every window. These tables describe the type of presentation style, the fields of each window (title of the field, size of the field, position in window, and many more...)
I did this to make the creation of the windows more effective. In this way that I have, I only have to make one window to display all the thousands of windows that I have in my database because the values of presentation are taken from the description in the tables.
I was able to do this through TextFields and JTables in Swing. But now I run into JSC. Is this possible with JSC? Say in case the presentation style of the window is Column, can I tell the data table to go read the description of the window that needs to be opened to obtain the amount of columns, the column names, the size of each column... then create the tables and present the values?
Or say the presentation style is Free... I need to go find how many fields need to be created and their positions in the form, and then the titles of each field. Any ideas how this can be performed?
Thank you.
Franklin Angulo>
I was able to do this through TextFields and JTables
in Swing. But now I run into JSC. Is this possible
with JSC? Say in case the presentation style of the
window is Column, can I tell the data table to go
read the description of the window that needs to be
opened to obtain the amount of columns, the column
names, the size of each column... then create the
tables and present the values?
Or say the presentation style is Free... I need to go
find how many fields need to be created and their
positions in the form, and then the titles of each
field. Any ideas how this can be performed?
Creator won't help you with the graphical design, but it's definitely possible to dynamically compose the set of components that are children of a particular component. Doing so leverages the basic component APIs of JSF (javax.faces.component.UIComponent), so you'll want to grab yourself a copy of the JSF Javadocs (or use Creator's lookup facilities as you type your code) to understand what's possible.
The most important detail is that all components have a getChildren() method that returns a java.util.List of the child components for that component (as well as a getParent() to get the parent component). Any manipulation you do on this returned list is reflected in the structure of the overal component tree.
As a simple example, assume you want to add an input text component as a child of the form. You'd do something like this:
HtmlInputText input = new HtmlInputText();
input.setXxx(..); // Set properties as needed
form1.getChildren().add(input); // add new childCraig McClanahan -
Dynamic Internal Table creation and population
Hi gurus !
my issue refers to the slide 10 provided in this slideshow : https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b332e090-0201-0010-bdbd-b735e96fe0ae
My example is gonna sound dumb, but anyway: I want to dynamically select from a table into a dynamically created itab.
Letu2019s use only EKPO, and only field MENGE.
For this, I use Classes cl_abap_elemdescr, cl_sql_result_set and the Data Ref for table creation. But while fetching the resultset, program dumps when fields like MENGE, WRBTR are accessed. Obviously their type are not correctly taken into account by my program.
Here it comes:
DATA: element_ref TYPE REF TO cl_abap_elemdescr,
vl_fieldname TYPE string,
tl_components TYPE abap_component_tab,
sl_components LIKE LINE OF tl_components_alv,
linetype_lcl TYPE REF TO cl_abap_structdescr,
ty_table_type TYPE REF TO cl_abap_tabledescr,
g_resultset TYPE REF TO cl_sql_result_set
u2026
CONCATENATE sg_columns-table_name '-' sg_columns-column_name INTO vl_fieldname.
* sg_columns-table_name contains 'EKPO'
* sg_columns-column_name contains 'MENGE'
* getting the element as a component
element_ref ?= cl_abap_elemdescr=>describe_by_name( vl_fieldname ).
sl_components-name = sg_columns-column_name.
sl_components-type ?= element_ref.
APPEND sl_components TO tl_components.
* dynamic creation of internal table
linetype_lcl = cl_abap_structdescr=>create( tl_components ).
ty_table_type = cl_abap_tabledescr=>create(
p_line_type = linetype_lcl ).
u2026
* Then I will create my field symbol table and line. Code has been cut here.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
u2026
* Then I will execute my query. Here itu2019s: Select MENGE From EKPO Where Rownum = 1.
g_resultset = g_stmt_ref->execute_query( stmt_str ).
* Then structure for the Resultset is set
CALL METHOD g_resultset->set_param_struct
EXPORTING
struct_ref = dy_line.
* Fetching the lines of the resultset => Dumpu2026
WHILE g_resultset->next( ) > 0.
ASSIGN dy_line->* TO <dyn_wa>.
APPEND <dyn_wa> TO <dyn_table>.
ENDWHILE.
Anyone has any clue to how prevent my Dump ??
The component for MENGE seems to be described as a P7 with 2 decimals. And the resultset wanna use a QUAN type... or something like that !Hello
I have expanded your sample coding for selecting three fields out of EKPO:
*& Report ZUS_SDN_SQL_RESULT_SET
*& Thread: Dynamic Internal Table creation and population
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1375510"></a>
*& NOTE: Coding for dynamic structure / itab creation taken from:
*& Creating Flat and Complex Internal Tables Dynamically using RTTI
*& https://wiki.sdn.sap.com/wiki/display/Snippets/Creating+Flat+and+
*& Complex+Internal+Tables+Dynamically+using+RTTI
REPORT zus_sdn_sql_result_set.
TYPE-POOLS: abap.
DATA:
go_sql_stmt TYPE REF TO cl_sql_statement,
go_resultset TYPE REF TO cl_sql_result_set,
gd_sql_clause TYPE string.
DATA:
gd_tabfield TYPE string,
go_table TYPE REF TO cl_salv_table,
go_sdescr_new TYPE REF TO cl_abap_structdescr,
go_tdescr TYPE REF TO cl_abap_tabledescr,
gdo_handle TYPE REF TO data,
gdo_record TYPE REF TO data,
gs_comp TYPE abap_componentdescr,
gt_components TYPE abap_component_tab.
FIELD-SYMBOLS:
<gs_record> TYPE ANY,
<gt_itab> TYPE STANDARD TABLE.
START-OF-SELECTION.
continued.
Maybe you are looking for
-
I don't find any image output sharpening options in InDesign CS5. Don't they exists or is there another workflow? In the past I was told to resize and sharpen images in Photoshop before I place them in InDesign. Unfortunatley this is a very cumbersom
-
What is -----BEGIN CERTIFICATE----- in SSL
Hi, I have to communicate via SSL with the server (Soap based messages). So I have received the file from server and it's contains the bellow. -----BEGIN CERTIFICATE----- some encrypted value .... -----END CERTIFICATE----- Let me know that what
-
I am Brazilian and I will make a trip to Orlando. I wonder if there is political exchange between an iphone 4s for a iphone 5. If so, how do I replace the unit?
-
I can not install my version of Presenter 7 on my PC which now uses window 8 The message is "Power Point can not be detected..." Can someone explain how to solve this problem please.
-
Solman and JDI !!!
Hi All, <b>Solution Manager:</b>The SAP Solution Manager supports you throughout the entire lifecycle of your solutions, from the Business Blueprint thru configuration to production operation. It provides central access to tools methods and preconfig