08-17-2006 12:32 PM
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
08-17-2006 12:37 PM
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
08-17-2006 12:37 PM
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
08-17-2006 12:40 PM
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
08-17-2006 12:54 PM
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
08-17-2006 1:01 PM
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
08-17-2006 1:10 PM
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
08-17-2006 1:13 PM
08-17-2006 12:43 PM
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.
08-17-2006 12:50 PM
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.