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 🇯🇵 🇩🇪

1y

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!

To view or add a comment, sign in

More articles by Michael Keller

  • Code, Comments, AI

    In my early days as a developer, I wrote a lot of comments. They were necessary because otherwise I would have quickly…

    11 Comments
  • Attributes, states and time

    Classes, with their attributes and methods, unite two fundamental concepts of computer science: data and algorithms…

    4 Comments
  • Distinguish between the functionality and its implementing code

    Many ABAP source codes clearly show signs of having been modified repeatedly over the years. The code bears the…

    3 Comments
  • What you can find in an ABAP class

    What would you least expect to find in an ABAP class? Take your time to think about it and create your own top three…

    1 Comment
  • The new public enemy number one: static code analysis

    Static ABAP code analysis can be a real asset. It depends on the specific checks being performed.

    9 Comments
  • Example of External Tools in Eclipse for ABAP developers

    By choosing Eclipse as the development environment for ABAP, SAP has opted for open source software that is inherently…

    1 Comment
  • Technically possible but not good style in ABAP

    There are different solutions for many ABAP tasks. Even if the result of each solution appears to be the same at first…

    4 Comments
  • ABAP Development Tools for Eclipse on Ubuntu Desktop

    Recently, I noticed a sentence on the SAP Development Tools website stating that you don’t need an SAP GUI for ABAP…

    8 Comments
  • 4 experiences with FINAL in ABAP

    With the declaration operator FINAL, you can create immutable variables in ABAP. This means that a variable is…

    9 Comments
  • 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…

Others also viewed

Explore content categories