2013 Jul 23 1:10 PM
Hi Experts,
I have a string variable whose values is coming dynamically at runtime.
For example v_stg = 'SHP10008006745'.
Here the string contains two values SHP1 and 0008006745. This is in fixed length format.
Here first value is 4 char length and second 10. spaces are replaced by leading zeros. ( we need nor worry about this ).
Similarly this variable can contain 3 values or more because it is dynamically populated.
Now i am creating a workarea dynamically. I am getting the fields for this workarea from a table. So it the above string variable has 2 values then the workarea will have 2 fields. Similarly if the string variable has 3 values then the workarea will have 3 fields.
Now I want to put the value of string variable into this workarea. Based on the length it should automatically assign the values to correct fields of the workarea..
I tried the below code but it does not work and getting the syntax error:
| The type of "V_STG" cannot be converted to the type of "STRUC_TAB" |
.
DATA: lo_dyn_type TYPE REF TO cl_abap_structdescr,
struc_tab TYPE REF TO data.
* Create a New Type using the node structure obtained above
lo_dyn_type = cl_abap_structdescr=>create( i_tot_comp_dyn ).
*i_tot_comp_dyn contains the fields required for the dynamic workarea
CREATE DATA struc_tab TYPE HANDLE lo_dyn_type. "<-- struc_tab is my dynamic workarea
struc_tab = v_stg. "<--v_stg is the string variable
Please help
Thanks
Gopal
2013 Jul 23 6:16 PM
Hi, you should build an internal table with fields details
DATA: gt_itab TYPE REF TO data
gt_fcat TYPE lvc_t_fcat.
FIELD-SYMBOLS: <fs_fcat> TYPE lvc_s_fcat,
<fs_itab> TYPE STANDARD TABLE,
<fs_wa> TYPE any.
* You can put your fields and their length
APPEND INITIAL LINE TO gt_fcat ASSIGNING <fs_fcat>.
<fs_fcat>-fieldname = 'FIELD01'.
<fs_fcat>-datatype = 'CHAR'.
<fs_fcat>-outputlen = 4.
APPEND INITIAL LINE TO gt_fcat ASSIGNING <fs_fcat>.
<fs_fcat>-fieldname = 'FIELD02'.
<fs_fcat>-datatype = 'CHAR'.
<fs_fcat>-outputlen = 10.
* Create internal table
cl_alv_table_create=>create_dynamic_table(
EXPORTING
it_fieldcatalog = gt_fcat
IMPORTING
ep_table = gt_itab ).
* Assign table
ASSIGN gt_itab->* TO <fs_itab>.
* Create structure
CREATE DATA gs_itab LIKE LINE OF <fs_itab>.
* Assign structure
ASSIGN gs_itab->* TO <fs_wa>.
* Assign values
<fs_wa> = v_stg.
I hope this help you
Regards
David Carballido