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

report code

Former Member
0 Likes
721

hi all

i want a report cantaining following field

plant :

material no :

material description :

material group :

opening date :

closing date :

Total Receipt Qtiesclosing stock :

Total Issue Quantities

closing date :

regards

rakesh

4 REPLIES 4
Read only

divya_nayudu
Participant
0 Likes
624

You can make that report by fetchin data from various tables like for material No.- mseg-matnr, material description - makt-maktx and so on so forth. Just run a select query on required tables.

Read only

Former Member
0 Likes
624

You may want to consider following tables:


MARA
MARC
MAKT
MKPF
MSEG

Regards

Eswar

Read only

Former Member
0 Likes
624

Hi,

Try this:

Hi check this code,, the dril down option is not avaliable, work on it will be exactly to ur req...

REPORT zm07mkon MESSAGE-ID m7.

*ENHANCEMENT-POINT RM07MKON_G4 SPOTS ES_RM07MKON STATIC.

*ENHANCEMENT-POINT RM07MKON_G5 SPOTS ES_RM07MKON.

*ENHANCEMENT-POINT RM07MKON_G6 SPOTS ES_RM07MKON STATIC.

*ENHANCEMENT-POINT RM07MKON_G7 SPOTS ES_RM07MKON.

CLASS cl_mmim_auth DEFINITION LOAD.

TABLES: msku, makt, mara, t001w, kna1.

SELECTION-SCREEN: BEGIN OF BLOCK dba WITH FRAME TITLE text-001.

SELECT-OPTIONS: matnr FOR mara-matnr,

werks FOR t001w-werks MEMORY ID wrk,

charg FOR msku-charg,

kunnr FOR msku-kunnr.

PARAMETERS: sobkz_w LIKE am07m-kukns AS CHECKBOX DEFAULT 'X',

sobkz_v LIKE am07m-lhgut AS CHECKBOX DEFAULT 'X'.

SELECTION-SCREEN: END OF BLOCK dba.

SELECTION-SCREEN: BEGIN OF BLOCK anz WITH FRAME TITLE text-005.

PARAMETERS: alv_def LIKE disvariant-variant,

zero LIKE am07m-xmnul AS CHECKBOX.

SELECTION-SCREEN: END OF BLOCK anz.

INCLUDE rm07alvi.

DATA: BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE msku.

DATA: maktx LIKE makt-maktx,

name1_w LIKE t001w-name1,

name1_k LIKE kna1-name1,

meins LIKE mara-meins,

dummy TYPE alv_dummy,

farbe TYPE slis_t_specialcol_alv, " color

kunres LIKE mbew-salk3, "total unrestricted stock

kinqul LIKE mbew-salk3, "total in quality inspection

krest LIKE mbew-salk3. "total restricted stock

ctotal LIKE mbew-salk3.

DATA: END OF itab.

DATA: BEGIN OF list OCCURS 0.

INCLUDE STRUCTURE itab.

DATA: END OF list.

DATA: BEGIN OF header OCCURS 0,

kunnr LIKE kna1-kunnr,

name1_k LIKE kna1-name1,

ctotal LIKE mbew-salk3,

END OF header.

DATA: fc TYPE slis_fieldcat_alv OCCURS 0 WITH HEADER LINE.

DATA: detail.

INITIALIZATION.

*ENHANCEMENT-POINT RM07MKON_01 SPOTS ES_RM07MKON.

PERFORM alv_init.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR alv_def.

PERFORM alv_f4.

AT SELECTION-SCREEN.

CALL FUNCTION 'MMIM_ENTRYCHECK_MAIN'

TABLES

it_matnr = matnr

it_werks = werks

it_kunnr = kunnr.

IF sobkz_w = space AND sobkz_v = space.

message changed from e159(at) to e831 "XJD 14.11.2001

SET CURSOR FIELD 'SOBKZ_W'. "XJD 14.11.2001

MESSAGE e831. "Please choose at least one stock type

ENDIF.

PERFORM alv_check.

START-OF-SELECTION.

PERFORM data_selection.

END-OF-SELECTION.

PERFORM calculate_and_colorize.

PERFORM fieldcatalog.

PERFORM list_display.

************************************************************************

FORM data_selection.

