Skip to Content
Author's profile photo Former Member

Program To display the triangle using special character

             Program To display the triangle using special character
                                 (By Polu Sreedevi)
Developed the program to display the
triangle using any special characters like ‘!@#$%^&*’. Here in selection
screen I am passing any special character and number of times and doing
validations on special character and num of times.
Validation: It should allow only special
characters
Num of times: it should not exceed 10 times.
Go to Se38 and enter the program name and
select create.
PRG.png
Write the below logic in source code.
DATA:i TYPE n,

      j TYPE n.

*Selection Screen

PARAMETERS:p_spec TYPE c,

           p_cnt(2) TYPE n.

*Declare constants

CONSTANTS: c_spec TYPE char10 VALUE‘!@#$%^&*()’,

           c_cnt TYPE char2 VALUE’10’.

*Validation

AT SELECTION-SCREEN .

*if it’s not special character
then display error message as ‘Enter valid input’.

  IF p_spec NA c_spec.

    MESSAGE  text001 TYPE ‘E’.

  ENDIF.

*If it’s exceeds 10 then display
error message as ‘Enter valid input’.

  IF p_cnt GT c_cnt.

    MESSAGE  text001 TYPE ‘E’.

  ENDIF.

START-OF-SELECTION .

*Logic

  i = 1.

  DO p_cnt TIMES.

    IF i LE p_cnt.

      j = 1.

      DO i TIMES.

        IF j LE i.

          WRITE: p_spec.

          j = j + 1.

        ENDIF.

      ENDDO.

      WRITE /.

      i = i + 1.

    ENDIF.

  ENDDO.

Selection Screen:
SL.png
Enter Special Character and enter number in no
of times field.
SL1.png
Click on Execute .
Output of the program (Below screen):
OUT.png

Assigned tags

      6 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Matthew Billingham
      Matthew Billingham

      Now re-write it in object oriented ABAP.

      Author's profile photo Arindam Mondal
      Arindam Mondal

      Reminds me of my first exercises in Programming.. These are what we all do in C, C++, JAVA etc. to learn 🙂

      Author's profile photo Custodio de Oliveira
      Custodio de Oliveira

      I'm pretty sure that "+" is a special character. Still, I got an error.

      Author's profile photo Former Member
      Former Member

      Initial codes we learnt from C and C++ thanks for remembering it...

      Author's profile photo Former Member
      Former Member

      Hi Sreedevi,

      Good Evening!

      Nice blog for beginners! Thanks for sharing.

      Regards,

      Hari Suseelan

      Author's profile photo Karon Christydoss
      Karon Christydoss

      hi, is this possible for printing full diamond shape output using the above concept.?