Pretty printer is very useful, but in some cases, you have to be a “Pretty coder” yourself.
Especially with ABAP 740, where all those expressions came up and finally made us feel like real programmers – as we now could do things like
data(ls_result) = new lcl_data_processor( new lcl_data_provider( p_matnr ) )->do_something_important( iv_simulation = abap_true ).
just like all the others.
The ABAP statements are getting longer these days, so I asked myself how to distribute them into several lines and keep the legibility. I started with something like
if line_exists( lt_process[ orderid = ls_queue-orderid activity = ls_queue-activity ] ).
But when it comes to real deeply nested expressions, this would lead to enormous line sizes. What I am doing nowadays, is more like this:
rt_res = value #( for s_oper in lt_operations where ( sub_activity = space ) ( value #( let ltext = actvt_longtext_read( s_oper ) in act_end_date = s_oper-act_end_date act_end_time = s_oper-act_end_time act_start_date = reduce d( init d = s_oper-act_start_date for s_sub in it_sub_oper where (
i.e. increase indentation by bracket level. When closing the brackets, I just do
then cond #( when s_subd-isdd < d then s_subd-isdd else d ) else d ) ) )
that is closing everything in one line.
Still I’m not totally satisfied with my approach, especially with the closing of bracket levels. But wasting a line for each closing bracket seems ugly to me.
What is your approach in coding very long ABAP statements?