DATA: BEGIN OF makt_key OCCURS 0,

matnr LIKE makt-matnr,

END OF makt_key.

DATA: BEGIN OF imakt OCCURS 0,

matnr LIKE makt-matnr,

maktx LIKE makt-maktx,

END OF imakt.

DATA: BEGIN OF mara_key OCCURS 0,

matnr LIKE mara-matnr,

END OF mara_key.

DATA: BEGIN OF imara OCCURS 0,

matnr LIKE mara-matnr,

meins LIKE mara-meins,

END OF imara.

DATA: BEGIN OF t001w_key OCCURS 0,

werks LIKE t001w-werks,

END OF t001w_key.

DATA: BEGIN OF it001w OCCURS 0,

werks LIKE t001w-werks,

name1 LIKE t001w-name1,

END OF it001w.

DATA: BEGIN OF kna1_key OCCURS 0,

kunnr LIKE kna1-kunnr,

END OF kna1_key.

DATA: BEGIN OF ikna1 OCCURS 0,

kunnr LIKE kna1-kunnr,

name1 LIKE kna1-name1,

END OF ikna1.

New table to hold the costs

DATA: BEGIN OF imbew_key OCCURS 0,

charg LIKE mchb-charg,

END OF imbew_key.

DATA: BEGIN OF imbew OCCURS 0,

matnr LIKE mbew-matnr,

bwkey LIKE mbew-bwkey,

salk3 LIKE mbew-salk3,

charg LIKE mchb-charg,

END OF imbew.

DATA: imbew TYPE STANDARD TABLE OF smbew.

RANGES sobkz FOR msku-sobkz.

Main data

REFRESH sobkz.

sobkz-sign = 'I'. sobkz-option = 'EQ'.

IF sobkz_w = 'X'. sobkz-low = 'W'. APPEND sobkz. ENDIF.

IF sobkz_v = 'X'. sobkz-low = 'V'. APPEND sobkz. ENDIF.

SELECT * FROM msku INTO CORRESPONDING FIELDS OF TABLE itab

WHERE matnr IN matnr

AND werks IN werks

AND charg IN charg

AND sobkz IN sobkz

AND kunnr IN kunnr.

Additional info: material text, plant name, debitor name

LOOP AT itab.

makt_key-matnr = itab-matnr. COLLECT makt_key.

mara_key-matnr = itab-matnr. COLLECT mara_key.

t001w_key-werks = itab-werks. COLLECT t001w_key.

kna1_key-kunnr = itab-kunnr. COLLECT kna1_key.

imbew_key-charg = itab-charg. COLLECT imbew_key.

ENDLOOP.

READ TABLE makt_key INDEX 1.

IF sy-subrc = 0.

SELECT matnr maktx INTO CORRESPONDING FIELDS OF TABLE imakt

FROM makt FOR ALL ENTRIES IN makt_key

WHERE matnr = makt_key-matnr

AND spras = sy-langu.

SORT imakt BY matnr.

ENDIF.

READ TABLE mara_key INDEX 1.

IF sy-subrc = 0.

SELECT matnr meins INTO CORRESPONDING FIELDS OF TABLE imara

FROM mara FOR ALL ENTRIES IN mara_key

WHERE matnr = mara_key-matnr.

SORT imara BY matnr.

ENDIF.

READ TABLE t001w_key INDEX 1.

IF sy-subrc = 0.

SELECT werks name1 INTO CORRESPONDING FIELDS OF TABLE it001w

FROM t001w FOR ALL ENTRIES IN t001w_key

WHERE werks = t001w_key-werks.

SORT it001w BY werks.

**new code to get costs

*selecting data into imbew, later reading imbew based on batch number

and placing the necessary values in the final structure itab-.

SELECT amatnr abwkey asalk3 bcharg INTO TABLE imbew

FROM mbew AS a

JOIN mchb AS b

ON amatnr = bmatnr AND

abwkey = bwerks

FOR ALL ENTRIES IN imbew_key

WHERE b~charg = imbew_key-charg AND

a~bwkey = t001w_key-werks.

SORT imbew BY matnr bwkey charg.

ENDIF.

READ TABLE kna1_key INDEX 1.

IF sy-subrc = 0.

