Showing posts with label Syntax. Show all posts
Showing posts with label Syntax. Show all posts

Jul 13, 2026

Remove Leading Zero of a Field in CDS (ADT)

Example: Field QAPP.PPSORTKEY



Original Code
      /*-- Sample / Inspection Point (from QAPP) ---------------------------*/
      qapp.probenr    as SampleInspectionPoint,
      qapp.ppsortkey, as InspectionPoint


The change, using ltrim (supported in CDS view entities):



New Code
      /*-- Sample / Inspection Point (from QAPP) ---------------------------*/
      qapp.probenr    as SampleInspectionPoint,
      ltrim( qapp.ppsortkey, '0' ) as InspectionPoint

Two notes on this:

  1. ltrim( field, '0' ) removes only leading '0' characters — an all-zero value becomes an empty string. If you'd rather show '0' in that case, wrap it: case when ltrim(...) = '' then '0' else ltrim(...) end. I didn't add that since you didn't ask.
  2. The result type stays character, same length — no dictionary impact, activation-safe. If the Fiori app later sorts or filters on InspectionPoint, remember it's now text-sorted without zero padding, so ordering across values of different lengths will look wrong ('12' before '3' is gone, but '3' now comes after '12' alphabetically... actually '12' < '3' as text). If sorting matters, keep the raw field as a hidden sort column.

Aug 28, 2025

What is the Difference between Statement RETURN and EXIT in SAP ABAP?

Both RETURN and EXIT are control flow statements, but they serve different purposes and behave differently depending on the context. Here's a clear breakdown:

🔁 RETURN Statement

Purpose:
Used to exit a procedure—like a function module, method, or form—immediately and return control to the calling program.

Where it's used:

  • Function modules
  • Methods
  • Subroutines (FORM routines)

Behavior:

  • Ends the current procedure and returns to the caller.
  • No further code in the procedure is executed after RETURN.

Example:

FORM my_form. 

  IF sy-subrc <> 0. 

    RETURN. 

  ENDIF. " More code here won't run if RETURN is triggered 

ENDFORM.


🚪 EXIT Statement

Purpose:
Used to exit a loop or control structure like DO, WHILE, or LOOP.

Where it's used:

  • Inside loops (LOOP, DO, WHILE)
  • Not valid in procedures like methods or function modules (outside loops)

Behavior:

  • Immediately exits the current loop, but the rest of the surrounding code continues.
  • Does not exit the entire procedure.

Example:

LOOP AT it_table INTO wa_table. 

  IF wa_table-flag = 'X'. 

    EXIT. " Exits the LOOP, not the FORM 

  ENDIF. 

ENDLOOP.


🧠 Summary Table




Let me know if you want to see how CHECK fits into this trio—it’s another control statement that behaves a bit differently again.