03-09-2023 4:46 AM
Hello experts!,
i have this sample program to fetch data from 2 table but with different fields taken, is there a way to make it fetch data from 2 table with the same field and then store the output to my Ztable ?
here's the sample program
REPORT ZGETFBL.<br><br>TABLES : MARA.<br><br>DATA : ITAB TYPE TABLE OF ZDATAGL,<br> WA TYPE ZDATAGL.<br><br>SELECT-OPTIONS : S_MATNR FOR MARA-MATNR.<br><br>START-OF-SELECTION.<br><br>PERFORM GET_DATA.<br>PERFORM DISPLAY_DATA.<br>*&---------------------------------------------------------------------*<br>*& Form GET-DATA<br>*&---------------------------------------------------------------------*<br>* text<br>*----------------------------------------------------------------------*<br>* --> p1 text<br>* <-- p2 text<br>*----------------------------------------------------------------------*<br>FORM GET_DATA.<br><br>SELECT A~MATNR<br> ERSDA<br> ERNAM<br> B~PSTAT<br> B~LVORM <br>INTO TABLE ITAB<br>FROM MARA AS A<br> INNER JOIN MARC AS B<br>ON B~MATNR = A~MATNR<br> WHERE MATNR IN S_MATNR.<br><br>ENDSELECT.<br>ENDFORM.
03-09-2023 6:52 AM
Yes, you could fetch the "same" fieldname from two different tables (or same table), you just have to rename the fields : (better is to give the same name of the internal table, but your code is hard to read)
SELECT mara~matnr as my_first_material, makt~matnr as my_second_material, ....
03-09-2023 5:22 AM
Hi
Please refer below code to fetch data from two different tables
TYPES :
"structure to hold customer details
BEGIN OF st_cust,
kunnr TYPE kna1-kunnr,
land1 TYPE kna1-land1,
vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
END OF st_cust.
DATA :
"internal table and workarea to hold customer details
wa_cust TYPE st_cust,
it_cust TYPE TABLE of st_cust.
SElect kna1~kunnr
kna1~land1
vbak~vbeln
vbak~erdat
INTO TABLE it_cust
from kna1
INNER JOIN vbak
on kna1~kunnr = VBAK~kunnr.
IF sy-subrc = 0 and it_cust is NOT INITIAL.
cl_demo_output=>display( it_cust ).
ENDIF.<br>
Thanks
Tarun
03-09-2023 7:06 AM
Hi Tarun
are those 2 table have the same field ?, if not what should i do it if i want to fetch same field from 2 different table ?
Thanks
Dema
03-09-2023 6:52 AM
Yes, you could fetch the "same" fieldname from two different tables (or same table), you just have to rename the fields : (better is to give the same name of the internal table, but your code is hard to read)
SELECT mara~matnr as my_first_material, makt~matnr as my_second_material, ....
03-09-2023 7:01 AM
this is the sample code i found, but this one fetching different field with 2 different table
REPORT ZGETFBL.
TABLES : MARA.
DATA : ITAB TYPE TABLE OF ZDATAGL,
WA TYPE ZDATAGL.
SELECT-OPTIONS : S_MATNR FOR MARA-MATNR.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM DISPLAY_DATA.
*&---------------------------------------------------------------------*
*& Form GET-DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA.
SELECT A~MATNR
ERSDA
ERNAM
B~PSTAT
B~LVORM
INTO TABLE ITAB
FROM MARA AS A
INNER JOIN MARC AS B
ON B~MATNR = A~MATNR
WHERE MATNR IN S_MATNR.
ENDSELECT.
ENDFORM.
03-09-2023 7:06 AM
this is a JOIN, so my proposal is a good one SELECT A~MATNR AS ..., B~MATNR AS ....
03-09-2023 7:28 AM
as u asked before, yes i want it in one column
im gonna make a table to store the data from that 2 table.
03-09-2023 6:58 AM
don't use answer to reply to a proposal, use comment
You want the two fields in the same column or in two differnt colums ?
03-09-2023 7:07 AM
in the same column, yes
here's how i want it to work:
1st i use parameter to search data according to G/L account number, with a date range of it
and then its supposed to show the data from the 2 different table with the same field which is G/L account number and the date range.
03-09-2023 11:48 AM
Please review the formatting of the code in your question, it's currently shown as only ONE line with many <br>. Possibly, pasting code using Ctrl+Shift+V may help you (unformatted paste).
03-09-2023 11:49 AM
Your code, correctly formatted:
REPORT ZGETFBL.
TABLES : MARA.
DATA : ITAB TYPE TABLE OF ZDATAGL,
WA TYPE ZDATAGL.
SELECT-OPTIONS : S_MATNR FOR MARA-MATNR.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM DISPLAY_DATA.
*&---------------------------------------------------------------------*
*& Form GET-DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA.
SELECT A~MATNR
ERSDA
ERNAM
B~PSTAT
B~LVORM
INTO TABLE ITAB
FROM MARA AS A
INNER JOIN MARC AS B
ON B~MATNR = A~MATNR
WHERE MATNR IN S_MATNR.
ENDSELECT.
ENDFORM.
03-09-2023 11:52 AM