cancel
Showing results for 
Search instead for 
Did you mean: 

COND operator adds empty lines

sh4il3sh
Participant
0 Kudos

Hi,

I am simply adding new rows to a table of type string, code below:

et_aud = VALUE #(
    ( data = 'No of Successful Records: ' && |{ iv_suc }| )
    ( data = 'No of Failed Records    : ' && |{ iv_err }| )
    ( data = '' )
    ( data = COND #( WHEN it_suc IS NOT INITIAL THEN '***************************************************SUCCESS RECORDS****************************************************************' ) )
    ( data = COND #( WHEN it_suc IS NOT INITIAL THEN '' ) ) 
    ( LINES OF it_suc )
    ( data = COND #( WHEN it_suc IS NOT INITIAL THEN '' ) )

    ( data = COND #( WHEN it_err IS NOT INITIAL THEN '****************************************************ERROR RECORDS*****************************************************************' ) )
    ( data = COND #( WHEN it_suc IS NOT INITIAL THEN '' ) )
    ( LINES OF it_err )
                    ).

for cases when IT_SUC IS INITIAL, it adds empty rows(see image) and its not required.

I cannot use Delete ITAB where rows are empty because I would need empty lines which I have added myself.

Any suggestion would be helpful.

Regards,
Shailesh

Accepted Solutions (1)

Accepted Solutions (1)

Sandra_Rossi
Active Contributor

Combine LINES OF and COND or SWITCH to choose between 0 and any number of lines:

et_aud = VALUE #(
    ( data = 'No of Successful Records: ' && |{ iv_suc }| )
    ( data = 'No of Failed Records    : ' && |{ iv_err }| )
    ( data = '' )
    ( LINES OF COND #( WHEN it_suc IS NOT INITIAL THEN VALUE #(
        ( data = '***************************************************SUCCESS RECORDS****************************************************************' ) )
        ( data = '' ) ) ) )
    ( LINES OF it_suc )
    ...
sh4il3sh
Participant

It worked as expected!!

didn't know the 'LINES OF' statement does this.
Thank You Sandra, new learning for me.

Answers (1)

Answers (1)

fprokopiuk
Active Participant

You can create header part as constant and add IF condition on each it_suc and it_err with logic to append entries only when the table is not initial. Something like:

et_aud = VALUE #(
    ( data = 'No of Successful Records: ' && |{ iv_suc }| )
    ( data = 'No of Failed Records    : ' && |{ iv_err }| )
    ( data = '' ))

IF it_suc IS NOT INITIAL.

APPEND LINES OF VALUE #(

    ( data = '***************************************************SUCCESS RECORDS****************************************************************' ) 
    ( data = '' ) 
    ( LINES OF it_suc )
    ( '' ) ) TO et_aud.
ENDIF.

IF it_err IS NOT INITIAL.
  APPEND LINES OF VALUE #(

    ( data = '***************************************************ERROR RECORDS****************************************************************' ) 
    ( data = '' ) 
    ( LINES OF it_err )
    ( '' ) ) TO et_aud.
ENDIF.