‎2014 Feb 24 11:27 AM
Hi Experts,
I have some difficult to find the correct syntax to assign a Generic Structure to an Explicit Structure.
Please, find my code below:
Declaration METHOD:
P_BRAND Importing Type SPART
T_CUSTOINF Importing Type TY_T_ZPLPCUSTINTERFAC
NAME_STRUC Importing Type STRING
TABLE_IN Importing Type TY_T_RSBANK
FOOTER Changing Type ZINT_RSBANKINV_FILE_FOOTER
HEADER Changing Type ZINT_RSBANKINV_FILE_HEADER
IMPLEMENTATION:
METHOD mapping_t_rsbank_file_foothead.
CONSTANTS lk_ostruct TYPE char10 VALUE 'lo_struct' .
FIELD-SYMBOLS <fs> TYPE any .
FIELD-SYMBOLS <fs_header> TYPE ZINT_RSBANKINV_FILE_FOOTER .* FIELD-SYMBOLS <fs> TYPE any .
DATA lo_struct TYPE REF TO data .
DATA ls_custoinf TYPE zplpcustinterfac .
DATA lt_fieldcat TYPE lvc_t_fcat .
DATA ls_fieldcat TYPE lvc_s_fcat .
DATA lv_tabfield TYPE string .
CREATE DATA lo_struct TYPE (name_struc) .
* Get Fieldcat from Structure
lt_fieldcat = zclplp_tools=>get_fieldcat_from_struct( name_struc ) .
LOOP AT lt_fieldcat INTO ls_fieldcat .
CONCATENATE lk_ostruct
ls_fieldcat-fieldname INTO lv_tabfield
SEPARATED BY zclplp_tools=>separator_arrow.
ASSIGN (lv_tabfield) TO <fs> .
READ TABLE t_custoinf INTO ls_custoinf
WITH KEY name = ls_fieldcat-fieldname .
<fs> = ls_custoinf-low .
ENDLOOP .
BREAK-POINT.
header ?= lo_struct. "// DUMP
ENDMETHOD.
Any idea ?
Many thx.
Rachid.
‎2014 Feb 24 11:35 AM
Find it:
Assign lo_struct ->* to <FS>.
header = <fs>.
Best regards.
‎2014 Feb 24 11:35 AM
Find it:
Assign lo_struct ->* to <FS>.
header = <fs>.
Best regards.
‎2014 Feb 24 11:41 AM
one uses ?= assignment with objects. Your "header" is a plain structure (I suppose). You can't assign those. You could try looping through the components of HEADER (do-enddo, assign component sy-index xyz of structure lo_struct to <value>). But for this purpose you would need to change the approach.
Use RTTI / RTTS for this purpose - CL_ABAP_STRUCTDESCR=>DESCRIBE_BY_NAME( NAME_STRUC ), loop through the components of the structure in a cycle - get components by CL_ABAP_STRUCTDESCR=>GET_COMPONENTS( ) and process as written.