Application Development 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: 

Appending Internal Table Data to a String

Former Member
0 Kudos

Good Morning,

I have a internal table and i want to append each of the internal table lines to a String. How can i do that?

Code follows:


*"----------------------------------------------------------------------
*"*"Interface local:
*"  EXPORTING
*"     REFERENCE(OUTPUT) TYPE  STRING
*"----------------------------------------------------------------------

SELECT * FROM pa0002
           INTO TABLE t_pa0002
             ORDER BY gbdat.

  LOOP AT t_pa0002 INTO w_pa0002.
    CONCATENATE sy-datum(4) w_pa0002-gbdat+4(2) w_pa0002-gbdat+6(2)
           INTO w_pa0002-gbdat.

    CHECK w_pa0002-gbdat GE first_day AND w_pa0002-gbdat LE last_day.

* I need to append the line to the String!!!

  ENDLOOP.

Best Regards,

Pedro Gaspar

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello Pedro,

Declare one itab like this.

DATA: BEGIN OF ITAB OCCURS 0,

STRING TYPE STRING,

END OF ITAB.

SELECT * FROM pa0002 INTO TABLE t_pa0002 ORDER BY gbdat. LOOP AT t_pa0002 INTO w_pa0002. CONCATENATE sy-datum(4) w_pa0002-gbdat4(2) w_pa0002-gbdat6(2) INTO w_pa0002-gbdat. CHECK w_pa0002-gbdat GE first_day AND w_pa0002-gbdat LE last_day.

  • I need to append the line to the String!!!

<b>MOVE w_pa0002 to itab.

append ITAB.

CLEAR ITAB</b>

ENDLOOP.

Note the bold marks.

Regards,

Vasanth

8 REPLIES 8

Former Member
0 Kudos

Hello Pedro,

Declare one itab like this.

DATA: BEGIN OF ITAB OCCURS 0,

STRING TYPE STRING,

END OF ITAB.

SELECT * FROM pa0002 INTO TABLE t_pa0002 ORDER BY gbdat. LOOP AT t_pa0002 INTO w_pa0002. CONCATENATE sy-datum(4) w_pa0002-gbdat4(2) w_pa0002-gbdat6(2) INTO w_pa0002-gbdat. CHECK w_pa0002-gbdat GE first_day AND w_pa0002-gbdat LE last_day.

  • I need to append the line to the String!!!

<b>MOVE w_pa0002 to itab.

append ITAB.

CLEAR ITAB</b>

ENDLOOP.

Note the bold marks.

Regards,

Vasanth

0 Kudos

try this..


data w_str type string.
SELECT * FROM pa0002
           INTO TABLE t_pa0002
             ORDER BY gbdat.
 
  LOOP AT t_pa0002 INTO w_pa0002.
    CONCATENATE sy-datum(4) w_pa0002-gbdat+4(2) w_pa0002-gbdat+6(2)
           INTO w_pa0002-gbdat.
 
    CHECK w_pa0002-gbdat GE first_day AND w_pa0002-gbdat LE last_day.
 
* I need to append the line to the String!!!
 concatenate w_str w_pa0002-gbdat into w_str.
  ENDLOOP.

~Suresh

0 Kudos

Maybe i didn't explain the problem clearly, here is the complete code of the function i'm creating:


FUNCTION z3_hr_get_anniversaries.
*"----------------------------------------------------------------------
*"*"Interface local:
*"  EXPORTING
*"     REFERENCE(OUTPUT) TYPE  STRING
*"----------------------------------------------------------------------
  DATA: w_pa0002 TYPE pa0002.

  DATA: t_pa0002 LIKE TABLE OF w_pa0002.

  DATA: first_day TYPE sy-datum,
        last_day  TYPE sy-datum,
        last_date TYPE sy-datum.

  CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'
   EXPORTING
     date          = sy-datum
   IMPORTING
