To compare two internal tables and delete records
Hi friends,
I have to compare two internal tables and should delete the records which is not present in both the tables. Reply me as soon as possible.
Thanks.
Hi Nagarajan,
1. I don't think there is any direct (one-shot statement)
way to achieve this.
one has to do by writing some logic.
2. Loop at ITAB1.
Read table ITAB2 with key Field1 = ITAB1-Field1.
If sy-subrc <> 0.
delete ITAB1.
endif.
Endloop.
Do the same again with ITAB2.
Loop at ITAB2.
Read table ITAB1 with key Field1 = ITAB2-Field1.
If sy-subrc <> 0.
delete ITAB2.
endif.
Endloop.
3. If any better way is found, i will let u know.
Hope it helps.
Regards,
Amit M.
Similar Messages
-
Comparing two internal tables and deleting the record not present in second
Hi All,
I have a internal table itaba with PERNR as primary key and various other columns (1000 records) and table B with PERNR as primary key and 800 records.
Now what is the best way to compare these two and delete the record from table A when its corresponding record is not present in table B?
Thanks and Regards,
MohanHI SIR
u trained us in accenture
Hi all
when ever m running this session in SM35 , M getting error as :
"LEAVE TO TRANSACTION" MARA-BISMT is not allow
in batch input
REPORT YASEC_BDC_NIK_SESSION
no standard page heading
message-id zmm
line-count 65
line-size 150.
tables : mara.
*Top includr program
INCLUDE YNEW_MAIN_TOP.
*include yasec_bdc_nik_session_top.
***********selection screen *******************
selection-screen begin of block b1 with frame title text-001.
selection-screen skip.
PARAMETERS: p_ifile(128) TYPE c .
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: rad1 TYPE c RADIOBUTTON GROUP 1 USER-COMMAND gr1,
rad2 TYPE c RADIOBUTTON GROUP 1 .
SELECTION-SCREEN SKIP.
PARAMETERS: p_sess TYPE c.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK b1.
Subroutine call***************************
INCLUDE YNEW_MAIN_F01.
*include yasec_bdc_nik_session_f01.
*********At selection event triggered *************
at selection-screen on value-request for p_ifile.
To get F4 help for the input file path
PERFORM f_f4_input_file.
AT SELECTION-SCREEN ON p_ifile.
To validate and upload the input file
PERFORM f_load_file.
AT SELECTION-SCREEN ON p_sess.
To validate the Number of Sessions field
IF rad2 IS NOT INITIAL AND sy-ucomm EQ c_onli.
PERFORM f_check_sessions.
ENDIF.
***********Start of selection *******************
start-of-selection.
*To process BDC
PERFORM f_process_bdc.
TOP OF PAGE
TOP-OF-PAGE.
Writes the report heading and for displaying line number.
PERFORM f_report_header.
TYPES : BEGIN OF t_final,
matnr(50) TYPE c,
bismt(18) type c,
end of t_final.
TYPES: BEGIN OF t_fdata,
data(256) TYPE c,
END OF t_fdata.
TYPES: BEGIN OF t_error,
message(100) TYPE c,
END OF t_error.
*Internal table declarations
*Internal table to load the data from the file that is changed throgh BDC
DATA : i_final TYPE STANDARD TABLE OF t_final,
wa_final TYPE t_final.
*Internal table to store the error messages
DATA : i_error TYPE STANDARD TABLE OF t_error,
wa_error TYPE t_error.
*Internal table to load the raw data
DATA : i_fdata TYPE STANDARD TABLE OF t_fdata,
wa_fdata TYPE t_fdata.
*Internal table to store records of BDC
DATA : i_bdcdata TYPE STANDARD TABLE OF bdcdata INITIAL SIZE 0,
wa_bdcdata TYPE bdcdata.
Internal table to store BDC messages
DATA: i_bdcmsgcoll TYPE STANDARD TABLE OF bdcmsgcoll INITIAL SIZE 0,
wa_bdcmsgcoll TYPE bdcmsgcoll.
VARIABLE DECLARATIONS
DATA: v_ifile TYPE string,
v_input TYPE i,
c_delimiter TYPE c VALUE 'X',
v_mode TYPE c VALUE 'A',
v_sessions TYPE i.
CONSTANTS
CONSTANTS : c_flagx TYPE c VALUE 'X',
c_slash TYPE c VALUE '/',
c_onli(4) TYPE c VALUE 'ONLI',
c_vl02(4) TYPE c VALUE 'VL02',
c_s TYPE c VALUE 'A'.
FORM f_f4_input_file .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = p_ifile.
ENDFORM. " f_f4_input_file
*& Form f_load_file
FORM f_load_file .
v_ifile = p_ifile.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_ifile
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = i_fdata
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
*Text-103-Input file does not exist.
MESSAGE e000 WITH text-103 .
ELSEIF NOT i_fdata IS INITIAL.
DELETE i_fdata WHERE data = space.
DESCRIBE TABLE i_fdata LINES v_input.
ENDIF.
IF v_input EQ 0.
Text-104 - Input file is empty.
MESSAGE e000 WITH text-104 .
ENDIF.
ENDFORM. " f_load_file
*& Form f_check_sessions
FORM f_check_sessions .
IF p_sess IS INITIAL.
MESSAGE e000 WITH text-106.
ELSE.
v_sessions = v_input DIV p_sess.
ENDIF.
ENDFORM. " f_check_sessions
*& Form f_process_bdc
text
FORM f_process_bdc.
LOOP AT i_fdata INTO wa_fdata.
SPLIT wa_fdata AT cl_abap_char_utilities=>horizontal_tab
INTO wa_final-matnr
wa_final-bismt.
APPEND wa_final TO i_final.
CLEAR wa_fdata.
ENDLOOP.
IF rad1 = c_flagx.
PERFORM f_passbdc_vl02.
ELSEIF rad2 = c_flagx.
PERFORM f_sessions_vl02.
ENDIF.
ENDFORM. "f_process_bdc
To populate the Screen information
p_program Program Name
p_dynpro Screen Number
FORM bdc_dynpro USING p_program TYPE any
p_dynpro TYPE any.
CLEAR wa_bdcdata.
Populate the BDC structure with the Screen Information.
Move the Program name PROGRAM
wa_bdcdata-program = p_program.
Move the Screen Number DYNPRO
wa_bdcdata-dynpro = p_dynpro.
Indicate the beginning of a new screen
wa_bdcdata-dynbegin = c_flagx.
APPEND wa_bdcdata TO i_bdcdata.
ENDFORM. "f_bdc_dynpro
*& Form f_passbdc_vl02
text
FORM f_passbdc_vl02.
DATA: l_lines_im TYPE i.
SORT i_final BY matnr ASCENDING.
CLEAR wa_final.
LOOP AT i_final INTO wa_final.
CLEAR: i_bdcmsgcoll[],
wa_bdcmsgcoll,
wa_bdcdata.
CLEAR: i_bdcdata[].
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RMMG1-MATNR'
wa_final-matnr.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
'X'.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MARA-BISMT'.
perform bdc_field using 'MARA-BISMT'
wa_final-bismt.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'MM02'.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'MM03'.
CALL TRANSACTION 'MM02' USING i_bdcdata
MODE v_mode
UPDATE c_s
MESSAGES INTO i_bdcmsgcoll.
If error occurred in call transaction 'VA02' then stores all
information of failed records into internal table i_error_im.
IF sy-subrc NE 0.
DESCRIBE TABLE i_bdcmsgcoll LINES l_lines_im.
CLEAR wa_bdcmsgcoll.
READ TABLE i_bdcmsgcoll INTO wa_bdcmsgcoll INDEX l_lines_im.
To capture success and error messages in BDC.
CALL FUNCTION 'FORMAT_MESSAGE' "#EC *
EXPORTING
id = wa_bdcmsgcoll-msgid
lang = wa_bdcmsgcoll-msgspra
no = wa_bdcmsgcoll-msgnr
v1 = wa_bdcmsgcoll-msgv1
v2 = wa_bdcmsgcoll-msgv2
v3 = wa_bdcmsgcoll-msgv3
v4 = wa_bdcmsgcoll-msgv4
IMPORTING
msg = wa_error-message
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
ELSE.
WRITE: text-111 COLOR 7.
ENDIF.
CLEAR: wa_final.
REFRESH i_bdcdata.
ENDLOOP.
ENDFORM. "f_passbdc_va02
*& Form bdc_field
text
-->P_FNAM text
-->P_FVAL text
FORM bdc_field USING p_fnam TYPE any
p_fval TYPE any.
CLEAR wa_bdcdata.
Populate the Field Name
wa_bdcdata-fnam = p_fnam.
Populate the field value
wa_bdcdata-fval = p_fval.
APPEND wa_bdcdata TO i_bdcdata.
ENDFORM. "f_bdc_field
*& Form f_sessions_vl02
text
FORM f_sessions_vl02 .
DATA: l_sindex TYPE sy-tabix VALUE 1,
l_eindex TYPE sy-tabix,
l_flag TYPE c VALUE space.
l_eindex = v_input.
SORT i_final BY matnr ASCENDING.
DO p_sess TIMES.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = 'Y_VL02_NIK'
user = sy-uname
keep = c_flagx
EXCEPTIONS
client_invalid = 1
destination_invalid = 2
group_invalid = 3
group_is_locked = 4
holddate_invalid = 5
internal_error = 6
queue_error = 7
running = 8
system_lock_error = 9
user_invalid = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CLEAR wa_final.
CLEAR: i_bdcdata[].
LOOP AT i_final INTO wa_final FROM l_sindex TO l_eindex .
IF l_flag = v_sessions.
CLEAR l_flag.
EXIT.
ENDIF.
l_flag = l_flag + 1.
CLEAR: i_bdcdata[].
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RMMG1-MATNR'
wa_final-matnr.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
'X'.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MARA-BISMT'.
perform bdc_field using 'MARA-BISMT'
wa_final-bismt.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'MM02'.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'MM03'.
l_sindex = l_sindex + 1.
ENDLOOP.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
not_open = 1
queue_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDDO.
ENDFORM. " f_sessions_vl02
*& Form f_report_header
FORM f_report_header .
FORMAT COLOR COL_HEADING INTENSIFIED ON.
ULINE.
text-201 - Company: Carrier
text-102- Batch Data Communication.
text-202 - System: SAP
WRITE: /1 sy-vline,
3 text-201,
50 text-102,
100 text-202,
AT sy-linsz sy-vline.
text-203 - Program:
text-204 - Date/Time:
WRITE: /1 sy-vline,
3 text-203, sy-repid ,
100 text-204,sy-datum ,c_slash, sy-uzeit,
AT sy-linsz sy-vline.
text-205 - User ID:
text-206 - Page:
WRITE: /1 sy-vline,
3 text-205, sy-uname,
100 text-206, sy-pagno,
AT sy-linsz sy-vline.
FORMAT COLOR OFF.
ULINE.
ENDFORM. " f_report_header
FORM bdc_transaction USING tcode.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = tcode
TABLES
dynprotab = i_bdcdata
EXCEPTIONS
internal_error = 1
not_open = 2
queue_error = 3
tcode_invalid = 4
printing_invalid = 5
posting_invalid = 6
OTHERS = 7.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
WRITE: / text-109 ,wa_final-matnr,
text-110 .
ENDIF.
ENDFORM. "bdc_transaction -
How to compare two internal table and store value in third table
Dear All,
There is two tabel say I_T1 & T2, in I_T1 there are 4 rows , in T2 there are multiple rows against the same field. Say there is a filed X common in both table .
Value of I_T1-X are
10
20
50
90
and value ot T2-X are
10
15
20
30
40
50
.100
Now i want to fetch data form T2 against the common field of I_T1-X and store into other internal table.
Plz suggest me the proper way of doing this.
Rewards points assured for proper answer.
Regards,
Gulrez Alamhi this is like your requirement.
in this i am storing the values into the final table
REPORT ZZZZ000000.
tables:mara,marc,mard,makt.
data:begin of it_mara occurs 0,
matnr like mara-matnr,
mtart like mara-mtart,
meins like mara-meins,
end of it_mara.
data:begin of it_marc occurs 0,
matnr like marc-matnr,
pstat like marc-pstat,
werks like marc-werks,
end of it_marc.
data:begin of it_mard occurs 0,
werks like mard-werks,
lgort like mard-lgort,
labst like mard-labst,
end of it_mard.
data:begin of it_final occurs 0,
matnr like mara-matnr,
mtart like mara-mtart,
meins like mara-meins,
pstat like marc-pstat,
werks like marc-werks,
lgort like mard-lgort,
labst like mard-labst,
maktx like makt-maktx,
end of it_final.
select-options:s_matnr for mara-matnr.
select matnr
mtart
meins
from mara
into table it_mara
where matnr in s_matnr.
if not it_mara[] is initial.
select matnr
pstat
werks
from marc
into table it_marc
for all entries in it_mara
where matnr = it_mara-matnr.
if not it_marc[] is initial.
select werks
lgort
labst
from mard
into table it_mard
for all entries in it_marc
where werks = it_marc-werks.
endif.
endif.
loop at it_mara.
it_final-matnr = it_mara-matnr.
it_final-mtart = it_mara-mtart.
it_final-meins = it_mara-meins.
read table it_marc with key matnr = it_mara-matnr.
it_final-werks = it_marc-werks.
it_final-pstat = it_marc-pstat.
read table it_mard with key werks = it_marc-werks.
it_final-lgort = it_mard-lgort.
it_final-labst = it_mard-labst.
if sy-subrc = 0.
select maktx from makt into it_final-maktx where matnr = it_final-matnr.
endselect.
endif.
append it_final.
endloop.
loop at it_final.
write:/ it_final-matnr under 'material',
it_final-mtart under 'material type',
it_final-meins under 'unit of measure',
it_final-werks under 'plant' ,
it_final-pstat under 'status',
it_final-lgort under 'storage loc',
it_final-labst under 'stock',
it_final-maktx.
endloop.
reward points if useful,
venkat. -
HI all!
I have two internal tables with single field values as below :
1st Internal Table : A,B,C,D
2nd Internal Table : A,B,C,D,E,F,G,
Now I want to compare these two Int. tables and delete the second int. table with values which are not there in the first int. table.Any simple logic to get this.
Regards
PavanSort internal table 1 by A B C D.
Now ..
copy contents of 2nd table to a temp table.
loop at 2nd internal table.
read 1st internal table with key a = 2internal table a
b = 2internal table b
c = 2internal table c
d = 2internal table d.
if sy-subrc ne 0.
delete entry from temp table.
now refresh table 2.
copy contents of temp to table 2.
Guys,
I guess DELETING THE SAME TABLE WITHIN A LOOP .. ENDLOOP is not advisable.Please correct me if i m wrong.
endif.
endloop.
Message was edited by: Nishanth Bhandar
Message was edited by: Nishanth Bhandar -
hi everybody
i have two internal tables ITAB1 AND ITAB2
I WANT TO COMPARE THE CONTENTS OF THESE INTERNAL TABLES HOW TO DO THIS
REGARDS
HRIDHANJILIHello Hridhayanjili
The most detailed comparison is to use the same logic as change documents are prepared. Assuming both of your itabs are of structure struc_a. Then define the following type:
TYPES: BEGIN OF ty_s_itab_di.
INCLUDE TYPE struc_a.
TYPES: CHIND TYPE bu_chind.
TYPES: END OF ty_s_itab_di.
TYPES: ty_t_itab_di TYPE STANDARD TABLE OF ty_s_itab_di
WITH DEFAULT KEY.
DATA:
gt_itab_old TYPE ty_t_itab_di,
gt_itab_new TYPE ty_t_itab_di.
Fill itabs gt_Itab_old with the corresponding data of itab1 and gt_itab_new with the corresponding data of itab2.
Very important: sort you itabs either by all key fields or by all fields.
Call function CHANGEDOCUMENT_PREPARE_TABLES with the following parameters
- CHECK_INDICATOR = ' '
- TABLE_NEW = gt_Itab_new
- TABLE_OLD = gt_itab_old
The function module will remove identical lines from both itabs. New entries in gt_itab_New will have CHIND = 'I' and deleted entries in gt_itab_old will have CHIND = 'D'.
Read the documentation of the function module and play around with it. You will see that this a quite easy yet powerful approach for comparing itabs.
Regards
Uwe -
Problem while comparing two internal tables
I have to modify work start date which are initial in the data base table for the records in the flat file.
my code is:
REPORT ZAUFK_WORKSTARTDATE_UPDATE .
Tables Declaration
TABLES: AUFK.
Type pools Declaration
TYPE-POOLS : SLIS.
Internal Table Declaration
DATA: I_AUFK LIKE AUFK OCCURS 0 WITH HEADER LINE,
IT_AUFK LIKE AUFK OCCURS 0 WITH HEADER LINE,
ITAB1 LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF I_AUFK1 OCCURS 0,
AUFNR(12),
AUART(4),
END OF I_AUFK1.
Data Declaration
DATA I_FIELDCAT TYPE SLIS_FIELDCAT_ALV OCCURS 0.
DATA WA_FCAT LIKE LINE OF I_FIELDCAT.
DATA: B1 TYPE I VALUE 1,
C1 TYPE I VALUE 1,
B2 TYPE I VALUE 256,
C2 TYPE I VALUE 65536.
Selection Screen Declaration
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_FILE LIKE RLGRAP-FILENAME.
SELECT-OPTIONS: S_AUFNR FOR AUFK-AUFNR,
S_AUART FOR AUFK-AUART.
PARAMETERS: P_USER7 LIKE AUFK-USER7 DEFAULT '20070101' OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
PARAMETERS: R1 RADIOBUTTON GROUP G1 DEFAULT 'X' USER-COMMAND UCOMM1, " Upload using File Path
R2 RADIOBUTTON GROUP G1. " Uplaod using particular IO's
SELECTION-SCREEN END OF BLOCK B2.
To get F4 Help for File path on selection screen.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
IMPORTING
FILE_NAME = P_FILE.
To disbale the filepath when r2 radiobutton is selected
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
Check if R1 is checked
IF R1 = 'X'.
IF SCREEN-NAME = 'S_AUFNR-LOW' OR
SCREEN-NAME = 'S_AUFNR-HIGH' OR
SCREEN-NAME = 'S_AUART-LOW' OR
SCREEN-NAME = 'S_AUART-HIGH'.
Make the Internal order number and order type field disable from the selection screen
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
ELSEIF R2 = 'X' AND SCREEN-NAME = 'P_FILE'.
Make the file path field disappear from the selection screen
SCREEN-INPUT = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
Start of executable code
START-OF-SELECTION.
To get the relavent IO data from the order master data table
SELECT *
FROM AUFK
INTO TABLE I_AUFK
WHERE AUFNR IN S_AUFNR
AND AUART IN S_AUART
AND ( AUART = '5200' OR AUART = '5500'
OR AUART = '5700' OR AUART = '8500'
OR AUART = '8700' ).
Table must be updated using flat file
IF R1 = 'X'.
To Upload Excel sheet data into an internal table
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = B1
I_BEGIN_ROW = C1
I_END_COL = B2
I_END_ROW = C2
TABLES
INTERN = ITAB1
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
To organize the data in the internal table(excel data) as per our requirement
PERFORM ORGANIZE_UPLOADED_DATA.
<b> LOOP AT I_AUFK1.
Comparing the excel data and the database table data
READ TABLE I_AUFK WITH KEY AUFNR = I_AUFK1-AUFNR.
IF SY-SUBRC EQ 0.
Check if the the work start date is initial(blank)
IF I_AUFK-USER7 IS INITIAL.
If work start is initial move the value in p_user7 to the work start date field in i_aufk
MOVE P_USER7 TO I_AUFK-USER7.
MODIFY I_AUFK.
Moving the data which is changed into it_aufk internal table(this table is for displaying the updated records)
MOVE-CORRESPONDING I_AUFK TO IT_AUFK.
APPEND IT_AUFK.
ENDIF.
ENDIF.
ENDLOOP.
endif.</b>
WA_FCAT-FIELDNAME = 'AUFNR'.
WA_FCAT-TABNAME = 'I_AUFK'.
WA_FCAT-SELTEXT_M = 'Internal Order Number'.
WA_FCAT-OUTPUTLEN = 12.
APPEND WA_FCAT TO i_fieldcat.
WA_FCAT-FIELDNAME = 'AUART'.
WA_FCAT-TABNAME = 'I_AUFK'.
WA_FCAT-SELTEXT_M = 'Order Type'.
WA_FCAT-OUTPUTLEN = 4.
APPEND WA_FCAT TO I_FIELDCAT.
WA_FCAT-FIELDNAME = 'KTEXT'.
WA_FCAT-TABNAME = 'I_AUFK'.
WA_FCAT-SELTEXT_M = 'Description'.
WA_FCAT-OUTPUTLEN = 40.
APPEND WA_FCAT TO I_FIELDCAT.
WA_FCAT-FIELDNAME = 'USER7'.
WA_FCAT-TABNAME = 'I_AUFK'.
WA_FCAT-SELTEXT_M = 'Work Start Date'.
WA_FCAT-OUTPUTLEN = 10.
APPEND WA_FCAT TO I_FIELDCAT.
Updating the AUFK(Internal Order Data Table) using i_aufk
*MODIFY AUFK FROM TABLE I_AUFK.
Check if the database table is modified
*IF SY-SUBRC = 0.
Display the modified data
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_GRID_TITLE = 'List of updated Records'
IT_FIELDCAT = I_FIELDCAT[]
TABLES
T_OUTTAB = IT_AUFK[]
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
ENDIF.
*& Form ORGANIZE_UPLOADED_DATA
text
FORM ORGANIZE_UPLOADED_DATA .
SORT ITAB1 BY ROW COL.
LOOP AT ITAB1.
CASE ITAB1-COL.
WHEN 1.
I_AUFK1-AUFNR = ITAB1-VALUE.
WHEN 2.
I_AUFK1-AUART = ITAB1-VALUE.
ENDCASE.
AT END OF ROW.
APPEND I_AUFK1.
ENDAT.
ENDLOOP.
LOOP AT I_AUFK1.
CONCATENATE '000000' I_AUFK1-AUFNR INTO I_AUFK1-AUFNR.
MODIFY I_AUFK1.
ENDLOOP.
ENDFORM. " ORGANIZE_UPLOADED_DATA
The bold are is were i'm facing problem. Please help me .its urgent.Hi try using the below code...
LOOP AT I_AUFK1.
Comparing the excel data and the database table data
READ TABLE I_AUFK WITH KEY AUFNR = I_AUFK1-AUFNR.
IF SY-SUBRC EQ 0.
Check if the the work start date is initial(blank)
IF I_AUFK-USER7 IS INITIAL.
If work start is initial move the value in p_user7 to the work start date field in i_aufk
MOVE P_USER7 TO I_AUFK-USER7.
[<u>b]MODIFY I_AUFK from i_aufk transporting user7.</b></u>
Moving the data which is changed into it_aufk internal table(this table is for displaying the updated records)
MOVE-CORRESPONDING I_AUFK TO IT_AUFK.
APPEND IT_AUFK.
ENDIF.
ENDIF.
ENDLOOP.
endif.
if you can't still solve some more questions
what is teh sy-subrc of teh read ..
what does the header line contain after teh read
and what happens after modify.. does the contents change? -
Comparing each value of two internal tables
HI everybody,
i have two internal tables itab1 and itab2 same structure
both r having four fields each and field with values
now i need to compare the two internal tables
and if every value of itab1 matches itab2
then i have to write one select quirie for the following given description
compare past and current shipping point
compare internal_table2 and internal_table3
if entry in internal_table2 and internal table3 match
variable_tknum = internal_table2-tknum
endif.
for each entry that matches:
select vlabdata into zi_vlabdata from vlbl where vbeln = variable_tknum and vlbl-vlabtyp = 'ZIBOOKNO'.
plz give me solution for this
thanks
hridhayanjili.sort : ITAB1 by f1,f2,f3,f4,
ITAB2 by f1,f2,f3,f4.
LOOP AT ITAB1.
READ TABLE ITAB2 WITH KEY F1 = ITAB1-F1
F2 = ITAB1-F2
F3 = ITAB1-F3
F4 = ITAB1-F4 BINARY SEARCH.
IF SY-SUBRC = 0.
*--all the fields of ITAB1 and ITAB2 are matching .
*--write your logic here
ELSE.
*--ITAB1 and ITAB2 records are not matching.
ENDIF.
ENDLOOP.
Regards
Srikanth
Message was edited by: Srikanth Kidambi -
Joining Two Internal Tables - ( Urgent )
Could anybody please give me the whole code for joining two internal tables
and putting the data in a third internal table. Please, very urgent.
Regards,
SAURAVHi,
Refer this code
*& Form SUB_READ_VBRK
text
FORM sub_read_vbrk.
SELECT vbeln
rplnr
bukrs
FROM vbrk
INTO TABLE it_vbrk
WHERE vbeln IN s_vbeln
AND rplnr NE ' '.
IF sy-subrc EQ 0.
SORT it_vbrk BY rplnr.
ENDIF.
ENDFORM. " SUB_READ_VBRK
*& Form SUB_READ_FPLTC
text
FORM sub_read_fpltc.
IF NOT it_vbrk[] IS INITIAL.
SELECT fplnr
fpltr
ccnum
FROM fpltc
INTO TABLE it_fpltc
FOR ALL ENTRIES IN it_vbrk
WHERE fplnr EQ it_vbrk-rplnr
AND ccins EQ 'GIFC'.
IF sy-subrc EQ 0.
SORT it_fpltc BY fplnr.
ENDIF.
ENDIF.
ENDFORM. " SUB_READ_FPLTC
*& Form SUB_COLLECT_DATA
text
FORM sub_collect_data.
*--Local variables
DATA : lv_count(3) TYPE c.
IF NOT it_fpltc[] IS INITIAL.
LOOP AT it_fpltc INTO wa_fpltc.
lv_count = wa_fpltc-fpltr+3(3).
wa_final-ccnum = wa_fpltc-ccnum.
wa_final-rfzei = lv_count.
CLEAR : wa_vbrk.
READ TABLE it_vbrk INTO wa_vbrk WITH KEY rplnr = wa_fpltc-fplnr
BINARY SEARCH.
IF sy-subrc EQ 0.
wa_final-vbeln = wa_vbrk-vbeln.
wa_final-bukrs = wa_vbrk-bukrs.
ENDIF.
APPEND wa_final TO it_final.
CLEAR : wa_vbrk,
wa_fpltc,
lv_count.
ENDLOOP.
ENDIF.
ENDFORM. " SUB_COLLECT_DATA
Regards,
prashant -
How to delete the matching records from two internal tables
Hi ,
I have two internal tables say A and B of the same type. If A has 10 records and B has 4 records , I want to delete the 4 records in B from A .
loop at B into wa .
delete A where key = wa - key .
endloop.
takes a long time if the table B is huge. how can I improve the performance.
Thanks.
GayathriHi Gayathri,
You could try field-symbols. It reduces the data transfer from the internal table B to the work area.
field-symbols <fs_itab_b> like line of B.
loop at B assigning <fs_itab_b>.
delete A where key = <fs_itab_b>?-key.
endloop.
Regards,
<a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=zwcc%2fwm4ups%3d">anand Mandalika</a>. -
Compare multiple variable selections between two internal tables
I am trying to work out the syntax for the following, however i am stumped on the 2nd part of the requirement....
I have two internal tables. and i need to compare the records.
1st, line by line, which i can do, however the 2nd requirement, i need to check a range of data against the same table...
here is an example of the tables:
Internal Table1 has the following records.
TL1
TL2
TL3
TL4
TL5
TL6
Internal table 2 has the following records...
LDOC1 TL1
LDOC1 TL2
LDOC1 TL3
LDOC1 TL7
LDOC2 TL1
LDOC2 TL5
LDOC3 TL6
LDOC3 TL7
but for the 2nd requirement, i have to group the LDOC1 (2, 3) and search for all TL* and report if they all exist, some exist or none exist within the 1st internal table.
so for requirement 1, the answer would be yes (as i can do a read table using the TL*), however i am not sure how i can check "for all entries" for TL1, Tl2, TL3, TL7 and return that only some entries exist.... LDOC1 should return "some", LDOC2 should return "all" and LDOC3 should return "none".
Hopefully that makes sense???
Can someone give me a keyword to investigate as i am not sure the At new would work.... Unless i do an at new and then loop and maybe add the record to a "range" to then compare and log the result as it runs through each result...
so if Itab1 = itab2 then variable = yes. else None.
if variable = yes, and itab1 = itab2 then variable = yes.
if variable = yes and itab1 <> itab2 then variable = some.
would that work?? i am worried about performance too as there could be 1000's of records....
and can i have an "at end" so at end, if variable = yes, then variable = all?
i have written all the rest of the report to get all the data into these tables... i am just a little baffled as to how i can validate and compare the multiple selection.... :o(Hi,
It is really confusing :-).. But i have tried to figure out.. may be this could be useful for you.
Internal Table1 has the following records.
TL1
TL2
TL3
TL4
TL5
Internal table 2 has the following records...
LDOC1 TL1
LDOC1 TL2
LDOC1 TL3
LDOC1 TL7
LDOC2 TL1
LDOC2 TL5
LDOC3 TL6
LDOC3 TL7
itab3[] = itab2[]
sort itab3 by field1.
delete adjacent duplicates from itab3 comparing field1.
itab3
LDCO1
LDCO2
LDCO3
loop at itab3.
clear: lv_flag, index, ind.
loop at itab2 where field1 = itab3-field1.
index = index + 1.
read table itab1 with key field1 = itab2-field2.
if sy-subrc NE 0.
lv_flag = 'X'.
ind = ind + 1.
endif.
endloop.
if lv_flag = 'X'.
if ind = index.
lv_val = 'NONE'.
elseif ind NE index.
lv_val = 'SOME'.
endif.
else.
lv_val = 'ALL'.
endif.
"here you can modify itab3 with lv_val in one field, so that you can figure out which is SOME, NONE, ALL
endloop.
Regards,
senthil -
Find if there is any common record in two internal tables
hi,
I have two internal tables of same structure... say A and B.
I need to know if there are any common lines in them.
one way is to loop in any one of them and keep executing a read on the other.
can anyone suggest a better way.
thanks,
Arindam.Hi Arindam,
To find common records in two internal tables, they can be compared
If INT_DATA1 EQ INT_DATA2.
endif.
The first criterion for comparing internal tables is the number of lines they contain. If two internal tables contain the same number of lines, they are compared line by line, component by component.
If the internal tables contain the same number of records and are sorted on the same key, the comparison stops at the line where the records are not common. For example, if the number of common records is 4, the comparison stops at the 5th line and sy-tabix becomes 5.
Hope it helps.
Regards,
Nupur -
How to get records into two internal tables from 1 internal table?
VERME LGPLA
252.000 EA 300 0149A 410 0149
276.000 EA 300 0149A 410 0107
516.000 EA 300 0149A 400 3013
528.000 EA 300 0149A 400 3013
528.000 EA 300 0149A 400 3013
528.000 EA 300 0149A 400 3013
528.000 EA 300 0149A 400 3013
528.000 EA 300 0149A 400 3013
528.000 EA 300 0149A 400 3013
I have above records in my one internal table ITAB.
I want to divide these records in to two internal tables ITAB1 and ITAB2. and this is based on LGPLA and VERME.
If there is same LGPLA (last column) and different VERME (1st column) available, then it should append ITAB1
Otherwise it should append ITAB2.
ITAB1 should contain ,
516.000 EA 300 0149A 400 3013
ITAB2 should contain ,
252.000 EA 300 0149A 410 0149
276.000 EA 300 0149A 410 0107
528.000 EA 300 0149A 400 3013
528.000 EA 300 0149A 400 3013
528.000 EA 300 0149A 400 3013
528.000 EA 300 0149A 400 3013
528.000 EA 300 0149A 400 3013
528.000 EA 300 0149A 400 3013
I have tried with this code
Loop at itab .
IF lv_prev_lgpla = wa-lgpla and lv_prev_verme <> wa-verme.
APPEND wa TO itab1.
else.
APPEND wa TO itab2.
endif.
lv_prev_lgpla = wa-vlpla.
lv_prev_verme = wa-anfme.
Endloop.
But it contains,
516.000 EA 300 0149A 400 3013
in table ITAB2 which I dont want.
Points rewarded soon.
Regards,
RonnDear Ronny,
i am gining the solution below.But would request you to change your ITAB STRUCTURE LIKE THIS BEFORE USING THE CODE
VERME LGPLA
252.000 EA 300 0149A 0149 410
276.000 EA 300 0149A 0107 410
516.000 EA 300 0149A 3013 400
528.000 EA 300 0149A 3013 400
528.000 EA 300 0149A 3013 400
528.000 EA 300 0149A 3013 400
528.000 EA 300 0149A 3013 400
528.000 EA 300 0149A 3013 400
528.000 EA 300 0149A 3013 400
then do as follows.
SORT ITAB BY LGPLA VERME.
LOOP AT ITAB INTO WITAB.
W_INDEX = SY-TABIX.
here take all the abOve fields in temp fieds.
LW_VERME = WITAB-VERME..AND SO ON.
AT END OF LGPLA.
MOVE: all LW fields to work area of ITAB1
APPEND work area of ITAB1 TO ITAB1.
DELETE ITAB INDEX W_INDEX
ENDAT.
ENDLOOP.
Basically what u r doing here is thet u r using processing event.
So whenerv VERME changes this event will be triggered.
Just try this out...something like this only will be he logic.
Please let me know further -
Function module for comparing contents of two internal tables
Hi All,
Is there any function module to compare contents of two internal tables of same structure?
If yes please let me know.
Thanks in advance.
AmolHi
call SE16 with table TFTIT in order to get a full list (it will be long...)
A list of FMs with parameters can be found in table FUNCT.
Finally go to sm37rsdf4
that will give you all the function modules with description
Here is the list:
http://www.erpgenie.com/abap/functions.htm
hope this helps...
Regards
CSM Reddy -
Hi,
I have two internal tables it_tab1 and it_tab2. The fields are,
it_tab1 it_tab2
F1 F1
F2 F2
F3 F4
F6 F5
I want to <b>merge</b>(coloumn wise) these two internal tables into a new internal table it_tab3 where it_tab3 has fields,
F1, F2, F3, F4, F5, F6.(All the fields)
Here, in it_tab1 and in it_tab2 the fields <b>F1 and F2 are the key fields</b>.The number of records in the two internal tables are different.
Can anybody help me. thanx for spending ur time.hi,
try this
hi,
itab1 - first
itab2 - second
itab3 - both
data l_count type i.
l_count = 1.
loop at itab1.
read table itab2 with key f1 = itab1-f1 f2 = itab1-f2.
itab3 = itab1
if sy-subrc is initial
itab3-field6 = itab2-field3.
itab3-field7 = itab2-field4.
append itab3.
endif.
endloop.
loop at itab2.
itab3 = itab2
read table itab1 with key f1 = itab2-f1 f2 = itab2-f2.
if sy-subrc is initial
itab3-field6 = itab1-field3.
itab3-field7 = itab1-field4.
append itab3.
endif.
endloop.
sort itab3 by f1 f2.
delete adjacent duplicates by comparing f1 f2.
hope this will solve your problem
cheers,
sasi
Cheers,
Sasi -
Reg comparison of two internal tables
hi friends,
please help me solving this.
there are two internal tables t_zvs38 and t_value
1.t_value like seahlpres
2.t_zvs38 like zvs38.
values in t_value will be like this.
first line wil contain zmdtype(mandatory document) and second line will contain
zmdtypet (the description for zmdtype).
eg.
D001 -
-zmdtype
internal----
zmdtypet
D002
external
D003
renewal
values in t_zvs38.
for a particular sales.org the zmdtype is filled.
select vkorg zmdtype into corrsponding fields of table t_zvs38
where vkorg = p_vkorg.
Now i want to compare t_value and t_zvs38 with field zmdtype
and delete the contents of t_value which are not in t_zvs38.
i have written like this.
loop at t_value.
read table t_zvs38 with key zmdtype = t_value-string.
if sy-subrc ne 0.
delete t_value. "to delete zmdtype
sy-tabix = sy-tabix + 1.
delete t_value. " to delete zmdtypet
else.
sy-tabix = sy-tabix +2. "to go to next zmdtype.
endif.
endloop.
but it is deleting all the contents of t_value.
points are assured.CLEAR zvs32t.
SELECT zvs32tzmdtype zvs32tzmdtypet
INTO (zvs32t-zmdtype, zvs32t-zmdtypet)
FROM zvs32t
JOIN zvs32
ON zvs32tzmdtype = zvs32zmdtype
WHERE zvs32t~spras = sy-langu
AND zvs32~zfrenewal = space.
WRITE zvs32t-zmdtype TO t_value.
APPEND t_value.
WRITE zvs32t-zmdtypet TO t_value.
APPEND t_value.
ENDSELECT.
SELECT vkorg vkbur zmdtype FROM zvs38 INTO CORRESPONDING FIELDS OF TABLE t_zvs38
WHERE vkorg = p_vkorg
AND vkbur = p_vkbur.
LOOP AT t_value INTO wa_area1.
v_index = sy-tabix.
READ TABLE t_zvs38 INTO wa_area2 WITH KEY zmdtype = wa_area1-string
BINARY SEARCH.
IF sy-subrc NE 0.
IF l_flag IS INITIAL.
DELETE t_value INDEX v_index.
ELSE.
CLEAR l_flag.
ENDIF.
ELSE.
l_flag = 'X'.
ENDIF.
ENDLOOP.
Using this code ,i am unable to ge the correct output.Thank u all for ur help.
Maybe you are looking for
-
Apparently I am in the extreme minority, but I really do miss the save dialog box when saving attachments in Mail. Is there anyway to kill off the automatic saving to the Downloads folder? And no I am not interested in merely moving the default from
-
When I watch a show at http://xfinitytv.comcast.net/ the progress bar is not shown. I attached a picture to better explain. I watched every show entirely. When I watched part of a show and stopped, the bar would show partial progress and I could resu
-
Contact's numbers dumped with 6.1
I updated my iPhone 5 to 6.1 today. It asked me if I wanted to sync my contacts with iCloud, I said yes. After the update finished I lost all my contact's phone numbers. All the contacts are still there, just no phone numbers. Any way to recover that
-
How do I truncate an audio file?
I received an audio file from a friend and I'd like to truncate it. How do I do that?
-
How to switch off a workflow ?
Hi , Anybody has an idea how to switch off a workflow ? Reply soon. Thanks a lot, Sandip.