Need ALV LIST for displaying Dynamic Internal Tables
Hi Guys,
I have some thing like 2 Dynamic internal tables.
Say 1st Internal table will be filled based on some condition.
say 2nd table will be filled based on some condition.
When appending the 1st Internal table, if that internal table is filled it creates another internal table of same kind and continues so on until some condition.
In the same way when appending the 2nd Internal table, if that internal table is filled it creates another internal table of same kind and continues so on until some condition.
My requirement is I need to display all these Internal tables in the output.
The output should look something like
1st Internal Table
some gap
2nd Internal Table
some gap
so on...................
Is there any standard ALV List, to display all these Internal Tables in such a way.
Thanks,
Prasad.
Hi.
One thing more here is code which get 10 records from 2 tables and then show them in ALV.
first when u execute it will show data from ist table.
when u go back (F3) then it will sow data from 2nd table.
But if u want to show both ALV on the same screen then u will have to use screen programin and using class u will have to create container and then have to do it.
But as i above mentioned. that sample code is as below.
REPORT ztn_test LINE-COUNT 100.
data: itab_ref type ref to data.
data: hstr type lvc_title.
data: tabname like DD02T-TABNAME.
tabname = 'MARA'. " First Table
create data itab_ref type standard table of (tabname).
field-symbols: <itab> type standard table.
assign itab_ref->* to <itab>.
select * UP TO 10 ROWS from (tabname) into corresponding fields of table <itab>.
perform showalv.
tabname = 'KNA1'. " 2nd Table
create data itab_ref type standard table of (tabname).
"field-symbols: <itab> type standard table.
assign itab_ref->* to <itab>.
select * UP TO 10 ROWS from (tabname) into corresponding fields of table <itab>.
perform showalv.
form showalv.
" to show that data in alv
type-pools: slis.
data: myalv type ref to cl_gui_alv_grid, "ALV Grid
fieldcat type slis_t_fieldcat_alv, "Field Catalog Table
ls_fcat type slis_fieldcat_alv, "Line of Field catalog.
ls_heading type slis_listheader, "Line of Heading.
layout type slis_layout_alv, "layout of ALV for Heading and Logo.
event type slis_t_event, "Event Raising to Display Heading.
event_str type slis_alv_event. "Event String.
type-pools: slis.
data: heading type slis_t_listheader. "List Heading.
if heading[] is initial.
ls_heading-typ = 'H'.
ls_heading-info = 'HR: Master Data Change History'.
append ls_heading to heading.
endif.
* ls_heading-typ = 'A'.
* ls_heading-info = ''.
* APPEND ls_heading TO heading.
* ALV DISPLAY *
*******Making Layout of ALV
layout-zebra = 'X'.
layout-colwidth_optimize = 'X'.
*Calling function to raise event to display heading and icon above ALV
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = event[]
* EXCEPTIONS
* LIST_TYPE_WRONG = 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.
******calling TOP_OF_PAGE Event
read table event with key name = 'TOP_OF_PAGE' into event_str.
if sy-subrc = 0.
move: 'TOP_OF_PAGE' to event_str-form.
modify event from event_str index sy-tabix.
endif.
**** Now use this Fuction to display ALV without any Screen Programming.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = 'SAPLZFSL_HR_UTILS' "sy-cprog
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
i_structure_name = tabname
* I_BACKGROUND_ID = ' '
i_grid_title = hstr "Heading of ALV Grid.
* I_GRID_SETTINGS =
is_layout = layout
* it_fieldcat = fieldcat[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
i_default = 'X'
i_save = 'X'
* IS_VARIANT =
it_events = event[]
* 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 = <itab>
* 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.
endform.
Similar Messages
-
No column text displayed in alv when i use dynamic internal table
Hi friends,
when I use dynamic internal table to display the fields in ALV formant, field column text was not displaying ,
total row of column text was blank.
can u sujjest me in this...
with regards,
prasad.Hi
That depends on how you've filled the catalog table, here u need to insert the description for the labels (short, medium and long) and the description for the layout variant management.
So u make sure to fill the fields like
SCRTEXT_L
SCRTEXT_M
SCRTEXT_S
REPTEXT
Max -
ALV rows to column dynamic internal table
Hello People ,
I am stuck in a report which displays an output in ALV as follows :-
bukrs | kntyp | konto | knfix | period | element | emeng | emein
1000 | 10 | 1100 | berlin | 11.2011 | AG | 0.148 | kgAG
1000 | 10 | 1100 | berlin | 11.2011 | AU | 0.104 | kgAU
1000 | 10 | 1100 | berlin | 11.2011 | GA | 0.207 | kgGA
And this table has many values corresponding to element AG,AU and GA respectively . For example , there would be many element AG's with many "EMENG" values . Similarly for AU and GA .
MY question :- I am asked to make AG , AU , GA as 3 different fields which should show the value "EMENG" under respective elements . Like :-
bukrs | kntyp | konto | knfix | period | AG | AU | GA | emein
1000 | 10 | 1100 | berlin | 11.2011 | 0.148 | 0.104 | 0.207 | kgAG
That should be my output . ( elements replaced by AG , AU and GA which comes from a Metal table ZXXXX where
metal no. 1 = AU
metal no. 2 = AG
metal no. 3 = GA
If there is any metal added to it would be metal no. 4 ,5,6,7 .... so on ) and then that should be added as a field in our report .. So that has to be DYNAMIC .
I am unable to move on with problem . Pls suggest ? I am pasting my report here ...
FORM select_table_gt_bb CHANGING p_gt_bb.
TABLES : zpam_as .
DATA : i_zpam_as TYPE TABLE OF zpam_as ,
wa_zpam_as LIKE LINE OF i_zpam_as ,
i_tcurr TYPE TABLE OF tcurr ,
wa_tcurr LIKE LINE OF i_tcurr,
zt_as TYPE TABLE OF zpam_as.
SELECT * FROM zpam_as INTO TABLE gt_as
WHERE bukrs EQ bukrs
AND kntyp IN kntyp
AND konto IN konto
AND knfix IN knfix
AND buper IN buper
AND element IN element
AND ameng IN ameng
AND ashkz IN ashkz
AND emeng IN emeng
AND eshkz IN eshkz
AND emein IN emein.
SELECT * FROM zpam_tcurr INTO TABLE gt_tcurr.
IF sy-subrc IS INITIAL.
LOOP AT gt_tcurr INTO gw_tcurr.
SELECT * FROM tcurr INTO wa_tcurr WHERE fcurr = gw_tcurr-fcurr AND
tcurr = tcurr.
ENDSELECT.
APPEND wa_tcurr TO i_tcurr.
DELETE ADJACENT DUPLICATES FROM i_tcurr.
ENDLOOP.
ENDIF.
IF i_tcurr IS NOT INITIAL.
LOOP AT gt_as INTO gw_as.
CLEAR sy-subrc.
LOOP AT i_tcurr
INTO wa_tcurr
WHERE fcurr = gw_as-emein.
gw_as-tcurr = wa_tcurr-tcurr.
gw_as-ukurs = wa_tcurr-ukurs.
gw_as-total = abs( gw_as-emeng ) * wa_tcurr-ukurs.
APPEND gw_as TO zt_as.
ENDLOOP.
IF sy-subrc <> 0.
gw_as-tcurr = 'None'.
gw_as-ukurs = ''.
gw_as-total = ''.
APPEND gw_as TO zt_as.
ENDIF.
ENDLOOP.
REFRESH gt_as.
LOOP AT zt_as INTO gw_as.
APPEND gw_as TO gt_as.
ENDLOOP.
ENDIF.
ENDFORM.
Priority normalized
Edited by: Rob Burbank on Dec 28, 2011 3:44 PMHey,
But after understanding my question correctly , you sure that dynamic internal table is the solution for it ? -
How to create Dynamic Internal table in ALV?
Hi all,
I have to create a ALV report based on dynamic internal table. The requirement is that when I enter the months in my selection screen I should get the data relevant to those many months only. For eg if in selection I have given January to March, I should get an ALV output with columns from January to March only.
Please help me with the coding part as I find it a bit confusing.
Please reply immediately.
Regards,
Bhavani.Hi BHAVANI,
first you have to prapare a field catalog [(see this)|http://help.sap.com/saphelp_470/helpdata/en/52/5f060de02d11d2b47d006094192fe3/frameset.htm]
and than you can use a Method cl_alv_table_create=>create_dynamic_table
I hope that help a little.
Regards Bogdan -
Usage of 'Select for all entries' for dynamic internal tables..
Hi all,
I have a situation where I need to use select for all entries for a dynamic internal table.
select * from /BIC/AZHSD_O1500 into i_table for all entries in <b>Dynamic_table</b> where doc_number = <dynamic_table????????>
here iam not knowing how to match the <dynamic_table????????> doc_number ?
the dynamic_table contains the doc_number as one field.
here dynaimc_table is the internal table which is dynamic.
I have tried various options but couldnot find the solution.
Please resolve.
Sidhartha.data : i_dyn_where type char72 occurs 0.
field-symbols : <fs> type table.
assign itab[] to <fs>.
i_dyn_where = 'docno = <fs>-docno'.
append i_dyn_where.
select *
from vbak
into table t_vbak
for all entries in <fs>
where (I_dyn_where). "Populate this where condition dynamically too
Hope this will solve ur prob. -
Select query for picking data in a dynamic internal table
Dear All,
Please help.
<u>The code is :</u>
p_table1 = itab_final-tabname1.
p_field1 = itab_final-fieldname1.
SELECT (p_field1) FROM (p_table1) INTO CORRESPONDING FIELDS OF TABLE <dyntable1>.
It is working fine when the domain is of CHAR
The piece of code is not working where domain is DATS, CURR, DEC, etc.
What shall I do so that it works for other domains also. Please its urgent......
<u>ERROR that came:</u>
An exception occurred. This exception will be dealt with in more detail
below. The exception, assigned to the class 'CX_SY_OPEN_SQL_DB', was not
caught, which
led to a runtime error. The reason for this exception is:
The data read during a SELECT access could not be inserted into the
target field.
Either conversion is not supported for the target field's type or the
target field is too short to accept the value or the data are not in a
form that the target field can acceptCheck below code
REPORT zpwtest .
*** Tables
DATA: lt_data TYPE REF TO data.
DATA: lt_fieldcatalog TYPE lvc_t_fcat.
data : p_field type string ,
p_table type string .
*** Structure
DATA: ls_fieldcatalog TYPE lvc_s_fcat.
*** Data References
DATA: new_line TYPE REF TO data.
*** Field Symbols
FIELD-SYMBOLS: <fs_data> TYPE REF TO data,
<fs_1> TYPE ANY TABLE,
<fs_2>,
<fs_3>.
ls_fieldcatalog-fieldname = 'MANDT'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'CARRID'. "Fieldname
ls_fieldcatalog-inttype = 'C'. "Internal Type C-> Character
APPEND ls_fieldcatalog TO lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'CONNID'.
ls_fieldcatalog-inttype = 'N'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'FLDATE'.
ls_fieldcatalog-inttype = 'D'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'PRICE'.
ls_fieldcatalog-inttype = 'P'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'CURRENCY'.
ls_fieldcatalog-inttype = 'C'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
ASSIGN lt_data TO <fs_data>.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fieldcatalog
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2
IF sy-subrc <> 0.
ENDIF.
*** So <FS_1> now points to our dynamic internal table.
ASSIGN <fs_data>->* TO <fs_1>.
*** Next step is to create a work area for our dynamic internal table.
CREATE DATA new_line LIKE LINE OF <fs_1>.
*** A field-symbol to access that work area
ASSIGN new_line->* TO <fs_2>.
<b>
p_field = 'mandt carrid connid fldate price currency' .
p_table = 'sflight' .
*** And to put the data in the internal table
SELECT (p_field)
FROM (p_table)
INTO CORRESPONDING FIELDS OF TABLE <fs_1>.
</b>
*** Access contents of internal table
LOOP AT <fs_1> ASSIGNING <fs_2>.
ASSIGN COMPONENT 5 OF STRUCTURE <fs_2> TO <fs_3>.
WRITE: / <fs_3>.
ENDLOOP. -
Building Field-Catalog for dynamic internal tables
Hi All,
I created a dynamic internal table(<fs_final>,<fs_final_line>) and populated data into it.Now I want to provide field catalog to these dynamic internal table.
Can anyone suggest me the how to create a field catalog for existing dynamic internal table.Thanks in advance.
Regards,
Chakradhar.
Moderator message - Please use proper subject line in future.
Message was edited by: Suhas SahaUse this code to get all components of internal table.
Then build fieldcatlog.
DATA: tab_return type abap_compdescr_tab,
components like line of tab_return.
perform get_int_table_fields using <fs_it> changing tab_return.
loop at tab_return into components.
wa_fldcat-fieldname = components-name. "Field Name
wa_fldcat-scrtext_m = components-name. "Column Heading
wa_fldcat-inttype = components-type_kind. "Data Type
wa_fldcat-intlen = components-length. "Data Lenght
wa_fldcat-decimals = components-decimals. "Data Decimal Places
append wa_fldcat to it_fldcat.
endloop.
form get_int_table_fields using t_data type any table
changing t_return type abap_compdescr_tab.
data:
oref_table type ref to cl_abap_tabledescr,
oref_struc type ref to cl_abap_structdescr,
oref_error type ref to cx_root,
text type string.
*Get the description of data object type
try.
oref_table ?=
cl_abap_tabledescr=>describe_by_data( t_data ).
catch cx_root into oref_error.
text = oref_error->get_text( ).
write: / text.
exit.
endtry.
*Get the line type
try.
oref_struc ?= oref_table->get_table_line_type( ).
catch cx_root into oref_error.
text = oref_error->get_text( ).
write: / text.
exit.
endtry.
append lines of oref_struc->components to t_return.
endform.
Regards
Sreekanth -
Popualting data into dynamic internal table
Hi all,
I am working on Dynamic internal tables.I have created the structure of internal table but i am unable to populate data into it.Though i have seen some of the forums but those didn't help me. please provide me the solution. Here is my code what i did.I have the data in itab and itab1.
My requirement is meinh fileds are dynamic.thie meinh and umren are two fileds in mvke table.for one record ihave to populate umren value for that particular meinh value.Pls help me.
mtart vkorg werks mtanr Meinh(kg) Meinh(gl)
fert 0353 0303 3231 Umren value Umren value
REPORT z123.
T Y P E - P O O L S
TYPE-POOLS :slis,abap.
T A B L E S
*Tables
TABLES: mara,marm,mvke,marc.
F I E L D - S Y M B O L S
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_wa> ,
<dyn_field>.
I N T E R N A L T A B L E S
Internal Tables declaration for ALV GRID/LIST
DATA: ls_fieldcat TYPE slis_fieldcat_alv, "FIELD CATALOG LIST
tb_uom_cat TYPE slis_t_fieldcat_alv, "FIELD CATALOG
ls_fieldcat1 TYPE lvc_s_fcat,
tb_dy_cat TYPE lvc_t_fcat, "FIELD CATALOG
tb_outputcat TYPE slis_t_fieldcat_alv,
tb_events TYPE slis_t_event,
ref_grid TYPE REF TO cl_gui_alv_grid,
t_events LIKE LINE OF tb_events.
DATA: BEGIN OF itab OCCURS 0,
mtart LIKE mara-mtart,
vkorg LIKE mvke-vkorg,
werks LIKE marc-werks,
matnr TYPE mara-matnr,
END OF itab.
DATA: BEGIN OF itab1 OCCURS 0,
matnr TYPE marm-matnr,
umren TYPE marm-umren,
meinh TYPE marm-meinh,
END OF itab1.
V A R I A B L E S
Global Variables
DATA: g_repid LIKE sy-repid. "Report ID
DATA: dy_table TYPE REF TO data,
dy_line TYPE REF TO data.
S E L E C T I O N S C R E E N
For User Input(Selection Criteria)
SELECTION-SCREEN BEGIN OF BLOCK b0 WITH FRAME TITLE text-001.
SELECT-OPTIONS :
s_mtart FOR mara-mtart OBLIGATORY, " Material type
s_vkorg FOR mvke-vkorg OBLIGATORY, " Sales Organization
s_plant FOR marc-werks, " Plant
s_meinh FOR marm-meinh. " Unit of Measure
SELECTION-SCREEN END OF BLOCK b0.
I N I T I A L I Z A T I O N
INITIALIZATION.
Program ID
g_repid = sy-repid. " Prog ID
A T S E L E C T I O N - S C R E E N
AT SELECTION-SCREEN.
Validate Material Type
PERFORM check_mtart.
Validate Sales Organization
PERFORM check_vkorg.
Validate Plant
PERFORM check_werks.
Validate Unit of Measure (UOM)
PERFORM check_meinh.
S T A R T - O F - S E L E C T I O N
START-OF-SELECTION.
Get Data
PERFORM get_data.
FIELD CATALOG FOR ALV
PERFORM fill_field_catalog_uom USING tb_uom_cat.
FIELD CATALOG FOR CREATING DYNAMIC INTERNAL TABLE
PERFORM fill_field_catalog_dy USING tb_dy_cat.
CREATING DYNAMIC INTERNAL TABLE
PERFORM dy_tab_create.
End of selection *
F O R M S
*& Form CHECK_MTART
Validate Material Type
FORM check_mtart .
Material Type
DATA :l_mtart LIKE t134-mtart.
CHECK NOT s_mtart IS INITIAL.
SELECT mtart UP TO 1 ROWS
INTO l_mtart
FROM t134
WHERE mtart IN s_mtart.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e899(mm) WITH 'Invalid Material Type'(002).
ENDIF.
ENDFORM. " CHECK_MTART
*& Form CHECK_VKORG
Validate Sales Organization
FORM check_vkorg .
Sales Oraganization
DATA :l_vkorg LIKE tvko-vkorg.
CHECK NOT s_vkorg IS INITIAL.
SELECT vkorg UP TO 1 ROWS
INTO l_vkorg
FROM tvko
WHERE vkorg IN s_vkorg.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e899(mm) WITH 'Invalid Sales Organization'(003).
ENDIF.
ENDFORM. " CHECK_VKORG
*& Form CHECK_WERKS
Validate Plant
FORM check_werks .
Plant
DATA :l_werks LIKE t001w-werks.
CHECK NOT s_plant IS INITIAL.
SELECT werks UP TO 1 ROWS
INTO l_werks
FROM t001w
WHERE werks IN s_plant.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e899(mm) WITH 'Invalid Plant'(004).
ENDIF.
ENDFORM. " CHECK_WERKS
*& Form CHECK_MEINH
Validate Unit of Measure (UOM)
FORM check_meinh .
Unit of Measure (UOM)
DATA :l_meinh LIKE t006-msehi.
CHECK NOT s_meinh IS INITIAL.
SELECT msehi UP TO 1 ROWS
INTO l_meinh
FROM t006
WHERE msehi IN s_meinh.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e899(mm) WITH 'Invalid Unit of Measure'(005).
ENDIF.
ENDFORM. " CHECK_MEINH
*& Form FILL_FIELD_CATALOG_UOM
text
FIELD CATALOG FOR ALV
FORM fill_field_catalog_uom USING l_fieldcat TYPE slis_t_fieldcat_alv.
DATA: BEGIN OF l_itab OCCURS 0,
meinh TYPE marm-meinh,
END OF l_itab.
DATA: l_count TYPE i.
DATA: l_fieldcat_col_pos TYPE i.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MTART'.
ls_fieldcat-key = ''.
ls_fieldcat-col_pos = 1.
ls_fieldcat-ref_fieldname = 'MTART'.
ls_fieldcat-ref_tabname = 'MARA'.
APPEND ls_fieldcat TO l_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'VKORG'.
ls_fieldcat-key = ''.
ls_fieldcat-col_pos = 2.
ls_fieldcat-ref_fieldname = 'VKORG'.
ls_fieldcat-ref_tabname = 'MVKE'.
APPEND ls_fieldcat TO l_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'WERKS'.
ls_fieldcat-key = ''.
ls_fieldcat-col_pos = 3.
ls_fieldcat-ref_fieldname = 'WERKS'.
ls_fieldcat-ref_tabname = 'MARC'.
APPEND ls_fieldcat TO l_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MATNR'.
ls_fieldcat-key = 'x'.
ls_fieldcat-col_pos = 4.
ls_fieldcat-ref_fieldname = 'MATNR'.
ls_fieldcat-ref_tabname = 'MARA'.
APPEND ls_fieldcat TO l_fieldcat.
CLEAR ls_fieldcat.
l_fieldcat_col_pos = 5.
Getting the UOM as per user selection
SELECT msehi FROM t006
INTO TABLE l_itab
WHERE msehi IN s_meinh.
LOOP AT l_itab.
ls_fieldcat-fieldname = l_itab-meinh.
ls_fieldcat-key = ''.
ls_fieldcat-col_pos = l_fieldcat_col_pos.
ls_fieldcat-ref_fieldname = 'MSEHI'.
ls_fieldcat-ref_tabname = 'T006'.
APPEND ls_fieldcat TO l_fieldcat.
CLEAR ls_fieldcat.
l_fieldcat_col_pos = l_fieldcat_col_pos + 1.
ENDLOOP.
ENDFORM. " FILL_FIELD_CATALOG_UOM
*& Form DISPLAY_DATA
text
--> p1 text
<-- p2 text
FORM display_data .
ENDFORM. " DISPLAY_DATAENDFORM. " FILL_FIELD_CATALOG_UOM
*& Form DY_TAB_CREATE
text
--> p1 text
<-- p2 text
FORM dy_tab_create .
CREATE DYNAMIC INTERNAL TABLE AND ASSIGN TO FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = tb_dy_cat
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
*CREATE DYNAMIC WORK AREA AND AASIGN TO FS
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
ENDFORM. " DY_TAB_CREATE
*& Form FILL_FIELD_CATALOG_DY
text
FIELD CATALOG FOR CREATING A DYNAMIC TABLE
FORM fill_field_catalog_dy USING l_fieldcat TYPE lvc_t_fcat.
DATA: BEGIN OF l_itab OCCURS 0,
meinh TYPE marm-meinh,
END OF l_itab.
DATA: l_count TYPE i.
DATA: l_fieldcat_col_pos TYPE i.
DATA: l_umren TYPE string.
DATA: l_var TYPE string.
CLEAR ls_fieldcat.
ls_fieldcat1-fieldname = 'MTART'.
ls_fieldcat1-key = ''.
ls_fieldcat1-col_pos = 1.
ls_fieldcat1-datatype = 'char'.
ls_fieldcat1-intlen = 4.
APPEND ls_fieldcat1 TO l_fieldcat.
CLEAR ls_fieldcat1.
ls_fieldcat1-fieldname = 'VKORG'.
ls_fieldcat1-key = ''.
ls_fieldcat1-col_pos = 2.
ls_fieldcat1-datatype = 'char'.
ls_fieldcat1-intlen = 4.
APPEND ls_fieldcat1 TO l_fieldcat.
CLEAR ls_fieldcat1.
ls_fieldcat1-fieldname = 'WERKS'.
ls_fieldcat1-key = ''.
ls_fieldcat1-col_pos = 3.
ls_fieldcat1-datatype = 'char'.
ls_fieldcat1-intlen = 4.
APPEND ls_fieldcat1 TO l_fieldcat.
CLEAR ls_fieldcat1.
ls_fieldcat1-fieldname = 'MATNR'.
ls_fieldcat1-key = 'x'.
ls_fieldcat1-col_pos = 4.
ls_fieldcat1-datatype = 'char'.
ls_fieldcat1-intlen = 18.
APPEND ls_fieldcat1 TO l_fieldcat.
CLEAR ls_fieldcat1.
l_fieldcat_col_pos = 5.
Getting the UOM as per user selection
SELECT msehi FROM t006
INTO TABLE l_itab
WHERE msehi IN s_meinh.
SORT l_itab ASCENDING.
DESCRIBE TABLE l_itab LINES l_count.
LOOP AT l_itab.
ls_fieldcat1-fieldname = l_itab-meinh.
ls_fieldcat1-key = ''.
ls_fieldcat1-col_pos = l_fieldcat_col_pos.
ls_fieldcat1-datatype = 'dec'.
ls_fieldcat1-intlen = 5.
APPEND ls_fieldcat1 TO l_fieldcat.
CLEAR ls_fieldcat1.
l_fieldcat_col_pos = l_fieldcat_col_pos + 1.
ENDLOOP.
ENDFORM. " FILL_FIELD_CATALOG_DY
*& Form GET_DATA
text
--> p1 text
<-- p2 text
FORM get_data .
SELECT
amtart bvkorg cwerks amatnr
INTO TABLE itab
FROM mara AS a
JOIN mvke AS b ON bmatnr = amatnr
JOIN marc AS c ON cmatnr = bmatnr
JOIN marm AS d ON dmatnr = cmatnr
WHERE a~mtart IN s_mtart
AND b~vkorg IN s_vkorg
AND c~werks IN s_plant.
SORT itab ASCENDING.
DELETE ADJACENT DUPLICATES FROM itab.
SELECT matnr umren meinh FROM marm
APPENDING TABLE itab1
FOR ALL ENTRIES IN itab
WHERE matnr = itab-matnr
AND meinh IN s_meinh .
ENDFORM. " GET_DATAcan you check this for creation of dynamic table
******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-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.
ENDLOOP. -
How to add new field into dynamic internal table
Hello Expert.
how to add new field into dynamic internal table.
PARAMETERS: P_TABLE(30). "table name
DATA: I_TAB TYPE REF TO DATA.
FIELD-SYMBOLS: <TAB> TYPE standard TABLE.
*Create dynamic FS
create DATA I_TAB TYPE TABLE OF (p_table).
ASSIGN I_TAB->* TO <TAB>.
SELECT * FROM (p_table) INTO TABLE <TAB>.
here i want to add one more field into <TAB> at LAST position and my
Field name = field_stype and
Field type = 'LVC_T_STYL'
could you please helpme out .Hi,
Please find the code below.You can add the field acc to your requirement.
Creating Dynamic internal table
TYPE-POOLS: slis.
FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE, u201C Dynamic internal table name
<fs_dyntable>, u201C Field symbol to create work area
<fs_fldval> type any. u201C Field symbol to assign values
PARAMETERS: p_cols(5) TYPE c. u201C Input number of columns
DATA: t_newtable TYPE REF TO data,
t_newline TYPE REF TO data,
t_fldcat TYPE slis_t_fldcat_alv,
t_fldcat TYPE lvc_t_fcat,
wa_it_fldcat TYPE lvc_s_fcat,
wa_colno(2) TYPE n,
wa_flname(5) TYPE c.
Create fields .
DO p_cols TIMES.
CLEAR wa_it_fldcat.
move sy-index to wa_colno.
concatenate 'COL'
wa_colno
into wa_flname.
wa_it_fldcat-fieldname = wa_flname.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 10.
APPEND wa_it_fldcat TO t_fldcat.
ENDDO.
Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_fldcat
IMPORTING
ep_table = t_newtable.
ASSIGN t_newtable->* TO <t_dyntable>.
Create dynamic work area and assign to FS
CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
ASSIGN t_newline->* TO <fs_dyntable>.
Populating Dynamic internal table
DATA: fieldname(20) TYPE c.
DATA: fieldvalue(10) TYPE c.
DATA: index(3) TYPE c.
DO p_cols TIMES.
index = sy-index.
MOVE sy-index TO wa_colno.
CONCATENATE 'COL'
wa_colno
INTO wa_flname.
Set up fieldvalue
CONCATENATE 'VALUE' index INTO
fieldvalue.
CONDENSE fieldvalue NO-GAPS.
ASSIGN COMPONENT wa_flname
OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
<fs_fldval> = fieldvalue.
ENDDO.
Append to the dynamic internal table
APPEND <fs_dyntable> TO <t_dyntable>.
Displaying dynamic internal table using Grid.
DATA: wa_cat LIKE LINE OF fs_fldcat.
DO p_cols TIMES.
CLEAR wa_cat.
MOVE sy-index TO wa_colno.
CONCATENATE 'COL'
wa_colno
INTO wa_flname.
wa_cat-fieldname = wa_flname.
wa_cat-seltext_s = wa_flname.
wa_cat-outputlen = '10'.
APPEND wa_cat TO fs_fldcat.
ENDDO.
Call ABAP List Viewer (ALV)
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = fs_fldcat
TABLES
t_outtab = <t_dyntable>. -
How to do parallel processing with dynamic internal table
Hi All,
I need to implement parallel processing that involves dynamically created internal tables. I tried doing so using RFC function modules (using starting new task and other such methods) but didn't get success this requires RFC enabled function modules and at the same time RFC enabled function modules do not allow generic data type (STANDARD TABLE) which is needed for passing dynamic internal tables. My exact requirement is as follows:
1. I've large chunk of data in two internal tables, one of them is formed dynamically and hence it's structure is not known at the time of coding.
2. This data has to be processed together to generate another internal table, whose structure is pre-defined. But this data processing is taking very long time as the number of records are close to a million.
3. I need to divide the dynamic internal table into (say) 1000 records each and pass to a function module and submit it to run in another task. Many such tasks will be executed in parallel.
4. The function module running in parallel can insert the processed data into a database table and the main program can access it from there.
Unfortunately, due to the limitation of not allowing generic data types in RFC, I'm unable to do this. Does anyone has any idea how to implement parallel processing using dynamic internal tables in these type of conditions.
Any help will be highly appreciated.
Thanks and regards,
Ashintry the below code...
DATA: w_subrc TYPE sy-subrc.
DATA: w_infty(5) TYPE c.
data: w_string type string.
FIELD-SYMBOLS: <f1> TYPE table.
FIELD-SYMBOLS: <f1_wa> TYPE ANY.
DATA: ref_tab TYPE REF TO data.
CONCATENATE 'P' infty INTO w_infty.
CREATE DATA ref_tab TYPE STANDARD TABLE OF (w_infty).
ASSIGN ref_tab->* TO <f1>.
* Create dynamic work area
CREATE DATA ref_tab TYPE (w_infty).
ASSIGN ref_tab->* TO <f1_wa>.
IF begda IS INITIAL.
begda = '18000101'.
ENDIF.
IF endda IS INITIAL.
endda = '99991231'.
ENDIF.
CALL FUNCTION 'HR_READ_INFOTYPE'
EXPORTING
pernr = pernr
infty = infty
begda = '18000101'
endda = '99991231'
IMPORTING
subrc = w_subrc
TABLES
infty_tab = <f1>
EXCEPTIONS
infty_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
subrc = w_subrc.
ELSE.
ENDIF. -
How to upload data with dynamic internal table
Hi,
I have to upload the basic , sales, purchasing view data by using bapi depend on check box selected for views.
i have filled fieldcatalog for selected views and pass the field catalog structure to dynamic int table and
import it into the field symbol <fs_data>. this field symbol assigned to <fs_1>.
then callED the 'GUI_UPLOAD ' and when i pass field symbo for function module i am getting first 10 rows 0f the file .
flat file has basic data,sales ,purchase fields data
ex: i was selected basicview and purchase view and execute i am getting basic,sales view data.
how can i get only basic and purchase data.hi ,
please find code.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fieldcatalog
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0. "#EC NEEDED
ENDIF.
So <FS_1> now points to our dynamic internal table.
ASSIGN <fs_data>->* TO <fs_1>.
Next step is to create a work area for our dynamic internal table.
CREATE DATA new_line LIKE LINE OF <fs_1>.
A field-symbol to access that work area
ASSIGN new_line->* TO <fs_2>.
ASSIGN new_line->* TO <fs_3>.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p_f
filetype = 'DAT'
TABLES
data_tab = <fs_1>
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. -
hi all,
i am working with dynamic internal table. how to use a read statement for the dynamic internal table.
Thankshi
try with this sample code.
DATA: tab TYPE TABLE OF mara,
field_key TYPE char100.
FIELD-SYMBOLS: <tab> TYPE ANY TABLE,
<wa> TYPE ANY.
SELECT * UP TO 10 ROWS FROM mara INTO TABLE tab[].
ASSIGN tab[] TO <tab>.
field_key = 'MATNR'.
READ TABLE <tab> ASSIGNING <wa>
WITH KEY (field_key) = '000000000000000200'.
Cheers,
Madhu -
Create a dynamic internal table
Hi ,
Can any one send me some code for creating dynamic internal table
My req is like this
Input table:
OP QUAN DATE
1 2 10/10/2009
2 3 10/10/2009
3 2 11/10/2009
4 1 12/10/2009
Output table should look like this ( there are 3 different dates in above input and my output should have 3 additional columns and quan should fall under date)
OP 10/10/2009 11/10/2009 12/10/2009
1 2 0 0
2 3 0 0
3 0 2 0
4 0 0 1
Any quick respone will be greatlt appreciated
Moderator message - Please search before asking - post locked
Edited by: Rob Burbank on Dec 16, 2009 4:52 PMThe dynamic creation of internal tables has been discussed many times before in the forum. Please search the forum for them. If you have difficulties after that, post a new message with the code you have to create the table along with a description of your difficulty.
Rob -
Dynamic internal tables using field symbols
Hello,
Is it possible to create a dynamic table where the no of fields in the internal table can be created dynamically(using field symbols).
Say sometimes internal tables with 10 fields and depending upon the requirement the fields can be dynamically increased or decreased in runtime.
Thanks.Hi,
Go through the following code....
*Data definitions
*** Tables
data: lt_data type ref to data.
data: lt_fieldcatalog type lvc_t_fcat.
*** Structure
data: ls_fieldcatalog type lvc_s_fcat.
*** Data References
data: new_line type ref to data,
fs_data type ref to data.
*** Field Symbols
field-symbols: <fs_data> type ref to data,
<fs_1> type any table,
<fs_2>,
<fs_3>.
*Populating the internal table with fieldnames required for our dynamic
*internal table
ls_fieldcatalog-fieldname = 'MANDT'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'CARRID'. "Fieldname
ls_fieldcatalog-inttype = 'C'. "Internal Type C-> Character
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'CONNID'.
ls_fieldcatalog-inttype = 'N'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'FLDATE'.
ls_fieldcatalog-inttype = 'D'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'PRICE'.
ls_fieldcatalog-inttype = 'P'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'CURRENCY'.
ls_fieldcatalog-inttype = 'C'.
append ls_fieldcatalog to lt_fieldcatalog.
*Calling the method CREATE_DYNAMIC_TABLE
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = lt_fieldcatalog
importing
ep_table = fs_data
exceptions
generate_subpool_dir_full = 1
others = 2
if sy-subrc <> 0.
endif.
*Assigning Field-Symbol to our dynamic internal table
assign lt_data to <fs_data>.
*Internal Table is ready, now to put data in that table
*** So <FS_1> now points to our dynamic internal table.
assign fs_data->* to <fs_1>.
*** Next step is to create a work area for our dynamic internal table.
create data new_line like line of <fs_1>.
*** A field-symbol to access that work area
assign new_line->* to <fs_2>.
*** And to put the data in the internal table
select
mandt
carrid
connid
fldate
price
currency
from sflight
into corresponding fields of table <fs_1>.
*** Access contents of internal table
loop at <fs_1> assigning <fs_2>.
do 5 times.
assign component sy-index of structure <fs_2> to <fs_3>.
write: <fs_3>.
enddo.
skip 1.
endloop.
top-of-page.
write:/5 'FUJITSU CONSULTING COMPANY' inverse color 6,
50 sy-datum inverse color 6,
70 sy-pagno inverse color 6.
uline.
<REMOVED BY MODERATOR>
Vijay C
Code Formatted by: Alvaro Tejada Galindo on Apr 14, 2008 1:47 PM -
Problem with grid display in ALV for dynamic internal tables
Hi,
I am using dynamic internal tables in my program. To display it in grid format after populating it, I have used the following class and method. Here Im getting sy-subrc = 0 but, the grid is not getting displayed. Can some one pls help me with this.,
DATA: W_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA: w_tabname TYPE w_tabname.
CREATE OBJECT W_GRID
EXPORTING I_PARENT = CL_GUI_CONTAINER=>SCREEN0.
CALL METHOD W_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME = W_TABNAME
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_LAYOUT =
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
IR_SALV_ADAPTER =
CHANGING
IT_OUTTAB = <FS_1>
IT_FIELDCATALOG = LT_FIELDCATALOG2
IT_SORT =
IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
others = 4
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Here, <FS_1> is the field symbol of table type and it holds all my data. and LT_FIELDCATALOG2 is the structure of my fieldcatalog
Thanks and Regards,
AvinashHi Avinash,
Either use parameter
I_STRUCTURE_NAME = W_TABNAME
or
IT_FIELDCATALOG = LT_FIELDCATALOG2
Both are not required.
At the end of ur program simply use a write statement like below. Your program will work.
IF SY-SUBRC 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Write /. <----
Thanks,
Edited by: Sap Fan on Oct 6, 2009 7:17 AM
Maybe you are looking for
-
I have a small hosting company and was wondering what is required to be installed on a Win2k Server to host Java Servlets and JSP pages for a client of mine?
-
Re: - WRT54GS Latest Firmware
Well I just wanted to ask which WRT54GS Firmware is the latest 7.0 or 7.2, they both got the same release date so I really dunno which 1 to go for any suggestions ? Thanks Yours Faithfully, iR0cKtHeBl0cK, ................!Hacking Boss!...............
-
I have been happily using imovie HD for some time. I distibute the finished article in the form of an SVCD made using toast 7.0.2. Usually I just drag the whole imovie project into the toast window and toast does the lot. No need to export first to f
-
Is there any issue with iphone 6 64gb storage?
Is there any issue with iphone 6 64gb storage?
-
Sdatellite M100 does not recognise CD/DVD drive in Windows XP
In device manager it is listed but with a yellow explanation mark. No mention of it in my computer. No icon. I am able to open the drawer and i have put several types of cd/dvds in their with no results. The light flashes orange on the drawer door. T