Modify BSEG from ZBSEG were ZBSEG has different field length

Modify BSEG from ZBSEG were ZBSEG has different field length



I'm trying to use following :
update bseg from zbseg. -> where tables are not from same length ( ZBSEG is reduced version of BSEG).



Whole idea is that BSEG is just an example, tables are dinamically changing where all cluster tables are covered. So everything should be dynamically. Table data from cluster is reduced to only several fields and copied to Transparent table ( Data dictionary in new transparent table has primary keys + only few of the field of cluster ) and afterwards data in transparent will be modified and copied back ( update ) to the cluster.



update bseg from zbseg -> following updates the field values from ZBSEG but for the rest will not keep old values , it will just put initial values.



I've tried with even I know that it couldn't be :



select *
from bseg
into table gt_bseg.



and right after:



select MANDT BUKRS BELNR GJAHR BUZEI BUZID AUGDT
from zbseg
into corresponding fields of table gt_bseg.



But it still overlaps those fields that are not considered in zbseg.



Maybe some operation that will update only certain number of fields exctracted from ZBEG into gt_bseg that comes directly from BSEG?



Any solutions ?



IMAGE : Looping over original full length and short table




2 Answers
2



I think you need get records from zbseg with limit because of there will be exists million records then get them from bseg one by one and update it, then remove or update flags of it from zbseg for performance.


tables: BSEG, ZBSEG.

data: GT_ZBSEG like ZBSEG occurs 1 with header line,
GS_BSEG type BSEG.

select *
into table GT_ZBSEG up to 1000 rows
from ZBSEG.

check SY-SUBRC is initial.
check SY-DBCNT is not initial.

loop at GT_ZBSEG.
select single * from BSEG into GS_BSEG
where BSEG~MANDT = GT_ZBSEG-MANDT
and BSEG~BUKRS = GT_ZBSEG-BUKRS
and BSEG~BELNR = GT_ZBSEG-BELNR
and BSEG~GJAHR = GT_ZBSEG-GJAHR
and BSEG~BUZEI = GT_ZBSEG-BUZEI.
if SY-SUBRC ne 0.
message E208(00) with 'Record not found!'.
endif.
if GS_BSEG-BUZID ne GT_ZBSEG-BUZID
or GS_BSEG-AUGDT ne GT_ZBSEG-AUGDT.
move-corresponding GT_ZBSEG to GS_BSEG.
update BSEG from GS_BSEG.
endif.
" delete same records and transfered
delete ZBSEG from GT_ZBSEG.
endloop.





Thanks for reply mkysoft. But everything is dynamic so I couldn't access them by the primary key. Therefore I must to do something that I realy don't like which is LOOP in LOOP so I will take original data and updated only corresponding fields from second table. Please take a look on the first post where I will post a picture from the loop. Thanks!
– Alexander
Aug 28 at 14:24






May be you can find key fields with FM BDL_DDIF_TABL_GET and create dynamic condition. On the other hand I think using native sql with row hash good option for determining changed rows. Then loop with them.
– mkysoft
Aug 28 at 14:31






Agreed with @mkysoft, a dynamic condition is easy to use (DATA where TYPE string. where = 'BSEG~MANDT = GT_ZBSEG~MANDT AND ...'. SELECT … WHERE (where)) ; prefer using RTTI, i.e. cl_abap_typedescr as explained by @AZn5ReD, over non supported function modules like (BDL_)DDIF_TABL_GET ; concerning the native SQL, generally it cannot be used on a clustered table (i.e. BSEG) because BSEG is a logical SAP-specific "view" of the real database table (which is RFBLG for BSEG).
– Sandra Rossi
Aug 29 at 4:51


DATA where TYPE string. where = 'BSEG~MANDT = GT_ZBSEG~MANDT AND ...'. SELECT … WHERE (where)





select SINGLE * from (tabname_new) ---> ZBSEG into <dyn_wa> ---> Field Symbol with ZBSEG structure WHERE (LV_WHERE_COND). LV_WHERE_COND = ( MANDT eq <dyn_wa_clust>-MANDT and BELNR eq <dyn_wa_clust>-BELNR and BUREG eq <dyn_wa_clust>-BUREG and LFDNR eq <dyn_wa_clust>-LFDNR ) Dump is raised with following reason : OBJECTS_NOT_FLAT ( The current statement is not supported for deep data objects. ) I also tried with ZBSEG~MANDT = <dyn_wa_clust>-MANDT but no success.
– Alexander
Sep 6 at 7:28






Nevermind for previous error. I fix it ! :) And it works very fast. Million thanks mkysoft !!
– Alexander
Sep 6 at 9:20




You could try to use the MODIFY statement to update the tables.



An other way to do it would be to use the cl_abap_typedescr to get the fields of each table and compare them for the update.



Here is an example of how to get the fields.


DATA : ref_table_des TYPE REF TO cl_abap_structdescr,
columns TYPE abap_compdescr_tab.

ref_table_des ?= cl_abap_typedescr=>describe_by_data( struc ).
columns = ref_table_des->components.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)