SELECT kunnr name1 INTO CORRESPONDING FIELDS OF TABLE ikna1

FROM kna1 FOR ALL ENTRIES IN kna1_key

WHERE kunnr = kna1_key-kunnr.

SORT ikna1 BY kunnr.

ENDIF.

LOOP AT itab.

READ TABLE imakt WITH KEY matnr = itab-matnr BINARY SEARCH.

IF sy-subrc = 0. itab-maktx = imakt-maktx. ENDIF.

READ TABLE imara WITH KEY matnr = itab-matnr BINARY SEARCH.

IF sy-subrc = 0. itab-meins = imara-meins. ENDIF.

READ TABLE it001w WITH KEY werks = itab-werks BINARY SEARCH.

IF sy-subrc = 0. itab-name1_w = it001w-name1. ENDIF.

READ TABLE ikna1 WITH KEY kunnr = itab-kunnr BINARY SEARCH.

IF sy-subrc = 0. itab-name1_k = ikna1-name1. ENDIF.

*new code

*get data from imbew to final structure

READ TABLE imbew WITH KEY matnr = itab-matnr

bwkey = itab-werks

charg = itab-charg BINARY SEARCH.

IF sy-subrc = 0. itab-kunres = imbew-salk3. ENDIF.

MODIFY itab.

ENDLOOP.

SORT itab BY kunnr matnr charg.

ENDFORM. "data_selection

************************************************************************

FORM fieldcatalog.

REFRESH fc. CLEAR fc.

fc-tabname = 'HEADER'.

fc-fieldname = 'KUNNR'.

fc-ref_tabname = 'MSKU'.

APPEND fc. CLEAR fc.

fc-tabname = 'HEADER'.

fc-fieldname = 'NAME1_K'.

fc-ref_tabname = 'KNA1'.

fc-ref_fieldname = 'NAME1'.

APPEND fc. CLEAR fc.

fc-tabname = 'HEADER'.

fc-fieldname = 'TOTAL'.

fc-ref_tabname = 'MBEW'.

fc-ref_fieldname = 'SALK3'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'MATNR'.

fc-ref_tabname = 'MSKU'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'MAKTX'.

fc-ref_tabname = 'MAKT'.

fc-no_out = 'X'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'CHARG'.

fc-ref_tabname = 'MSKU'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'WERKS'.

fc-ref_tabname = 'MSKU'.

fc-no_out = 'X'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'NAME1_W'.

fc-ref_tabname = 'T001W'.

fc-ref_fieldname = 'NAME1'.

fc-no_out = 'X'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'SOBKZ'.

fc-ref_tabname = 'MSKU'.

fc-no_out = 'X'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'KULAB'.

fc-qfieldname = 'MEINS'.

fc-ref_tabname = 'MSKU'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'KUINS'.

fc-qfieldname = 'MEINS'.

fc-ref_tabname = 'MSKU'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'KUEIN'.

fc-qfieldname = 'MEINS'.

fc-ref_tabname = 'MSKU'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'MEINS'.

fc-ref_tabname = 'MARA'.

fc-seltext_l = 'WMU'.

fc-seltext_m = 'WMU'.

fc-seltext_s = 'WMU'.

APPEND fc. CLEAR fc.

fc-tabname = 'HEADER'.

fc-fieldname = 'CTOTAL'.

fc-ref_tabname = 'MARA'.

fc-seltext_l = 'WMU'.

fc-seltext_m = 'WMU'.

fc-seltext_s = 'WMU'.

APPEND fc. CLEAR fc.

*New code

fc-fieldname = 'DUMMY'.

fc-tabname = 'LIST'.

fc-row_pos = '2'.

fc-outputlen = 59.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'KUNRES'.

fc-row_pos = '2'.

fc-seltext_s = 'Total'.

fc-do_sum = 'X'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'KINQUL'.

fc-row_pos = '2'.

fc-seltext_s = 'Total'.

fc-outputlen = 18.

fc-do_sum = 'X'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'KREST'.

fc-row_pos = '2'.

fc-seltext_s = 'Total'.

fc-outputlen = 18.

fc-do_sum = 'X'.

APPEND fc. CLEAR fc.

ENDFORM. "fieldcatalog

************************************************************************

FORM list_display.

