‎2011 Mar 02 5:10 PM
Dear Developer,
I have a challenge in "dynamic development", and believe there are people out there for whom this is absolutely no problem.
After calling the function 'DB6_PM_1ST4' I get back an internal table with exactly one single line, but many many fields.
For download and further processing I want to to split this up into a 2nd internal table with SID, DATE, KEY and VALUE.
So the content of the 1st table looked like:
"20101011150647" | "20101018040059" | "" | "0" | "25165824" | ...
And I want to convert this into:
"PBW" | "2010/10/18" | "DBMSTRTTME" | "20101011150647"
"PBW" | "2010/10/18" | "COMPTIME" | "20101018040059"
"PBW" | "2010/10/18" | "LAST_RESET" | ""
"PBW" | "2010/10/18" | "BUFFPAGE" | "0"
"PBW" | "2010/10/18" | "BP_SZ" | "25165824"...
u2026
I've started with the following code but got stuck.
The problem is in the assignment to T_Z1DB6PERF-VALUE.
It would be great if someone could help.
Best regards,
Peter
*-----------------------------------------------------------------------
* find out fields of structure DB6PM1ST4
TABLES: DD03L.
TYPES: BEGIN OF T_FIELDNAME,
fieldname TYPE DD03L-FIELDNAME,
END OF T_FIELDNAME.
data: T_FIELDS type standard table of T_FIELDNAME with header line.
select FIELDNAME from DD03L into corresponding fields of TABLE T_FIELDS
where TABNAME = 'DB6PM1ST4'.
*----------------------------------------------------------------------
* call the function
CALL FUNCTION 'DB6_PM_1ST4'
EXPORTING
ACTION = 12
PARTITN = 0
TABLES
IT_DB6PM1ST4 = T_DB6PM1ST4
EXCEPTIONS
ERROR_CALCULATING = 1
INVALID_PARAMETER_SET = 2
ADBC_ERROR = 3
others = 4.
RET = sy-subrc.
...
*-----------------------------------------------------------------------
* add result to output structure
T_Z1DB6PERF-SID = SY-SID.
T_Z1DB6PERF-DATE = SY-DATUM.
loop at T_FIELDS.
field = t_fields-fieldname.
T_Z1DB6PERF-KEY = field.
T_Z1DB6PERF-VALUE = T_DB6PMST4-(field). "does not work :-(
append T_Z1DB6PERF.
...
‎2011 Mar 02 6:51 PM
@Arbind,
this is a bit confusing, because the T_DB6PM1ST4 of my original code example is already an internal table with a header line ^ work area:
DATA: T_DB6PM1ST4 TYPE STANDARD TABLE OF DB6PM1ST4 with header line.
DATA: T_FIELDS type standard table of T_FIELDNAME with header line.The syntax error I get for the below code fragment is
The data object "T_DB6PM1ST4" does not have a component called "".
Could you please explain this further? Your help is really appreciated!
loop at T_DB6PM1ST4.
loop at T_FIELDS.
field = T_FIELDS-FIELDNAME.
T_Z1DB6PERF-KEY1 = field.
T_Z1DB6PERF-VALUE = T_DB6PM1ST4-(field).
append T_Z1DB6PERF.
endloop.
endloop.
‎2011 Mar 02 5:46 PM
Hi,
Since T_DB6PM1ST4 is a table you can't assign value like that, you have to take the value in work area than only you can assign.
Try the below code....
loop at T_FIELDS.
field = t_fields-fieldname.
T_Z1DB6PERF-KEY = field.
"you can loop here into work area with where condition or
"read the table with the key and take the value in a work Area through
"work area assign the field values
T_Z1DB6PERF-VALUE = wa_DB6PMST4-(field). "Change of code
append T_Z1DB6PERF.
.............................
endloop.
Thanks
Arbind
Edited by: Arbind Prasad on Mar 2, 2011 11:17 PM
Edited by: Arbind Prasad on Mar 2, 2011 11:18 PM
‎2011 Mar 02 6:03 PM
T_Z1DB6PERF-VALUE = T_DB6PMST4-(field). "does not work :-(=> use field-symbols
‎2011 Mar 02 6:34 PM
@Sebastian:
I already tried to use field-symbols, but somehow I did not get the syntax right ... so all attempts ended in a short dump ... could you please give me a code example?
Thanks,
Peter
‎2011 Mar 02 7:01 PM
some time ago i wrote some similiar routine...here are some relevant lines.
FIELD-SYMBOLS: <fs_excel> TYPE alsmex_tabline,
<campo> TYPE ANY.
" gt_excel has fields: row, col and value.
LOOP AT gt_excel ASSIGNING <fs_excel>.
" gt_camposcarga contains a list of fields to be filled from the excel file
" looks like this:
" orden | destino
" 1 | bukrs
" 2 | belnr
READ TABLE gt_camposcarga INTO gs_camposcarga WITH KEY orden = <fs_excel>-col.
IF sy-subrc NE 0.
MESSAGE e003.
ENDIF.
ASSIGN COMPONENT gs_camposcarga-destino OF STRUCTURE <gs_dynamic> TO <campo>.
TRY .
<campo> = <fs_excel>-value.
CATCH cx_sy_conversion_no_number.
MESSAGE e004 WITH <fs_excel>-col <fs_excel>-row.
ENDTRY.
AT END OF row.
IF <gs_dynamic> IS NOT INITIAL.
PERFORM conv_routines.
INSERT <gs_dynamic> INTO TABLE <gt_dynamic>.
CLEAR <gs_dynamic>.
ENDIF.
ENDAT.
‎2011 Mar 02 6:51 PM
@Arbind,
this is a bit confusing, because the T_DB6PM1ST4 of my original code example is already an internal table with a header line ^ work area:
DATA: T_DB6PM1ST4 TYPE STANDARD TABLE OF DB6PM1ST4 with header line.
DATA: T_FIELDS type standard table of T_FIELDNAME with header line.The syntax error I get for the below code fragment is
The data object "T_DB6PM1ST4" does not have a component called "".
Could you please explain this further? Your help is really appreciated!
loop at T_DB6PM1ST4.
loop at T_FIELDS.
field = T_FIELDS-FIELDNAME.
T_Z1DB6PERF-KEY1 = field.
T_Z1DB6PERF-VALUE = T_DB6PM1ST4-(field).
append T_Z1DB6PERF.
endloop.
endloop.
‎2011 Mar 02 7:12 PM
if your problem is just at this statement then try this way.
data:lv type char100.
field-symbols:<fs> type any.
loop at T_DB6PM1ST4.
loop at T_FIELDS.
field = T_FIELDS-FIELDNAME.
T_Z1DB6PERF-KEY1 = field.
concatenate 'T_DB6PM1ST4-' field into lv.
condense lv no-gaps.
assign (lv) to <fs>.
if <fs> is assigned.
T_Z1DB6PERF-VALUE = <fs>.
endif.
append T_Z1DB6PERF.
endloop.
or
data:lv type char100.
field-symbols:<fs> type any.
loop at T_DB6PM1ST4.
loop at T_FIELDS.
field = T_FIELDS-FIELDNAME.
T_Z1DB6PERF-KEY1 = field.
assign component T_Z1DB6PERF-KEY1 of structure T_DB6PM1ST4 to <fs>.
if <fs> is assigned.
T_Z1DB6PERF-VALUE = <fs>.
endif.
append T_Z1DB6PERF.
endloop.
‎2011 Mar 03 7:52 AM
Many thanks to everybody who helped me.
The credits goes to Keshav.T
His code fragment worked perfectly for my purpose.
Again, many thanks.
Peter
field-symbols:<fs> type any.
loop at T_DB6PM1ST4.
loop at T_FIELDS.
field = T_FIELDS-FIELDNAME.
T_Z1DB6PERF-KEY1 = field.
assign component T_Z1DB6PERF-KEY1 of structure T_DB6PM1ST4 to <fs>.
if <fs> is assigned.
T_Z1DB6PERF-VALUE = <fs>.
endif.
append T_Z1DB6PERF.
endloop.