SAP Jobsuche bei DV-Treff
Armin93
  • Armin93
  • SAP Forum - Neuling Thema Starter
vor 5 Jahre
Hallo zusammen,

ich möchte gerne den Befehl Concatenate ausführen leider bekomme ich immer wieder eine Fehlermeldung.

Meine interne tabelle hat die CHAR und NUMC typen

aber die vv126 vv... usw sind CURR Typen.

Mit welchen Code kann ich dies umwandeln.

Ich bin noch ziemlicher neuling bitte vesucht es mir so einfach wie möglich zu erklären.

Vielen Dank

LOOP AT itab1.
    CONCATENATE itab1-rec_waers
                itab1-paledger
                itab1-vrgar
                itab1-perio
                itab1-belnr
                itab1-hzdat
                itab1-kndnr
                itab1-rbeln
                itab1-rposn
                itab1-usnam
                itab1-bukrs
                itab1-frwae
                itab1-prctr
                itab1-vv126
                itab1-vv125
                itab1-absmg_me
                itab1-vv121
                itab1-vv122
                itab1-vv010
                itab1-vv030
                itab1-vv020
                itab1-vv050
                itab1-vv040
                itab1-prodh
                itab1-absmg


                 INTO v_transfer SEPARATED BY ';'.
    TRANSFER v_transfer TO filename.
  ENDLOOP.
Förderer

wreichelt
vor 5 Jahre
Hallo,

du musst jedes einzelne Feld umwandeln - etwa so:

data : amount like bsis-dmbtr value '100.20',

char(20) type c.

char = amount.

CONDENSE char NO-GAPS.

oder

DATA:

value_n TYPE i VALUE '12344',

value_c TYPE char25.

WRITE value_n TO value_c.

Gruß Wolfgang

Horst_1959
vor 5 Jahre
Moin, in SAP gibt es dafür ein Objekt.

Ich weiß aber leider nicht mehr wie das heißt.

Das hab ich mal getestet und es gab Probleme mit Packed- und Float-Typen.

Bevor es die gab habe ich mal selber eine gemacht und die funktioniert auch mit float und packed.

Ich stelle sie mal rein :

Data :

INCLUDE zcl_new_csvgen.

DATA o_new_csv TYPE REF TO zcl_new_csvgen.

TYPES : BEGIN OF ty_csv,

data TYPE di_data.

TYPES : END OF ty_csv.

DATA ta_csv TYPE STANDARD TABLE OF ty_csv.

Aufruf :

o_new_csv = zcl_new_csvgen=>create( ).

READ TABLE i_tab INDEX 1 ASSIGNING .

CALL METHOD o_new_csv->head

EXPORTING

e_structur =

IMPORTING

i_head = head.

CALL METHOD o_new_csv->csv

EXPORTING

e_anytab = i_tab

IMPORTING

i_csvtab = ta_csv.

CALL METHOD o_new_csv->free.

CLEAR o_new_csv.

Objekt :

*&---------------------------------------------------------------------*

*& Include ZCL_NEW_CSVGEN *

*&---------------------------------------------------------------------*

*----------------------------------------------------------------------

*

* CLASS ZCL_NEW_CSVGEN DEFINITION

*----------------------------------------------------------------------

*

*

*----------------------------------------------------------------------

*

CLASS zcl_new_csvgen DEFINITION.

TYPE-POOLS : abap,

sydes.

PUBLIC SECTION.

TYPES : i_self TYPE REF TO zcl_new_csvgen,

ty_shortterm TYPE REF TO zcl_new_shortterm.

TYPES : BEGIN OF ty_csv,

data TYPE di_data,

END OF ty_csv.

TYPES : ty_table TYPE STANDARD TABLE OF ty_csv.

CLASS-METHODS create RETURNING VALUE(ref) TYPE i_self.

METHODS : head IMPORTING e_structur TYPE any

EXPORTING i_head TYPE di_data.

METHODS : csv IMPORTING e_anytab TYPE ANY TABLE

EXPORTING i_csvtab TYPE ty_table.

METHODS free.

PRIVATE SECTION.

TYPES : ty_str256(256) TYPE c.

TYPES : BEGIN OF ty_in_out,

input TYPE ty_str256,

f_dec TYPE i,

counter TYPE i,

shortterm TYPE ty_shortterm,

END OF ty_in_out.

DATA : ta_in_out TYPE HASHED TABLE OF ty_in_out

WITH UNIQUE KEY input f_dec.

TYPES : BEGIN OF ty_lang,

