0
votes

I am writing a simple program given as an assignment in sap abap workbench to generate table using do enddo loop. There I used variable m inside do loop which is declared as m type i value 1. but its not getting printed please help.

*&---------------------------------------------------------------------*
*& Report  Z_BASIC_OUTPUT_PATTERN
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  z_basic_output_pattern NO STANDARD PAGE HEADING LINE-COUNT
100(4).
DATA m  TYPE i VALUE 1 .
.
WRITE 40'student marksheet'.
WRITE 73'date:'.
WRITE /73'time:'.
SKIP 3 .
WRITE 10'student information :-'.
ULINE /10(19).
WRITE /10'student roll no.:'.
WRITE /10'student class   :'.
WRITE /10'student section :'.
WRITE /10'student name    :'.
SKIP 2.
ULINE 10(33).
WRITE /10'|'.
WRITE'subject details'.
WRITE 42'|'.
ULINE  /10(33).
WRITE /10'|'.
WRITE'sno.'.
WRITE 15'|'.
WRITE'subject'.
WRITE 24'|'.
WRITE'marks'.
WRITE 30'|'.
WRITE'grade'.
WRITE 42'|'.
ULINE /10(33).
DO 3 TIMES .
  WRITE /10 '|'.
  WRITE : m .
  WRITE 15'|'.
  IF sy-index = '1' .
    WRITE 'maths'.
  ELSEIF sy-index = '2'.
    WRITE 'science'.
  ELSE.
    WRITE 'english'.
  ENDIF.
  WRITE 24 '|'.
  WRITE 30 '|'.
  WRITE 42'|'.
  ULINE /10(33).
  m = m + 1.
ENDDO.

below is output (output of the program )

output of the program

3

3 Answers

0
votes

Modify the loop like this:

DO 3 TIMES .
 WRITE /10 '|'.
  WRITE 4: m .
  WRITE 15'|'.
  IF sy-index = '1' .
    WRITE 'maths'.
  ELSEIF sy-index = '2'.
    WRITE 'science'.
  ELSE.
    WRITE 'english'.
  ENDIF.
  WRITE 10 '|'.
  WRITE 24 '|'.
  WRITE 30 '|'.
  WRITE 42'|'.
  ULINE /10(33).
  m = m + 1.
ENDDO.

Apparently one line was overlapping the m variable.

0
votes

Lets look step by step what you do:

WRITE /10 '|'.

Write a bar at position 10,.

WRITE : m .

Write m. m is an integer and the output is 10 characters long (maybe I'm wrong, but it is longer then 5 characters). The number is aligned to the right. So on position 21 is now a number.

WRITE 15'|'.

No you go back on position 15 and start a new output. The next write command overwrites your number.

A possible solution: Restrict the length of the output:

WRITE : (4) m .

As recommended in the comments: If you replace WRITE 15 '|'. with WRITE /15 '|'. you get the following result:

enter image description here

You get a new line after the printout of the number and you see the number is at the same place as the subject text. In other words: Without the new line, the subject overwrites the number.

If you restrict the place for the number with WRITE : (4) m . you get the wanted solution:

enter image description here


Instead of writing and change always the position I woudl recommend to write the elements one after the other and each field gets it owns output length.

Example:

DATA: subject TYPE string.
DO 3 TIMES .
* Get the variable text
  CASE sy-index.
    WHEN '1'.
      subject = 'maths'.
    WHEN '2'.
      subject = 'science'.
    WHEN OTHERS.
      subject = 'english'.
  ENDCASE.
* And now the central output part:
  WRITE: /10 '|' NO-GAP,
        (3) m, '|',
        (6) subject, '|',
        (3) space, '|',
        (9) space, '|'.
  ULINE /10(33).
  m = m + 1.
ENDDO.

Remark: space is just an empty placeholder until you have the real data for the columns.

0
votes

You have to increase the space for m; if you write an integer, SAP reserves 10 spaces for the variable and writes it right-justified. That means the m variable is being overwritten by the science/math/english word.