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: 

loop inside a loop.

Former Member
0 Kudos
105

hi ,

i hav used loop(w_cdpos) inside the same loop, so it is showing error, is there any alternate solution for this. pls send me hard code.

SELECT * FROM cdhdr INTO TABLE w_cdhdr

WHERE objectclas = 'KRED'

AND objectid = w_lfa1-lifnr

AND udate IN c_date

AND change_ind = 'I'.

SELECT * FROM cdpos INTO TABLE w_cdpos

FOR ALL ENTRIES IN w_cdhdr

WHERE objectclas = 'KRED'

AND objectid = w_lfa1-lifnr

AND tabname = 'LFBK'

AND changenr = w_cdhdr-changenr .

loop at w_cdpos. (giv me alternate solution)

IF sy-dbcnt GT 1 .

SORT w_cdpos BY changenr ASCENDING .

CLEAR w_result .

w_result-lifnr = w_lfa1-lifnr .

w_result-fname = 'BANK' .

w_result-ddtext = text-001 .

LOOP AT w_cdpos.(giv me alternate solution)

ws_cdpos = w_cdpos .

AT NEW changenr .

IF w_result-value_old IS INITIAL .

w_result-value_old = ws_cdpos-tabkey+13(57) .

ELSE .

w_result-value_new = ws_cdpos-tabkey+13(57) .

ENDIF .

ENDAT .

AT END OF changenr .

IF w_result-value_old IS NOT INITIAL

AND w_result-value_new IS NOT INITIAL .

w_result-value_old = w_result-value_new .

CLEAR w_result-value_new .

ENDIF .

ENDAT .

MOVE-CORRESPONDING ws_cdpos TO w_result.

APPEND w_result .

ENDLOOP.

ENDIF .

endloop.

1 ACCEPTED SOLUTION

rajesh_akarte2
Active Participant
0 Kudos
69

Hi,

You will use 2 loops only if u want to get the desired o/p like for one row of first loop you want to

execute the second loop for all entry.

But I feel if u don't want to do that then you can get the desired o/p using one loop only.Don't forget to sort the table when u r using AT NEW of AT END OF w_cdpos by changenr.

Regards,

Rajesh Akarte

5 REPLIES 5

sachin_mathapati
Contributor
0 Kudos
69

Hii,.,

Try this,,

DESCRIBE TABLE w_cdpos LINES wf_lines.

If wf_lines GT 1.

SORT w_cdpos BY changenr ASCENDING .

CLEAR w_result .

w_result-lifnr = w_lfa1-lifnr .

w_result-fname = 'BANK' .

w_result-ddtext = text-001 .

LOOP AT w_cdpos.(giv me alternate solution)

ws_cdpos = w_cdpos .

AT NEW changenr .

IF w_result-value_old IS INITIAL .

w_result-value_old = ws_cdpos-tabkey+13(57) .

ELSE .

w_result-value_new = ws_cdpos-tabkey+13(57) .

ENDIF .

ENDAT .

AT END OF changenr .

IF w_result-value_old IS NOT INITIAL

AND w_result-value_new IS NOT INITIAL .

w_result-value_old = w_result-value_new .

CLEAR w_result-value_new .

ENDIF .

ENDAT .

MOVE-CORRESPONDING ws_cdpos TO w_result.

APPEND w_result .

ENDLOOP.

Endif.

Regards,

Sachin M M

Edited by: Sachin Mathapati on Jul 21, 2008 2:31 PM

former_member705122
Active Contributor

rajesh_akarte2
Active Participant
0 Kudos
70

Hi,

You will use 2 loops only if u want to get the desired o/p like for one row of first loop you want to

execute the second loop for all entry.

But I feel if u don't want to do that then you can get the desired o/p using one loop only.Don't forget to sort the table when u r using AT NEW of AT END OF w_cdpos by changenr.

Regards,

Rajesh Akarte

former_member182371
Active Contributor
0 Kudos
69

Hi,

have a look at this SDN blog:

Best regards.

Former Member
0 Kudos
69

Hi,

before starting the loop, you need to use DESCRIBE statement to check the number of records in that internal table.

if records found ...then sort the internal table.

Regards,

venkat n