row TYPE i,

len TYPE i,

END OF ty_lang.

DATA : ta_lang TYPE STANDARD TABLE OF ty_lang.

DATA : my_error TYPE sysubrc,

my_counter TYPE i.

METHODS : kompakt IMPORTING p_table TYPE ANY TABLE.

METHODS : wandel IMPORTING p_input TYPE any

RETURNING VALUE(my_string) TYPE ty_str256.

ENDCLASS. "ZCL_NEW_CSVGEN DEFINITION

*----------------------------------------------------------------------*

* CLASS ZCL_NEW_CSVGEN IMPLEMANTATION

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

*

CLASS zcl_new_csvgen IMPLEMENTATION.

METHOD create.

CREATE OBJECT ref.

ENDMETHOD. "create

METHOD wandel.

DATA : f_times TYPE i,

f_type TYPE c,

f_dec TYPE i,

f_len TYPE i,

l_puffer TYPE ty_str256.

DATA : wa_in_out TYPE ty_in_out.

FIELD-SYMBOLS : TYPE ty_in_out.

my_counter = my_counter + 1.

IF my_counter >= 100000.

my_counter = 0.

DELETE ta_in_out WHERE counter = 0. "#EC CI_HASHSEQ

ENDIF.

CLEAR my_string.

CHECK NOT p_input IS INITIAL.

DESCRIBE FIELD p_input TYPE f_type.

CASE f_type.

WHEN 'T'.

READ TABLE ta_in_out WITH TABLE KEY input = p_input

f_dec = 0

ASSIGNING .

IF sy-subrc = 0.

CALL METHOD -shortterm->get_data

IMPORTING

i_data = my_string.

-counter = -counter + 1.

ELSE.

SEARCH p_input FOR ':'.

IF sy-subrc <> 0.

CONCATENATE p_input+0(2) ':' p_input+2(2) ':' p_input+4(2)

INTO my_string.

ELSE.

my_string = p_input.

ENDIF.

CLEAR wa_in_out.

wa_in_out-input = p_input.

wa_in_out-f_dec = 0.

wa_in_out-counter = 0.

wa_in_out-shortterm = zcl_new_shortterm=>create( ).

CALL METHOD wa_in_out-shortterm->set_data

EXPORTING

e_data = my_string

IMPORTING

i_error = my_error.

IF my_error = 0.

INSERT wa_in_out INTO TABLE ta_in_out.

ENDIF.

ENDIF.

WHEN 'D'.

READ TABLE ta_in_out WITH TABLE KEY input = p_input

f_dec = 0

ASSIGNING .

IF sy-subrc = 0.

CALL METHOD -shortterm->get_data

IMPORTING

i_data = my_string.

-counter = -counter + 1.

ELSE.

SEARCH p_input FOR '.'.

IF sy-subrc <> 0.

CONCATENATE p_input+6(2) '.' p_input+4(2) '.' p_input+0(4)

INTO my_string.

ELSE.

my_string = p_input.

ENDIF.

CLEAR wa_in_out.

wa_in_out-input = p_input.

wa_in_out-f_dec = 0.

wa_in_out-counter = 0.

wa_in_out-shortterm = zcl_new_shortterm=>create( ).

CALL METHOD wa_in_out-shortterm->set_data

EXPORTING

e_data = my_string

IMPORTING

i_error = my_error.

IF my_error = 0.

INSERT wa_in_out INTO TABLE ta_in_out.

ENDIF.

ENDIF.

WHEN 'F'.

UNPACK p_input TO my_string.

DESCRIBE FIELD p_input DECIMALS f_dec.

READ TABLE ta_in_out WITH TABLE KEY input = my_string

f_dec = f_dec

ASSIGNING .

IF sy-subrc = 0.

CALL METHOD -shortterm->get_data

IMPORTING

i_data = my_string.

-counter = -counter + 1.

ELSE.

l_puffer = my_string.

SHIFT my_string LEFT DELETING LEADING '0'.

f_len = strlen( my_string ).

IF f_len < f_dec.

f_times = f_dec - f_len.

DO f_times TIMES.

CONCATENATE '0' my_string INTO my_string.

ENDDO.

f_len = f_dec.

ENDIF.

IF f_dec > 0.

f_times = f_len - f_dec.

IF f_times = 0.

CONCATENATE '0,' my_string INTO my_string.

ELSE.

CONCATENATE my_string+0(f_times) ','

my_string+f_times(f_dec)

INTO my_string.

ENDIF.

