Application Development and Automation 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: 
Read only

Append condition

Former Member
0 Likes
1,026

hi all,

in loop i have 2 append statements if in the below code third read statement satisfies first append statement fills particular belnr then the second append should skip else if third read statement is not satisfied append condition is not satisfied then second append should fill.

please check my code below,

LOOP AT lt_bseg WHERE matnr NE ' '.

MOVE lt_bseg-belnr TO lt_output-belnr.

READ TABLE lt_bkpf WITH KEY belnr = lt_bseg-belnr BINARY SEARCH.

IF sy-subrc = 0.

MOVE lt_bkpf-monat TO lt_output-monat.

ENDIF.

READ TABLE gt_stxh WITH KEY tdname+0(18) = lt_bseg-belnr.

IF sy-subrc = 0.

CALL FUNCTION 'READ_TEXT'

EXPORTING

id = gt_stxh-tdid

language = gt_stxh-tdspras

name = gt_stxh-tdname

object = gt_stxh-tdobject

TABLES

lines = lt_text.

LOOP AT lt_text.

MOVE lt_text-tdline TO lt_output-tdline.

APPEND lt_output.

CLEAR lt_output.

ENDLOOP.

ENDIF.

APPEND lt_output.

thanks in advance.

5 REPLIES 5
Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
836

Simplest way is to set a flag when 3rd read returns subrc 0 and check this while appending table at the very end.

Read only

Former Member
0 Likes
836

Hi,

Now you check with below code.

LOOP AT lt_bseg WHERE matnr NE ' '.

MOVE lt_bseg-belnr TO lt_output-belnr.

READ TABLE lt_bkpf WITH KEY belnr = lt_bseg-belnr BINARY SEARCH.

IF sy-subrc = 0.

MOVE lt_bkpf-monat TO lt_output-monat.

IF sy-subrc <> 0.

READ TABLE gt_stxh WITH KEY tdname+0(18) = lt_bseg-belnr.

IF sy-subrc = 0.

CALL FUNCTION 'READ_TEXT'

EXPORTING

id = gt_stxh-tdid

language = gt_stxh-tdspras

name = gt_stxh-tdname

object = gt_stxh-tdobject

TABLES

lines = lt_text.

LOOP AT lt_text.

MOVE lt_text-tdline TO lt_output-tdline.

APPEND lt_output.

CLEAR lt_output.

ENDLOOP.

ENDIF.

APPEND lt_output.

ENDIF.

Regards

Md.MahaboobKhan

Read only

Former Member
0 Likes
836

Hi neethu,

You can do this in 2 ways,

1. Set a flag to 1 if ur read stmt holds true otherwise set to 0.Before executing Read stmt chk if ur flag is 0,then only go ahead otherwise SKIP.

2. Use IF....... ELSE stmt.

Read stmt.

If sy-subrc = 0.

Read stmt.

If sy-subrc = 0.

append

else.

Read stmt.

If sy-subrc = 0.

append

endif.

endif.

endif.

Regards,

ajit.

Edited by: AJIT THAKUR on May 13, 2009 9:06 AM

Read only

Former Member
0 Likes
836

Hi,

Please check the modified code below.

LOOP AT lt_bseg WHERE matnr NE ' '.

MOVE lt_bseg-belnr TO lt_output-belnr.

READ TABLE lt_bkpf WITH KEY belnr = lt_bseg-belnr BINARY SEARCH.

IF sy-subrc = 0.

MOVE lt_bkpf-monat TO lt_output-monat.

ENDIF.

READ TABLE gt_stxh WITH KEY tdname+0(18) = lt_bseg-belnr.

IF sy-subrc = 0.

CALL FUNCTION 'READ_TEXT'

EXPORTING

id = gt_stxh-tdid

language = gt_stxh-tdspras

name = gt_stxh-tdname

object = gt_stxh-tdobject

TABLES

lines = lt_text.

LOOP AT lt_text.

MOVE lt_text-tdline TO lt_output-tdline.

APPEND lt_output.

CLEAR lt_output.

ENDLOOP.

else.

APPEND lt_output.

ENDIF.

Read only

0 Likes
836

Hi Neetu,

.

LOOP AT lt_bseg WHERE matnr NE ' '.

MOVE lt_bseg-belnr TO lt_output-belnr.

READ TABLE lt_bkpf WITH KEY belnr = lt_bseg-belnr BINARY SEARCH.

IF sy-subrc = 0.

MOVE lt_bkpf-monat TO lt_output-monat.

ENDIF.

READ TABLE gt_stxh WITH KEY tdname+0(18) = lt_bseg-belnr.

IF sy-subrc = 0.

CALL FUNCTION 'READ_TEXT'

EXPORTING

id = gt_stxh-tdid

language = gt_stxh-tdspras

name = gt_stxh-tdname

object = gt_stxh-tdobject

TABLES

lines = lt_text.

if lt_text[] is not initial.

LOOP AT lt_text.

MOVE lt_text-tdline TO lt_output-tdline.

APPEND lt_output.

CLEAR lt_output.

ENDLOOP.

endif.

else.

APPEND lt_output.

ENDIF.