Skip to Content

Abap code Logic for splitting is not working

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Best Answer
    Sep 03, 2010 at 05: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.

    Add comment
    10|10000 characters needed characters exceeded

    • 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[].}