*     week          =
     monday        = first_day
     sunday        = last_day
            .

  PERFORM go_back_days CHANGING first_day.

  PERFORM go_back_days CHANGING last_day.

  SELECT * FROM pa0002
           INTO TABLE t_pa0002
             ORDER BY gbdat.

  LOOP AT t_pa0002 INTO w_pa0002.
    CONCATENATE sy-datum(4) w_pa0002-gbdat+4(2) w_pa0002-gbdat+6(2)
           INTO w_pa0002-gbdat.

    CHECK w_pa0002-gbdat GE first_day AND w_pa0002-gbdat LE last_day.

* Append to string field GBDAT to my output String

  ENDLOOP.
ENDFUNCTION.

I want to pick-up field w_pa0002-gbdat and append it to my output which is a only one string with all the data from the table on it... Example of the String <b><w_pa0002-gbdat[1]>|<w_pa0002-gbdat[2]>|...</b>

Resuming... What i really want is one output. A String (output) with all the fields i want (GBDAT) from the internal table concatenated one after another.

Thank You.

Pedro Gaspar

0 Kudos

 FUNCTION z3_hr_get_anniversaries.
 *"----------------------------------------------------
 ------------------
 *"*"Interface local:
 *"  EXPORTING
 *"     REFERENCE(OUTPUT) TYPE  STRING
 *"----------------------------------------------------
 ------------------
   DATA: w_pa0002 TYPE pa0002.
 
   DATA: t_pa0002 LIKE TABLE OF w_pa0002.
 
   DATA: first_day TYPE sy-datum,
         last_day  TYPE sy-datum,
         last_date TYPE sy-datum.
   DATA: l_out TYPE string.
 
   CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'
    EXPORTING
      date          = sy-datum
    IMPORTING
 *     week          =
      monday        = first_day
      sunday        = last_day
            .
 
   PERFORM go_back_days CHANGING first_day.

   PERFORM go_back_days CHANGING last_day.
 
   SELECT * FROM pa0002
            INTO TABLE t_pa0002
              ORDER BY gbdat.
 
   LOOP AT t_pa0002 INTO w_pa0002.
 CONCATENATE sy-datum(4) w_pa0002-gbdat+4(2)
 4(2) w_pa0002-gbdat+6(2)
            INTO w_pa0002-gbdat.
 
 CHECK w_pa0002-gbdat GE first_day AND
 AND w_pa0002-gbdat LE last_day.
 
 * Append to string field GBDAT to my output String
   IF NOT l_out is initial.
      CONCATENATE l_out '|' into l_out.
   ENDIF.
   CONCATENATE l_out w_pa0002-gbdat into l_out.
 
   ENDLOOP.
 ENDFUNCTION.

 

Kind Regards

Eswar

0 Kudos

Basic...

(This is not one of my days...)

Thank You All. Points Rewarded!

Eswar... I could not give you the Solved Problem Reward Points since there was a answer before yours that was also the solution, so i've rewarded chronologically.

Best Regards,

Pedro Gaspar

0 Kudos

No Probs. Pedro. Glad that we could help you.

Kind Regards

Eswar

Former Member
0 Kudos
LOOP AT t_pa0002 INTO w_pa0002. 
   CONCATENATE sy-datum(4) w_pa0002-gbdat+4(2) w_pa0002-gbdat+6(2)           INTO w_pa0002-gbdat.   
 CHECK w_pa0002-gbdat GE first_day AND 
       w_pa0002-gbdat LE last_day.
* I need to append the line to the String!!!
<b>*--    move all those fields to a variable V_CHAR(100)
   CONCATENATE V_STRING
               V_CHAR
               INTO V_STRING.</b> 
 ENDLOOP.

andreas_mann3
Active Contributor
0 Kudos

hi,

use field-symbols

and abap command assign component:

data str type string.

loop...
free str.
do.
assign component sy-index of structure w_pa0002 to <f>.
if sy-subrc <> 0. 
 exit.
endif.

 concatenate str <f> into str.
enddo.

transfer str to file.

endloop.

A.