Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Basic report

I would like to display Sequence number, Plant, Material numbre and Quantity from 1st row.

Iam i am doing subtotal Plant wise and Grand total for all plants.

Using the following program i am getting Material number and Quantity in 2nd row. But i would like to display from first row.

Please suggest me any code.

TABLES: ekpo.

TYPES: BEGIN OF t_data,

werks TYPE matnr,

matnr TYPE werks_d,

menge TYPE bstmg,

END OF t_data.

DATA: it_data type standard table of t_data with header line.

DATA: it_final TYPE STANDARD TABLE OF t_data WITH HEADER LINE.

DATA: lv_count type i value 1.

SELECT-OPTIONS: s_matnr FOR ekpo-matnr,

s_werks FOR ekpo-werks.

START-OF-SELECTION.

SELECT werks

matnr

menge FROM ekpo INTO TABLE it_data

WHERE werks in s_werks

AND matnr in s_matnr.

IF NOT it_data[] is INITIAL.

LOOP AT it_data.

MOVE-CORRESPONDING it_data TO it_final.

COLLECT it_final.

ENDLOOP.

ENDIF.

SORT it_final by werks matnr.

LOOP AT it_final.

AT FIRST.

WRITE:/3 'Material details in Plant'.

WRITE:/ sy-uline+1(96).

WRITE:/1 sy-vline,

3(17) 'Sequence NO' COLOR 4,

21 sy-vline,

23(20) 'Plant' COLOR 3,

45 sy-vline,

50(20) 'Material Number' COLOR 5,

72 sy-vline,

75(20) 'Quantity' COLOR 7,

96 sy-vline.

WRITE:/ sy-uline+1(96).

ENDAT.

AT NEW werks.

WRITE: /1 sy-vline,

5 lv_count,

21 sy-vline,

25 it_final-werks,

45 sy-vline,

72 sy-vline,

96 sy-vline.

ENDAT.

WRITE:/1 sy-vline,

21 sy-vline.

WRITE: 45 sy-vline,

58 it_final-matnr,

72 sy-vline,

77 it_final-menge,

96 sy-vline.

AT END OF werks.

SUM.

WRITE:/1 sy-vline,

21 sy-vline,

45 sy-vline,

50 'Quantity of Plant' COLOR 4,

72 sy-vline,

77 it_final-menge COLOR 4,

96 sy-vline.

WRITE:/ sy-uline+1(96).

lv_count = lv_count + 1.

ENDAT.

AT LAST.

SUM.

WRITE:/1 sy-vline,

21 sy-vline,

45 sy-vline,

50 'Total Quantity of Plant' COLOR 4,

72 sy-vline,

77 it_final-menge COLOR 4,

96 sy-vline.

WRITE:/ sy-uline+1(96).

ENDAT.

ENDLOOP.

Thanks,

sai

Tags:
replied

try this code...

TABLES: ekpo.

TYPES: BEGIN OF t_data,
  werks TYPE matnr,
  matnr TYPE werks_d,
  menge TYPE bstmg,
END OF t_data.

DATA : lv_flag TYPE c .

DATA: it_data TYPE STANDARD TABLE OF t_data WITH HEADER LINE.
DATA: it_final TYPE STANDARD TABLE OF t_data WITH HEADER LINE.
DATA: lv_count TYPE i VALUE 1.
SELECT-OPTIONS: s_matnr FOR ekpo-matnr,
                s_werks FOR ekpo-werks.

START-OF-SELECTION.
  SELECT werks
  matnr
  menge FROM ekpo INTO TABLE it_data
  WHERE werks IN s_werks
  AND matnr IN s_matnr.

  IF NOT it_data[] IS INITIAL.
    LOOP AT it_data.
      MOVE-CORRESPONDING it_data TO it_final.
      COLLECT it_final.
    ENDLOOP.
  ENDIF.

  SORT it_final BY werks matnr.
  LOOP AT it_final.

    AT FIRST.
      WRITE:/3 'Material details in Plant'.
      WRITE:/ sy-uline+1(96).
      WRITE:/1 sy-vline,
      3(17) 'Sequence NO' COLOR 4,
      21 sy-vline,
      23(20) 'Plant' COLOR 3,
      45 sy-vline,
      50(20) 'Material Number' COLOR 5,
      72 sy-vline,
      75(20) 'Quantity' COLOR 7,
      96 sy-vline.
      WRITE:/ sy-uline+1(96).
    ENDAT.

    AT NEW werks.
      lv_flag = 'X' .
      WRITE: /1 sy-vline,
      5 lv_count,
      21 sy-vline,
      25 it_final-werks,
      45 sy-vline,
      72 sy-vline,
      96 sy-vline.
    ENDAT.
    IF lv_flag = 'X' .
      WRITE:1 sy-vline.
    ELSE.
      WRITE:/1 sy-vline.
    ENDIF.
    CLEAR lv_flag .

    WRITE: 21 sy-vline.
    WRITE: 45 sy-vline,
           58 it_final-matnr,
           72 sy-vline,
           77 it_final-menge,
           96 sy-vline.

    AT END OF werks.
      SUM.
      WRITE:/1 sy-vline,
      21 sy-vline,
      45 sy-vline,
      50 'Quantity of Plant' COLOR 4,
      72 sy-vline,
      77 it_final-menge COLOR 4,
      96 sy-vline.
      WRITE:/ sy-uline+1(96).
      lv_count = lv_count + 1.
    ENDAT.

    AT LAST.
      SUM.
      WRITE:/1 sy-vline,
      21 sy-vline,
      45 sy-vline,
      50 'Total Quantity of Plant' COLOR 4,
      72 sy-vline,
      77 it_final-menge COLOR 4,
      96 sy-vline.
      WRITE:/ sy-uline+1(96).
    ENDAT.
  ENDLOOP.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question