Home > Enterprise >  ABAP two table how to merge a table
ABAP two table how to merge a table

Time:09-16






Thank you very much!

CodePudding user response:

If it is to do a query! Can be associated; If it is to do the table, please define table fields, required then correlation,

CodePudding user response:

Here are examples of writing code, I hope can help you, please compile implementation in your environment, there are any problems, please contact

*& -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - *
*& The Report YYZGMMB0005
*& -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - *
*&
*& -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - *
The REPORT YYZGMMB0005.

TYPES:
The BEGIN OF G_TYP_EKES_MSEG,
EBELN TYPE EKES - EBELN,
EBELP TYPE EKES - EBELP,
EINDT TYPE EKES - EINDT,
ERDAT TYPE EKES - ERDAT,
MENGE TYPE EKES - MENGE,
DABMG TYPE EKES - DABMG,
EBELN_M TYPE MSEG - EBELN,
EBELP_M TYPE MSEG - EBELP,
PBAMG TYPE MSEG - PBAMG,
MEINS TYPE MSEG - MEINS,
SHKZG TYPE MSEG - SHKZG,
MATNR TYPE MSEG - MATNR,
MBLNR TYPE MSEG - MBLNR,
ZEILE TYPE MSEG - ZEILE,
BWART TYPE MSEG - BWART,
HSDAT TYPE MSEG - HSDAT,
END OF G_TYP_EKES_MSEG,
G_TYP_TAB__EKES_MSEG TYPE STANDARD TABLE OF G_TYP_EKES_MSEG.

START - OF - SELECTION.

PERFORM F_MAIN_PROCESS.


The FORM F_MAIN_PROCESS.

DATA:
L_WRK_INDEX TYPE I,
L_REC_EKES TYPE EKES,
L_REC_MSEG TYPE MSEG,
L_REC_EKES_MSEG TYPE G_TYP_EKES_MSEG,
L_TAB_EKES TYPE STANDARD TABLE OF EKES,
L_TAB_MSEG TYPE STANDARD TABLE OF MSEG,
L_TAB_EKES_MSEG TYPE G_TYP_TAB__EKES_MSEG.

SELECT *
The FROM EKES
INTO the TABLE L_TAB_EKES.

SORT L_TAB_EKES BY EBELN ASCENDING EBELP ASCENDING.

SELECT *
The FROM MSEG
INTO the TABLE L_TAB_MSEG.

SORT L_TAB_MSEG BY EBELN ASCENDING EBELP ASCENDING.

LOOP AT L_TAB_EKES INTO L_REC_EKES.

The CLEAR: L_WRK_INDEX.

READ the TABLE L_TAB_MSEG TRANSPORTING NO FIELDS
WITH the KEY EBELN=L_REC_EKES - EBELN
EBELP=L_REC_EKES - EBELP
BINARY SEARCH.

IF SY - SUBRC=0.

L_WRK_INDEX=SY - TABIX.
LOOP AT L_TAB_MSEG INTO L_REC_MSEG FROM L_WRK_INDEX.
IF L_REC_MSEG - EBELN=L_REC_EKES - EBELN AND
L_REC_MSEG - EBELP=L_REC_EKES - EBELP.

The CLEAR:
L_REC_EKES_MSEG.
MOVE - CORRESPONDING L_REC_EKES TO L_REC_EKES_MSEG.
MOVE - CORRESPONDING L_REC_MSEG TO L_REC_EKES_MSEG.
L_REC_EKES_MSEG - EBELN_M=L_REC_EKES - EBELN.
L_REC_EKES_MSEG - EBELP_M=L_REC_EKES - EBELP.
APPEND L_REC_EKES_MSEG TO L_TAB_EKES_MSEG.

ENDIF.
ENDLOOP.

ELSE.

The CLEAR:
L_REC_EKES_MSEG.
MOVE - CORRESPONDING L_REC_EKES TO L_REC_EKES_MSEG.
APPEND L_REC_EKES_MSEG TO L_TAB_EKES_MSEG.

ENDIF.

ENDLOOP.

ENDFORM.

CodePudding user response:

After 740 version can directly SELECT column column column column into table @ data (LT_ * * * * *)

the from list ALEFTJOIN table 2
Where A.A=@ input variable
Refer to the grammar

CodePudding user response:

SELECT * INTO @ DATA (LT_ITAB)
The FROM ekko as a inner join ekpo as b

On a ~ ebeln=b ~ vebeln
  • Related