ENDIF.

IF p_input < 0.

CONCATENATE '-' my_string INTO my_string.

ENDIF.

CLEAR wa_in_out.

wa_in_out-input = l_puffer.

wa_in_out-f_dec = f_dec.

wa_in_out-counter = 0.

wa_in_out-shortterm = zcl_new_shortterm=>create( ).

CALL METHOD wa_in_out-shortterm->set_data

EXPORTING

e_data = my_string

IMPORTING

i_error = my_error.

IF my_error = 0.

INSERT wa_in_out INTO TABLE ta_in_out.

ENDIF.

ENDIF.

WHEN 'P'.

UNPACK p_input TO my_string.

DESCRIBE FIELD p_input DECIMALS f_dec.

READ TABLE ta_in_out WITH TABLE KEY input = p_input

f_dec = f_dec

ASSIGNING .

IF sy-subrc = 0.

CALL METHOD -shortterm->get_data

IMPORTING

i_data = my_string.

-counter = -counter + 1.

ELSE.

l_puffer = my_string.

SHIFT my_string LEFT DELETING LEADING '0'.

f_len = strlen( my_string ).

IF f_len < f_dec.

f_times = f_dec - f_len.

DO f_times TIMES.

CONCATENATE '0' my_string INTO my_string.

ENDDO.

f_len = f_dec.

ENDIF.

IF f_dec > 0.

f_times = f_len - f_dec.

IF f_times = 0.

CONCATENATE '0,' my_string INTO my_string.

ELSE.

CONCATENATE my_string+0(f_times) ','

my_string+f_times(f_dec)

INTO my_string.

ENDIF.

ENDIF.

IF p_input < 0.

CONCATENATE '-' my_string INTO my_string.

ENDIF.

CLEAR wa_in_out.

wa_in_out-input = l_puffer.

wa_in_out-f_dec = f_dec.

wa_in_out-counter = 0.

wa_in_out-shortterm = zcl_new_shortterm=>create( ).

CALL METHOD wa_in_out-shortterm->set_data

EXPORTING

e_data = my_string

IMPORTING

i_error = my_error.

IF my_error = 0.

INSERT wa_in_out INTO TABLE ta_in_out.

ENDIF.

ENDIF.

WHEN OTHERS.

READ TABLE ta_in_out WITH TABLE KEY input = p_input

f_dec = 0

ASSIGNING .

IF sy-subrc = 0.

CALL METHOD -shortterm->get_data

IMPORTING

i_data = my_string.

-counter = -counter + 1.

ELSE.

my_string = p_input.

IF f_type = 'C'

OR f_type = 'G'.

FIND ';' IN my_string.

IF sy-subrc = 0.

CONCATENATE '"' my_string '"' INTO my_string.

ENDIF.

ENDIF.

CONDENSE my_string.

ENDIF.

CLEAR wa_in_out.

wa_in_out-f_dec = 0.

wa_in_out-counter = 0.

wa_in_out-input = p_input.

wa_in_out-shortterm = zcl_new_shortterm=>create( ).

CALL METHOD wa_in_out-shortterm->set_data

EXPORTING

e_data = my_string

IMPORTING

i_error = my_error.

IF my_error = 0.

INSERT wa_in_out INTO TABLE ta_in_out.

ENDIF.

ENDCASE.

ENDMETHOD. "wandel

METHOD kompakt.

DATA : wa_lang TYPE ty_lang.

" l_type(1) TYPE c.

FIELD-SYMBOLS : TYPE any,

TYPE any,

TYPE ty_lang.

DATA : my_string TYPE ty_str256,

my_erster TYPE boolean,

olen TYPE i.

" offset TYPE i.

FREE ta_lang.

my_erster = abap_false.

LOOP AT p_table ASSIGNING .

DO.

ASSIGN COMPONENT sy-index

OF STRUCTURE

TO .

IF sy-subrc <> 0.

EXIT.

ENDIF.

my_string = me->wandel( ).

olen = strlen( my_string ).

IF my_erster = abap_false.

wa_lang-row = sy-index.

wa_lang-len = olen.

APPEND wa_lang TO ta_lang .

ELSE.

READ TABLE ta_lang INDEX sy-index ASSIGNING .

IF olen > -len.

-len = olen.

ENDIF.

ENDIF.

ENDDO.

my_erster = abap_true.

ENDLOOP.

ENDMETHOD. "kompakt

METHOD head.

TYPES : feld_name TYPE sydes_nameinfo.

DATA : td TYPE sydes_desc,

