2014 Feb 12 6:24 AM
Hi There,
I have a situation here, where I need to display my internal table records horizontally in one Form.
Example: Suppose my it_tab has Text-1
Text-2
Text-3
Text-4
Text-5
Now I have to display my internal table data like this:
Text-1 Space Text-2 Space Text-3 ( Should display only 3 records in line 1)
Text-2 Space Text-3....(Again should display 3 records, other wise the remaining)
If internal table has only 2 records, it should display like:
Text-1 Space Text-2
kindly advise how to achieve this.
Thanks,
Priya
Hi There,
I have a situation here, where I need to display my internal table records horizontally in one Form.
Example: Suppose my it_tab has Text-1
Text-2
Text-3
Text-4
Text-5
Now I have to display my internal table data like this:
Text-1 Space Text-2 Space Text-3 ( Should display only 3 records in line 1)
Text-2 Space Text-3....(Again should display 3 records, other wise the remaining)
If internal table has only 2 records, it should display like:
Text-1 Space Text-2
kindly advise how to achieve this.
Thanks,
Priya
2014 Feb 12 6:39 AM
hi Priya
Please define another it_itab2 with one filed type string.
data: lv_line type i,
lv_counts type i.
lv_counts = lines ( it_itab).
loop at it_itab.
concatenate it_itab2-text it_itab-text ' ' into it_itab2-text.
lv_line = sy-tabix mod 3.
if lv_line eq 0.
append it_itab2.
elseif lv_counts eq sy_tabix.
append it_itab2. " only 2 records, will save to itab2.
endif.
endloop.
regards,
Archer
2014 Feb 12 7:27 AM
Thank you all for your inputs.
Dengyong, your answer works good. Thank you.
2014 Feb 12 6:44 AM
hi,
as per my understanding, my suggestions is .
Example: Suppose my it_tab has matnr " key field
Text-1
Text-2
Text-3
Text-4
Text-5
create the final internal table with
type: begin of ty_final,
matnr
text1
text2
text3
end of ty_final
create internal table of ty_final
create one more internal table IT_TAB1same as IT_TAB .
move the contented of IT_TAB into ITab1.
loop at it_tab1.
read table it-tab with key matnr .
if sy-subrc eq 0.
case sy-index.
when '1'.
it_final-text1 = it-tab-text.
when '2'
it_final-text2 = it-tab-text.
when'3'.
it_final-text3 = it-tab-text.
append wa_final to it_final. " since you want to require only 3 text
clear it_final
when '4'.
it_final-text1 = it-tab-text.
when '5'.
it_final-text2 = it-tab-text.
endcase.
else.
append wa_final to it_final.
endif.
endloop.
delete the duplicate entires of it_final where text 1 is initial. " if it-tab contains only 3 records so unneccessary one record is added in it_final.
2014 Feb 12 6:52 AM
Paste code in abap editor and alter as per needed.
data : begin of itab occurs 0,
main(10) type c,
end of itab.
data : begin of it occurs 0,
field1(50) type c,
end of it.
itab-main = 'one'. append itab.
itab-main = 'two'.append itab.
itab-main = 'three'.append itab.
itab-main = 'four'.append itab.
itab-main = 'five'.append itab.
data: cnt type i.
loop at itab.
cnt = sy-tabix mod 3.
concatenate it-field1 itab-main into it-field1 separated by ' '.
if cnt eq 0.
append it.
clear it.
endif.
endloop.
if cnt eq 1 or cnt eq 2.
append it.
clear it.
endif.
2014 Feb 12 7:03 AM
hey Priya,
For your Scenario!
LOOP AT itab INTO wa,
count = count +1.
IF count = 1.
var1 = wa-text1.
ENDIF.
IF count = 2.
var2 = wa-text1.
ENDIF.
IF count = 3 .
var3 = wa-text1.
CONCATENATE var1 var2 var3 INTO string SEPARATED BY space.
CLEAR count.
ENDIF.
ENDLOOP.
Hope this helps!
Happy Coding,
Santhosh Yadav
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |