TRY & CATCH to Avoid Short Dump in ABAP Program

Berikut adalah tips yang bisa digunakan untukmenghindari short dump pada abap program dikarenakan data conversion dari text ke currency atau decimal.

  DATA:ld_text(10) VALUE '1,000.00',
       ld_text1(10), ld_text2(10),
       ld_dec TYPE p LENGTH 7 DECIMALS 2.

  SPLIT ld_text AT '.' INTO ld_text1 ld_text2.
  REPLACE ALL OCCURRENCES OF ',' IN ld_text1 WITH ''.
  CONDENSE: ld_text1, ld_text2.
  CONCATENATE ld_text1 '.' ld_text2 INTO ld_text1.
  CONDENSE ld_text1.
  TRY .
      ld_dec = ld_text1.
      WRITE ld_dec.
    CATCH cx_root.
      WRITE 'Error converting currency'.
  ENDTRY.

Pada code di atas, value ld_text dapat diganti menjadi ‘testing’ untuk melihat apakah try-catch berhasil menangkap exception CX_SY_CONVERSION_NO_NUMBER sehingga tidak terjadi short dump, melainkan menampilkan informasi bahwa hasil konversi gagal ‘Error converting cirrency’.

Semoga bermanfaat 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s