on 11-22-2005 8:53 AM
DATA: t184 LIKE TABLE OF t184 WITH HEADER LINE.
DATA: BEGIN OF pstyd OCCURS 0,
pstyd TYPE pstyd,
END OF pstyd.
LOOP AT t184.
pstyd-pstyd = t184-psty1. APPEND pstyd.
pstyd-pstyd = t184-psty2. APPEND pstyd.
pstyd-pstyd = t184-psty3. APPEND pstyd.
pstyd-pstyd = t184-psty4. APPEND pstyd.
pstyd-pstyd = t184-psty5. APPEND pstyd.
pstyd-pstyd = t184-psty6. APPEND pstyd.
pstyd-pstyd = t184-psty7. APPEND pstyd.
pstyd-pstyd = t184-psty8. APPEND pstyd.
pstyd-pstyd = t184-psty9. APPEND pstyd.
pstyd-pstyd = t184-psty10. APPEND pstyd.
pstyd-pstyd = t184-psty11. APPEND pstyd.
pstyd-pstyd = t184-pstyv. APPEND pstyd.
ENDLOOP.
How can I shorten the code. Somthing to this effect:
DATA name TYPE string.
FIELD-SYMBOLS <char> LIKE pstyd-pstyd.
LOOP AT t184.
DO 12 TIMES.
name = sy-index.
IF name = '12'. name = ''. ENDIF.
CONCATENATE 't184-pstyv' name INTO name.
ASSIGN (name) TO <char>.
Write <char> to pstyd-pstyd.
APPEND pstyd.
ENDDO.
ENDLOOP.
The above code is, of course, not working. I have posted it just to give an idea of what I want.
Hi use the below logic,
DATA: itab1 LIKE TABLE OF t184,
itab2 LIKE TABLE OF t184
wa1 LIKE t184,
wa2 LIKE t184.
LOOP AT itab1 INTO wa1.
MOVE wa1 TO wa2.
APPEND wa2 TO itab2.
ENDLOOP.
Hi please dont use internal table with header lines,these are old forms of internal table which wont be supported in OOABAP.Let us clean up our coding style according to OO Context..
Regards,
Abdul
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Flora,
Try the below code it is working for me.
REPORT ZSIRI_DYN .
DATA: BEGIN OF pstyd OCCURS 0,
pstyd TYPE pstyd,
END OF pstyd.
DATA: t184 LIKE TABLE OF t184 WITH HEADER LINE.
select * from
t184
* up to 1 rows
into table t184.
data : name(20),
v_no(2) type c.
LOOP AT t184.
do 12 times.
if sy-index = 12.
pstyd-pstyd = t184-pstyv.
APPEND pstyd.
else.
clear : v_no,name.
v_no = sy-index.
concatenate 't184-psty' v_no into name.
write (name) to pstyd-pstyd.
APPEND pstyd.
endif.
enddo.
ENDLOOP.
loop at pstyd.
write : / pstyd.
endloop.
Thanks&Regards,
Siri.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Flora,
1. Such kind of problems are known as REPEAT STRUCTURE.
To achieve such looping thru REPEAT STRUCTURE
there is a abap statment
VARYING
which will achieve such thing.
JUST NOTE HOW VARYING STATEMENT WORKS BELOW:
IT CAN BE USED FOR OTHER REPEAT STRCUTURES ALSO.
2. Please see the code below :
Just paste and check.
REPORT abc.
DATA: t184 LIKE TABLE OF t184 WITH HEADER LINE.
DATA: BEGIN OF pstyd OCCURS 0,
pstyd TYPE pstyd,
END OF pstyd.
*----
Start-Of-Selection
START-OF-SELECTION.
BREAK-POINT.
SELECT * FROM t184 INTO TABLE t184
WHERE mtpos = 'NORM'
AND auart = 'AG'.
*----
Loop and Fetch [IMPORTANT IMPORTANT]
LOOP AT t184.
CLEAR pstyd.
DO 11 TIMES
VARYING pstyd-pstyd FROM t184-psty1 NEXT t184-psty2.
APPEND pstyd.
ENDDO.
pstyd-pstyd = t184-pstyv.
APPEND pstyd.
ENDLOOP.
*----
Done
BREAK-POINT.
HOPE THE ABOVE HELPS.
Regards,
Amit M.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Change the following,
<b> CONCATENATE 't184-pstyv' name INTO name.</b>
to,
<b> CONCATENATE 'T184-PSTYV' name INTO name.</b>
Alternatively you can also do some thing like the following,
DATA: l_pstyv LIKE t184-pstyv.
DO 12 TIMES VARYING l_pstyv FROM t184-pstyv
NEXT t184-psty1.
***Your logic here
ENDDO.
Sri
Message was edited by: Srikanth Pinnamaneni
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi!
You can reference the fields of the structure by there position (it's not tested, but it will work in general):
DATA: t184 LIKE TABLE OF t184 WITH HEADER
> LINE.
> DATA: BEGIN OF pstyd OCCURS 0,
> pstyd TYPE pstyd,
> END OF pstyd,
number type i.
>
> FIELD-SYMBOLS <char> LIKE pstyd-pstyd.
> LOOP AT t184.
> DO 12 TIMES.
number = sy-index + 7
ASSIGN COMPONENT number OF STRUCTURE t184 TO <char>.
> Write <char> to pstyd-pstyd.
> APPEND pstyd.
> ENDDO.
> ENDLOOP.
>
Regards,
Christian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
103 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.