Programming

Date Operation in ABAP/4

The date variable in ABAP/4 have format "YYYYMMDD". If you want to get no. of year, month or day for the date, you can offset this variable.

Example


DATA: lv_date TYPE D VALUE sy-datum, "20050312
lv_year(4),
lv_month(2),
lv_day(2).

lv_year = lv_date(4). "2005
lv_month = lv_date+4(2). "03
lv_day = lv_date+6(2). "12

If you want to find next n day of the date, you can apply opration sign ’+’ to this point.

Example

How to converts string number into integer without leading zeroes in ABAP/4

We can apply function module "CONVERSION_EXIT_ALPHA_OUTPUT’ to convert string number to integer without leading zeroes.

Example


  DATA: lv_number TYPE I,
lv_string(10) TYPE C VALUE ’0000000012’.

CALL FUNCTION ’CONVERSION_EXIT_ALPHA_OUTPUT’
  EXPORTING
    INPUT       = lv_string
  IMPORTING
    OUTPUT      = lv_number
          .

How to converts number into string with leading zeroes in ABAP/4

We can apply function module "CONVERSION_EXIT_ALPHA_INPUT’ to convert number into string with leading zeroes.

Example


  DATA: lv_number TYPE I VALUE 12,
lv_string(10) TYPE C.

CALL FUNCTION ’CONVERSION_EXIT_ALPHA_INPUT’
   EXPORTING
     INPUT        = lv_number
   IMPORTING
     OUTPUT       = lv_string
           .

How to read data from application server to internal table in ABAP/4

Normally, when you want to read the file from application server, you will have 5 steps:

  1. Open file in application server by statement:
    OPEN DATASET file_name FOR INPUT IN TEXT MODE.
  2. Checking the file is opened sucessfully by SY-SUBRC = 0
  3. After checking, you can read data from file by statement:
    READ DATASET file_name INTO itab.  
    Note: This statement should be in DO statement
  4. Append data to internal table
  5. Close file by statement:
    CLOSE DATASET file_name

Example

How to transfer data from internal table to application server in ABAP/4

Normally, when you want to transfer data the file to application server, you will
have 3 steps:

  1. Open file in application server by statement:

    OPEN DATASET file_name FOR OUTPUT IN TEXT MODE.
  2. Transfer data from file by statement:

    TRANSFER itab TO file_name. 
    Note: This statement should be in LOOP statement for Internal table
  3. Close file by statement:

CLOSE DATASET file_name.

Example

How to apply function module 'DATE_COMPUTE_DAY' in ABAP/4

The function module "DATE_COMPUTE_DAY" will return the day by 1...7 when you input date. If the date have day:

  • Monday : System will return value = 1
  • Tuesday : System will return value = 2
  • Wednesday : System will return value = 3
  • Thursday : System will return value = 4
  • Friday : System will return value = 5
  • Saturday : System will return value = 6
  • Sunday : System will return value = 7

Example


   CALL FUNCTION ’DATE_COMPUTE_DAY’
     EXPORTING
       date         = l_date1
     IMPORTING
       DAY          = l_day. "Return Value