1

"Pretty Printer" does its job Pretty bad in some cases. I wonder how should ABAP code be formatted. Especially long select statements like;

SELECT SINGLE * INTO CORRESPONDING FIELDS OF ls_doc
FROM ztable INNER JOIN bkpf
ON ztable~bukrs = bkpf~bukrs
AND ztable~belnr = bkpf~belnr
AND ztable~gjahr = bkpf~gjahr
WHERE ztable~bukrs EQ gt_help_tab-bukrs
AND ztable~hkont EQ gt_help_tab-hkont
AND ztable~dekont_no EQ u_out-dekont_no
AND ztable~fiziksel_islem_tarihi EQ '01012018'
AND ztable~gjahr EQ u_out-year(4)
AND ztable~stblg EQ ''.

or performs;

perform get_type using '1' '2' '3' tables it_table changing lv_char.

I wonder how I should format my abap code for better readibility.

  • Which statement should be indented ?
  • When should I go to next line ?
  • Which statements should be on the same vertical line ?
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Mtok
  • 1,600
  • 11
  • 36
  • 62
  • 2
    There is no true answer to your question, because any one of us should have his own preferences. – VXLozano Sep 19 '18 at 11:21
  • @VXLozano yes I know but there should be a well-accepted format of writing abap code I think. – Mtok Sep 19 '18 at 13:41
  • 1
    I doubt that. The well-accepted format of writing ABAP code should be "the one that not crashes" XD – VXLozano Sep 19 '18 at 15:11
  • 1
    For information, [SAP guidelines](https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenuse_pretty_printer_guidl.htm) just give general (but important) recommendations, but nothing about your questioning. As @VXLozano says, there is the risk of many opinions. From my point of view, all should be approximately the same, and will vary **very slightly**. I don't see the importance to know those little differences, there is no real added value to have 4 or 8 space characters on the left, or a newline at a given place, or whatever... – Sandra Rossi Sep 20 '18 at 19:21

1 Answers1

4

There are lot of code format usage, we generally use below format in our company.

SELECT SINGLE * 
  INTO CORRESPONDING FIELDS OF ls_doc
  FROM ztable 
 INNER JOIN bkpf ON ztable~bukrs EQ bkpf~bukrs
                AND ztable~belnr EQ bkpf~belnr
                AND ztable~gjahr EQ bkpf~gjahr
 WHERE ztable~bukrs                 EQ gt_help_tab-bukrs
   AND ztable~hkont                 EQ gt_help_tab-hkont
   AND ztable~dekont_no             EQ u_out-dekont_no
   AND ztable~fiziksel_islem_tarihi EQ '01012018'
   AND ztable~gjahr                 EQ u_out-year(4)
   AND ztable~stblg                 EQ ''.

  perform get_type 
    using '1' '2' '3' 
   tables it_table 
 changing lv_char.

Abap lint project grooving. It is not check multi-lines codes yet.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
mkysoft
  • 5,392
  • 1
  • 21
  • 30
  • 3
    As I said, this is more a debate than a question. In my case, my eyes hurt looking at your PERFORM indentation, although your SQL is near my preferred format. – VXLozano Sep 19 '18 at 12:54