f_names_tab TYPE STANDARD TABLE OF feld_name,

f_names TYPE feld_name,

" f_name(15) TYPE c,

l_longname(61) TYPE c,

l_index TYPE i.

DATA : ref_fieldname TYPE fieldname,

ref_tabname TYPE tabname,

rollname TYPE rollname,

l_lang TYPE i,

scrtext_m TYPE scrtext_m.

FIELD-SYMBOLS : TYPE any.

CLEAR i_head.

DO.

CLEAR : scrtext_m,

rollname.

ASSIGN COMPONENT sy-index OF STRUCTURE e_structur TO .

IF sy-subrc <> 0.

EXIT.

ENDIF.

DESCRIBE FIELD INTO td.

f_names_tab[] = td-names[].

l_index = 2.

READ TABLE f_names_tab INDEX l_index INTO f_names.

IF sy-subrc = 0.

l_longname = f_names-name.

ENDIF.

IF f_names-continue = '*'.

DO.

l_index = l_index + 1.

READ TABLE f_names_tab INDEX l_index INTO f_names.

CONCATENATE l_longname f_names-name INTO l_longname.

IF f_names-continue <> '*'.

EXIT.

ENDIF.

ENDDO.

ENDIF.

FIND '-' IN l_longname.

IF sy-subrc = 0.

SPLIT l_longname AT '-' INTO ref_tabname ref_fieldname.

SELECT SINGLE rollname ##WARN_OK

INTO rollname

FROM dd03l

WHERE tabname = ref_tabname

AND fieldname = ref_fieldname

AND as4local = 'A'.

IF sy-subrc <> 0.

l_lang = strlen( ref_fieldname ).

l_lang = l_lang - 1.

IF l_lang > 1.

ref_fieldname+l_lang(1) = '%'.

SELECT SINGLE rollname ##WARN_OK

INTO rollname

FROM dd03l

WHERE tabname = ref_tabname

AND fieldname LIKE ref_fieldname

AND as4local = 'A'.

IF sy-subrc <> 0.

rollname = '???'.

ENDIF.

ENDIF.

ENDIF.

ELSE.

rollname = l_longname.

ENDIF.

IF rollname <> ''.

SELECT SINGLE scrtext_m ##WARN_OK

INTO scrtext_m

FROM dd04t

WHERE rollname = rollname

AND ddlanguage = sy-langu

AND as4local = 'A'.

IF sy-subrc <> 0.

scrtext_m = '???'.

ENDIF.

ELSE.

scrtext_m = '???'.

ENDIF.

CONCATENATE i_head scrtext_m ';' INTO i_head.

ENDDO.

ENDMETHOD. "head

METHOD csv.

FIELD-SYMBOLS : TYPE any,

TYPE any,

TYPE ty_lang.

DATA : my_string TYPE ty_str256,

wa_csv TYPE ty_csv,

wa_string TYPE string,

olen TYPE i,

offset TYPE i,

char_leer TYPE c LENGTH 1.

CALL METHOD me->kompakt

EXPORTING

p_table = e_anytab.

CLEAR char_leer.

LOOP AT e_anytab ASSIGNING .

offset = 0.

CLEAR wa_csv-data.

DO.

ASSIGN COMPONENT sy-index OF STRUCTURE TO .

IF sy-subrc <> 0.

olen = strlen( wa_csv ).

olen = olen - 1.

wa_csv = wa_csv+0(olen).

wa_string = wa_csv.

CALL FUNCTION 'Z_ASCII_CONVERTER'

EXPORTING

i_string = wa_string

IMPORTING

e_string = wa_string.

wa_csv = wa_string.

APPEND wa_csv TO i_csvtab.

EXIT.

ENDIF.

my_string = me->wandel( ).

WRITE my_string TO wa_csv-data+offset.

READ TABLE ta_lang INDEX sy-index ASSIGNING .

offset = offset + -len.

WRITE ';' TO wa_csv-data+offset.

offset = offset + 1.

ENDDO.

ENDLOOP.

ENDMETHOD. "csv

METHOD free.

FIELD-SYMBOLS : TYPE ty_in_out.

LOOP AT ta_in_out ASSIGNING .

CALL METHOD -shortterm->free.

ENDLOOP.

FREE : ta_in_out,

ta_lang.

* CALL METHOD cl_abap_memory_utilities=>do_garbage_collection.

ENDMETHOD. "free

ENDCLASS. "ZCL_NEW_CSVGEN IMPLEMENTATION