REFRESH header.

LOOP AT list.

ON CHANGE OF list-kunnr.

MOVE-CORRESPONDING list TO header.

APPEND header.

ENDON.

ENDLOOP.

alv_keyinfo-header01 = 'KUNNR'.

alv_keyinfo-item01 = 'KUNNR'.

alv_keyinfo-item02 = 'MATNR'.

CLEAR detail.

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

i_interface_check = ' '

i_callback_program = alv_repid

i_callback_pf_status_set = 'SET_STATUS'

i_callback_user_command = 'USER_COMMAND'

is_layout = alv_layout

it_fieldcat = fc[]

i_default = 'X'

i_save = 'A'

is_variant = alv_variant

i_tabname_header = 'HEADER'

i_tabname_item = 'LIST'

is_keyinfo = alv_keyinfo

is_print = alv_print

TABLES

t_outtab_header = header

t_outtab_item = list.

ENDFORM. "list_display

************************************************************************

************************************************************************

FORM calculate_and_colorize.

DATA: sum LIKE msku-kulab,

cust_sum LIKE mbew-salk3.

REFRESH list.

LOOP AT itab.

CHECK cl_mmim_auth=>check( i_object = 'M_MATE_WRK'

i_value1 = itab-werks ) IS INITIAL.

Authorization for total fields

CHECK ZCL_NAME1_AUTH=>check( i_object = 'ZSALK3'

i_value1 = itab-kunres ) IS INITIAL.

cust_sum = itab-kunres + cust_sum.

AT NEW kunnr.

itab-ctotal = cust_sum.

CLEAR cust_sum.

ENDAT.

IF zero = ' '.

sum = itab-kulab + itab-kuein + itab-kuins.

CHECK sum 0.

ENDIF.

MOVE-CORRESPONDING itab TO list.

PERFORM convert_to_ea.

APPEND list.

ENDLOOP.

ENDFORM. "calculate_and_colorize

************************************************************************

FORM set_status USING rt_extab TYPE slis_t_extab.

DATA: wa TYPE slis_extab.

IF cl_mmim_auth=>level( ) IS INITIAL.

APPEND 'AUTH' TO rt_extab.

ENDIF.

IF cl_mmim_auth=>level( ) = cl_mmim_auth=>c_error.

MESSAGE s124(m7).

ENDIF.

Deactivate detail list if in detail list

IF detail = 'X'.

wa-fcode = 'DETAIL'.

APPEND wa TO rt_extab.

ENDIF.

SET PF-STATUS 'STANDARD' EXCLUDING rt_extab.

ENDFORM. "set_status

************************************************************************

FORM user_command USING rf_ucomm LIKE sy-ucomm

rs TYPE slis_selfield.

Call from detail list: Change tablename

IF rs-tabname = '1'.

rs-tabname = 'LIST'.

ENDIF.

Read the correct table

CLEAR: list, header.

CASE rs-tabname.

WHEN 'HEADER'.

READ TABLE header INDEX rs-tabindex.

MOVE-CORRESPONDING header TO list.

WHEN 'LIST'.

READ TABLE list INDEX rs-tabindex.

ENDCASE.

CHECK sy-subrc = 0.

Double click targets

IF rf_ucomm = '&IC1'.

CASE rs-tabname.

WHEN 'HEADER'.

rf_ucomm = 'ADDR'.

WHEN 'LIST'.

CASE rs-fieldname.

WHEN 'MATNR'.

rf_ucomm = 'MMBE'.

WHEN OTHERS.

rf_ucomm = 'DOCU'.

ENDCASE.

ENDCASE.

ENDIF.

Commands

CASE rf_ucomm.

WHEN 'MMBE'.

CHECK rs-tabname = 'LIST'. "only for items

SET PARAMETER ID 'MAT' FIELD list-matnr.

SET PARAMETER ID 'WRK' FIELD list-werks.

CALL TRANSACTION 'MMBE' AND SKIP FIRST SCREEN.

WHEN 'DOCU'.

CHECK rs-tabname = 'LIST'.

SUBMIT rm07docs WITH matnr = list-matnr

WITH werks = list-werks

WITH charg = list-charg

WITH sobkz = list-sobkz

WITH kunnr = list-kunnr

