Simple Abap Program Example

Some short simple abap program example for beginners.

How we can draw triangle in reports like we can make square and rectangle?

constants : c_cent type i value '65',
            c_star value '*'.
data : v_last(200),
        v_st type i,
        v_end type i.

 write  at c_cent c_star.

do 10 times .
  clear : v_st , v_end.
  v_st = c_cent - sy-index .
  v_end = c_cent + sy-index .
  concatenate c_star v_last into v_last.
  write /.
  write : at v_st c_star ,  at v_end c_star.
  enddo.
do.
write :  at v_st c_star.
  v_st = v_st + 1.
if not v_st <= v_end.
  exit.
endif.
enddo.
 

How to print this?
1
3 2
4 5 6
10 9 8 7
11 12 13 14 15

*&---------------------------------------------------------------------*
*& Report  Y_TGH_TEST1 
*&---------------------------------------------------------------------*

REPORT  y_tgh_test1.

DATA : h TYPE i, v TYPE i,
      counter TYPE i,
      nummod TYPE i,
      num TYPE i.

DATA : BEGIN OF it_num OCCURS 0,
    int TYPE i,
  END OF it_num.

h = 5.
counter = 1.

*DO 5 TIMES.
*  v = sy-index.
*  DO v TIMES.
*    WRITE counter.
*    counter = counter + 1.
*  ENDDO.
*  NEW-LINE.
*ENDDO.

DO 5 TIMES.
  REFRESH it_num.
  clear it_num.
  v = sy-index.
  DO v TIMES.
    nummod = v MOD 2.
    IF nummod = 0.
      it_num-int = counter.
      append it_num.
      counter = counter + 1.
    ELSE.
      WRITE counter.
      counter = counter + 1.
    ENDIF.
  ENDDO.

  SORT it_num by int DESCENDING.
  LOOP AT it_num.
    write it_num-int.
  ENDLOOP.

  NEW-LINE.
ENDDO. 
 

How I can remove any blank  records from an internal table e.g. ITAB?

We can use the below statement for deleting blank lines.

"DELETE itab where matnr IS INITIAL AND matkl IS INITIAL."

From the internal table "itab" by checking the fields in the internal table.

ABAP

See Also:
Program To Download Batch Session Log Into Excel

Tables
Database Table

ABAP Books List
ABAP/4 Certification, Programming, Smartforms, Sapscripts and Object Oriented Programming Books

Smart Forms
SAP Smartforms

ABAP Menu:
ABAP Example Hints and Tips

Return to Index:-
SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.