title: Add leading zeros only to numeric field in CDS?
body: <p>In my AS ABAP 7.50 system, I have a table where the material length is 18 and I need to expose it via CDS as if the material length was 40 like in S/4. The material IDs in the system can be numeric (with leading zeros) or alphanumeric. The material field needs to be casted to MATNR40, and if the ID is numeric, the leading zeros need to be added up to the 40 characters.</p>
  <p>First, I tried `lpad. But of course, it also adds the leading zeros to the alphanumeric values:</p>
  <pre><code>lpad( cast(matnr as matnr40), 40, '0' ) as material_long,
  </code></pre>
  <p>Then I added a <code>case</code> but I'm not able to make the condition work as I expect. As konstantin confirmed in the comments, it's not possible to use regex here as I attempted:</p>
  <pre><code>case when matnr like '%[^0-9.]%'
       then lpad( cast(matnr as matnr40), 40, '0' )
       else cast(matnr as matnr40)
  end as material_long,
  </code></pre>
  <p>Is there a solution within the CDS itself to this problem?</p>
  <p>Source table:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>MATNR18</th>
  <th>Description</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>000000000000000142</td>
  <td>Numeric ID material</td>
  </tr>
  <tr>
  <td>MATERIAL_2</td>
  <td>Alphanumeric ID</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Expected result:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>MATNR40</th>
  <th>Description</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>0000000000000000000000000000000000000142</td>
  <td>Numeric ID material</td>
  </tr>
  <tr>
  <td>MATERIAL_2</td>
  <td>Alphanumeric ID</td>
  </tr>
  </tbody>
  </table>
  </div>