Skip to Content
0

ABAPLIST to string in ECC6 (with the first four charactes)

Sep 28, 2017 at 10:31 AM

67

avatar image
Former Member

Hello.

I'm going to ECC6 from 46C and I have more programs that read the spool files and sometimes they change them. Usually I use "SUBMIT rspolst2 EXPORTING LIST TO MEMORY", then I call "LIST_FROM_MEMORY" to get an ABAPLIST. Finally from this ABAPLIST i get an internal table from LIST_TO_ASCI putting directly the entire structure of ABAPLIST resulting into a char field. It works fine.

Always in 46C i tried other two ways for the last step: using SPLIT from the ABAPLIST structure to a string field by a separator '|' and using the FM "LIST_TO_TXT". The "SPLIT" works fine, while the FM "LIST_TO_TXT" works but it isn't very useful because all the rows are concatenated.

Now, in ECC6, I must put the unicode flag on my Zprogram and after that no one among the three methods is accepted. I can't pass from the entire structure ABAPLIST to a string filed (or a char field).

SPLIT works only with the field RFCRECORD, but by this way I lose the first four characters. The same thing using the FM HR_KR_XSTRING_TO_STRING: I lose the first four character, but I want to get them.

How can I do?

Here is a sample program to test this three ways: "mem_tab" is the ABAPLIST, and in the comments I specified FIRST, SECOND and THIRD METHOD.

In ECC6 the FIRST and the SECOND are not accepted, I can't activate the program, instead by the third method I can ACTIVATE it but if I run it I get an " UC_OBJECTS_NOT_CHAR" error.

------

REPORT  Zmassimiliano NO standard page heading.


  TABLES: zmail_spool.


  TYPES: BEGIN OF t_zmspool,
            agente    TYPE lfa1-lifnr,
            nrspool   TYPE zmail_spool-nrspool,
            rqcretime TYPE zmail_spool-rqcretime,
            rqowner   TYPE zmail_spool-rqowner,
            chiave    TYPE zmail_spool-chiave,
            note      TYPE zmail_spool-note,
            dtultmail TYPE zmail_spool-dtultmail,
            orultmail TYPE zmail_spool-orultmail,
            utultmail TYPE zmail_spool-utultmail,
         END OF t_zmspool.


  DATA: wa_zmspool  TYPE t_zmspool,
        it_zmspool  TYPE STANDARD TABLE OF t_zmspool.


*types: begin of t_asci,
*        include type abaplist,
*       end of t_asci.
types: begin of tt,
        line(202),
       end of tt.
data: v_asci type standard table of abaplist,
      wa_asci type abaplist,
      it_xtext TYPE STANDARD TABLE OF tt,
      wa_xtext TYPE tt,
      f_xtext1 TYPE string,
      f_xtext2 TYPE string.


  DATA: mem_tab TYPE STANDARD TABLE OF abaplist,
        wa_tab TYPE tline,
        it_tab TYPE STANDARD TABLE OF tline,
        size   TYPE I.
  DATA: f_nrspool TYPE zmail_spool-nrspool,
        f_numsp(10) TYPE n,
        f_chiave  TYPE zmail_spool-chiave,
        wa_tsp01  TYPE tsp01,
        it_tsp01  TYPE STANDARD TABLE OF tsp01,
        f_mt(10)       TYPE C,
        f_st(30)       TYPE C,
        f_avdipa       TYPE C,
        f_agedes(30)   TYPE C,
        f_codage(6)    TYPE C,
        f_codag(10)    TYPE N,
        f_alleg        TYPE zmail_def-alleg,
        f_divid(1)     TYPE C,
        f_filename     TYPE STRING,
        wa_zmail       TYPE zmail_spool,
        f_str(200)     TYPE C,
        f_x            TYPE I.
*--------------------------------------------------------------------
*                        SELEZIONI INIZIALI
*--------------------------------------------------------------------


 SELECTION-SCREEN BEGIN OF BLOCK datibase WITH FRAME TITLE text-001.
   SELECTION-SCREEN BEGIN OF LINE.
     SELECTION-SCREEN COMMENT (30) text-usr.
     PARAMETERS s_user TYPE zmail_spool-rqowner DEFAULT sy-uname.
   SELECTION-SCREEN END OF LINE.
   SELECTION-SCREEN BEGIN OF LINE.
     SELECTION-SCREEN COMMENT (27) text-dta.
     SELECT-OPTIONS s_data FOR zmail_spool-rqcretime.
   SELECTION-SCREEN END OF LINE.
 SELECTION-SCREEN END OF BLOCK datibase.


*--------------------------------------------------------------------
*                        START-OF-SELECTION
*--------------------------------------------------------------------


