‎2010 Sep 03 6:22 AM
Hi,
I have a requirement to split a single amount and product into several parts. so far my logic is not working as only the first row is being fetched.
TYPES: BEGIN of map_tab,
ZPRODH4 TYPE NEWMAPPINGTABLE-/BIC/ZNEW_MP,
ZSPRATIO TYPE NEWMAPPINGTABLE-/BIC/ZSP_RATIO,
ZMATERIAL TYPE NEWMAPPINGTABLE-MATERIAL,
END OF map_tab.
Data:IT_MAP_TAB TYPE HASHED table of MAP_TAB with unique Key ZPRODH4,
wa_it_map_tab like line of IT_MAP_TAB.
Data rp TYPE _ty_s_TG_1.
LOOP AT RESULT_PACKAGE into rp.
Clear wa_it_map_tab.
read table IT_MAP_TAB into wa_it_map_tab with table key ZPRODH4 =
rp-prodh4.
IF sy-subrc EQ 0.
select SINGLE /BIC/ZNEW_MP /BIC/ZSP_RATIO MATERIAL into corresponding
fields of wa_it_map_tab from NEWMAPPINGTABLE
where PRODH4 = rp-PRODH4.
IF sy-subrc EQ 0.
rp-PRODH4 = wa_it_map_tab-ZPRODH4.
rp-AMOUNT = rp-AMOUNT * wa_it_map_tab-Zspratio.
rp-MATERIAL = wa_it_map_tab-ZMATERIAL.
ENDIF.
ENDIF.
MODIFY RESULT_PACKAGE FROM rp.
.
ENDLOOP.
<br><br>
This is how my tables looks like
Source Table
PROD AMOUNT
900006600999 1000
400004400000 500
NEW MAPPING TABLE
PROD NEWPROD MATERIAL SPLITRATIO
900006600999 1000066001111 7000 0.5
900006600999 1000066002222 7001 0.4
900006600999 1000066003333 7002 0.1
OLD MAPPING TABLE
PROD MATERIAL
4000044000000 7100
TARGET TABLE
PROD PROD3 MATERIAL AMOUNT
1000066001111 100006600 7000 500
1000066002222 100006600 7001 400
1000066003333 100006600 7002 100
4000044000000 400004400 7100 500
‎2010 Sep 03 6:35 AM
hi ,
will you explian clearly how is your data in internal table . how many internal table are there .
and what you want to do .
i will tell you how to split .
regards
Deepak.
‎2010 Sep 03 6:35 AM
hi ,
will you explian clearly how is your data in internal table . how many internal table are there .
and what you want to do .
i will tell you how to split .
regards
Deepak.
‎2010 Sep 03 6:47 AM
hi ,
use this logic
data : delimiter(1) value space.
or data : delemiter(1) value ' ' .
loop at internal table .
split internaltable at delimiter into some feilds .
append to another internal table by assigning those values in feilds of intrenal table .
endloop.
in such way you will get internal table with two seperate values prod and amount in different field .
Regards
Deepak.
‎2010 Sep 03 6:48 AM
Hi,
My requirement is to split the amount 1000 of one MAIN PRODUCT into several new products based on split ratio values in NEW MAPPING TABLE.
For example
PROD 900006600999 has amount 1000.
IN NEW MAPPING table this same PROD 900006600999 has 3 new Products which are
1000066001111
1000066002222
1000066003333
with different split ratio 0.5 , 0.4 and 0.1 respectively.
Now I want to split the amount 1000 into 3 different parts according to the split ratio assigned to the new products.
so I will hava a new amount after multiplying the split ratio with 1000.
1000066001111 - 500
1000066002222 - 400
1000066003333 - 100
secondly,
If MAIN PRODUCT ( PROD) is not found in NEW MAPPING TABLE then I should check the MAIN PRODUCT from OLD MAPPING TABLE and pick the amount without splitting it.
Finally we load MAIN PRODUCT ( PROD) with values coming NEWPROD into a new table ( TARGET )
So far I have 1 internal table for storing the data from NEW MAPPING TABLE.
thanks
Edited by: Bhat Vaidya on Sep 3, 2010 7:48 AM
Edited by: Bhat Vaidya on Sep 3, 2010 7:51 AM
‎2010 Sep 03 7:12 AM
HI BHAT ,
USE THIS LOGIC
THIS WILL SOLVE YOUR PROBLEM
ALSO GIVE PROPER NAME TO INTERNAL TABLE .
AS GIVEN BELOW .
LOOP AT IT_SOURCE .
READ TABLE IT_NEWMAP WITH KEY PROD = IT_SOURCE-PROD .
IF SY-SUBRC = 0 .
IT_TARGET-PROD = IT_NEWMAP-NEWPROD .
IT_TARGET-PROD3 = IT_NEWMAP-NEWPROD+0(9) .
IT_TARGET-MATERIAL = IT_NEWMAP-MATERIAL .
IT_TARGET-AMOUNT = ( IT_NEWMAP * ( 1 / IT_NEWMAP-SPLITRATIO )) .
APPEND IT_TARGET .
ELSE.
READ TABLE IT_OLDMAPWITH KEY PROD = IT_SOURCE-PROD .
IF SY-SUBRC = 0 .
IT_TARGET-PROD = IT_OLDMAP-PROD .
IT_TARGET-PROD3 = IT_OLDMAP-PROD+0(9) .
IT_TARGET-MATERIAL = IT_OLDMAP-MATERIAL .
IT_TARGET-AMOUNT = IT_SOURCE-AMOUNT .
APPEND IT_TARGET .
ENDIF
ENDIF.
ENDLOOP.
REGARDS
dEEPAK.
Moderator message: please do not write all upper case and use code markups!
Edited by: Thomas Zloch on Sep 3, 2010 9:10 AM
‎2010 Sep 03 8:15 AM
Your READ TABLE only gets 1 entry from IT_MAP_TAB
Replace
read table IT_MAP_TAB into wa_it_map_tab with table key ZPRODH4 = rp-prodh4.with
LOOP AT IT_MAP_TAB into wa_it_map_tab WHERE ZPRODH4 = rp-prodh4.And in this loop append an entry to your target internal table.
‎2010 Sep 03 9:24 AM
Hi,
I have tried and it doesn't work. Main product and amount are not splitted.
* Internal table for New Mapping table
TYPES: BEGIN OF new_tab,
PRODH4 TYPE /BIC/AZMAP_TAB00-PRODH4,
/BIC/ZNEW_MP TYPE /BIC/AZMAP_TAB00-/BIC/ZNEW_MP,
/BIC/ZSP_RATIO TYPE /BIC/AZMAP_TAB00-/BIC/ZSP_RATIO,
MATERIAL TYPE /BIC/AZMAP_TAB00-MATERIAL,
END OF new_tab.
* Internal table for old Mapping table
TYPES: BEGIN OF old_tab,
PRODH4 TYPE /BIC/AZPR4MTCV00-PRODH4,
MATERIAL TYPE /BIC/AZPR4MTCV00-MATERIAL,
END OF old_tab.
Data: it_tab TYPE STANDARD TABLE OF new_tab INITIAL SIZE 0,
wa_tab TYPE new_tab.
Data: it_oldtab TYPE STANDARD TABLE OF new_tab INITIAL SIZE 0,
wa_oldtab TYPE old_tab.
Data rp TYPE _ty_s_TG_1.
LOOP AT RESULT_PACKAGE INTO rp.
LOOP AT it_tab into wa_tab where PRODH4 = rp-PRODH4.
IF sy-subrc EQ 0.
rp-PRODH4 = wa_tab-/BIC/ZNEW_MP.
rp-MATERIAL = wa_tab-MATERIAL.
rp-AMOUNT = rp-AMOUNT * wa_tab-/BIC/ZSP_RATIO.
ELSE.
SELECT SINGLE PRODH4 MATERIAL from /BIC/AZPR4MTCV00 into corresponding
fields of wa_oldtab.
IF sy-subrc EQ 0.
rp-MaTERIAL = wa_oldtab-MATERIAL.
rp-PRODH4 = wa_oldtab-PRODH4.
rp-AMOUNT = rp-AMOUNT.
rp-PRODH3 = wa_oldtab-PRODH4+0(9).
ENDIF.
ENDIF.
ENDLOOP.
MODIFY RESULT_PACKAGE FROM rp.
ENDLOOP.
‎2010 Sep 03 9:33 AM
LOOP AT it_tab INTO wa_tab WHERE prodh4 = rp-prodh4.
IF sy-subrc EQ 0.
rp-prodh4 = wa_tab-/bic/znew_mp.
rp-material = wa_tab-material.
rp-amount = rp-amount * wa_tab-/bic/zsp_ratio.
ELSE.
SELECT SINGLE prodh4 material FROM /bic/azpr4mtcv00 INTO CORRESPONDING
FIELDS OF wa_oldtab.
IF sy-subrc EQ 0.
rp-material = wa_oldtab-material.
rp-prodh4 = wa_oldtab-prodh4.
rp-amount = rp-amount.
rp-prodh3 = wa_oldtab-prodh4+0(9).
ENDIF.
ENDIF.
ENDLOOP.change to
LOOP AT it_tab INTO wa_tab WHERE prodh4 = rp-prodh4.
rp-prodh4 = wa_tab-/bic/znew_mp.
rp-material = wa_tab-material.
rp-amount = rp-amount * wa_tab-/bic/zsp_ratio.
* append in some other target internal table and work from there
ENDLOOP.
‎2010 Sep 03 10:14 AM
Hi,
LOOP AT it_tab INTO wa_tab WHERE prodh4 = rp-prodh4.
rp-prodh4 = wa_tab-/bic/znew_mp.
rp-material = wa_tab-material.
rp-amount = rp-amount * wa_tab-/bic/zsp_ratio.
* append in some other target internal table and work from there
ENDLOOP.
I have already declared 2 internal tables to store the data coming from new mapping table and old mapping table. can you please give me an example of what I should do next i.e code snippet.
thanks
‎2010 Sep 03 10:31 AM
Try somehting like this. I am using the names from your examples and not from your source code.
*Source Table
*PROD AMOUNT
*900006600999 1000
*400004400000 500
*
*NEW MAPPING TABLE
*PROD NEWPROD MATERIAL SPLITRATIO
*900006600999 1000066001111 7000 0.5
*900006600999 1000066002222 7001 0.4
*900006600999 1000066003333 7002 0.1
*
*OLD MAPPING TABLE
*PROD MATERIAL
*4000044000000 7100
*
*TARGET TABLE
*
*PROD PROD3 MATERIAL AMOUNT
*1000066001111 100006600 7000 500
*1000066002222 100006600 7001 400
*1000066003333 100006600 7002 100
*4000044000000 400004400 7100 500
LOOP AT it_source INTO wa_source.
LOOP AT it_new_maptab INTO wa_new_maptab WHERE prod EQ wa_source-prod.
wa_target-prod = wa_new_maptab-newprod.
wa_target-prod3 = wa_new_maptab-newprod(9).
wa_target-material = wa_new_maptab-material.
wa_target-amount = wa_source-amount * wa_new_maptab-splitratio.
APPEND wa_target TO it_target.
ENDLOOP.
IF sy-subrc NE 0.
LOOP AT it_old_maptab INTO wa_old_maptab WHERE prod EQ eq WA_SOURCE-PROD.
wa_target-prod = wa_old_maptab-prod.
wa_target-prod3 = wa_old_maptab-prod(9).
wa_target-material = wa_old_maptab-material.
wa_target-amount = wa_source-amount.
APPEND wa_target TO it_target.
ENDLOOP.
ENDIF.
ENDLOOP.
‎2010 Sep 22 7:18 AM
Hi,
I rewrote the code the like this and it is still not working as the new value is not being fetched.
{* TABLES: ...
Defining tables
Tables: /BIC/OLDTABLE,/BIC/NEWTABLE.
$$ end of global - insert your declaration only before this line -
The follow definition is new in the BW3.x
TYPES:
BEGIN OF DATA_PACKAGE_STRUCTURE.
INCLUDE STRUCTURE /BIC/CS8ZSEM_TC03.
TYPES:
RECNO LIKE sy-tabix,
END OF DATA_PACKAGE_STRUCTURE.
DATA:
DATA_PACKAGE TYPE STANDARD TABLE OF DATA_PACKAGE_STRUCTURE
WITH HEADER LINE
WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 0.
New Material table
DATA: BEGIN OF I_S_NEWTAB,
PRODH4 TYPE /BIC/NEWTABLE-PRODH4,
/BIC/ZNEW_MP TYPE /BIC/NEWTABLE-/BIC/ZNEW_MP,
/BIC/ZSP_RATIO TYPE /BIC/NEWTABLE-/BIC/ZSP_RATIO,
MATERIAL TYPE /BIC/NEWTABLE-MATERIAL,
END OF I_S_NEWTAB.
Data: i_t_newtab LIKE TABLE OF I_S_NEWTAB.
*Old Material table
DATA: BEGIN OF I_S_OLDTAB,
PRODH4 TYPE /BIC/OLDTABLE-PRODH4,
MATERIAL TYPE /BIC/OLDTABLE-MATERIAL,
END OF I_S_OLDTAB.
DATA: i_t_oldtab like table of I_S_oldTAB.
data: e_s_result type STANDARD TABLE OF DATA_PACKAGE_STRUCTURE WITH
HEADER LINE
WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 0.
data: e_t_result type STANDARD TABLE OF DATA_PACKAGE_STRUCTURE WITH
HEADER LINE
WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 0.
data: amount type DATA_PACKAGE_STRUCTURE-/BIC/AMOUNT.
data: CUSTSOLD type DATA_PACKAGE_STRUCTURE-/BIC/CUSTSOLD.
selecting data from new table
Select PRODH4 /BIC/ZNEW_MP /BIC/ZSP_RATIO MATERIAL FROM /BIC/NEWTABLE
into corresponding fields of table i_t_newtab.
SORT i_t_newtab by PRODH4.
Selecting data from old material table
Select PRODH4 MATERIAL FROM /BIC/OLDTABLE into corresponding fields
of table i_t_oldtab.
SORT i_t_oldtab by PRODH4.
LOOP AT DATA_PACKAGE INTO e_s_result.
read table i_t_oldtab into i_s_oldtab with key PRODH4 =
e_s_result-PRODH4.
if sy-subrc EQ 0.
MOVE i_s_oldtab-PRODH4 to e_s_result-PRODH4.
MOVE i_s_oldtab-PRODH4(14) to e_s_result-PRODH3.
MOVE i_s_oldtab-MATERIAL to e_s_result-MATERIAL.
APPEND e_s_result to e_t_result.
ELSE.
LOOP AT i_t_newtab into i_s_newtab where PRODH4 = e_s_result-PRODH4.
amount = i_s_newtab-/BIC/ZSP_RATIO * e_s_result-/BIC/AMOUNT.
CONCATENATE DATA_PACKAGE-SOLD_TO i_s_newtab-PRODH4(10) into AMOUNT.
MOVE i_s_newtab-/BIC/ZNEW_MP to e_s_result-PRODH4.
MOVE i_s_newtab-MATERIAL to e_s_result-MATERIAL.
MOVE i_s_newtab-/BIC/ZNEW_MP(14) to e_s_result-PRODH3.
MOVE amount to e_s_result-/BIC/AMOUNT.
MOVE ZASTUOTE to e_s_result-/BIC/CUSTSOLD.
APPEND e_s_result to e_t_result.
ENDLOOP.
ENDIF.
ENDLOOP.
REFRESH DATA_PACKAGE.
MOVE e_t_result to DATA_PACKAGE[].}