Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Explain this code

Former Member
0 Likes
435

Hi,

yesterday i write this question and i have answer and its working great the problem is i dont understand the lines(in answer) :

col = col + 10.

col = 1.

way he do that?

Regards

i have internal table like that and i wont to do pivot like e.g. .

i have

pernr      orgeh       sick_days        sum
 
123        5555            3                   7
123        5555            4                   7
456        6666            7                  16
456        6666            1                  16
456        6666            8                  16
789        5656            3                  6
789        5656            3                  6


i wont :

pernr    123       123      456     456    456         789       789 
orgeh    5555     5555    6666   6666  6666       5656    5656
sick_days  3        4        7         1       8            3         3
sum          7        7        16       16      16          6         6


what is the simple way to do that?

the answer:

DATA:
  BEGIN OF myrec,
    pernr(10)      TYPE n,
    orgeh(10)      TYPE n,
    sick(10)       TYPE n,
    sum(10)        TYPE n,
 END OF myrec,
 itab LIKE STANDARD TABLE OF myrec.
DATA:
  BEGIN OF fld_rec,
    fld(10)         TYPE n,
  END OF fld_rec,
  BEGIN OF data_rec,
    pernr LIKE STANDARD TABLE OF fld_rec,
    orgeh LIKE STANDARD TABLE OF fld_rec,
    sick  LIKE STANDARD TABLE OF fld_rec,
    sum   LIKE STANDARD TABLE OF fld_rec,
  END OF data_rec,
  itab2 LIKE STANDARD TABLE OF data_rec.
 
DATA: col     TYPE i.
 
START-OF-SELECTION.
 
  PERFORM load_itab.
 
  LOOP AT itab INTO myrec.
    APPEND myrec-pernr TO data_rec-pernr.
    APPEND myrec-orgeh TO data_rec-orgeh.
    APPEND myrec-sick  TO data_rec-sick.
    APPEND myrec-sum   TO data_rec-sum.
 
  ENDLOOP.
  APPEND data_rec TO itab2.
 
  LOOP AT itab2 INTO data_rec.
    col = 1.
    LOOP AT data_rec-pernr INTO fld_rec.
      WRITE AT col fld_rec-fld RIGHT-JUSTIFIED NO-ZERO.
      col = col + 10.
    ENDLOOP.
    NEW-LINE.
    col = 1.
    LOOP AT data_rec-orgeh INTO fld_rec.
      WRITE AT col fld_rec-fld RIGHT-JUSTIFIED NO-ZERO.
      col = col + 10.
    ENDLOOP.
    NEW-LINE.
    col = 1.
    LOOP AT data_rec-sick INTO fld_rec.
      WRITE AT col fld_rec-fld RIGHT-JUSTIFIED NO-ZERO.
      col = col + 10.
    ENDLOOP.
    NEW-LINE.
    col = 1.
    LOOP AT data_rec-sum INTO fld_rec.
      WRITE AT col fld_rec-fld RIGHT-JUSTIFIED NO-ZERO.
      col = col + 10.
    ENDLOOP.
 
  ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
402

Hi ,

col = 1 ,it is maintaining the point from where to start .

WRITE AT col fld_rec-fld RIGHT-JUSTIFIED NO-ZERO

so this will write at 1 first position .

now the fld_rec-fld is of size 10 .

so col = col + 10 would make it to start with 11 .

so the next record would start on 11 postion .

I hope you got it .

Please reward if useful.

3 REPLIES 3
Read only

Former Member
0 Likes
403

Hi ,

col = 1 ,it is maintaining the point from where to start .

WRITE AT col fld_rec-fld RIGHT-JUSTIFIED NO-ZERO

so this will write at 1 first position .

now the fld_rec-fld is of size 10 .

so col = col + 10 would make it to start with 11 .

so the next record would start on 11 postion .

I hope you got it .

Please reward if useful.

Read only

Former Member
0 Likes
402

Hi ,

here u want to display the values of a field in a row rather than in table format.

so the logic is like that all the values ofa field is getting displayed to make the position properly the column width are making 10 characters.By the end of displaying the values of perner is at 300 column.while displaying the other field values from left of the window the column values is resetting to 1.

Reward if find useful

Read only

Former Member
0 Likes
402

The code is explained as follows.

1. Instead of the table format u r displaying the values of a field.

2. The values of all the fields are getting displayed so as to make the column width position as

10 characters.

3. At the end of display of the values of perner is at 300 column

4. While displaying the other field values from left of the window the column values is resetting to 1.

Regards,

Jagadish.