Code: Alles auswählen.
REPORT.
data: gv_counter type i.
DATA: BEGIN OF trivial_solution,
field_one TYPE string,
field_two TYPE string,
END OF trivial_solution.
START-OF-SELECTION.
PERFORM mystery USING syst. " --> fields missing
PERFORM mystery USING trivial_solution. " --> AB
*&---------------------------------------------------------------------*
*& Form mystery
*&---------------------------------------------------------------------*
FORM mystery USING is_input TYPE any.
FIELD-SYMBOLS: <field_one> TYPE ANY,
<field_two> TYPE ANY.
DATA: c1 TYPE string,
c2 TYPE string,
result TYPE string,
len TYPE i.
add 1 to gv_counter.
write:/(4) gv_counter,':'.
ASSIGN COMPONENT 'FIELD_ONE' OF STRUCTURE is_input TO <field_one>.
ASSIGN COMPONENT 'FIELD_TWO' OF STRUCTURE is_input TO <field_two>.
IF <field_one> IS NOT ASSIGNED OR <field_two> IS NOT ASSIGNED.
WRITE: 'fields missing'.
ELSE.
<field_one> = 'A'.
<field_two> = 'B'.
c1 = <field_one>.
c2 = <field_two>.
CONCATENATE c1 c2 INTO result.
len = STRLEN( result ).
IF len > 4.
WRITE: result(4).
ELSE.
WRITE: result.
ENDIF.
ENDIF.
ENDFORM. "mystery
Code: Alles auswählen.
FORM mystery USING us_data TYPE any.
DATA:
lr_value TYPE REF TO data,
ls_dfies TYPE dfies,
ld_name TYPE fieldname,
ld_convert TYPE funcname,
ld_timezone TYPE timezone,
ld_date TYPE d,
ld_time TYPE t,
lr_elemdescr TYPE REF TO cl_abap_elemdescr,
lr_typedescr TYPE REF TO cl_abap_typedescr,
lr_structdescr TYPE REF TO cl_abap_structdescr.
FIELD-SYMBOLS:
<ls_component> TYPE abap_compdescr,
<lt_table> TYPE ANY TABLE,
<la_data> TYPE any,
<la_value> TYPE any,
<la_line> TYPE any.
ASSIGN us_data TO <la_data>.
lr_typedescr = cl_abap_typedescr=>describe_by_data( us_data ).
* Referenzen auflösen
WHILE lr_typedescr IS BOUND AND lr_typedescr->kind EQ cl_abap_typedescr=>kind_ref.
ASSIGN <la_data>->* TO <la_data>.
lr_typedescr = cl_abap_typedescr=>describe_by_data( us_data ).
ENDWHILE.
IF lr_typedescr IS NOT BOUND.
RETURN.
ENDIF.
CASE lr_typedescr->kind.
WHEN cl_abap_typedescr=>kind_table.
ASSIGN <la_data> TO <lt_table>.
LOOP AT <lt_table> ASSIGNING <la_line>.
NEW-LINE.
PERFORM mystery USING <la_line>.
ENDLOOP.
WHEN cl_abap_typedescr=>kind_struct.
lr_structdescr ?= lr_typedescr.
LOOP AT lr_structdescr->components ASSIGNING <ls_component>.
ASSIGN COMPONENT <ls_component>-name OF STRUCTURE <la_data> TO <la_value>.
PERFORM mystery USING <la_value>.
ENDLOOP.
WHEN cl_abap_typedescr=>kind_intf OR cl_abap_typedescr=>kind_class.
* Hier vielleicht die Public-Attribue auslesen und ausgeben (ist mir aber jetzt zu aufwändig)
WHEN cl_abap_typedescr=>kind_elem.
lr_elemdescr ?= lr_typedescr.
ld_name = lr_elemdescr->get_relative_name( ).
CLEAR ls_dfies.
IF ld_name IS NOT INITIAL.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = ld_name
ALL_TYPES = abap_true
IMPORTING
dfies_wa = ls_dfies
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
ENDIF.
IF ls_dfies-convexit IS NOT INITIAL AND ls_dfies-outputlen IS NOT INITIAL.
CREATE DATA lr_value TYPE c LENGTH ls_dfies-outputlen.
ASSIGN lr_value->* TO <la_value>.
<la_value> = <la_data>.
CONCATENATE 'CONVERSION_EXIT_' ls_dfies-convexit '_OUTPUT' INTO ld_convert.
TRANSLATE ld_convert TO UPPER CASE. "#EC SYNTCHAR
CONDENSE ld_convert NO-GAPS.
TRY.
CALL FUNCTION ld_convert
EXPORTING
input = <la_data>
IMPORTING
output = <la_value>.
CATCH cx_root. "#EC NO_HANDLER
* Alle Fehler der Konvertierung abfangen
ENDTRY.
WRITE <la_value>.
ELSE.
CASE ls_dfies-tabname.
WHEN 'TIMESTAMPL' OR 'TIMESTAMP'.
ld_timezone = 'UTC'.
WRITE <la_data> TIME ZONE ld_timezone.
WHEN OTHERS.
CASE lr_elemdescr->type_kind.
WHEN cl_abap_typedescr=>typekind_date OR cl_abap_typedescr=>typekind_time.
WRITE <la_data>.
WHEN cl_abap_typedescr=>typekind_packed OR cl_abap_typedescr=>typekind_decfloat
OR cl_abap_typedescr=>typekind_decfloat16 OR cl_abap_typedescr=>typekind_decfloat34
OR cl_abap_typedescr=>typekind_float OR cl_abap_typedescr=>typekind_int
OR cl_abap_typedescr=>typekind_int1 OR cl_abap_typedescr=>typekind_int2
OR cl_abap_typedescr=>typekind_num OR cl_abap_typedescr=>typekind_numeric.
WRITE <la_data> EXPONENT 0 RIGHT-JUSTIFIED.
WHEN cl_abap_typedescr=>typekind_hex OR cl_abap_typedescr=>typekind_xstring
OR cl_abap_typedescr=>typekind_xsequence.
WRITE <la_data>. "Vielleicht noch eine spezielle Aufbereitung für Binärdaten
WHEN OTHERS.
FIND REGEX '@[0-9A-Z]{2}(\\Q[^@])?@.*' IN <la_data>.
IF sy-subrc EQ 0.
WRITE <la_data> AS ICON.
ELSE.
WRITE <la_data>.
ENDIF.
ENDCASE.
ENDCASE.
ENDIF.
ENDCASE.
ENDFORM. "mystery
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Form mystery
*&---------------------------------------------------------------------*
FORM mystery USING is_input TYPE any.
FIELD-SYMBOLS: <field_one> TYPE ANY,
<field_two> TYPE ANY.
DATA: c1 TYPE string,
c2 TYPE string,
result TYPE string,
len TYPE i.
ADD 1 TO gv_counter.
WRITE:/(4) gv_counter,':'.
ASSIGN COMPONENT 'FIELD_ONE' OF STRUCTURE is_input TO <field_one>.
ASSIGN COMPONENT 'FIELD_TWO' OF STRUCTURE is_input TO <field_two>.
IF <field_one> IS NOT ASSIGNED OR <field_two> IS NOT ASSIGNED.
WRITE: 'fields missing'.
ELSE.
<field_one> = 'A'.
<field_two> = 'B'.
c1 = <field_one>.
c2 = <field_two>.
CONCATENATE c1 c2 INTO result.
len = STRLEN( result ).
IF len > 4.
WRITE: result(4).
ELSE.
WRITE: result.
ENDIF.
ENDIF.
ENDFORM. "mystery
Einspruch eure Eiligkeit!black_adept hat geschrieben:Nachdem ewx sich ein paar Lösungen durch psychologisches Profiling ergaunert hat, hier noch ein paar Hinweise.
Code: Alles auswählen.
types: begin of gty_1,
field_one type char1,
end of gty_1.
data: begin of special5.
include type gty_1 as field_two.
data: end of special5.
Code: Alles auswählen.
types: begin of gty_1,
dummy type char1,
field_one type char1,
end of gty_1.
data: begin of special5.
include type gty_1 as field_two.
data: end of special5.
Folgende Benutzer bedankten sich beim Autor black_adept für den Beitrag:
ewx