‎2007 May 14 3:24 AM
Hi SDN's
I have a internal table with the following fields
-
BUKRS |ZUONR |WRBTR |SGTXT
-
1 -|A1190 -|100 -|310 static
1 -|A1190 -|200 -|310 static
1 -|A1192 -|150 -|311 static
1 -|A2330 -|100 -|310 static
1 -|A2330 -|150 -|310 static
1 -|A2330 -|500 -|321 static
1 -|A3450 -|100 -|310 static
1 -|A3450 -|200 -|311 static
1 -|A3450 -|300 -|321 static
-
I need an output like this... considering the first 3 characters of SGTXT i need dynamic columns for each unique SGTXT and sum up all the amounts related to the ZUONR
-
BUKRS |ZUONR |310 WRBTR |311 WRBTR |321 WRBTR |so on......
-
1 -| A1190 -|300 -|150 -|----
-|so on .....
1 -| A2330 -|250 -|----
-|500 -|so on .....
1 -| A3450 -|100 -|200 -|300 -|so on .....
-
I am not sure of the number of SGTXT's.. so i need them dynamical columns based on the number SGTXT's in the internal table
Regards
Pratyusha
‎2007 May 14 3:50 AM
‎2007 May 14 5:24 AM
data : pos type i value 25.
data : v_sgtxt(50).
sort itab by sgtxt.
loop at itab.
on change of itab-sgtxt.
concatenate v_sgtxt itab-asgtxt 'WRBTR' into v_sgtxt separated by space.
endon.
endloop.
*for heading
write : /1'BUKRS',12 'ZUONR',25 V_SGTXT.
sort itab by zuonr sgtxt.
loop at itab.
on change of itab-sgtxt.
sum.
write : pos(8) itab-wrbtr.
pos = pos + 10.
endon.
at end of zuonr.
write : 1 itab-bukrs, 12 itab-zuonr.
write : / .
clear : pos.
endat.
endloop.
change the prog as per your requirement...
regards
shiba dutta
‎2007 May 14 6:31 AM
Hi Pratyu Usha,
Check this small program. Just run this program. Please follow the order of columns.
REPORT ytesting11.
DATA : BEGIN OF itab OCCURS 0,
bukrs(1) TYPE c,
zuonr(5) TYPE c,
sgtxt(10) TYPE c,
wrbtr TYPE i,
END OF itab.
DATA : BEGIN OF jtab OCCURS 0,
sgtxt TYPE i,
END OF jtab.
itab-bukrs = '1'.
itab-zuonr = 'A1190'.
itab-wrbtr = 100.
itab-sgtxt = '310 static'.
APPEND itab.
itab-bukrs = '1'.
itab-zuonr = 'A1190'.
itab-wrbtr = 200.
itab-sgtxt = '310 static'.
APPEND itab.
itab-bukrs = '1'.
itab-zuonr = 'A1190'.
itab-wrbtr = 150.
itab-sgtxt = '311 static'.
APPEND itab.
itab-bukrs = '1'.
itab-zuonr = 'A2330'.
itab-wrbtr = 100.
itab-sgtxt = '310 static'.
APPEND itab.
itab-bukrs = '1'.
itab-zuonr = 'A2330'.
itab-wrbtr = 150.
itab-sgtxt = '310 static'.
APPEND itab.
itab-bukrs = '1'.
itab-zuonr = 'A2330'.
itab-wrbtr = 500.
itab-sgtxt = '321 static'.
APPEND itab.
itab-bukrs = '1'.
itab-zuonr = 'A3450'.
itab-wrbtr = 100.
itab-sgtxt = '310 static'.
APPEND itab.
itab-bukrs = '1'.
itab-zuonr = 'A3450'.
itab-wrbtr = 200.
itab-sgtxt = '311 static'.
APPEND itab.
itab-bukrs = '1'.
itab-zuonr = 'A3450'.
itab-wrbtr = 300.
itab-sgtxt = '321 static'.
APPEND itab.
LOOP AT itab.
jtab-sgtxt = itab-sgtxt+0(3).
APPEND jtab.
ENDLOOP.
SORT jtab BY sgtxt.
DELETE ADJACENT DUPLICATES FROM jtab
COMPARING sgtxt.
DATA : wa_fcat TYPE lvc_s_fcat,
it_fcat TYPE lvc_t_fcat.
DATA: new_table TYPE REF TO data,
new_line TYPE REF TO data,
lcl_txt(10) TYPE c,
lcl_txt1(3) TYPE c.
*-- Field-Symbols
FIELD-SYMBOLS: <l_table> TYPE STANDARD TABLE,
<l_line> TYPE ANY.
wa_fcat-fieldname = 'BUKRS'.
wa_fcat-inttype = 'C'.
wa_fcat-intlen = '1'.
APPEND wa_fcat TO it_fcat.
wa_fcat-fieldname = 'ZUONR'.
wa_fcat-inttype = 'C'.
wa_fcat-intlen = '5'.
APPEND wa_fcat TO it_fcat.
LOOP AT jtab.
lcl_txt1 = jtab-sgtxt.
CONCATENATE 'WRBTR_' lcl_txt1
INTO lcl_txt.
wa_fcat-fieldname = lcl_txt.
wa_fcat-inttype = 'I'.
wa_fcat-intlen = '4'.
APPEND wa_fcat TO it_fcat.
CLEAR : lcl_txt, lcl_txt1.
ENDLOOP.
*
IF NOT it_fcat[] IS INITIAL.
Create a new Table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fcat
IMPORTING
ep_table = new_table.
IF sy-subrc EQ 0.
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>.
ENDIF.
ENDIF.
DATA : sum TYPE i,
BEGIN OF ktab OCCURS 0,
f_zuonr(10) TYPE c,
f_sgtxt(10) TYPE c,
wrbtr TYPE i,
END OF ktab.
sum = 0.
LOOP AT itab.
lcl_txt = itab-sgtxt.
AT NEW sgtxt.
sum = 0.
ENDAT.
sum = itab-wrbtr + sum.
AT END OF sgtxt.
ktab-wrbtr = sum.
ktab-f_sgtxt = itab-sgtxt.
ktab-f_zuonr = itab-zuonr.
APPEND ktab.
ENDAT.
ENDLOOP.
FIELD-SYMBOLS : <fs>.
LOOP AT ktab.
CLEAR : lcl_txt.
CONCATENATE 'WRBTR_' ktab-f_sgtxt+0(3) INTO lcl_txt.
READ TABLE it_fcat INTO wa_fcat
WITH KEY fieldname = lcl_txt.
IF sy-subrc EQ 0.
ASSIGN COMPONENT wa_fcat-fieldname OF STRUCTURE <l_line> TO <fs>.
<fs> = ktab-wrbtr.
ASSIGN COMPONENT 'ZUONR' OF STRUCTURE <l_line> TO <fs>.
<fs> = ktab-f_zuonr.
ASSIGN COMPONENT 'BUKRS' OF STRUCTURE <l_line> TO <fs>.
<fs> = '1'.
ENDIF.
AT END OF f_zuonr.
APPEND <l_line> TO <l_table>.
CLEAR : <l_line>.
ENDAT.
ENDLOOP.
LOOP AT <l_table> ASSIGNING <l_line>.
LOOP AT it_fcat INTO wa_fcat.
ASSIGN COMPONENT wa_fcat-fieldname OF STRUCTURE <l_line> TO <fs>.
WRITE : <fs>.
ENDLOOP.
WRITE 😕 .
ENDLOOP.
-SatyaPriya
‎2007 May 14 11:00 AM
hi all, thnx for the answers
i did the same thing, btu when i use the method to create a dyn_table it leads to dump. the dump is as below
Error analysis
A RAISE statement in the program "CL_ABAP_TYPEDESCR=============CP " raised the
exception
condition "TYPE_NOT_FOUND".
Since the exception was not intercepted by a superior program
in the hierarchy, processing was terminated.
Short description of exception condition:
For detailed documentation of the exception condition, use
Transaction SE37 (Function Library). You can take the called
function module from the display of active calls.
-
Information on where termination occurred
The termination occurred in the ABAP/4 program
"CL_ABAP_TYPEDESCR=============CP " in
"DESCRIBE_BY_NAME".
The main program was "ZTEST_DYNAMIC ".
The termination occurred in line 54
of the source code of program "CL_ABAP_TYPEDESCR=============CM002 " (when
calling the editor 540).
Kindly suggest me as wht to be done...
Regards
pratyusha
‎2007 May 14 7:54 AM
try this:
REPORT znrw_dyn_tab_cols .
*BUKRS |ZUONR |WRBTR |SGTXT
*----
*----
*1 -|A1190 -|100 -|310 static
*1 -|A1190 -|200 -|310 static
*1 -|A1192 -|150 -|311 static
*1 -|A2330 -|100 -|310 static
*1 -|A2330 -|150 -|310 static
*1 -|A2330 -|500 -|321 static
*1 -|A3450 -|100 -|310 static
*1 -|A3450 -|200 -|311 static
*1 -|A3450 -|300 -|321 static
DEFINE table_populate.
w_t1-bukrs = &1.
w_t1-zuonr = &2.
w_t1-wrbtr = &3.
w_t1-sgtxt = &4.
append w_t1 to tab.
END-OF-DEFINITION.
TYPES: BEGIN OF ty_1,
bukrs TYPE t001-bukrs,
zuonr TYPE bseg-zuonr,
wrbtr TYPE bseg-wrbtr,
sgtxt TYPE bseg-sgtxt,
END OF ty_1.
DATA w_t1 TYPE ty_1.
TYPES: BEGIN OF ty_2,
bukrs TYPE t001-bukrs,
zuonr TYPE bseg-zuonr,
sgtxt(3),
wrbtr TYPE bseg-wrbtr,
END OF ty_2.
DATA w_t2 TYPE ty_2.
TYPES: BEGIN OF ty_3,
sgtxt(3),
END OF ty_3.
DATA w_t3 TYPE ty_3
.
DATA tab TYPE TABLE OF ty_1 WITH HEADER LINE.
DATA tab2 TYPE TABLE OF ty_2 WITH HEADER LINE.
DATA tab3 TYPE TABLE OF ty_3 WITH HEADER LINE.
table_populate '1' 'A1190' 100 '310 static'.
table_populate '1' 'A1190' 200 '310 static'.
table_populate '1' 'A1192' 150 '311 static'.
table_populate '1' 'A2330' 100 '310 static'.
table_populate '1' 'A2330' 150 '310 static'.
table_populate '1' 'A2330' 500 '321 static'.
table_populate '1' 'A3450' 100 '310 static'.
table_populate '1' 'A3450' 200 '311 static'.
table_populate '1' 'A3450' 300 '321 static'.
LOOP AT tab.
MOVE-CORRESPONDING tab TO tab2.
COLLECT tab2.
MOVE-CORRESPONDING tab TO tab3.
COLLECT tab3.
ENDLOOP.
data declarations for internal table
DATA: lt TYPE lvc_t_fcat,
ls TYPE lvc_s_fcat,
fldname(50) TYPE c,
it_ddfields TYPE TABLE OF ddfield,
wa_ddfields LIKE LINE OF lt.
DATA lt_data TYPE REF TO data.
FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
wa_ddfields-fieldname = 'BUKRS'.
wa_ddfields-datatype = 'CHAR'.
wa_ddfields-intlen = 4.
wa_ddfields-decimals = '0'.
APPEND wa_ddfields TO lt.
wa_ddfields-fieldname = 'ZUONR'.
wa_ddfields-datatype = 'CHAR'.
wa_ddfields-intlen = 18.
wa_ddfields-decimals = '0'.
APPEND wa_ddfields TO lt.
LOOP AT tab3.
CONCATENATE 'WRBTR' tab3-sgtxt INTO wa_ddfields-fieldname.
wa_ddfields-datatype = 'CURR'.
wa_ddfields-intlen = 13.
wa_ddfields-decimals = '2'.
APPEND wa_ddfields TO lt.
ENDLOOP.
ASSIGN lt_data TO <fs_data>.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
FIELD-SYMBOLS <fs_tab> TYPE table.
FIELD-SYMBOLS <fs_line>.
FIELD-SYMBOLS <wrbtr>.
DATA: lineref TYPE REF TO data.
ASSIGN <fs_data>->* TO <fs_tab>.
CREATE DATA lineref LIKE LINE OF <fs_tab>.
ASSIGN lineref->* TO <fs_line>.
LOOP AT tab2.
CLEAR <fs_line>.
MOVE-CORRESPONDING tab2 TO <fs_line>.
CONCATENATE 'WRBTR' tab2-sgtxt INTO wa_ddfields-fieldname.
ASSIGN COMPONENT wa_ddfields-fieldname OF STRUCTURE <fs_line>
TO <wrbtr>.
ADD tab2-wrbtr TO <wrbtr>.
collect <fs_line> INTO <fs_tab>.
ENDLOOP.
FIELD-SYMBOLS <field> TYPE ANY.
LOOP AT <fs_tab> ASSIGNING <fs_line>.
NEW-LINE.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs_line> TO <field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
WRITE <field>.
ENDDO.
ENDLOOP.
‎2007 May 14 11:06 AM
Hi Praty Usha,
U can't pass field names starting with number say like <b>"310 Static"</b>. Can u please check ur field catalogue. Or post it here.
-SatyaPriya