AND RETURN.

WHEN 'ADDR'.

SET PARAMETER ID 'KUN' FIELD list-kunnr.

CALL TRANSACTION 'VD03' AND SKIP FIRST SCREEN.

WHEN 'AUTH'.

CALL METHOD cl_mmim_auth=>display.

WHEN 'DETAIL'.

PERFORM detail_list.

ENDCASE.

CLEAR rf_ucomm.

ENDFORM. "user_command

************************************************************************

FORM detail_list.

DATA: fc_detail TYPE slis_fieldcat_alv OCCURS 0 WITH HEADER LINE.

DATA: variant_detail LIKE disvariant.

DATA: lt_base_list LIKE list[]. "401421

The detail ALV may modify the list (sorting). If returned to the

base list, the original list needs to be restored.

lt_base_list] = list[. "401421

REFRESH fc_detail.

LOOP AT fc.

MOVE-CORRESPONDING fc TO fc_detail.

CLEAR fc_detail-tabname.

APPEND fc_detail.

ENDLOOP.

CLEAR variant_detail.

variant_detail-report = alv_repid.

variant_detail-handle = 'DETA'.

detail = 'X'. "needed for GUI status differentiation

CALL FUNCTION alv_detail_func

EXPORTING

i_callback_program = alv_repid

i_callback_pf_status_set = 'SET_STATUS'

i_callback_user_command = 'USER_COMMAND'

it_fieldcat = fc_detail[]

i_default = 'X'

is_variant = variant_detail

i_save = 'A'

is_layout = alv_layout

is_print = alv_print

TABLES

t_outtab = list[].

CLEAR detail.

list] = lt_base_list[. "401421

ENDFORM. "detail_list

&----


*& Form convert_to_ea

&----


text

-


--> p1 text

<-- p2 text

-


FORM convert_to_ea .

DATA: l_lvsme TYPE lvs_lvsme,

l_lgnum TYPE lgnum,

l_lbkum TYPE lbkum,

l_salk3 TYPE salk3,

l_peinh TYPE peinh,

l_verpr TYPE verpr,

l_bwtty TYPE bwtty_d,

factor TYPE f.

l_lgnum = list-werks+1.

SELECT SINGLE lvsme

INTO l_lvsme

FROM mlgn

WHERE matnr = list-matnr

AND lgnum = l_lgnum.

*...for Standard materials...

SELECT SINGLE lbkum salk3 peinh verpr bwtty

INTO (l_lbkum, l_salk3, l_peinh, l_verpr, l_bwtty)

FROM mbew

WHERE matnr = list-matnr

AND bwkey = list-werks.

IF l_lbkum = 0.

factor = l_verpr / l_peinh.

ELSE.

factor = l_salk3 / l_lbkum.

ENDIF.

*Totals

Total unrestricted stock

list-kunres = list-kulab * factor.

Total stock in quality

list-kinqul = list-kuins * factor.

Total restricted stock

list-krest = list-kuein * factor.

*.......for Configurable items.........

IF l_bwtty = 'X'.

SELECT SINGLE salk3 INTO (l_salk3)

FROM mbew

WHERE matnr = list-matnr AND

bwkey = list-werks AND

bwtar = list-charg.

list-kunres = l_salk3.

ENDIF.

*.........................................

IF NOT l_lvsme IS INITIAL.

CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'

EXPORTING

input = list-kulab

matnr = list-matnr

meinh = l_lvsme

meins = list-meins

charge = list-charg

werks = list-werks

IMPORTING

output = list-kulab

EXCEPTIONS

conversion_not_found = 1

input_invalid = 2

material_not_found = 3

meinh_not_found = 4

meins_missing = 5

no_meinh = 6

output_invalid = 7

overflow = 8

OTHERS = 9.

CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'

EXPORTING

input = list-kuins

matnr = list-matnr

meinh = l_lvsme

meins = list-meins

charge = list-charg

werks = list-werks

IMPORTING

output = list-kuins

EXCEPTIONS

conversion_not_found = 1

input_invalid = 2

material_not_found = 3

meinh_not_found = 4

meins_missing = 5

no_meinh = 6

output_invalid = 7

overflow = 8

OTHERS = 9.

CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'

EXPORTING

input = list-kuein

matnr = list-matnr

meinh = l_lvsme

meins = list-meins

charge = list-charg

werks = list-werks

IMPORTING

output = list-kuein

EXCEPTIONS

conversion_not_found = 1

input_invalid = 2

material_not_found = 3

meinh_not_found = 4

meins_missing = 5

no_meinh = 6

output_invalid = 7

overflow = 8

OTHERS = 9.

list-meins = l_lvsme.

ENDIF.

ENDFORM. " convert_to_ea

Reward Points if found helpfull..

Cheers,

Chandra Sekhar.

Read only

0 Likes
624

Hi there

to make code more readable insert Curly bracket code before the start of the code and curly bracket code at the end of code

for example



your code

Now FORGET the SLIS stuff --Old, obsolete, too complicated and you need forever to code even a simple GRID as shown by the zillions of lines of abap code in your example.

If you don't need an editable GRID use class salv otherwise use OO cl_gui_alv_grid (or the TREE versions - OO if you need hierarchial displays).

finally it's really horrible code to have umpteen calls to the same function module like you've done in in the calling this function module several times.FUNCTION 'MATERIAL_UNIT_CONVERSION'.

Just do a PERFORM using .... or even a method call.

To make the whole thing much easier as well define your structure , build a DYNAMIC FCAT using RTTI and then in ONE STEP create a dynamic table and populate it.

I'm afraid any potential abbaper I would recruit would CERTAINLY NOT get the job if your example above was presented as usable PRODUCTION code.

These days UI and OO programming make stuff really easy so try and forget the old "Elephantine" way of doing it.

for example here's how to build an EASY dynamic FCAT and dynamic table using ANY structure you care to name (excluding deep components as they are not yet supported).



* Define any structure
types:  begin of s_elements,
  vbeln   type vapma-vbeln,
  posnr   type vapma-posnr,
  matnr   type vapma-matnr,
  kunnr   type vapma-kunnr,
  werks   type vapma-werks,
  vkorg   type vapma-vkorg,
  vkbur   type vapma-vkbur,
  status  type c,

end of  s_elements.

* end of your structure
data lr_rtti_struc type ref to cl_abap_structdescr .
data:
    zog                     like line of lr_rtti_struc->components .
data:
  zogt                    like table of zog,
wa_it_fldcat type lvc_s_fcat,
it_fldcat type lvc_t_fcat ,
dy_line            type ref to data,
dy_table           type ref to data.


data:  dref               type ref to data.
field-symbols: <fs> type any,
   <dyn_table>    type  standard table,
   <dyn_wa>.

..... other code

*now I want to build a field catalog
* First get your data structure into a field symbol

create data dref type s_elements.
assign dref->* to <fs>.

lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( <fs> ).

* Now get the structure details into a table.
* table zogt[] contains the structure details
* From which we can build the field catalog

zogt[]  = lr_rtti_struc->components.
loop at zogt into zog.
  clear wa_it_fldcat.
  wa_it_fldcat-fieldname = zog-name .
  wa_it_fldcat-datatype = zog-type_kind.
  wa_it_fldcat-inttype = zog-type_kind.
  wa_it_fldcat-intlen = zog-length.
  wa_it_fldcat-decimals = zog-decimals.
  wa_it_fldcat-coltext = zog-name.
  wa_it_fldcat-lowercase = 'X'.
  append wa_it_fldcat to it_fldcat .
endloop.
*
* You can perform any modifications / additions to your field catalog
* here such as your own column names etc.

* Now using the field catalog created above we can
* build a dynamic table
* and populate it

* First build the dynamic table
* the table will contain entries for
* our structure defined at the start of the program

call method cl_alv_table_create=>create_dynamic_table
       exporting
            it_fieldcatalog = it_fldcat
       importing
            ep_table = dy_table.


assign dy_table->* to <dyn_table>.
create data dy_line like line of <dyn_table>.
assign dy_line->* to <dyn_wa>.

* Now fill our table with data

select vbeln posnr matnr kunnr werks vkorg vkbur
       up to 200 rows
       from vapma
       into  corresponding fields of table <dyn_table>.

* Call the screen to display the grid
call screen 100.

Simplicity itself !!!!!!!

Cheers

Jimbo