Powered By

Free XML Skins for Blogger

Powered by Blogger

Thursday, February 12, 2009

sap abap program for Reincarnation of REUSE_ALV_FIELDCATALOG_MERGE

* Author Jayanta Narayan Choudhuri
* Flat 302
* 395 Jodhpur Park
* Kolkata 700 068
* Email sss@cal.vsnl.net.in
* URL: http://www.geocities.com/ojnc

These FORMs are for people accustomed to
REUSE_ALV_FIELDCATALOG_MERGE (despite the 72 ch source line limit)
but not happy with LVC_FIELDCATALOG_MERGE which has NO Internal
table option

We do not want to crowd DDIC with too many structures!

The routines handle any internal table using field name as title
if not a DDIC data element.

Create a Include ZJNCINCLUDE with the 2 FORMs

There are two FORMs: ZJNC_DUMP_LIST will be very useful as it is
simple and needs no screen and can be called any number of times.

Should be very useful also for debugging esp. where Excel is not
available as you can dump any internal table anytime and inspect contents.

I wrote these routine mainly for debugging and the problem created by
half-line long comments in internal tables. With RTTI there is no source
code dependency.

ZJNC_DUMP_GRID is for OO-GRID loving people who can adapt that routine
for one off reports.
You can call this ONLY ONCE as it is best used using a dummy selection
screen - tip from SDN ABAP FAQ.

As FORMs use RTTI there is no special case for Structures!

-----------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include ZJNCINCLUDE
*
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Reincarnations of REUSE_ALV_FIELDCATALOG_MERGE
*&---------------------------------------------------------------------*

* Author Jayanta Narayan Choudhuri
* Flat 302
* 395 Jodhpur Park
* Kolkata 700 068
* Email sss@cal.vsnl.net.in
* URL: http://www.geocities.com/ojnc

*-----------------------------------------------------------------------
* These FORMs are for people accustomed to
* REUSE_ALV_FIELDCATALOG_MERGE (despite the 72 ch source line limit)
* but not happy with LVC_FIELDCATALOG_MERGE
* We do not want to crowd DDIC with too many structures!
*-----------------------------------------------------------------------

*&--------------------------------------------------------------------*
*& Form ZJNC_DUMP_LIST Our Good Old ALV list - RECOMMENDED!
*&--------------------------------------------------------------------*
FORM zjnc_dump_list USING value(p_it_name) TYPE c
value(p_wa_name) TYPE c
value(p_heading) TYPE c.

TYPE-POOLS: slis.

DATA:
stru_ref TYPE REF TO cl_abap_structdescr,
comp_tab TYPE abap_compdescr_tab,
one_comp TYPE abap_compdescr,
one_name TYPE string,
type_ref TYPE REF TO cl_abap_typedescr,
is_ddic TYPE abap_bool,
lt_ddic TYPE dd_x031l_table,
wa_ddic TYPE x031l,
lt_fcat TYPE slis_t_fieldcat_alv,
wa_fcat TYPE slis_fieldcat_alv,
ls_layo TYPE slis_layout_alv,
l_alv TYPE REF TO cl_gui_alv_grid.

FIELD-SYMBOLS: TYPE ANY,
TYPE STANDARD TABLE,
TYPE ANY.

ASSIGN (p_it_name) TO .

ASSIGN (p_wa_name) TO .

ls_layo-colwidth_optimize = 'X'.
ls_layo-zebra = 'X'.
ls_layo-window_titlebar = p_heading.
ls_layo-box_tabname = p_it_name.

stru_ref ?= cl_abap_structdescr=>describe_by_data( ).

comp_tab = stru_ref->components.

LOOP AT comp_tab INTO one_comp.
CLEAR wa_fcat.
wa_fcat-tabname = p_it_name.
wa_fcat-fieldname = one_comp-name.

CONCATENATE p_wa_name '-' one_comp-name INTO one_name.

ASSIGN (one_name) TO .

type_ref ?= cl_abap_typedescr=>describe_by_data( ).

is_ddic = type_ref->is_ddic_type( ).

IF is_ddic = abap_true.
lt_ddic = type_ref->get_ddic_object( ).

LOOP AT lt_ddic INTO wa_ddic.
CLEAR wa_ddic-tabname.
SELECT SINGLE
dd03l~tabname
INTO wa_ddic-tabname
FROM dd03l
WHERE dd03l~fieldname = wa_ddic-fieldname
AND dd03l~tabname NOT LIKE '/%'. " I live in normal
namespace