START-OF-SELECTION.


* Nella tabella it carico solo gli spool non già presenti
*   in zmail_spool
  SELECT * INTO wa_tsp01
    FROM tsp01
    WHERE rqcretime IN s_data AND rqowner = s_user.
*         AND rq0name = 'SAP08'.


    f_numsp = wa_tsp01-rqident.
    f_nrspool = f_numsp.
    SELECT SINGLE chiave FROM zmail_spool INTO f_chiave
      WHERE nrspool = f_nrspool.
    INSERT wa_tsp01 INTO TABLE it_tsp01.


*    WRITE:/ wa_tsp01-rqident.


    EXIT.
  ENDSELECT.


  LOOP AT it_tsp01 INTO wa_tsp01.
*    WRITE:/ 'loop', wa_tsp01-rqident.
    SUBMIT rspolst2 EXPORTING LIST TO MEMORY AND RETURN
      WITH rqident = wa_tsp01-rqident
      WITH first = '1'.
    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        listobject = mem_tab
      EXCEPTIONS
        not_found = 1
        others = 2.
*    WRITE:/ 'sy-subrc', sy-subrc.
    IF not mem_tab[] is initial.
      REFRESH v_asci.
      CALL FUNCTION 'LIST_TO_ASCI'
        TABLES
          listasci   = v_asci
          listobject = mem_tab
        EXCEPTIONS
          empty_list = 1
          list_index_invalid = 2
          others = 3.
      CLEAR f_x.


* ///// FIRST METHOD: DIRECTLY ////////////////
      LOOP AT v_asci INTO wa_asci.
        wa_tab-tdline = wa_asci.
        WRITE:/ wa_tab-tdline.
        f_x = f_x + 1.
        IF f_x = 15.
          EXIT.
        ENDIF.
      ENDLOOP.
      WRITE:/ '********************************************'.
* ///// SECOND METHOD: BY SPLIT ////////////////
      CLEAR f_x.
      LOOP AT v_asci INTO wa_asci.
        SPLIT wa_asci AT  '|'
              INTO f_xtext1 f_xtext2.


        WRITE:/ f_xtext1.
*        WRITE:/ f_xtext2.


        f_x = f_x + 1.
        IF f_x = 15.
          EXIT.
        ENDIF.
      ENDLOOP.
      WRITE:/ '********************************************'.
* ///// THIRD METHOD: LIST_TO_TXT ////////////////
      CALL FUNCTION 'LIST_TO_TXT'
*        EXPORTING
*          LIST_INDEX               = '1'
        TABLES
          listtxt                 = it_xtext
          LISTOBJECT              = mem_tab
        EXCEPTIONS
         EMPTY_LIST               = 1
         LIST_INDEX_INVALID       = 2
         OTHERS                   = 3.
      CLEAR f_x.
      LOOP AT it_xtext INTO wa_xtext.
        WRITE:/ wa_xtext-line.
        WRITE:/ '--'.
        f_x = f_x + 1.
        IF f_x = 15.
          EXIT.
        ENDIF.
      ENDLOOP.
    ENDIF.


  ENDLOOP.
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Sandra Rossi Sep 28, 2017 at 11:08 AM
1

With Unicode, you must distinguish variables of type C (characters) from those of type X (bytes) because one "SAP Unicode character" is 2 bytes (before Unicode, there was no issue, because one character was stored in one byte).

In your code, you call LIST_TO_ASCI with variable V_ASCI which is a table of ABAPLIST, which contains X type. You must only use C type.

It works with LIST_TO_TXT because IT_XTEXT is of type C.

You should post the full short dump (TXT zipped) so that we can understand where and what the error is exactly.

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

I understood now.

LIST_TO_TXT works but:

1) The rows are concatenated separated by "##", e.g. "//XSAPWIN 0702 00000+00000+ ##IN01IZ_RVDELNOTE_CF FIRST ##OPDINA4 P 144 240 1683811906000010000100001" (ok: I can write the code to divide them)

2) If I want to insert or manage rows to get a new ABAPLIST, how can I do it?

My target is, for example, load a spool file to add columning and images and after that I can get a pdf (passing through a new sapscript). In another case the user has to change something in the spool file before getting a pdf to send it via e-mail. I hope I must not to re-write all these programs.

Thank you for your answer!

0

In all honesty, this whole thing doesn't sound like a good idea and I'd totally redo this. And if the same functionality is used in many programs then it should've been moved into a separate object even earlier. Might be a good opportunity to implement a better design. Just sayin'...

2

+1 for Jelena.

I don't understand the question anymore. It looks like very complex. Could you ask a new question with all details? (and pictures if possible)

0