Skip to Content
0
Former Member
Nov 29, 2005 at 06:28 PM

regaring select statement

23 Views

hello every one give me the answer for all the tables which iam showing using for all entries and the answer should be in the final out put internal table iam attaching the code also as well. iam not getting the result for all the tables only three iam getting try to give some good code and make me happy iam trying this from past ten days help me

thank u .

&----


*& Report ZTABLEREPORT2 *

*& *

&----


*& *

*& *

&----


REPORT ZTABLEREPORT2 NO STANDARD PAGE HEADING

LINE-SIZE 250

LINE-COUNT 22(3).

TABLES : MARA,

MAKT,

MARC,

VBAP,

EKKO,

EKPO,

KNA1.

DATA : BEGIN OF T_MARA OCCURS 0,

MATNR LIKE MARA-MATNR,

MTART LIKE MARA-MTART,

MEINS LIKE MARA-MEINS,

END OF T_MARA.

DATA : BEGIN OF T_MAKT OCCURS 0,

MATNR LIKE MAKT-MATNR,

MAKTX LIKE MAKT-MAKTX,

SPRAS LIKE MAKT-SPRAS,

END OF T_MAKT.

DATA : BEGIN OF T_MARC OCCURS 0,

MATNR LIKE MARC-MATNR,

WERKS LIKE MARC-WERKS,

END OF T_MARC.

DATA : BEGIN OF T_KNA1 OCCURS 0,

KUNNR LIKE KNA1-KUNNR,

NAME1 LIKE KNA1-NAME1,

LAND1 LIKE KNA1-LAND1,

END OF T_KNA1.

DATA : BEGIN OF T_VBAP OCCURS 0,

MATNR LIKE VBAP-MATNR,

POSNR LIKE VBAP-POSNR,

MATKL LIKE VBAP-MATKL,

VBELN LIKE VBAP-VBELN,

END OF T_VBAP.

DATA : BEGIN OF T_EKPO OCCURS 0,

EBELN LIKE EKPO-EBELN,

EBELP LIKE EKPO-EBELP,

BUKRS LIKE EKPO-BUKRS,

WERKS LIKE EKPO-WERKS,

LGORT LIKE EKPO-LGORT,

MATNR LIKE EKPO-MATNR,

MANDT LIKE EKPO-MANDT,

END OF T_EKPO.

DATA : BEGIN OF T_FINAL OCCURS 0,

MATNR LIKE MARA-MATNR,

MTART LIKE MARA-MTART,

MEINS LIKE MARA-MEINS,

WERKS LIKE MARC-WERKS,

MAKTX LIKE MAKT-MAKTX,

SPRAS LIKE MAKT-SPRAS,

VBELN LIKE VBAP-VBELN,

POSNR LIKE VBAP-POSNR,

MATKL LIKE VBAP-MATKL,

EBELN LIKE EKPO-EBELN,

EBELP LIKE EKPO-EBELP,

BUKRS LIKE EKPO-BUKRS,

KUNNR LIKE KNA1-KUNNR,

LAND1 LIKE KNA1-LAND1,

NAME1 LIKE KNA1-NAME1,

LGORT LIKE EKPO-LGORT,

END OF T_FINAL.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS : S_BUKRS FOR EKPO-BUKRS,

S_KUNNR FOR KNA1-KUNNR,

S_WERKS FOR MARC-WERKS,

S_MATNR FOR MARA-MATNR.

SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

SELECT MATNR mtart meins

FROM MARA INTO CORRESPONDING FIELDS OF TABLE T_MARA

WHERE MATNR IN S_MATNR.

IF SY-SUBRC <> 0.

WRITE : / 'NO RECORDS FOUND'.

EXIT.

ENDIF.

SELECT MATNR WERKS

FROM MARC

INTO CORRESPONDING FIELDS OF TABLE T_MARC

FOR ALL ENTRIES IN T_MARA

WHERE MATNR = T_MARA-MATNR

and werks in s_werks.

SORT t_mara BY matnr.

SORT t_marc BY matnr.

LOOP AT T_MARA.

MOVE T_MARA-matnr TO T_FINAL-matnr.

move t_mara-mtart to t_final-mtart.

move t_mara-meins to t_final-meins.

