The magic of write statement with edit mask SAP ABAP tutorial - Sap 4 All

Latest

Please enter your email and get the updates in your inbox.

Sunday 17 July 2016

The magic of write statement with edit mask SAP ABAP tutorial

In this SAP ABAP tutorial I will show you how powerful write statement actually is.Please refer to the following programs.

Program 1:     

Real time requirement – The client wants to display the date field in YYMMDD format. Mainly used in smart forms where different company wants to display the smart forms in different date format.

DATA LV_OUTPUT(50TYPE C.

WRITE SY-DATUM.

ULINE.
WRITE SY-DATUM TO LV_OUTPUT YYMMDD.
WRITE LV_OUTPUT.

Output : 140813


Program 2:

Real time requirement – The client wants to display the output without leading zeros. Mainly used in smart forms where the client wants a character value to be displayed as ‘123’ instead of ‘0000000123’ or vice versa.

DATAnum(10)            TYPE VALUE '123',

      formatted_text(10TYPE c .


WRITE num TO formatted_text.
WRITE formatted_text.
WRITE num TO formatted_text NO-ZERO.
WRITE formatted_text.

Program 3:

Real time requirement – The client wants to display the output without leading zeros. Mainly used in smart forms where the client wants a character value to be displayed as ‘123’ instead of ‘0000000123’ or vice versa.

DATAlv_char(10)     TYPE c VALUE '0000000123',

      lv_output_c(10TYPE c,

      lv_output_n(10TYPE n.

WRITE 'Original Value : 'lv_char.

WRITE lv_char TO lv_output_c NO-ZERO.
WRITE lv_char TO lv_output_n NO-ZERO.
WRITE lv_char TO lv_char     NO-ZERO.


WRITE  'Value assigned to type c : '40 lv_output_c.
WRITE  'Value assigned to type n : ',40 lv_output_n.
WRITE  'Value assigned to the same variable : ',40 lv_char.

Program 4:

Real time requirement – The client wants to display the output without any sign neither + nor -. Mainly used in smart forms where the client wants  a character value to be displayed as the number itself without any sign.

DATAlv_var1   TYPE i,

      lv_output TYPE c LENGTH 10.


DO 10 TIMES.
  lv_var1 sy-index 5.
  IF lv_var1 >= 0.
    WRITE lv_var1 TO lv_output.
    WRITE / lv_output.

  ELSE.
    WRITE lv_var1 TO lv_output NO-SIGN.
    WRITE / lv_output.

  ENDIF.
ENDDO.



Program: 5.

Real time requirement – The client wants to display the output without any sign neither + nor -. Mainly used in smart forms where the client wants  a character value to be displayed as the number itself without any sign.

DATAlv_var1   TYPE i VALUE -10,

      lv_output TYPE c LENGTH 10.

WRITE / lv_var1.
WRITE lv_var1 NO-SIGN.



Thanks a lot again friends for reading this tutorial. If you find this is useful and helpful to you, please consider it sharing to your friends using the social buttons below. 

2 comments:

  1. Thanks for sharing this Information,

    Got to learn new things from your Blog on Sap abap.

    http://thecreatingexperts.com/sap-abap-training-in-chennai/

    Both online and classroom training is provided.

    Contact 8122241286

    ReplyDelete