Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to convert table type element to String

Former Member
0 Likes
3,196

Hi All,

I have a requirement where i have to convert table type element to String and then update it in the workflow container as workflow container can take type string or character of 255 or integer, ect

How do i convert Table type element to Char of 255? the data in the table is always a sentence or just a string.

Regards,

Lavanya

6 REPLIES 6
Read only

brad_bohn
Active Contributor
0 Likes
1,618

A simple MOVE or CONCATENATE operation will work from the source to the target...

Read only

Former Member
0 Likes
1,618

It throws an error saying element can not be converted to a table type element.

Here i have my data in Ptex type tablet.

I have Ptext1(225) type C.

I am trying to move from ptext to Ptext1, it says " The type of "PTEXT" cannot be converted to the type of "PTEXT1".

Regards,

Lavanya.

Read only

brad_bohn
Active Contributor
0 Likes
1,618

I don't know what type 'tablet' is - what type is your PTEXT field? Give more info and you'll get a better answer .

Read only

Former Member
0 Likes
1,618

DATA: lv_Begda1 TYPE BEGDA,

lv_ENDDA1 TYPE ENDDA,

PTEXT TYPE RP50M-TEXT1 OCCURS 0,

TX-KEY LIKE PSKEY.

if lv_tmart = 'J2'.

SELECT SINGLE

Begda Endda from PA0019

INTO (lv_Begda1 , lv_ENDDA1)

where pernr = lv_pernr AND tmart = 'J2' .

TX-KEY-PERNR = lv_pernr.

TX-KEY-INFTY = '0019'.

TX-KEY-SUBTY = 'J2'.

TX-KEY-ENDDA = lv_Begda1.

TX-KEY-BEGDA = lv_ENDDA1.

TX-KEY-SEQNR = '000'.

IMPORT ptext FROM DATABASE pcl1(tx) ID tx-key.

DATA: Ptext1(225) TYPE C.

Ptext1 = ptext .

Move 'Abs_Reason' TO itab_wf-element.

MOVE ptext1 to itab_wf-Value.

APPEND itab_wf.

Move 'Abs_Begda' TO itab_wf-element.

MOVE lv_Begda1 to itab_wf-Value.

APPEND itab_wf.

Move 'Abs_Endda' TO itab_wf-element.

MOVE lv_ENDDA1 to itab_wf-Value.

APPEND itab_wf.

This is my code. I am importing ptext from a cluster table and then move it to Ptext1.

Read only

Former Member
0 Likes
1,618

Hi,

You can use the class CL_ABAP_CONTAINER_UTILITIES -->method FILL_CONTAINER_C to convert a structure to string.

The variables ptext and ptext1 are of different types. One is a structure/ internal table and the other is a CHAR.

So instead of using " ptext1 = ptext ", you must loop at each record in the internal table and concatenate all the fields in the record into ptext1.

Hope this solves.

Thanks,

Teja.

Read only

kiran_k8
Active Contributor
0 Likes
1,618

Hi.

Is it something like this that you are looking for



*&---------------------------------------------------------------------*
*&      Form  convert_table_to_string
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM convert_table_to_string .
  DATA: str TYPE string,
        len TYPE i,
        tot_len TYPE i.

TYPES : BEGIN OF ty_text ,
        tdformat TYPE tline-tdformat,
        tdline TYPE tline-tdline,
        END OF ty_text.

data: g_t_text TYPE STANDARD TABLE OF ty_text WITH HEADER LINE,

 FIELD-SYMBOLS <fs1> TYPE ANY.


  IF g_t_ekpo-ebeln IS NOT INITIAL.
    CONCATENATE g_t_ekpo-ebeln  g_t_ekpo-ebelp  INTO g_ebeln. "CRQ94538-Capture text
    SHIFT g_ebeln LEFT DELETING LEADING space.
    PERFORM read_text USING g_ebeln g_t_text[].

    IF g_t_text[] IS NOT INITIAL.
      CLEAR: len,
             tot_len,
              str.
      DO.
        ASSIGN COMPONENT sy-index OF STRUCTURE g_t_text TO <fs1>.
        IF sy-subrc NE 0.
          EXIT.
        ENDIF.
        DESCRIBE FIELD <fs1> LENGTH len IN CHARACTER MODE.
        ADD len TO tot_len.
      ENDDO.
      CALL FUNCTION 'CONVERT_TABLE_TO_STRING'
        EXPORTING
          i_tabline_length = tot_len
        IMPORTING
          e_string         = str
        TABLES
          it_table         = g_t_text[].
      IF sy-subrc = 0.
        g_t_ekpo-text = str.

      ENDIF.
    ELSE.
      CLEAR: g_t_ekpo-text,
             tot_len,
             len,
             str.     .
    ENDIF.
  ENDIF.
ENDFORM.                    " convert_table_to_string

Thanks,

Kiran.