loop at t_marc where matnr eq t_mara-matnr.

move t_marc-werks to t_final-werks.

endloop.

select matnr maktx spras

from makt

into corresponding fields of table t_makt

for all entries in t_mara

where matnr = t_mara-matnr

and spras = sy-langu.

loop at t_makt.

move t_makt-maktx to t_final-maktx.

move t_makt-spras to t_final-spras.

endloop.

append t_final.

endloop.

  • SELECT SINGLE posnr matkl vbeln FROM vbap

  • INTO (T_FINAL-MAtkl,T_FINAL-vbeln,t_final-posnr)

  • WHERE MATNR = T_MARA-MATNR.

  • select matnr posnr vbeln matkl

  • from vbap

  • into corresponding fields of table t_vbap

  • for all entries in t_mara

  • where matnr = t_mara-matnr

  • and posnr = ''.

loop at t_final.

write : t_final-matnr,

5 t_final-mtart,

15 t_final-meins,

25 t_final-werks,

40 t_final-maktx,

65 t_final-spras,

80 t_final-posnr,

95 t_final-matkl,

110 t_final-vbeln.

endloop.

  • loop at t_vbap.

  • move t_vbap-posnr to t_final-posnr.

  • move t_vbap-vbeln to t_final-vbeln.

  • move t_vbap-matkl to t_final-matkl.

  • READ TABLE T_MARC WITH KEY MATNR = T_MARA-MATNR.

  • WERKS = T_MARC-WERKS.

  • LOOP AT T_MARD WHERE MATNR EQ T_MARC-MATNR.

  • MOVE T_MARC-WERKS TO T_FINAL-WERKS.

  • APPEND t_FINAL.

  • CLEAR t_FINAL.

  • SELECT single POSNR MATKL VBELN

  • FROM VBAP

  • INTO CORRESPONDING FIELDS OF T_vbap

  • WHERE MATNR = T_MARA-MATNR.

*if sy-subrc eq 0.

  • move-corresponding t_vbap to t_final.

*

  • else.

  • continue.

  • endif.

  • endloop.

  • SELECT SINGLE MAKTX SPRAS FROM MAKT

  • INTO (T_FINAL-MAKTX,T_FINAL-SPRAS)

  • WHERE MATNR = T_MARA-MATNR

  • AND SPRAS = SY-LANGU.

*

  • SELECT POSNR MATKL VBELN

  • FROM VBAP

  • INTO CORRESPONDING FIELDS OF TABLE T_FINAL

  • WHERE MATNR = T_MARA-MATNR.

*

  • select vbeln posnr

  • from vbap

  • into table t_final

  • where matnr = t_mara-matnr.

*

  • SELECT KUNNR NAME1 LAND1

  • APPENDING TABLE T_FINAL

  • FROM KNA1

  • WHERE WERKS = T_MARC-WERKS.

*

  • WRITE : / T_FINAL-MATNR, 15 T_FINAL-MTART,

  • 30 T_FINAL-MEINS, 45 T_FINAL-MAKTX, 80 T_FINAL-SPRAS,

  • 95 T_FINAL-POSNR, 110 T_FINAL-MATKL, 120 T_FINAL-VBELN,

  • 140 t_final-maktx, 165 t_final-spras, 180 t_final-vbeln,

  • 200 t_final-posnr, 210 t_final-kunnr, 225 t_final-name1,

  • 245 t_final-land1.

*

  • LOOP AT T_MARC WHERE MATNR EQ T_MARA-MATNR.

*

  • MOVE T_MARC TO T_FINAL.

  • APPEND T_FINAL.

*

  • CLEAR T_FINAL.

*

  • ENDLOOP.

*

  • LOOP AT T_FINAL.

  • WRITE :70 T_MARC-WERKS.

  • ENDLOOP.

  • endloop.

*SELECT KUNNR NAME1 LAND1

  • APPENDING TABLE T_FINAL

  • FROM KNA1

  • WHERE WERKS = T_MARC-WERKS.

  • ENDSELECT.

  • LOOP AT T_KNA1.

  • WRITE : 180 T_FINAL-KUNNR, 195 T_FINAL-NAME1,

  • 210 T_FINAL-LAND1.