‎2009 May 13 7:26 AM
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.
‎2009 May 13 7:32 AM
Simplest way is to set a flag when 3rd read returns subrc 0 and check this while appending table at the very end.
‎2009 May 13 7:35 AM
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
‎2009 May 13 7:40 AM
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
‎2009 May 13 7:41 AM
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.
‎2009 May 13 8:40 AM
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.