Markdown table via ABAP CDS and ABAP SQL
Image source: pixabay.com/PublicDomainPictures

Markdown table via ABAP CDS and ABAP SQL

Dear SAP Community, since I really appreciate Markdown and you can easily design tables with it, I was wondering whether you could have the database generate a Markdown table directly using ABAP CDS (so to say some kind of "Code Pushdown").

This task is easily possible purely via ABAP, but via ABAP CDS? The answer is: it works. At least in my solution ABAP CDS does most of the work. The ABAP SQL SELECT statement has to do the rest.

Before you continue reading, please note that this is a fun blog without a serious business use case. At least none that comes to mind right away. So just for your infotainment 😁

Design

The goal is to output entries from database table /DMO/AIRPORT as Markdown table. To fulfill this requirement, I created 4 different ABAP CDS:

  1. ZI_MD_HEADER: To define headline with needed columns
  2. ZI_MD_ALIGNMENT: To set alignment of columns
  3. ZI_MD_LINES: To select all entries from database table /DMO/AIRPORT
  4. ZC_MD_TABLE: To combine the output of other ABAP CDS from 1. to 3. by UNION

As UNION has no special sort order and I didn't find a good solution to bring the whole thing into right order, I solved that problem via ABAP SQL statement "SELECT" with addition "ORDER BY".

METHOD if_oo_adt_classrun~main.
  SELECT * FROM zc_md_table 
                 ORDER BY AirportID 
                 INTO TABLE @DATA(markdown_table).
  out->write( markdown_table ).
ENDMETHOD.        

Example

I couldn't show the raw and formatted output on LinkedIn for technical reason. Please check my GitHub repository to see an example.


Have fun, thanks for reading and stay healthy

Michael


P.S.: I'm always happy to make new contacts. Everyone learns more through exchange of information. So feel free to connect on LinkedIn or GitHub.




Gunter Albrecht

Solution Architect | Director at SAP Architecture & Platform Advisory 🇯🇵 🇩🇪

10mo

LLMs handle markdown very well, therefore your approach removes the conversion step. It's certainly useful (e.g. from an ABAP GenAI SDK perspective 😉)! Thanks for sharing!

Javier Exposito González

SAP BTP Solution Architect at Nestlé

10mo

Thanks for sharing

To view or add a comment, sign in

More articles by Michael Keller

  • Thoughts about taking data records out of use

    Dear developer community, "taking data records out of use" is a common topic in IT. Many applications require such a…

  • My impressions of ABAPConf 2024

    On Thursday, June 6, 2024, the time had come: the first ABAPConf in person - organized by the SAP/ABAP community for…

    3 Comments

Insights from the community

Others also viewed

Explore topics