2007 Jul 30 6:14 AM
Hi,
In this program I had used Inner join statement, But I want to use For All entries statement. Plz tell me the format. I am highlighting the Innerjoin Staement in Bold letters.
REPORT ZFS_TAB1 LINE-SIZE 180
LINE-COUNT 26(2)
NO STANDARD PAGE HEADING.
TYPES:
BEGIN OF TY_LFB1,
MINDK TYPE LFB1-MINDK,
END OF TY_LFB1,
BEGIN OF TY_EKKO,
EKGRP TYPE EKKO-EKGRP,
AEDAT TYPE EKKO-AEDAT,
EBELN TYPE EKKO-EBELN,
SUBMI TYPE EKKO-SUBMI,
BSART TYPE EKKO-BSART,
KTWRT TYPE EKKO-KTWRT,
LIFNR TYPE EKKO-LIFNR,
END OF TY_EKKO,
BEGIN OF TY_LFA1,
KTOKK TYPE LFA1-KTOKK,
NAME1 TYPE LFA1-NAME1,
ORT01 TYPE LFA1-ORT01,
REGIO TYPE LFA1-REGIO,
PSTLZ TYPE LFA1-PSTLZ,
TELF1 TYPE LFA1-TELF1,
TELFX TYPE LFA1-TELFX,
END OF TY_LFA1,
BEGIN OF TY_ADRC,
HOUSE_NUM1 TYPE ADRC-HOUSE_NUM1,
STREET TYPE ADRC-STREET,
PO_BOX TYPE ADRC-PO_BOX,
END OF TY_ADRC,
BEGIN OF TY_ADR6,
SMTP_ADDR TYPE ADR6-SMTP_ADDR,
END OF TY_ADR6,
BEGIN OF TY_WYT3,
LIFN2 TYPE WYT3-LIFN2,
END OF TY_WYT3.
TYPES:
BEGIN OF TY_OUTPUT,
MINDK TYPE LFB1-MINDK,
EKGRP TYPE EKKO-EKGRP,
AEDAT TYPE EKKO-AEDAT,
EBELN TYPE EKKO-EBELN,
SUBMI TYPE EKKO-SUBMI,
BSART TYPE EKKO-BSART,
KTWRT TYPE EKKO-KTWRT,
LIFNR TYPE EKKO-LIFNR,
KTOKK TYPE LFA1-KTOKK,
NAME1 TYPE LFA1-NAME1,
ORT01 TYPE LFA1-ORT01,
REGIO TYPE LFA1-REGIO,
PSTLZ TYPE LFA1-PSTLZ,
TELF1 TYPE LFA1-TELF1,
TELFX TYPE LFA1-TELFX,
HOUSE_NUM1 TYPE ADRC-HOUSE_NUM1,
STREET TYPE ADRC-STREET,
PO_BOX TYPE ADRC-PO_BOX,
SMTP_ADDR TYPE ADR6-SMTP_ADDR,
LIFN2 TYPE WYT3-LIFN2,
END OF TY_OUTPUT.
D A T A
DATA:
ST_LFB1 TYPE TY_LFB1,
IT_LFB1 TYPE TABLE OF TY_LFB1,
ST_EKKO TYPE TY_EKKO,
IT_EKKO TYPE TABLE OF TY_EKKO,
ST_LFA1 TYPE TY_LFA1,
IT_LFA1 TYPE TABLE OF TY_LFA1,
ST_ADRC TYPE TY_ADRC,
IT_ADRC TYPE TABLE OF TY_ADRC,
ST_ADR6 TYPE TY_ADR6,
IT_ADR6 TYPE TABLE OF TY_ADR6,
ST_WYT3 TYPE TY_WYT3,
IT_WYT3 TYPE TABLE OF TY_WYT3,
ST_OUTPUT TYPE TY_OUTPUT,
IT_OUTPUT TYPE TABLE OF TY_OUTPUT.
S E L E C T I O N S C R E E N
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:
SMINDK FOR ST_LFB1-MINDK,
SAEDAT FOR ST_EKKO-AEDAT,
SEKGRP FOR ST_EKKO-EKGRP,
SLIFNR FOR ST_EKKO-LIFNR.
SELECTION-SCREEN END OF BLOCK B1.
T O P O F P A G E.
TOP-OF-PAGE.
WRITE:/2'PUR GROUP' ,7 'DATE',15 'DOCNO', 20 'CNO', 25 'PDTY', 27 'PL VALUE',35 'VNDOR NO',40 'ACCGRP',45'NAME',55 'CITY', 65 'REGION', 75 'PCODE',
83 'TELPH',90 'TELFAX', 98 'MIND', 103 'H NUM',110 'STREET', 120 'POBOX',129 'EMAILID', 141 'INPT NUMB'.
A T S E L E C T I O N S C R E E N
AT SELECTION-SCREEN.
PERFORM VALIDATE_MINDK.
PERFORM VALIDATE_EKGRP.
PERFORM VALIDATE_LIFNR.
S T A R T O F S E L E C T I O N.
START-OF-SELECTION.
PERFORM GETDATA_EKKO.
PERFORM GETMIND_LFB1.
PERFORM GET_VENDORMASTERDATA.
PERFORM GET_VENDORADDRESS.
PERFORM GET_VENDOREMAIL.
PERFORM GET_INVOICEPARTY.
<b>SELECT EKKOEKGRP EKKOAEDAT EKKOEBELN EKKOSUBMI EKKOBSART EKKOKTWRT EKKO~LIFNR
LFA1KTOKK LFA1NAME1 LFA1ORT01 LFA1REGIO LFA1PSTLZ LFA1TELF1 LFA1TELFX LFB1MINDK ADRCHOUSE_NUM1 ADRCSTREET ADRCPO_BOX ADR6SMTP_ADDR WYT3~LIFN2 INTO
CORRESPONDING FIELDS OF TABLE IT_OUTPUT
FROM EKKO INNER JOIN LFA1 ON EKKOLIFNR EQ LFA1LIFNR
JOIN LFB1 ON LFA1LIFNR EQ LFB1LIFNR
JOIN WYT3 ON LFA1LIFNR EQ WYT3LIFNR
JOIN ADRC ON LFA1ADRNR EQ ADRCADDRNUMBER
JOIN ADR6 ON ADRCADDRNUMBER EQ ADR6ADDRNUMBER
WHERE LFB1~MINDK IN SMINDK AND
EKKO~AEDAT IN SAEDAT AND
EKKO~EKGRP IN SEKGRP AND
EKKO~LIFNR IN SLIFNR.</b>
IF SY-SUBRC EQ 0.
LOOP AT IT_OUTPUT INTO ST_OUTPUT.
WRITE:/ 2 ST_OUTPUT-EKGRP,7 ST_OUTPUT-AEDAT,15 ST_OUTPUT-EBELN,20 ST_OUTPUT-SUBMI,25 ST_OUTPUT-BSART,27 ST_OUTPUT-KTWRT,35 ST_OUTPUT-LIFNR,40 ST_OUTPUT-KTOKK,
45 ST_OUTPUT-NAME1,55 ST_OUTPUT-ORT01,65 ST_OUTPUT-REGIO,75 ST_OUTPUT-PSTLZ,83 ST_OUTPUT-TELF1,90 ST_OUTPUT-TELFX,98
ST_OUTPUT-MINDK,103 ST_OUTPUT-HOUSE_NUM1,110 ST_OUTPUT-STREET,120 ST_OUTPUT-PO_BOX,129 ST_OUTPUT-SMTP_ADDR,141 ST_OUTPUT-LIFN2.
ENDLOOP.
ELSE.
WRITE:/ 'NO RECORDS FOUND'.
ENDIF.
&----
*& Form GETDATA_EKKO
&----
text
----
--> p1 text
<-- p2 text
----
FORM GETDATA_EKKO .
SELECT EKGRP "PURCHASING GROUP
AEDAT "DATE ON WHICH RECORD WAS CREATED
EBELN "PURCHASING DOCUMENT NUMBER
SUBMI "COLLECTIVE NUMBER
BSART "PURCHASE DOCUMENT TYPE
KTWRT "CUMULATIVE PLANNED VALUE
LIFNR "VENDOR ACCOUNT NUMBER
FROM EKKO INTO TABLE IT_EKKO
WHERE EKGRP IN SEKGRP AND LIFNR IN SLIFNR AND AEDAT IN SAEDAT AND BSTYP = 'A'.
IF SY-SUBRC EQ 0.
LOOP AT IT_EKKO INTO ST_EKKO.
WRITE:/ ST_EKKO-EKGRP,ST_EKKO-AEDAT,ST_EKKO-EBELN,ST_EKKO-SUBMI,ST_EKKO-BSART,ST_EKKO-KTWRT,ST_EKKO-KTWRT,ST_EKKO-LIFNR.
ENDLOOP.
ENDIF.
ENDFORM. " GETDATA_EKKO
&----
*& Form GETMIND_LFB1
&----
text
----
--> p1 text
<-- p2 text
----
FORM GETMIND_LFB1 .
SELECT MINDK "MINORIY INDICATORS
FROM LFB1 INTO TABLE IT_LFB1 WHERE MINDK IN SMINDK.
IF SY-SUBRC EQ 0.
LOOP AT IT_LFB1 INTO ST_LFB1.
WRITE:/ ST_LFB1-MINDK.
ENDLOOP.
ENDIF.
ENDFORM. " GETMIND_LFB1
&----
*& Form GET_VENDORMASTERDATA
&----
text
----
--> p1 text
<-- p2 text
----
FORM GET_VENDORMASTERDATA .
SELECT KTOKK "VENDOR ACCOUNT NUMBER
NAME1 "NAME1
ORT01 "CITY
REGIO "REGION
PSTLZ "POSTAL CODE
TELF1 "FIRST TELEPHONE NUMBER
TELFX "FAX NUMBER
FROM LFA1 INTO TABLE IT_LFA1.
IF SY-SUBRC EQ 0.
LOOP AT IT_LFA1 INTO ST_LFA1.
WRITE:/ ST_LFA1-KTOKK,ST_LFA1-NAME1,ST_LFA1-ORT01,ST_LFA1-REGIO,ST_LFA1-PSTLZ,ST_LFA1-TELF1,ST_LFA1-TELFX.
ENDLOOP.
ENDIF.
ENDFORM. " GET_VENDORMASTERDATA
&----
*& Form GET_VENDORADDRESS
&----
text
----
--> p1 text
<-- p2 text
----
FORM GET_VENDORADDRESS .
SELECT HOUSE_NUM1 "HOUSE NUMBER1
STREET "STREET
PO_BOX "PO BOX
FROM ADRC INTO TABLE IT_ADRC.
IF SY-SUBRC EQ 0.
LOOP AT IT_ADRC INTO ST_ADRC.
WRITE:/ ST_ADRC-HOUSE_NUM1,ST_ADRC-STREET,ST_ADRC-PO_BOX.
ENDLOOP.
ENDIF.
ENDFORM. " GET_VENDORADDRESS
&----
*& Form GET_VENDOREMAIL
&----
text
----
--> p1 text
<-- p2 text
----
FORM GET_VENDOREMAIL .
SELECT SMTP_ADDR "VENDOR EMAIL ADDRESS
FROM ADR6 INTO TABLE IT_ADR6.
IF SY-SUBRC EQ 0.
LOOP AT IT_ADR6 INTO ST_ADR6.
WRITE:/ ST_ADR6-SMTP_ADDR.
ENDLOOP.
ENDIF.
ENDFORM. " GET_VENDOREMAIL
&----
*& Form GET_INVOICEPARTY
&----
text
----
--> p1 text
<-- p2 text
----
FORM GET_INVOICEPARTY .
SELECT LIFN2
FROM WYT3 INTO TABLE IT_WYT3.
IF SY-SUBRC EQ 0.
LOOP AT IT_WYT3 INTO ST_WYT3.
WRITE:/ ST_WYT3-LIFN2.
ENDLOOP.
ENDIF.
ENDFORM. " GET_INVOICEPARTY
&----
*& Form VALIDATE_MINDK
&----
text
----
--> p1 text
<-- p2 text
----
FORM VALIDATE_MINDK .
DATA:
LW_MINDK TYPE T059M-MINDK,
W_INPUT TYPE C.
IF SMINDK NE 'EX'.
SELECT MINDK FROM T059M INTO LW_MINDK
WHERE MINDK IN SMINDK.
ENDSELECT.
ENDIF.
IF SY-SUBRC NE 0.
MESSAGE E000(0) WITH 'NO MINORITY INDICATOR FOR THIS CUSTOMER'.
ELSE.
W_INPUT = 'X'.
ENDIF.
ENDFORM. " VALIDATE_MINDK
&----
*& Form VALIDATE_EKGRP
&----
text
----
--> p1 text
<-- p2 text
----
FORM VALIDATE_EKGRP .
DATA:
LW_EKGRP TYPE T024-EKGRP,
W_INPUT TYPE C.
IF SAEDAT IS NOT INITIAL.
SELECT EKGRP FROM T024 INTO LW_EKGRP
WHERE EKGRP IN SEKGRP.
ENDSELECT.
ENDIF.
IF SY-SUBRC NE 0.
MESSAGE E000(0) WITH 'INVALID PURCHASE GROUP RANGE'.
ELSE.
W_INPUT = 'X'.
ENDIF.
ENDFORM. " VALIDATE_EKGRP
&----
*& Form VALIDATE_LIFNR
&----
text
----
--> p1 text
<-- p2 text
----
FORM VALIDATE_LIFNR .
DATA:
LW_LIFNR TYPE EKKO-LIFNR,
W_INPUT TYPE C.
IF SLIFNR IS NOT INITIAL.
SELECT LIFNR FROM EKKO INTO LW_LIFNR
WHERE LIFNR IN SLIFNR.
ENDSELECT.
ENDIF.
IF SY-SUBRC NE 0.
MESSAGE E000(0) WITH 'INVALID VENDOR GROUP RANGE'.
ELSE.
W_INPUT = 'X'.
ENDIF.
ENDFORM. " VALIDATE_LIFNR
2007 Jul 30 6:17 AM
hi,
Check this one
&----
*& Report ZALLREADINNERJOIN
*&
&----
*&
*&
&----
REPORT ZALLREADINNERJOIN.
tables : mara,
makt .
data :BEGIN OF T_MAKT OCCURS 0,
MATNR LIKE MAKT-MATNR,
MAKTX LIKE MAKT-MAKTX,
END OF T_MAKT.
DATA:BEGIN OF T_MATERIAL OCCURS 0,
MATNR LIKE MARA-MATNR,
MEINS LIKE MARA-MEINS,
MTART LIKE MARA-MTART,
MAKTX LIKE MAKT-MAKTX,
END OF T_MATERIAL .
FIELD-SYMBOLS <FS_MATERIAL> LIKE T_MATERIAL .
ASSIGN T_MATERIAL TO <FS_MATERIAL> .
PARAMETERS : MATNUM LIKE MARA-MATNR.
*SELECT-OPTIONS: MATNUM FOR MARA-MATNR.
SELECT MATNR
MAKTX
FROM MAKT
INTO TABLE T_MAKT
WHERE MATNR = MATNUM.
IF T_MAKT[] IS NOT INITIAL.
SELECT MATNR
MEINS
MTART
FROM MARA
INTO TABLE T_MATERIAL
FOR ALL ENTRIES IN T_MAKT
WHERE MATNR = T_MAKT-MATNR.
ENDIF.
LOOP AT T_MATERIAL ."ASSIGNING <FS_MATERIAL>.
READ TABLE T_MAKT WITH KEY MATNR = T_MATERIAL.
IF SY-SUBRC EQ 0.
<FS_MATERIAL>-MAKTX = T_MAKT-MAKTX.
ENDIF.
WRITE:/ <FS_MATERIAL>-MATNR,
<FS_MATERIAL>-MEINS,
<FS_MATERIAL>-MTART,
<FS_MATERIAL>-MAKTX.
ENDLOOP.
<b>Rewars point</b>
Regards
Ashok Kumar
2007 Jul 30 6:17 AM
hi,
Check this one
&----
*& Report ZALLREADINNERJOIN
*&
&----
*&
*&
&----
REPORT ZALLREADINNERJOIN.
tables : mara,
makt .
data :BEGIN OF T_MAKT OCCURS 0,
MATNR LIKE MAKT-MATNR,
MAKTX LIKE MAKT-MAKTX,
END OF T_MAKT.
DATA:BEGIN OF T_MATERIAL OCCURS 0,
MATNR LIKE MARA-MATNR,
MEINS LIKE MARA-MEINS,
MTART LIKE MARA-MTART,
MAKTX LIKE MAKT-MAKTX,
END OF T_MATERIAL .
FIELD-SYMBOLS <FS_MATERIAL> LIKE T_MATERIAL .
ASSIGN T_MATERIAL TO <FS_MATERIAL> .
PARAMETERS : MATNUM LIKE MARA-MATNR.
*SELECT-OPTIONS: MATNUM FOR MARA-MATNR.
SELECT MATNR
MAKTX
FROM MAKT
INTO TABLE T_MAKT
WHERE MATNR = MATNUM.
IF T_MAKT[] IS NOT INITIAL.
SELECT MATNR
MEINS
MTART
FROM MARA
INTO TABLE T_MATERIAL
FOR ALL ENTRIES IN T_MAKT
WHERE MATNR = T_MAKT-MATNR.
ENDIF.
LOOP AT T_MATERIAL ."ASSIGNING <FS_MATERIAL>.
READ TABLE T_MAKT WITH KEY MATNR = T_MATERIAL.
IF SY-SUBRC EQ 0.
<FS_MATERIAL>-MAKTX = T_MAKT-MAKTX.
ENDIF.
WRITE:/ <FS_MATERIAL>-MATNR,
<FS_MATERIAL>-MEINS,
<FS_MATERIAL>-MTART,
<FS_MATERIAL>-MAKTX.
ENDLOOP.
<b>Rewars point</b>
Regards
Ashok Kumar
2007 Jul 30 6:19 AM
Hi Ram,
Refer to this sample program and replace and use accordingly in your program too
http://www.sap-img.com/abap/several-nested-inner-join-statements-can-be-inefficient.htm
Regardss,
Santosh
2007 Jul 30 6:20 AM
Hi
Declare the ITAb with the same fields of this select
SELECT EKKOEKGRP EKKOAEDAT EKKOEBELN EKKOSUBMI EKKOBSART EKKOKTWRT EKKO~LIFNR
into table Itab ITAB
WHERE EKKO~AEDAT IN SAEDAT AND
EKKO~EKGRP IN SEKGRP AND
EKKO~LIFNR IN SLIFNR.
Declare the ITAB1 with the same fields as that of this select statement only
if not itab[] is initial.
LFA1KTOKK LFA1NAME1 LFA1ORT01 LFA1REGIO LFA1PSTLZ LFA1TELF1 LFA1TELFX LFB1MINDK ADRCHOUSE_NUM1 ADRCSTREET ADRCPO_BOX ADR6SMTP_ADDR WYT3~LIFN2 INTO
CORRESPONDING FIELDS OF TABLE ITAB1
FROM LFA1 JOIN LFB1 ON LFA1LIFNR EQ LFB1LIFNR
JOIN WYT3 ON LFA1LIFNR EQ WYT3LIFNR
JOIN ADRC ON LFA1ADRNR EQ ADRCADDRNUMBER
JOIN ADR6 ON ADRCADDRNUMBER EQ ADR6ADDRNUMBER
for all entries of ITAB
WHERE LFB1~MINDK IN SMINDK AND
LFA1~LIFNR EQ ITAB-LIFNR.
endif.
Now move the data from ITAB and ITAB1 into a i_final internal table and display the data
<b>Reward points for useful Answers</b>
Regards
Anji