‎2009 Feb 10 5:27 AM
hi friends,,,,
my requirement is suppose if i ve a DB TABLE with 3 records like....
DB TABLE :
name no qty
cust1 100 10
cust2 200 20
cust3 300 30
then i ve to display as....
i ve to display the customer name records as fields ...columns....cust1 cust2 cust3
please help me out...
‎2009 Feb 10 5:30 AM
‎2009 Feb 10 5:30 AM
‎2009 Feb 10 5:31 AM
‎2009 Feb 10 5:32 AM
Hi,
Plz find belwo simple code, which will create Fields(dynamic) for each plant , and under the plants releavnt materials will display.
let me know if any issues.
data: itab1 type table of mara with header line,
itab2 type table of marc with header line,
itab3 like itab2 occurs 0 with header line.
data: cl_cont type ref to cl_gui_custom_container,
cl_grd type ref to cl_gui_alv_grid,
scr type scrfname value 'SCR'.
DATA: t_cat TYPE LVC_T_FCAT,
w_cat type lvc_s_fcat.
select matnr ersda from mara into corresponding fields of table itab1 up to 30 rows.
select matnr werks from marc into corresponding fields of table itab2 for all entries in itab1 where matnr = itab1-matnr.
itab3[] = itab2[].
sort itab3 by werks.
delete adjacent duplicates from itab3 comparing werks.
data : n type i value 1.
loop at itab3.
w_cat-col_pos = n.
w_cat-fieldname = itab3-werks.
w_cat-coltext = itab3-werks.
append w_cat to t_cat.
clear w_cat.
n = n + 1.
endloop.
field-symbols:
<ts2> type table,
<wa> type any,
<ts4> type any,
<ts5> type any,
<ts6> type any,
<ts7> type any.
data: t_ref type ref to data,
t_rf1 type ref to data,
var(5) type c.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = t_cat
IMPORTING
EP_TABLE = t_ref
* E_STYLE_FNAME =
* EXCEPTIONS
* GENERATE_SUBPOOL_DIR_FULL = 1
* others = 2
.
assign t_ref->* to <ts2>. u201C Field cat should be table , so <ts2> shud be
u201C table
create data t_rf1 like line of <ts2>. u201C <WA> shud be used to get the
u201Cstructure of Field Catalog
assign t_rf1->* to <wa>.
IF SY-SUBRC <> 0.
ENDIF.
loop at itab2 assigning <ts4>.
assign component 'MATNR' of structure <ts4> to <ts5>.
assign component 3 of structure <ts4> to <ts6>. u201CWERKS Is component 3
move <ts6> to var.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = <ts5>
IMPORTING
OUTPUT = <ts5> .
assign component var of structure <wa> to <ts7>.
<ts7> = <ts5>.
append <wa> to <ts2>.
clear <wa>.
endloop.
call screen '0100'.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
if cl_cont is initial.
CREATE OBJECT CL_CONT
EXPORTING
* PARENT =
CONTAINER_NAME = scr.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT CL_grd
EXPORTING
* I_SHELLSTYLE = 0
* I_LIFETIME =
I_PARENT = CL_CONT
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endif.
CALL METHOD CL_grd->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = <ts2>
IT_FIELDCATALOG = t_cat
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SET PF-STATUS 'TEST'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
case sy-ucomm.
when 'EXT'.
leave to screen 0.
endcase.
ENDMODULE. " USER_COMMAND_0100 INPUT
Regards,
Naveen
‎2009 Feb 10 5:33 AM
This may help.
DATA: d_ref TYPE REF TO data,
d_ref2 TYPE REF TO data ,
i_alv_cat TYPE TABLE OF lvc_s_fcat,
ls_alv_cat LIKE LINE OF i_alv_cat.
TYPES tabname LIKE dcobjdef-name .
parameter: p_tablen type tabname.
data: begin of itab occurs 0.
INCLUDE STRUCTURE dntab.
data: end of itab.
FIELD-SYMBOLS : <F_FS> TYPE table,
<F_FS1> TYPE TABLE,
<F_FS2> TYPE ANY,
<F_FS3> TYPE TABLE.
REFRESH itab.
CALL FUNCTION 'NAMETAB_GET'
EXPORTING
langu = sy-langu
tabname = p_tablen
TABLES
nametab = itab
EXCEPTIONS
no_texts_found = 1.
LOOP AT itab .
ls_alv_cat-fieldname = itab-fieldname.
ls_alv_cat-ref_table = p_tablen.
ls_alv_cat-ref_field = itab-fieldname.
APPEND ls_alv_cat TO i_alv_cat.
ENDLOOP.
* internal table build
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING it_fieldcatalog = i_alv_cat
IMPORTING ep_table = d_ref .
ASSIGN d_ref->* TO <F_FS>.
SELECT * FROM (p_tablen) INTO CORRESPONDING FIELDS OF TABLE <F_FS>.
LOOP AT <F_FS> ASSIGNING <F_FS2>.
*your code goes here.
ENDLOOP.
Regards,
Mon Magallanes
‎2009 Feb 10 5:33 AM
‎2009 Feb 10 5:34 AM
Hi
PARAMETERS : p_table(10) TYPE C.
DATA: w_tabname TYPE w_tabname,
w_dref TYPE REF TO data,
w_grid TYPE REF TO cl_gui_alv_grid.
FIELD-SYMBOLS: <t_atab> TYPE ANY TABLE.
tabname = p_table.
CREATE DATA w_dref TYPE TABLE OF (tabname).
ASSIGN w_ref->* TO <t_atab>.
‎2009 Feb 10 5:36 AM
Hi,
Please Test the following Code it will Create a Dynamic internal table like any DB table, you must enter the Correct DB table name in the Input Parameter.
PARAMETERS: tabname TYPE string. " DB Table Name
DATA: itab_ref TYPE REF TO data.
CREATE DATA itab_ref TYPE STANDARD TABLE OF (tabname).
FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
ASSIGN itab_ref->* TO <itab>.
BREAK-POINT.Kind Regards,
Faisal
‎2009 Feb 10 5:53 AM
check the code
REPORT Z_RTTC.
PARAMETERS:
p_tab TYPE dd02l-tabname . " Input data table name
FIELD-SYMBOLS:
<fsym_itab> TYPE ANY TABLE, " Field symbol for internal table
<fsym_warea> TYPE ANY, " Field symbol for work area
<fsym_field> TYPE ANY. " Field symbol for field value
DATA:
ref_rowtype
TYPE REF TO cl_abap_structdescr, " Rowtype ref to RTTS
ref_tabletype
TYPE REF TO cl_abap_tabledescr. " Internal table type ref to RTTS
DATA:
ref_wa TYPE REF TO data, " Declaration of work area instance
ref_itab TYPE REF TO data. " Declaration of internal table instance
*"---------------------------------------------------------------------
* START-OF-SELECTION
*"---------------------------------------------------------------------
START-OF-SELECTION.
* Create row type and tabletype by RTTC technique
ref_rowtype ?= cl_abap_typedescr=>describe_by_name( p_tab ).
ref_tabletype = cl_abap_tabledescr=>create( p_line_type = ref_rowtype).
* Object type created by RTTC.
CREATE DATA ref_itab TYPE HANDLE ref_tabletype.
CREATE DATA ref_wa TYPE HANDLE ref_rowtype.
*Type assignment
ASSIGN ref_itab->* TO <fsym_itab>.
ASSIGN ref_wa->* TO <fsym_warea>.
* Value assignment to the internal table
SELECT *
FROM (p_tab)
INTO TABLE <fsym_itab>.
* Display Output
LOOP AT <fsym_itab> INTO <fsym_warea>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fsym_warea> TO
<fsym_field>.
IF sy-subrc NE 0.
NEW-LINE. " Shift Cursor to next line
EXIT. " EXIT to next work area
ENDIF. " IF sy-subrc NE 0.
WRITE <fsym_field>.
ENDDO.
ENDLOOP. " LOOP AT <fsym_itab> INTO <fsym_warea>.