wa_fcat-ref_tabname = wa_ddic-tabname.
wa_fcat-ref_fieldname = wa_ddic-fieldname.

SELECT SINGLE
dd04t~scrtext_s
dd04t~scrtext_m
dd04t~scrtext_l
INTO (wa_fcat-seltext_s, wa_fcat-seltext_m,
wa_fcat-seltext_l)
FROM dd04t
WHERE dd04t~rollname = wa_ddic-fieldname
AND dd04t~ddlanguage = sy-langu.

ENDLOOP.
ELSE.
MOVE one_comp-name TO: wa_fcat-seltext_s, wa_fcat-seltext_m,
wa_fcat-seltext_l.
ENDIF.

APPEND wa_fcat TO lt_fcat.

ENDLOOP.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
is_layout = ls_layo
it_fieldcat = lt_fcat
TABLES
t_outtab = .

ENDFORM. "ZJNC_DUMP_LIST

*&--------------------------------------------------------------------*
*& Form ZJNC_DUMP_GRID Object Oriented
*&--------------------------------------------------------------------*
FORM zjnc_dump_grid USING value(p_it_name) TYPE c
value(p_wa_name) TYPE c
value(p_screen) TYPE n
value(p_heading) TYPE c.

DATA:
stru_ref TYPE REF TO cl_abap_structdescr,
comp_tab TYPE abap_compdescr_tab,
one_comp TYPE abap_compdescr,
one_name TYPE string,
type_ref TYPE REF TO cl_abap_typedescr,
is_ddic TYPE abap_bool,
lt_ddic TYPE dd_x031l_table,
wa_ddic TYPE x031l,
lt_fcat TYPE lvc_t_fcat,
wa_fcat TYPE lvc_s_fcat,
ls_layo TYPE lvc_s_layo,
l_alv TYPE REF TO cl_gui_alv_grid.

FIELD-SYMBOLS: TYPE ANY,
TYPE ANY TABLE,
TYPE ANY.

ASSIGN (p_it_name) TO .

ASSIGN (p_wa_name) TO .

ls_layo-cwidth_opt = 'X'.
ls_layo-zebra = 'X'.
ls_layo-grid_title = p_heading.
ls_layo-box_fname = p_it_name.

stru_ref ?= cl_abap_structdescr=>describe_by_data( ).

comp_tab = stru_ref->components.

LOOP AT comp_tab INTO one_comp.
CLEAR wa_fcat.
wa_fcat-tabname = p_it_name.
wa_fcat-fieldname = one_comp-name.

CONCATENATE p_wa_name '-' one_comp-name INTO one_name.

ASSIGN (one_name) TO .

type_ref ?= cl_abap_typedescr=>describe_by_data( ).

is_ddic = type_ref->is_ddic_type( ).

IF is_ddic = abap_true.
lt_ddic = type_ref->get_ddic_object( ).

LOOP AT lt_ddic INTO wa_ddic.
CLEAR wa_ddic-tabname.
SELECT SINGLE
dd03l~tabname
INTO wa_ddic-tabname
FROM dd03l
WHERE dd03l~fieldname = wa_ddic-fieldname
AND dd03l~tabname NOT LIKE '/%'. " I live in normal
namespace


wa_fcat-ref_table = wa_ddic-tabname.
wa_fcat-ref_field = wa_ddic-fieldname.

SELECT SINGLE
dd04t~scrtext_s
dd04t~scrtext_m
dd04t~scrtext_l
INTO (wa_fcat-scrtext_s, wa_fcat-scrtext_m,
wa_fcat-scrtext_l)
FROM dd04t
WHERE dd04t~rollname = wa_ddic-fieldname
AND dd04t~ddlanguage = sy-langu.

ENDLOOP.

ELSE.
MOVE one_comp-name TO: wa_fcat-scrtext_s, wa_fcat-scrtext_m,
wa_fcat-scrtext_l.
ENDIF.

APPEND wa_fcat TO lt_fcat.

ENDLOOP.

CREATE OBJECT l_alv EXPORTING i_parent = cl_gui_container=>screen0.

CALL METHOD l_alv->set_table_for_first_display
EXPORTING
is_layout = ls_layo
CHANGING
it_outtab =
it_fieldcatalog = lt_fcat.

CALL SELECTION-SCREEN p_screen.

ENDFORM. "ZJNC_DUMP_GRID

-----------------------------------------------------------------------------------
* SAMPLE TEST PROGRAM

REPORT yjnc1.

INCLUDE zjncinclude.

