Skip to content
Skip to content
Menu
SAP ABAP DWIMAN
  • About
SAP ABAP DWIMAN

SAP ABAP – NEW OPEN SQL – Query Substring NUMC

By juananda.satria on December 28, 2023

There are some fields with data type NUMC that we want to fetch using a query table.

In this case, I want to show you how to split the DATS data type into Year, Month, and Day in a single query.

  1. We have a SUBSTRING function in open SQL to cut your data by the length.
    • SUBSTRING( <data> , <start_pointer> , <sub_length> )
  2. The return of the SUBSTRING function is data with data type CHAR. So we have to convert it to NUMC again using the CAST function.
    • CAST( <data> AS <data_type> )

Here the example

  TYPES: BEGIN OF ty_data,
           year  TYPE numc4,
           month TYPE numc2,
           day   TYPE numc2,
         END OF ty_data,
         tt_data TYPE TABLE OF ty_data.
  DATA: ls_data TYPE ty_data.

  SELECT SINGLE
    CAST( substring( fldate, 1, 4 ) AS NUMC ) AS year,
    CAST( substring( fldate, 5, 2 ) AS NUMC ) AS month,
    CAST( substring( fldate, 7, 2 ) AS NUMC ) AS day
    FROM sbook
    WHERE fldate NE '00000000'
    INTO @ls_data.

  WRITE:/(8) 'Year' , ':', ls_data-year.
  WRITE:/(8) 'Month' , ':', ls_data-month.
  WRITE:/(8) 'Day' , ':', ls_data-day.

Thank you for reading. I hope you can do it better. See you on the next post.

Post navigation

SAP ABAP – Local Class DEFINITION DEFERRED
SAP ABAP – BAPI on PS Module #1 – Create Network and Activity

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • SAP ABAP – Generate Fiori URL
  • SAP ABAP – Workflow Agents CDS
  • SAP ABAP – Workflow Level with Table Function
  • SAP ABAP – Download ALV to Excel with Total and Subtotal
  • SAP ABAP – BDC Template

Recent Comments

  1. SAP ABAP – Simple Interface FTP Inbound (SAP Consume File From FTP) – SAP ABAP DWIMAN on SAP ABAP – String Encode & Decode BASE64
  2. Upload file – SAP ABAP DWIMAN on F4 Search Help File

Archives

  • May 2025
  • August 2024
  • June 2024
  • May 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • May 2023
  • April 2023

Categories

  • Uncategorized
©2026 SAP ABAP DWIMAN | WordPress Theme by SuperbThemes.com