How to use dynamic internal table with FOR ALL ENTRIES
Hello SDNers,
I am having a dynamic internal table & want to use FOR ALL ENTRIES(FAE) using this dyn. table.
This works fine for me:
IF <lt_tmp> IS NOT INITIAL. "<lt_tmp> is my dyn. internal table
SELECT field1 field2
FROM TABLE ztable
INTO TABLE itab "Itab is a static table
FOR ALL ENTRIES IN <lt_tmp>
WHERE (lv_dynwhere). "lv_dynwhere -> dynamic where clause
ENDIF.
SAP documentation says:
"The logical expression sql_cond of the WHERE condition can be comprised of several logical expressions using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one comparison with a column of the internal table itab that can be specified statically or dynamically. "
How do we specify the column of the internal table dynamically ? Can we do something like this:
IF <lt_tmp> IS NOT INITIAL. "<lt_tmp> is my dyn. internal table
SELECT field1 field2
FROM TABLE
INTO TABLE itab "Itab is a static table
FOR ALL ENTRIES IN <lt_tmp>
WHERE key_field1 = (dynamic token for column1 of <lt_tmp>)
key_field2 = (dynamic token for column2 of <lt_tmp>)
ENDIF.
ENDIF.
Let me know if i am not clear about my requirement.
BR,
Suhas
Hello Thomas,
What i meant was something like this:
WHERE key_field1 = ('<LT_TMP-COL1>') AND
key_field2 = ('<LT_TMP-COL2>')
I am confused by what SAP means with "dynamic representation of internal table columns" in FAE ?
@Rob: I was referring to SAPNW 7.0 documentation & the phrase (release 6.40 & higher) is missing. Anyways fyi i am on ECC5.0 ABAP release 6.40.
@Subhankar: This is what Marcin had proposed in For all entries and dynamic table.
Thanks,
Suhas
Edited by: Suhas Saha on Apr 6, 2010 11:53 AM
Similar Messages
-
How to use single buffered table with FOR ALL ENTRIES KEYWORD
Hai,
I'm Using TJ02T Database table, It is single buffered table but at the same time I want to use FOR ALL ENTRIES KEYWORD , Please Help me.
Regards,
S.JananiHi,
FOR ALL ENTRIES will not depend on the buffering nature of the table. The single buffered table will only only buffer one record into memory. You can still use the statement to query the values, but it may have performance problems if the data volume is high since the records are not completely buffered into memory, the time will spent in getting data from DB.
Thanks..
Preetham S -
Dynamic Select Query including Dynamic Tables with For all Entries
Hello everyone,
I need to create a select query which involves using of Dynamic Tables.
Suppose I have a dynamic table <d1> which consist of let say 10 records.
Now i need to make a select query putting data into another dynamic table <d2>
CONCATENATE keyfield '=' '<d1>' INTO g_condition SEPARATED BY space.
CONCATENATE g_condition '-' keyfield INTO g_condition.
SELECT * FROM (wa_all_tables-name) INTO CORRESPONDING FIELDS OF TABLE <d1>
FOR ALL ENTRIES IN <d1>
WHERE (g_condition).
But it is giving dump.
Please help me on this....Short text
A condition specified at runtime has an unexpected format.
What happened?
Error in the ABAP Application Program
The current ABAP program "ZNG_CUSTOMWRITE" had to be terminated because it has
come across a statement that unfortunately cannot be executed.
Error analysis
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SEMANTICS', was
not caught in
procedure "WRITE_ARCHIVE_PROD" "(FORM)", nor was it propagated by a RAISING
clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
The current ABAP program has tried to execute an Open SQL statement
which contains a WHERE, ON or HAVING condition with a dynamic part.
The part of the WHERE, ON or HAVING condition specified at runtime in
a field or an internal table, contains the invalid value "ZCOURIER-ZCOURIERID".
CONCATENATE keyfield '=' g_header INTO g_condition SEPARATED BY space.
CONCATENATE g_condition '-' keyfield INTO g_condition.
SELECT * FROM (wa_all_tables-name) INTO CORRESPONDING FIELDS OF TABLE <dyn_table1>
FOR ALL ENTRIES IN <dyn_table>
WHERE (g_condition). -
Using aggregate function along with for all entries: sugest alternative
My requirement:
For each record in i_vbap for which 'charg' is initial, need to determine batch using the following logic:
For the material (MATNR) in i_vbap, select the batch (CHARG) which has the largest (MAX) unrestricted inventory quantity (CLABS) from MCHB table.
How do I implement this logic without using select statement inside a loop as I cannot use MAX ( CLABS ) function along with FOR ALL ENTRIES in a SELECT?
Suggest an alternative.For each record in i_vbap for which 'charg' is initial ,fetch all the existing 'clabs' value.
[ Remember to include all the key fields in selct ]
Sort the new table .
Put a loop,use at end of 'charg' and append to another table. U get ur solution
I think this should be the most economic way to do so. -
How to use dynamic internal table when using gui_upload?
Hi Experts,
my scenario is like i have header data, item data and serial numbers.
so with respect to the quantity in unit of measure ,there will be number of serial numbers..
i have declared the dynamic internal table,but i am not getting the logic to change the structure accordingly with respect to the flat file entries..
is it possible to do or its not possible....any suggestion!!!!i have declared like this....
TYPES: BEGIN OF ty_final,
bldat TYPE string, "Document Date
budat TYPE string, "Psting Date
bktxt TYPE string, "Document Header Text
werks TYPE string, "Plant
lgort TYPE string, "Storage Location
matnr TYPE string, "Material Number
erfmg TYPE string, "Quantity in Unit Of Entry
anln1 TYPE string, "Asset Number
anln2 TYPE string, "Asset Subnumber
sernr TYPE string, "serial Number
END OF ty_final.
DATA : it_final TYPE TABLE OF ty_final,
wa_final TYPE ty_final.
FIELD-SYMBOLS : <fs_final> TYPE table.
ASSIGN it_final TO <fs_final>.
after this i called gui upload and passed internal table it_final..
but i have to change the internal table structure dynamically before the upload function.so that it will match with the flat file...
Regards
KarthickThere are at least two approaches you can use to change/generate new dynamic-structured table. Either with [RTTI + RTTS|https://wiki.sdn.sap.com/wiki/display/Snippets/CreatingFlatandComplexInternalTablesDynamicallyusingRTTI] or using [CL_ALV_TABLE_CREATE|http://www.sdn.sap.com/irj/scn/advancedsearch?query=cl_alv_table_create] . In this one just determine fieldcatalog of current table and change it accordingly, then regenarate table.
There are plenty of examples in SCN for this. You should not face difficulties applying this.
Regards
Marcin -
How to create Dynamic internal table with columns also created dynamically.
Hi All,
Any info on how to create a dynamic internal table along with columns(fields) also to be created dynamically.
My requirement is ..On the selection screen I enter the number of fields to be in the internal table which gets created dynamically.
I had gone thru some posts on dynamic table creation,but could'nt find any on the dynamic field creation.
Any suggestions pls?
Thanks
NaraI don't understand ...
something like that ?
* Form P_MODIFY_HEADER. *
form p_modify_header.
data : is_fieldcatalog type lvc_s_fcat ,
v_count(2) type n ,
v_date type d ,
v_buff(30).
* Update the fieldcatalog.
loop at it_fieldcatalog into is_fieldcatalog.
check is_fieldcatalog-fieldname+0(3) eq 'ABS' or
is_fieldcatalog-fieldname+0(3) eq 'VAL' .
move : is_fieldcatalog-fieldname+3(2) to v_count ,
p_perb2+5(2) to v_date+4(2) ,
p_perb2+0(4) to v_date+0(4) ,
'01' to v_date+6(2) .
v_count = v_count - 1.
call function 'RE_ADD_MONTH_TO_DATE'
exporting
months = v_count
olddate = v_date
importing
newdate = v_date.
if is_fieldcatalog-fieldname+0(3) eq 'ABS'.
concatenate 'Quantité 0'
v_date+4(2)
v_date+0(4)
into v_buff.
else.
concatenate 'Montant 0'
v_date+4(2)
v_date+0(4)
into v_buff.
endif.
move : v_buff to is_fieldcatalog-scrtext_s ,
v_buff to is_fieldcatalog-scrtext_m ,
v_buff to is_fieldcatalog-scrtext_l ,
v_buff to is_fieldcatalog-reptext .
modify it_fieldcatalog from is_fieldcatalog.
endloop.
* Modify the fieldcatalog.
call method obj_grid->set_frontend_fieldcatalog
exporting it_fieldcatalog = it_fieldcatalog.
* Refresh the display of the grid.
call method obj_grid->refresh_table_display.
endform. " P_MODIFY_HEADER -
How to use Dynamic Internal table
Hello,
I have a requirement where I need to pick a field from final internal table and display that field as ALV columns and I have to pick another field in the same INternal table to display it as a corresponding value for each header DYNAMICALLY.
lw_fieldcat-col_pos = 1.
lw_fieldcat-tabname = 'T_FINAL'.
lw_fieldcat-fieldname = 'ATTR20A'.
lw_fieldcat-seltext_m = 'SUBSTANCE ID'.
lw_fieldcat-outputlen = '21'.
lw_fieldcat-fix_column = 'X'.
lw_fieldcat-key = 'X'.
APPEND lw_fieldcat TO lt_fieldcat.
CLEAR LW_FIELDCAT.
lw_fieldcat-col_pos = 2.
lw_fieldcat-tabname = 'T_FINAL'.
lw_fieldcat-fieldname = 'PRVSY'.
lw_fieldcat-seltext_m = 'R3 MAT NBR'.
lw_fieldcat-outputlen = '14'.
lw_fieldcat-FIX_COLUMN = 'X'.
lw_fieldcat-key = 'X'.
APPEND lw_fieldcat TO lt_fieldcat.
CLEAR LW_FIELDCAT.
These 2 fields are constant, now i need to display fields dynamically from the field STCTS (for dynamic header) CCNGN (for the value in each header)
In the below code the logic is working to pick appropriate value for each header.
DATA : Y_I_FCAT TYPE LVC_T_FCAT,
Y_WA_FCAT LIKE LINE OF Y_I_FCAT.
DATA : T_NEWFINAL TYPE STANDARD TABLE OF TY_FINAL,
WA_NEWFINAL TYPE TY_FINAL.
LOOP AT T_FINAL INTO WA_FINAL
WHERE STCTS IS NOT INITIAL
CONCATENATE 'SUBID CLASSIFICATION-' WA_FINAL-STCTS
INTO Y_WA_FCAT-FIELDNAME.
INTO Y_WA_FCAT-SCRTEXT_M.
APPEND Y_WA_FCAT TO Y_I_FCAT. "Header of column appear as
'SUBID SUBID CLASSIFICATION-AR-HTS'
CLEAR Y_WA_FCAT.
MOVE WA_FINAL-CCNGN TO WA_NEWFINAL-CCNGN. "HERE IT WILL PICK THE VALUE FOR THE ABOVE " HEADER EX : '2345'
*&THIS STATEMENT WILL MOVE THE KEY FIELD TO
*&WA_NEWFINAL.
MOVE WA_FINAL-GUID_PR TO WA_NEWFINAL-GUID_PR.
APPEND WA_NEWFINAL TO T_NEWFINAL.
CLEAR : WA_FINAL,
WA_NEWFINAL.
ENDLOOP.
How should i pass it to the dynamic interanl table and then to the ALV grid filed catlog.
Below is my code for refernce :
**DATA : Y_I_FCAT TYPE LVC_T_FCAT,
Y_WA_FCAT LIKE LINE OF Y_I_FCAT.
Y_WA_FCAT TYPE LVC_S_FCAT.
**DATA : T_NEWFINAL TYPE STANDARD TABLE OF TY_FINAL,
WA_NEWFINAL TYPE TY_FINAL.
*DATA : W_STRING TYPE STRING.
DATA : WA_FLNAME(32) TYPE C.
*LOOP AT T_FINAL INTO WA_FINAL
WHERE STCTS IS NOT INITIAL
AND CCNGN IS NOT INITIAL.
*ADD 1 TO COUNTER.
*ENDLOOP.
*DO COUNTER TIMES.
LOOP AT T_FINAL INTO WA_FINAL
WHERE STCTS IS NOT INITIAL
AND CCNGN IS NOT INITIAL.
CONCATENATE 'SUBID CLASSIFICATION-' WA_FINAL-STCTS
INTO Y_WA_FCAT-FIELDNAME.
INTO Y_WA_FCAT-SCRTEXT_M.
INTO WA_FLNAME.
Y_WA_FCAT-FIELDNAME = WA_FLNAME.
Y_WA_FCAT-SELTEXT = WA_FLNAME.
APPEND Y_WA_FCAT TO Y_I_FCAT.
CLEAR Y_WA_FCAT.
MOVE WA_FINAL-CCNGN TO W_STRING.
MOVE WA_FINAL-CCNGN TO WA_NEWFINAL-CCNGN.
*&THIS STATEMENT WILL MOVE THE KEY FIELD TO
*&WA_NEWFINAL.
MOVE WA_FINAL-GUID_PR TO WA_NEWFINAL-GUID_PR.
APPEND WA_NEWFINAL TO T_NEWFINAL.
CLEAR : WA_FINAL,
WA_NEWFINAL.
ENDIF.
*ENDDO.
ENDLOOP.
PERFORM CREATE_DYNAMIC_ITAB.
LOOP AT Y_I_FCAT INTO Y_WA_FCAT. "IT_FIELDCAT INTO LW_FIELDCAT.
MOVE : Y_WA_FCAT-SCRTEXT_M TO LW_FIELDCAT-SELTEXT_M,
Y_WA_FCAT-FIELDNAME TO LW_FIELDCAT-FIELDNAME,
Y_WA_FCAT-TABNAME TO LW_FIELDCAT-TABNAME,
Y_WA_FCAT-COL_POS TO LW_FIELDCAT-COL_POS,
Y_WA_FCAT-SCRTEXT_M TO LW_FIELDCAT-SELTEXT_M.
Y_WA_FCAT-DATATYPE TO LW_FIELDCAT-DATATYPE,
Y_WA_FCAT-INTLEN TO LW_FIELDCAT-INTLEN.
APPEND LW_FIELDCAT TO LT_FIELDCAT.
ENDLOOP.
ENDFORM. " DYNAMIC
*& Form CREATE_DYNAMIC_ITAB
text
--> p1 text
<-- p2 text
FORM CREATE_DYNAMIC_ITAB .
*DATA : DY_TABLE TYPE REF TO DATA,
DY_LINE TYPE REF TO DATA.
DATA : Y_LV_COMP TYPE STRING.
*FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,
<DYN_WA>,
<DYN_FIELD>.
*FIELD-SYMBOLS : <y_fld> TYPE ANY.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = Y_I_FCAT
IMPORTING
EP_TABLE = DY_TABLE.
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 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>.
LOOP AT T_FINAL INTO WA_FINAL.
Y_LV_COMP = 'ATTR20A'.
ASSIGN COMPONENT Y_LV_COMP OF STRUCTURE <DYN_WA> TO <Y_FLD>.
<Y_FLD> = WA_FINAL-ATTR20A.
Y_LV_COMP = 'PRVSY'.
ASSIGN COMPONENT Y_LV_COMP OF STRUCTURE <DYN_WA> TO <Y_FLD>.
<Y_FLD> = WA_FINAL-PRVSY.
Y_LV_COMP = 'PRTXT'.
ASSIGN COMPONENT Y_LV_COMP OF STRUCTURE <DYN_WA> TO <Y_FLD>.
<Y_FLD> = WA_FINAL-PRVSY.
Y_LV_COMP = 'GRVSY'.
ASSIGN COMPONENT Y_LV_COMP OF STRUCTURE <DYN_WA> TO <Y_FLD>.
<Y_FLD> = WA_FINAL-GRVSY.
LOOP AT T_NEWFINAL INTO WA_NEWFINAL
WHERE GUID_PR = WA_FINAL-GUID_PR.
CONCATENATE 'SUBID Classification-'
WA_FINAL-STCTS
INTO Y_LV_COMP.
ASSIGN COMPONENT Y_LV_COMP OF STRUCTURE <DYN_WA> TO <Y_FLD>.
<Y_FLD> = WA_NEWFINAL-CCNGN.
ENDLOOP.
APPEND <DYN_WA> TO <DYN_TABLE>.
FREE : <DYN_WA>, <Y_FLD>.
ENDLOOP.
ENDFORM. " CREATE_DYNAMIC_ITA
ANy suggestion would be apprecaited.
Regards,
KittuI think I need to put it in more descriptive way...
I am closing this thread -
How to use dynamic internal table in interactive report syntax
pls let me know
Hi Aarif,
Go through the below code for better understanding:
*& Report ZDYN_INT_TABLE_02 *
REPORT ZDYN_INT_TABLE_02.
TYPE-POOLS: slis. " ALV Global types
SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS : p_max(3) TYPE n OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
TYPES: BEGIN OF wa_gt_data,
matnr TYPE mara-matnr,
END OF wa_gt_data.
DATA gt_data TYPE STANDARD TABLE OF wa_gt_data WITH HEADER LINE.
*INITIALIZATION.
v_1 = 'Maximum of records to read'.
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_display_data.
Form f_read_data
FORM f_read_data.
SELECT matnr INTO TABLE gt_data
FROM mara
UP TO p_max ROWS.
ENDFORM. " F_READ_DATA
Form F_DISPLAY_DATA
FORM f_display_data.
DATA:
l_column TYPE sy-tabix,
lp_struct TYPE REF TO data,
lp_table TYPE REF TO data, " Pointer to dynamic table
ls_lvc_cat TYPE lvc_s_fcat,
lt_lvc_cat TYPE lvc_t_fcat, " Field catalog
lt_fcat TYPE slis_t_fieldcat_alv, " Field catalog
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv, " Field catalog
ls_layout TYPE slis_layout_alv.
FIELD-SYMBOLS :
<header> TYPE ANY,
<field_header> TYPE ANY,
<field_mara> TYPE ANY,
<lt_data> TYPE table. " Data to display
ls_lvc_cat-fieldname = 'COLUMNTEXT'.
ls_lvc_cat-ref_table = 'LVC_S_DETA'.
APPEND ls_lvc_cat TO lt_lvc_cat.
ls_fieldcat-fieldname = 'COLUMNTEXT'.
ls_fieldcat-ref_tabname = 'LVC_S_DETA'.
ls_fieldcat-key = 'X'.
APPEND ls_fieldcat TO lt_fieldcat.
DO p_max TIMES.
For each line, a column 'VALUEx' is created in the fieldcatalog
Build Fieldcatalog
WRITE sy-index TO ls_lvc_cat-fieldname LEFT-JUSTIFIED.
CONCATENATE 'VALUE' ls_lvc_cat-fieldname
INTO ls_lvc_cat-fieldname.
ls_lvc_cat-ref_field = 'VALUE'.
ls_lvc_cat-ref_table = 'LVC_S_DETA'.
APPEND ls_lvc_cat TO lt_lvc_cat.
Build Fieldcatalog
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = ls_lvc_cat-fieldname.
ls_fieldcat-ref_fieldname = 'VALUE'.
ls_fieldcat-ref_tabname = 'LVC_S_DETA'.
APPEND ls_fieldcat TO lt_fieldcat.
ENDDO.
Create internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_lvc_cat
IMPORTING
ep_table = lp_table.
ASSIGN lp_table->* TO <lt_data>.
Create structure = structure of the internal table
CREATE DATA lp_struct LIKE LINE OF <lt_data>.
ASSIGN lp_struct->* TO <header>.
Create field catalog from dictionary structure
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'MARA'
CHANGING
ct_fieldcat = lt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT lt_fcat INTO ls_fieldcat WHERE fieldname = 'MATNR'.
ASSIGN COMPONENT 1 OF STRUCTURE <header> TO <field_header>.
IF sy-subrc NE 0. EXIT .ENDIF.
READ TABLE lt_fcat INTO ls_fieldcat INDEX sy-index.
<field_header> = ls_fieldcat-seltext_m.
IF <field_header> IS INITIAL.
<field_header> = ls_fieldcat-fieldname.
ENDIF.
LOOP AT gt_data.
l_column = sy-tabix + 1.
ASSIGN COMPONENT 1 OF STRUCTURE gt_data TO <field_mara>.
IF sy-subrc NE 0. EXIT .ENDIF.
ASSIGN COMPONENT l_column OF STRUCTURE <header> TO <field_header>.
IF sy-subrc NE 0. EXIT .ENDIF.
WRITE <field_mara> TO <field_header> LEFT-JUSTIFIED.
ENDLOOP.
APPEND <header> TO <lt_data>.
ENDLOOP.
ls_layout-colwidth_optimize = 'X'.
ls_layout-no_colhead = 'X'.
ls_layout-zebra = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = ls_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = <lt_data>.
ENDFORM. " F_DISPLAY_DATA
END OF PROGRAM Z_ALV_LIST_TRANSPOSED *********************
*Always reward point for helpful answers
Regards,
Amit -
How to populate field catalogue fields in ALV using dynamic internal table
Hi All,
Please let me know how to populate field catalogue fields in ALV using dynamic internal table.
I have created <dyn_table> using code below.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = g_t_ifc
it_fieldcatalog = g_t_fieldcat
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>.
Now this <dyn_table> has fields like idoc no.,creation date ,
segment field 1, segment field 2 etc..Now idoc no.,creation date are static fields from table EDIDC. And segment field 1, segment field 2 etc are dynamic fields from table EDSAPPL.
In my ALV report I am getting the final layout properly but I am unable to move values to corresponding fields in the final layout shown.Please let me know how to populate these fields from different tables.
I tried this way but its not working.
SORT g_t_edid4 BY docnum.
LOOP AT g_t_edidc INTO g_r_edidc.
READ TABLE g_t_edid4 into g_r_edid4
WITH KEY docnum = g_r_edidc-docnum
BINARY SEARCH.
IF sy-subrc = 0.
<dyn_wa> = g_r_edid4-sdata.
MOVE-CORRESPONDING g_r_edid4 to <dyn_wa>.
CLEAR g_r_edid4.
ENDIF.
MOVE-CORRESPONDING g_r_edidc to <dyn_wa>.
APPEND <dyn_wa> TO <dyn_table>.You have to assign each field to field symbol and then assign the value to that field symbol and asssign that field symbol to workarea field symbol.
LOOP AT g_t_edidc INTO g_r_edidc.
READ TABLE g_t_edid4 into g_r_edid4
WITH KEY docnum = g_r_edidc-docnum
BINARY SEARCH.
IF sy-subrc = 0.
ASSIGN COMPONENT 'SDATA' OF STRUCTURE <DYN_WA> TO <DYN_FLD>.
<DYN_FLD> = g_r_edid4-sdata.
" <dyn_wa> = g_r_edid4-sdata.
" Assign each fields like this.
" MOVE-CORRESPONDING g_r_edid4 to <dyn_wa>.
CLEAR g_r_edid4.
ENDIF.
" MOVE-CORRESPONDING g_r_edidc to <dyn_wa>.
APPEND <dyn_wa> TO <dyn_table>.
Regards,
Naimesh Patel -
How 2 create dynamic internal table and can we pass it to gui_download FM
HI all,
How can we create a dynamic internal table?
I have a requirement where i have to create an internal table with the no. of fields depending on the selection screen values, i think tat can be possible though dynamic creation only.
How to solve this issue..?Pointers will be very much useful..
Thanks
Sunny.hi
Follow the code it will help you out....
REPORT YUSMM_TEXT2 .
*TABLES
TABLES: MARA, " General Material Data
MAKT, " Material Descriptions
T002. " Language Keys
* GLOBAL TYPE-POOL
TYPE-POOLS : SLIS.
* GLOBAL TYPES
TYPES: BEGIN OF TP_LANG ,
SPRAS LIKE T002-SPRAS,
LAISO LIKE T002-LAISO,
SRNO(3) TYPE N,
END OF TP_LANG.
TYPES: BEGIN OF TP_MATNR,
MATNR LIKE MARA-MATNR,
BEGRU LIKE MARA-BEGRU,
END OF TP_MATNR.
* DECLARATION FOR GLOBAL INTERNAL TABLES (WITH INCLUDE STRUCTURE)
DATA:GT_MAKT TYPE STANDARD TABLE OF MAKT, "Materialkurztexte,
GT_THEAD TYPE STANDARD TABLE OF THEAD, "SAPscript: Text-Header,
GT_LINETAB TYPE STANDARD TABLE OF TLINE, "SAPscript: Text-Zeilen,
GT_T002 TYPE STANDARD TABLE OF T002. "Language key
DATA: BEGIN OF GV_TEXT_OUTPUT_LINE,
MATNR LIKE MARA-MATNR,
BEGRU LIKE MARA-BEGRU,
MAKTX LIKE MAKT-MAKTX,
LTXT40(1250) TYPE C,
SRNO(3) TYPE N,
SPRAS LIKE T002-SPRAS,
END OF GV_TEXT_OUTPUT_LINE.
DATA: GT_MATNR TYPE STANDARD TABLE OF TP_MATNR,
WA_GT_MATNR TYPE TP_MATNR.
DATA: GT_LANG TYPE STANDARD TABLE OF TP_LANG,
WA_GT_LANG TYPE TP_LANG.
DATA: GT_TEXT_OUTPUT_LINE LIKE STANDARD TABLE OF GV_TEXT_OUTPUT_LINE,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
GV_FIELDCAT LIKE LINE OF GT_FIELDCAT,
CT_GT_FIELDCAT_IN LIKE GV_FIELDCAT,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
GV_REPID TYPE SY-REPID.
DATA: BEGIN OF GV,
FORMER_ERROR LIKE SY-MARKY, " Fehlermeldung bereits
FILE_OPEN(1), " Flag open file
REC_LENGTH TYPE I, " record length
MATNR TYPE MARA-MATNR, " material
REPID TYPE SYST-REPID,
RETCO TYPE SY-SUBRC,
END OF GV.
DATA: GV_MAKT TYPE MAKT,
GV_T002 TYPE T002,
GV_LANGU TYPE THEAD-TDSPRAS.
* DECLARATION FOR FIELD-SYMBOLS
FIELD-SYMBOLS: <FS_DATA> TYPE REF TO DATA,
<FS_DATA1> TYPE REF TO DATA,
<FS_2> TYPE STANDARD TABLE,
<FS_22> TYPE STANDARD TABLE,
<FS_1>,
<FS_11>,
<F>,
<FA>,
<LWA_LINE_WA>,
<LWA_LINE_WA1>.
DATA: IT_FLDCAT TYPE LVC_T_FCAT.
DATA: T_FLDCAT1 TYPE SLIS_T_FIELDCAT_ALV.
DATA: L_LT TYPE SLIS_LAYOUT_ALV.
DATA: WA_IT_FLDCAT TYPE LVC_S_FCAT.
DATA: WA_IT_FLDCAT1 TYPE SLIS_FIELDCAT_ALV.
DATA: GP_TABLE TYPE REF TO DATA.
DATA: WA_NEWLINE TYPE REF TO DATA.
*DECLARATION FOR CONSTANTS
CONSTANTS:
BEGIN OF GC,
TDID_GRUN TYPE THEAD-TDID VALUE 'GRUN',
TDOBJECT_MAT TYPE THEAD-TDOBJECT VALUE 'MATERIAL',
ON(01) TYPE C VALUE 'X',
YES(01) TYPE C VALUE 'X',
TXT(25) TYPE C VALUE 'MATERIAL DETAILS',
MAT(25) TYPE C VALUE 'MATERIAL NUMBER',
AUT(25) TYPE C VALUE 'AUTHORIZATION GROUP',
FOUND TYPE SY-SUBRC VALUE '00', " Return-Code
RC_OK TYPE SY-SUBRC VALUE '00', " Return-Code
OFF TYPE SY-SUBRC VALUE '00', " return code
FALSE TYPE SY-SUBRC VALUE '00', " boolean
TRUE TYPE SY-SUBRC VALUE '01', " boolean
END OF GC.
* DECLARATION FOR VARIABLES
DATA: V(3) TYPE N,
STR TYPE STRING,
STR1 TYPE STRING,
V_VAR(3) TYPE N,
V_VAR1(3) TYPE N,
V_FIELDNAME(15) TYPE C,
V_CHAR(15) TYPE C,
V_LINES(3) TYPE N,
MAKTEXT LIKE MAKT-MAKTX,
LT_DATA TYPE REF TO DATA,
LT_DATA1 TYPE REF TO DATA,
LWA_LINE TYPE REF TO DATA,
LWA_LINE1 TYPE REF TO DATA.
*SELECTION-SCREEN AND PARAMETERS
SELECTION-SCREEN: BEGIN OF BLOCK A1 WITH FRAME TITLE TEXT-002.
SELECT-OPTIONS:
S_MATNR FOR MARA-MATNR, "MATERIAL NUMBER
S_MTART FOR MARA-MTART, "MATERIAL TEXT
S_LANG FOR MAKT-SPRAS. "LANGUAGE
PARAMETER: GP_SIZE TYPE I DEFAULT 200. "DATA LENGTH
SELECTION-SCREEN: END OF BLOCK A1.
* AT SELECTION SCREEN
AT SELECTION-SCREEN.
IF GP_SIZE < 0.
MESSAGE E002(00).
ENDIF.
IF GP_SIZE > 50000.
MESSAGE W130(26) WITH TEXT-004.
SET CURSOR FIELD 'gp_size'.
ENDIF.
* INITIALIZATION
INITIALIZATION.
GV-REPID = SY-REPID.
*START-OF-SELECTION
START-OF-SELECTION.
PERFORM GET_MARA_DATA
TABLES
GT_TEXT_OUTPUT_LINE
USING
S_MATNR[]
S_MTART[]
GP_SIZE
CHANGING
GV-RETCO
PERFORM GET_MAT_TEXT
TABLES
GT_MAKT
GT_TEXT_OUTPUT_LINE
GT_THEAD
GT_LINETAB
USING
GC
GV-RETCO
CHANGING
GV_TEXT_OUTPUT_LINE
GV_MAKT
PERFORM GET_LANG.
PERFORM DYNAMIC_TABLES.
PERFORM POPULATE_FINAL_TABLE.
PERFORM POPULATE_DYNAMIC_TABLE.
* END-OF-SELECTION
END-OF-SELECTION.
PERFORM DATA_OUTPUT.
*& Form get_mara_data
* Materialdaten lesen
* <->ct_gt_text_output_line Ausgabetabelle
* -->it_s_matnr Parameter Materialnummer
* -->it_s_mtart Parameter Materialart
* -->if_gp_size Parameter Anzahl Materialnummern
FORM GET_MARA_DATA TABLES CT_GT_TEXT_OUTPUT_LINE STRUCTURE
GV_TEXT_OUTPUT_LINE
USING IT_S_MATNR LIKE S_MATNR[]
IT_S_MTART LIKE S_MTART[]
IF_GP_SIZE
CHANGING IF_GV-RETCO. "#EC *
* MARA in die Übergabestruktur einlesen
SELECT MATNR BEGRU
FROM MARA UP TO IF_GP_SIZE ROWS
APPENDING CORRESPONDING FIELDS OF TABLE GT_MATNR
WHERE MATNR IN IT_S_MATNR
AND MTART IN IT_S_MTART.
IF_GV-RETCO = SY-SUBRC.
ENDFORM. " get_mara_data
*& Form get_mat_text
* Kurz- und Langtexte zum Material lesen
* <->ct_gt_makt Materialkurztexte
* <->ct_gt_text_output_line Ausgabetabelle
* <->ct_gt_thead Kopftabelle für ALV
* <->ct_gt_linetab Zeilentabelle für ALV
* -->if_gc Globale Konstanten
* <--cf_gv_text_output_line Struktur Ausgabetabelle
* <--cf_gv_makt Struktru Materialkurztexte
FORM GET_MAT_TEXT TABLES CT_GT_MAKT STRUCTURE MAKT
CT_GT_TEXT_OUTPUT_LINE STRUCTURE
GV_TEXT_OUTPUT_LINE
CT_GT_THEAD STRUCTURE THEAD
CT_GT_LINETAB STRUCTURE TLINE
USING
IF_GC LIKE GC
IF_GV-RETCO
CHANGING CF_GV_TEXT_OUTPUT_LINE LIKE
GV_TEXT_OUTPUT_LINE
CF_GV_MAKT LIKE GV_MAKT
DATA: STRG TYPE STRING,
STRG1(1255) TYPE C.
IF IF_GV-RETCO = IF_GC-FOUND.
* Materialkurztexte in alles Sprachen einlesen
SELECT * FROM MAKT APPENDING TABLE CT_GT_MAKT
FOR ALL ENTRIES IN GT_MATNR "ct_gt_text_output_line
WHERE MATNR = GT_MATNR-MATNR " ct_gt_text_output_line-matnr
* Kurztexte in die sprachabhängigen Felder bringen
LOOP AT GT_MATNR INTO WA_GT_MATNR.
LOOP AT CT_GT_MAKT INTO CF_GV_MAKT
WHERE MATNR = WA_GT_MATNR-MATNR.
CF_GV_TEXT_OUTPUT_LINE-MATNR = WA_GT_MATNR-MATNR.
CF_GV_TEXT_OUTPUT_LINE-BEGRU = WA_GT_MATNR-BEGRU.
CF_GV_TEXT_OUTPUT_LINE-MAKTX = CF_GV_MAKT-MAKTX.
CF_GV_TEXT_OUTPUT_LINE-SPRAS = CF_GV_MAKT-SPRAS.
* LANGTEXT
CLEAR CT_GT_THEAD[].
CT_GT_THEAD-TDOBJECT = IF_GC-TDOBJECT_MAT.
CT_GT_THEAD-TDNAME = WA_GT_MATNR-MATNR.
CT_GT_THEAD-TDID = IF_GC-TDID_GRUN.
CT_GT_THEAD-TDSPRAS = CF_GV_MAKT-SPRAS.
CALL FUNCTION 'TEXT_READ'
EXPORTING
I_HEADER = CT_GT_THEAD
I_READONLY = IF_GC-ON
IMPORTING
E_HEADER = CT_GT_THEAD
TABLES
T_LINES = CT_GT_LINETAB[]
EXCEPTIONS
NOTFOUND = 1.
IF SY-SUBRC = IF_GC-FOUND.
LOOP AT CT_GT_LINETAB.
STRG = CT_GT_LINETAB-TDLINE.
IF STRG1 <> ' '.
CONCATENATE STRG1 ';' STRG INTO STRG1.
ELSE.
STRG1 = STRG.
ENDIF.
ENDLOOP.
CF_GV_TEXT_OUTPUT_LINE-LTXT40 = STRG1.
APPEND CF_GV_TEXT_OUTPUT_LINE TO CT_GT_TEXT_OUTPUT_LINE.
CLEAR CF_GV_TEXT_OUTPUT_LINE.
STRG1 = ' '.
ELSE.
APPEND CF_GV_TEXT_OUTPUT_LINE TO CT_GT_TEXT_OUTPUT_LINE.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
ENDFORM. " get_mat_text
*& Form data_output
* Daten mit ALV ausgeben
* <->ct_GT_FIELDCAT Feldkatalog für ALV
* <->ct_gt_text_output_line Ausgabetabelle
* -->P_GS_LAYOUT Layout für ALV
* -->if_gc Globale Konstanten
* <--cf_GV_REPID Zur Zeit aufgerufener Reportname
* <--cf_gv_fieldcat Struktur Feldkatalog
* <--cf_gv Globale Variablen
FORM DATA_OUTPUT.
PERFORM FIELDCATBUILD.
PERFORM LAYOUT.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = GV-REPID
I_CALLBACK_PF_STATUS_SET = 'EVENT_SET_STATUS_01'
I_CALLBACK_USER_COMMAND = 'EVENT_USER_COMMAND'
IS_LAYOUT = L_LT
IT_FIELDCAT = T_FLDCAT1[]
TABLES
T_OUTTAB = <FS_2>
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> GC-FOUND.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " data_output
*& Form fieldcatbuild
* text
* --> p1 text
* <-- p2 text
FORM FIELDCATBUILD. " TABLES ct_gt_fieldcat_in STRUCTURE gv_fieldcat.
LOOP AT IT_FLDCAT INTO WA_IT_FLDCAT.
WA_IT_FLDCAT1-FIELDNAME = WA_IT_FLDCAT-FIELDNAME.
WA_IT_FLDCAT1-TABNAME = WA_IT_FLDCAT-TABNAME.
WA_IT_FLDCAT1-SELTEXT_L = WA_IT_FLDCAT-FIELDNAME.
APPEND WA_IT_FLDCAT1 TO T_FLDCAT1.
CLEAR : WA_IT_FLDCAT,WA_IT_FLDCAT1.
ENDLOOP.
ENDFORM. " fieldcatbuild
* Form event_set_status_01*
FORM EVENT_SET_STATUS_01 USING LT_EXCL TYPE SLIS_T_EXTAB.
SET PF-STATUS 'ABCD' .
ENDFORM. "EVENT_SET_STATUS_01
*& Form Name: event_user_command *
*& Form Desc: For Handling USER_COMMAND *
FORM EVENT_USER_COMMAND USING
IF_UCOMM TYPE SY-UCOMM
IS_SELFIELD TYPE SLIS_SELFIELD.
CASE IF_UCOMM.
WHEN 'DOWNLOAD'.
PERFORM POPULATE_DOWNLOAD_TABLE.
DATA: L_LENGHT TYPE I.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:data.xls'
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = 'X'
TRUNC_TRAILING_BLANKS = 'X'
DAT_MODE = 'X'
IMPORTING
FILELENGTH = L_LENGHT
TABLES
DATA_TAB = <FS_22>.
IF SY-SUBRC <> GC-FOUND.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF L_LENGHT NE GC-FOUND.
MESSAGE S398(00) WITH 'DATA downloaded to c:data.xls'.
ENDIF.
ENDCASE.
ENDFORM. "event_user_command
*& Form get_lang
* text
* --> p1 text
* <-- p2 text
FORM GET_LANG.
SELECT SPRAS
LAISO FROM T002 INTO CORRESPONDING FIELDS OF TABLE GT_LANG
WHERE SPRAS IN S_LANG.
DESCRIBE TABLE GT_LANG LINES V_LINES.
LOOP AT GT_LANG INTO WA_GT_LANG.
V = V + 1.
WA_GT_LANG-SRNO = V.
MODIFY GT_LANG FROM WA_GT_LANG TRANSPORTING SRNO.
ENDLOOP.
LOOP AT GT_LANG INTO WA_GT_LANG.
CONCATENATE 'MATEDESC-' WA_GT_LANG-LAISO INTO V_FIELDNAME.
CLEAR WA_IT_FLDCAT.
WA_IT_FLDCAT-FIELDNAME = V_FIELDNAME.
WA_IT_FLDCAT-SELTEXT = V_FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-INTLEN = 40.
WA_IT_FLDCAT-TABNAME = '<FS_2>'.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_GT_LANG.
ENDLOOP.
LOOP AT GT_LANG INTO WA_GT_LANG.
CONCATENATE 'BASDAT-' WA_GT_LANG-LAISO INTO V_FIELDNAME.
CLEAR WA_IT_FLDCAT.
WA_IT_FLDCAT-FIELDNAME = V_FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-INTLEN = 255.
WA_IT_FLDCAT-SELTEXT = V_FIELDNAME.
WA_IT_FLDCAT-TABNAME = '<FS_2>'.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_GT_LANG.
ENDLOOP.
V_FIELDNAME = 'MATNR'.
CLEAR WA_IT_FLDCAT.
WA_IT_FLDCAT-FIELDNAME = V_FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-SELTEXT = 'Matnr'.
WA_IT_FLDCAT-INTLEN = 18.
WA_IT_FLDCAT-TABNAME = '<FS_2>'.
INSERT WA_IT_FLDCAT INTO IT_FLDCAT INDEX 1.
V_FIELDNAME = 'BEGRU'.
CLEAR WA_IT_FLDCAT.
WA_IT_FLDCAT-FIELDNAME = V_FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-SELTEXT = 'BEGRU'.
WA_IT_FLDCAT-INTLEN = 4.
WA_IT_FLDCAT-TABNAME = '<FS_2>'.
INSERT WA_IT_FLDCAT INTO IT_FLDCAT INDEX 2.
ENDFORM. " get_lang
*& Form dynamic_tables
* text
* --> p1 text
* <-- p2 text
FORM DYNAMIC_TABLES.
ASSIGN LT_DATA TO <FS_DATA>.
* Creating the Dynamic Internal Table
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FLDCAT " Fieldcatalogue
IMPORTING
EP_TABLE = <FS_DATA> " Dynamic Internal Table
EXCEPTIONS
GENERATE_SUBPOOL_DIR_FULL = 1
OTHERS = 2.
* Assign Dyn Table To Field Sumbol
ASSIGN <FS_DATA>->* TO <FS_1>.
* Assigning the Internal Table TYPE ANY to Standard internal Table
ASSIGN <FS_1> TO <FS_2>.
* Creating a Workarea
CREATE DATA LWA_LINE LIKE LINE OF <FS_2> .
* Assigning the Content to the workares as a Pointer
ASSIGN LWA_LINE->* TO <LWA_LINE_WA>.
ENDFORM. " dynamic_tables
*& Form populate_final_table
* text
* --> p1 text
* <-- p2 text
FORM POPULATE_FINAL_TABLE.
LOOP AT GT_TEXT_OUTPUT_LINE INTO GV_TEXT_OUTPUT_LINE.
READ TABLE GT_LANG INTO WA_GT_LANG
WITH KEY SPRAS = GV_TEXT_OUTPUT_LINE-SPRAS.
IF SY-SUBRC EQ GC-FOUND.
GV_TEXT_OUTPUT_LINE-SRNO = WA_GT_LANG-SRNO.
ENDIF.
MODIFY GT_TEXT_OUTPUT_LINE FROM GV_TEXT_OUTPUT_LINE.
ENDLOOP.
ENDFORM. " populate_final_table
*& Form populate_dynamic_table
* text
* --> p1 text
* <-- p2 text
FORM POPULATE_DYNAMIC_TABLE.
DATA: INDX TYPE SY-TABIX.
LOOP AT GT_TEXT_OUTPUT_LINE INTO GV_TEXT_OUTPUT_LINE.
AT NEW MATNR.
INDX = SY-TABIX.
ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA> TO <F>.
<F> = GV_TEXT_OUTPUT_LINE-MATNR.
ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA> TO <F>.
<F> = GV_TEXT_OUTPUT_LINE-BEGRU.
ENDAT.
LOOP AT GT_LANG INTO WA_GT_LANG.
IF GV_TEXT_OUTPUT_LINE-SRNO = WA_GT_LANG-SRNO.
V_VAR = GV_TEXT_OUTPUT_LINE-SRNO + 2.
ASSIGN COMPONENT V_VAR OF STRUCTURE <LWA_LINE_WA> TO <F>.
<F> = GV_TEXT_OUTPUT_LINE-MAKTX.
V_VAR = GV_TEXT_OUTPUT_LINE-SRNO + V_LINES + 2.
ASSIGN COMPONENT V_VAR OF STRUCTURE <LWA_LINE_WA> TO <F>.
<F> = GV_TEXT_OUTPUT_LINE-LTXT40.
ENDIF.
ENDLOOP.
AT END OF MATNR.
APPEND <LWA_LINE_WA> TO <FS_2>.
CLEAR <LWA_LINE_WA>.
ENDAT.
ENDLOOP.
ENDFORM. " populate_dynamic_table
*& Form LAYOUT
* text
* --> p1 text
* <-- p2 text
FORM LAYOUT.
CLEAR L_LT.
L_LT-ZEBRA = GC-YES.
L_LT-COLWIDTH_OPTIMIZE = 'X'.
L_LT-WINDOW_TITLEBAR = GC-TXT.
ENDFORM. " LAYOUT
*& Form populate_download_table
* text
* --> p1 text
* <-- p2 text
FORM POPULATE_DOWNLOAD_TABLE.
ASSIGN LT_DATA1 TO <FS_DATA1>.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FLDCAT " Fieldcatalogue
IMPORTING
EP_TABLE = <FS_DATA1> " Dynamic Internal table
EXCEPTIONS
GENERATE_SUBPOOL_DIR_FULL = 1
OTHERS = 2.
* Assign Dyn Table To Field Sumbol
ASSIGN <FS_DATA1>->* TO <FS_11>.
* Assigning the Internal Table TYPE ANY to Standard internal Table
ASSIGN <FS_11> TO <FS_22>.
* Creating a Workarea
CREATE DATA LWA_LINE1 LIKE LINE OF <FS_22> .
* Assigning the Content to the workares as a Pointer
ASSIGN LWA_LINE1->* TO <LWA_LINE_WA1>.
DATA: STRN1 TYPE STRING,
STRN2 TYPE STRING,
INDX TYPE SY-TABIX.
ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = GC-MAT.
ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = GC-AUT.
LOOP AT GT_LANG INTO WA_GT_LANG.
V_VAR1 = WA_GT_LANG-SRNO + 2.
CONCATENATE 'MATERIALDESCRIPTION-' WA_GT_LANG-LAISO INTO STRN1.
ASSIGN COMPONENT V_VAR1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = STRN1.
V_VAR1 = WA_GT_LANG-SRNO + V_LINES + 2.
CONCATENATE 'BASICDATA-' WA_GT_LANG-LAISO INTO STRN2.
ASSIGN COMPONENT V_VAR1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = STRN2.
ENDLOOP.
APPEND <LWA_LINE_WA1> TO <FS_22>.
CLEAR <LWA_LINE_WA1>.
APPEND <LWA_LINE_WA1> TO <FS_22>.
V_VAR1 = 0.
LOOP AT GT_TEXT_OUTPUT_LINE INTO GV_TEXT_OUTPUT_LINE.
AT NEW MATNR.
INDX = SY-TABIX.
ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = GV_TEXT_OUTPUT_LINE-MATNR.
ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = GV_TEXT_OUTPUT_LINE-BEGRU.
ENDAT.
LOOP AT GT_LANG INTO WA_GT_LANG.
IF GV_TEXT_OUTPUT_LINE-SRNO EQ WA_GT_LANG-SRNO.
V_VAR1 = GV_TEXT_OUTPUT_LINE-SRNO + 2.
ASSIGN COMPONENT V_VAR1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = GV_TEXT_OUTPUT_LINE-MAKTX.
V_VAR1 = GV_TEXT_OUTPUT_LINE-SRNO + V_LINES + 2.
ASSIGN COMPONENT V_VAR1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
* STR = GV_TEXT_OUTPUT_LINE-LTXT40.
* SEARCH STR FOR ';'.
* DO.
* IF SY-SUBRC = 0.
* SPLIT STR AT ';' INTO STR1 STR.
* <FA> = STR1.
* APPEND <LWA_LINE_WA1> TO <FS_22>.
* SEARCH STR FOR ';'.
* CLEAR <LWA_LINE_WA1>.
* ELSE.
* EXIT.
* ENDIF.
* ENDDO.
* <FA> = STR.
* APPEND <LWA_LINE_WA1> TO <FS_22>.
<FA> = GV_TEXT_OUTPUT_LINE-LTXT40.
ENDIF.
ENDLOOP.
AT END OF MATNR.
APPEND <LWA_LINE_WA1> TO <FS_22>.
CLEAR <LWA_LINE_WA1>.
ENDAT.
ENDLOOP.
ENDFORM. " populate_download_table
thanks
Nitya -
Creating Dynamic Internal table with a dynamic name
Hi,
I want to create dynamic internal tables with dynamic names.
For example:
Suppose I have a table with three fields.
1. Structure name
2.Fields
3.file
And the structure of the internal table is as follows:
TYPES:BEGIN OF table_type,
struct TYPE char70,
fields TYPE tt_type OCCURS 0,
File TYPE ttab_type OCCURS 0,
END OF table_type.
Suppose I have one record inside my internal table with struct as "STRUCTURE", fields have an internal table content of set of fields and File has some set of records.
Now I want to create dynamic internal table whose name will be "STRUCTURE" , the fields of the dynamic internal table structure[] will be as in fields, and the records will be as in File.
Like this if i have 100 records in my internal table then I have to create 100 dynamic internal table dynamically.
Can anyone suggest how to do this?
Edited by: Jjammy on Jul 22, 2009 7:52 AMHi,
Check the sample program and develop your program accordingly.
<font color=blue><pre>
REPORT ztest_notepad.
*& Declarations
*Type-pools
TYPE-POOLS:
slis.
*Types
TYPES:
ty_fcat TYPE lvc_s_fcat,
ty_fcatalog TYPE slis_fieldcat_alv.
*Work areas
DATA:
wa_fcat TYPE ty_fcat,
wa_fcatalog TYPE ty_fcatalog.
*Internal tables
DATA:
it_fcat TYPE STANDARD TABLE OF ty_fcat,
it_fcatalog TYPE STANDARD TABLE OF ty_fcatalog.
*Type reference
DATA:
it_dyn_tab TYPE REF TO data,
wa_newline TYPE REF TO data.
*Filed symbols
FIELD-SYMBOLS:
<gt_table> TYPE STANDARD TABLE,
<fs_dyntable>,
<fs_fldval> TYPE ANY,
<l_field> TYPE ANY.
*Variables
DATA:
l_fieldname TYPE lvc_s_fcat-fieldname,
l_tabname TYPE lvc_s_fcat-tabname,
l_fieldtext TYPE lvc_s_fcat-seltext,
l_index TYPE char2.
"Selection-screen
PARAMETERS:
p_colms TYPE i.
*& start-of-selection.
START-OF-SELECTION.
PERFORM build_fieldcat.
PERFORM create_dynamic_table.
DO 20 TIMES.
DO p_colms TIMES.
l_index = sy-index.
CONCATENATE 'FIELD' l_index INTO l_fieldname.
ASSIGN COMPONENT l_fieldname OF STRUCTURE <fs_dyntable> TO <l_field>.
<l_field> = sy-index.
ENDDO.
INSERT <fs_dyntable> INTO TABLE <gt_table>.
ENDDO.
LOOP AT it_fcat INTO wa_fcat.
PERFORM fieldcatalog1 USING: wa_fcat-fieldname
wa_fcat-tabname
wa_fcat-seltext.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = 'ZTEST_NOTEPAD'
it_fieldcat = it_fcatalog
TABLES
t_outtab = <gt_table>.
*& Form BUILD_FIELDCAT
FORM build_fieldcat .
CLEAR: l_fieldname,
l_tabname,
l_fieldtext,
l_index.
DO p_colms TIMES.
CLEAR l_index.
l_index = sy-index.
CONCATENATE 'FIELD' l_index INTO l_fieldname.
CONCATENATE 'Field' l_index INTO l_fieldtext.
l_tabname = '<GT_TABLE>'.
PERFORM fieldcatalog USING: l_fieldname
l_tabname
l_fieldtext.
ENDDO.
ENDFORM. " BUILD_FIELDCAT
*& Form CREATE_DYNAMIC_TABLE
FORM create_dynamic_table .
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fcat
IMPORTING
ep_table = it_dyn_tab.
ASSIGN it_dyn_tab->* TO <gt_table>.
Create dynamic work area and assign to FS
CREATE DATA wa_newline LIKE LINE OF <gt_table>.
ASSIGN wa_newline->* TO <fs_dyntable>.
ENDFORM. " CREATE_DYNAMIC_TABLE
*& Form FIELDCATALOG
FORM fieldcatalog USING field table f_txt.
wa_fcat-fieldname = field.
wa_fcat-tabname = table.
wa_fcat-seltext = f_txt.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ENDFORM. " FIELDCATALOG
*& Form FIELDCATALOG1
FORM fieldcatalog1 USING field table f_txt.
wa_fcatalog-fieldname = field.
wa_fcatalog-tabname = table.
wa_fcatalog-seltext_m = f_txt.
APPEND wa_fcatalog TO it_fcatalog.
CLEAR wa_fcatalog.
ENDFORM. " FIELDCATALOG1 </pre>
</font>
Thanks
Venkat.O -
Create dynamic internal table with deep structure;cell coloring dynamic ALV
Hi,
My requirement is to do cell colouring for a dynamic ALV.
So I am creating a dynamic internal table using the following method.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_fieldcatalog[]
IMPORTING
ep_table = i_output.
But how do I define field COLORS which should be again an internal table ?
Is there any other way for cell colouring?
Putting my problem in another way:
How do I create a dynamic internal table with one field as another internal table.
Quick replies are highly appreciated.
Thanks,
Nisha Vengal.halo Nisha
Before building the display table . you can add the field in the feild catalog right . This display table gets generated from the field catalog right
1 Create a global structute say ZEXTEND_FIELDCAT
2 Have fields like STYLE type lvc_t_styl
COLOR type LVC_T_SCOL.
3 Now you have to extend ur fieldcatalog
l_fieldcat-fieldname = COLOR'.
l_fieldcat-ref_field = 'COLOR'.
l_fieldcat-ref_table = 'ZEXTEND_FIELDCAT'.
APPEND l_fieldcat TO lt_field_catalog.
CLEAR l_fieldcat. -
Dynamic internal table with repeated structure
Hi,
I have a requirement, in which I need to create a dynamic internal table with the below structure.
Dynamic Int. table structure: fld1 and fld2.
If another internal table (say int2), contains 3 records, then my final output table should contain the below structure.
Value 1 Value 2 Value3
fld1 fld2 fld1 fld2 fld1 fld2
If in case, the int2 table contains 10 records, then my final output table should contain the structure below.
Value 1 Value 2 ..... Value10
fld1 fld2 fld1 fld2 ..... fld1 fld2
Please advice on how to acquire this. Thanks in advance for your help.
Regards,
Swetha.You can do it...but it won't be table... it would be some thing like
itab
ref1-> strycture (field 1 field 2 field 3)
ref2-> structure (field1 field 4 )
ref3-> structure (field5 field7 )
say Define a internal table with a single field to hold a reference of Data
Go on creating Rows of different structures and storing the address into the table... you can use RTTS for same
Use the below link for RTTS (search on wiki for examples).
http://wiki.sdn.sap.com/wiki/display/ABAP/RuntimeTypeServices+%28RTTS%29 -
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 -
Performance Problems with "For all Entries" and a big internal table
We have big Performance Problems with following Statement:
SELECT * FROM zeedmt_zmon INTO TABLE gt_zmon_help
FOR ALL ENTRIES IN gt_zmon_help
WHERE
status = 'IAI200' AND
logdat IN gs_dat AND
ztrack = gt_zmon_help-ztrack.
In the internal table gt_zmon_help are over 1000000 entries.
Anyone an Idea how to improve the Performance?
Thank you!>
Matthias Weisensel wrote:
> We have big Performance Problems with following Statement:
>
>
SELECT * FROM zeedmt_zmon INTO TABLE gt_zmon_help
> FOR ALL ENTRIES IN gt_zmon_help
> WHERE
> status = 'IAI200' AND
> logdat IN gs_dat AND
> ztrack = gt_zmon_help-ztrack.
>
> In the internal table gt_zmon_help are over 1000000 entries.
> Anyone an Idea how to improve the Performance?
>
> Thank you!
You can't expect miracles. With over a million entries in your itab any select is going to take a bit of time. Do you really need all these records in the itab? How many records is the select bringing back? I'm assuming that you have got and are using indexes on your ZEEDMT_ZMON table.
In this situation, I'd first of all try to think of another way of running the query and restricting the amount of data, but if this were not possible I'd just run it in the background and accept that it is going to take a long time.
Maybe you are looking for
-
How do I get the sync of my 3GS on my computer to transfer everything (files, apps, etc.) to my new iphone4? And then how do I move the sync to a newer computer so I can sync the new phone with the new computer? My 3GS is dying and it's synced to an
-
Mobile Sales - Error while Saving Sales Order
Hi, When I try to create and save a sales order in the Mobile Sales, the error message UI_CONT_STATUSBAR_ICON_TT is displayed, blocking the saving process and the new order is not saved. I tried to debug the SAP Mobile Application Studio(Visual Basic
-
GT70-2OD GTX780 no longer working?? Intel HD only??
So, starting last night, I seem to be having a problem where the integrated Intel HD graphics processor is the only one which will operate. the system still detects the nVidia card, but does not leverage it. I have set in the nVidia control panel t
-
I'm getting the following Error message when trying to import some of my folders from my external hard drive. This is not happening with all of my photos. How can I access my photos? I now have Aperture 3.5, but I'm guessing I exported those with an
-
NIO read stalls in Windows -- URGENT
Hi , I have a NIO server running on Linux.If a NIO client running on windows connects to this server, the client doesnot read the complete information from the server. But if both server and client are run on Windows the client reads all the data sen