TYPES : BEGIN OF ty_pur,
ebeln1 TYPE ekko-ebeln,
aedat TYPE ekko-aedat,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
txz01 TYPE ekpo-txz01,
menge1 TYPE ekpo-menge,
belnr1 TYPE ekbe-belnr,
budat1 TYPE ekbe-budat,
bwart TYPE ekbe-bwart,
menge2 TYPE ekbe-menge,
belnr2 TYPE ekbz-belnr,
budat2 TYPE ekbz-budat,
menge3 TYPE ekbz-menge,
dmbtr TYPE ekbz-dmbtr,
buzei TYPE ekbz-buzei,
jnc1 TYPE sy-datum,
jnc2 TYPE i,
jnc3(4) TYPE c,
END OF ty_pur.

DATA: it_pur TYPE STANDARD TABLE OF ty_pur,
wa_pur TYPE ty_pur,
rows TYPE i.

* Not Recommended Style but still used!
DATA: BEGIN OF it_mat OCCURS 0,
jnc1 TYPE sy-datum,
matnr LIKE makt-matnr,
jnc2 TYPE i,
maktx LIKE makt-maktx,
mtart TYPE mara-mtart,
jnc3(4) TYPE c,
END OF it_mat.

DATA: BEGIN OF it_str OCCURS 0.
INCLUDE STRUCTURE makt.
DATA: END OF it_str.

SELECTION-SCREEN BEGIN OF SCREEN 1001.
SELECTION-SCREEN END OF SCREEN 1001.

START-OF-SELECTION.

MOVE 100 TO rows.

SELECT ekko~ebeln
ekko~aedat
ekpo~ebelp
ekpo~matnr
ekpo~txz01
ekpo~menge
ekbe~belnr
ekbe~budat
ekbe~bwart
ekbe~menge
ekbz~belnr
ekbz~budat
ekbz~menge
ekbz~dmbtr
ekbz~buzei
INTO TABLE it_pur
UP TO rows ROWS
FROM ekko
INNER JOIN ekpo
ON ekko~ebeln = ekpo~ebeln
AND ekpo~loekz = ' '
INNER JOIN ekbe
ON ekpo~ebeln = ekbe~ebeln
AND ekpo~ebelp = ekbe~ebelp
AND ekbe~bewtp = 'E'
LEFT OUTER JOIN ekbz
ON ekpo~ebeln = ekbz~ebeln
AND ekpo~ebelp = ekbz~ebelp
AND ekbz~bewtp = 'M'
WHERE ekko~bstyp = 'F'
AND ekko~loekz = ' '
ORDER BY ekko~ebeln
ekpo~ebelp.

LOOP AT it_pur INTO wa_pur.
COMPUTE wa_pur-jnc1 = sy-datum - sy-tabix.
MOVE sy-tabix TO wa_pur-jnc2.
MOVE 'Helo' TO wa_pur-jnc3.
MODIFY it_pur FROM wa_pur.
ENDLOOP.

* PERFORM zjnc_dump_grid USING 'IT_PUR' 'WA_PUR' 1001 'Purchase
Report'.

* IT_PUR is as per recommended OO style
PERFORM zjnc_dump_list USING 'IT_PUR' 'WA_PUR' 'Purchase Dump'.

SELECT makt~matnr
makt~maktx
mara~mtart
INTO CORRESPONDING FIELDS OF TABLE it_mat
UP TO rows ROWS
FROM mara INNER JOIN makt
ON makt~matnr = mara~matnr
AND makt~spras = sy-langu.

LOOP AT it_mat.
COMPUTE it_mat-jnc1 = sy-datum - sy-tabix.
MOVE sy-tabix TO it_mat-jnc2.
MOVE 'Helo' TO it_mat-jnc3.
MODIFY it_mat.
ENDLOOP.


* PERFORM zjnc_dump_grid USING 'IT_MAT[]' 'IT_MAT' 1001 'Material
Dump'.

* Note that IT_MAT with Header line is 2 in 1
* IT_MAT[] is the table object and IT_MAT is the header work area

PERFORM zjnc_dump_list USING 'IT_MAT[]' 'IT_MAT' 'Material Dump'.

SELECT *
INTO TABLE it_str
UP TO rows ROWS
FROM makt
WHERE makt~spras = sy-langu.

* Note that IT_STR with Header line is 2 in 1
* IT_STR[] is the table object and IT_STR is the header work area
* As FORM zjnc_dump_list uses RTTI there is no special case for
Structures

PERFORM zjnc_dump_list USING 'IT_STR[]' 'IT_STR' 'Structure Dump'.

No comments:

Archives