Skip to Content
0
Dec 02, 2006 at 07:42 AM

ABAP LOGIC

54 Views

Respected Members

I have a problem need a logic to resolve it.

I have three Internal Tables.

DETAIL_TAB (Containing Profiles of all Employees)

Fields (PERNR, NAME, DOB, COUNT, degree, institution, passyear, organizatoin, join_date, leave_date )

EDU_TAB (Containing Education details of each PERNR can be 1 to Many )

Fields (PERNR Degree, Institution, PassYear COUNT)

EXP_TAB (Containing Experience of each pernr can be 1 to Many )

Fields (PERNR, Organization, join_date, leave_date, count)

Now the problem is that I want to move the fields of EDU_TAB and EXP_TAB to DETAIL_TAB.

If the same number of records exsists in EDU_TAB and EXP_TAB as in DETAIL_TAB for a PERNR then we can modify the DETAIL_TAB with new values of EDU_TAB and EXP_TAB if not then we insert a new record in DETAIL_TAB contaning values for EDU_TAB and EXP_TAB.

Suppose the following data is there in DETAIL_TAB.

PERNR NAME COUNT DEGREEE INSTITUION ORGANIZATION JOIN LEA

22 XY 1

23 AB 1

and in EDU_TAB

PERNR DEGREE INSTITUTION COUNT

22 MAB FG 1

22 MBA FG2 2

23 AC DM 1

23 ACCA FG 2

23 CA OP 3

and in EXP_TAB

PERNR ORG FROM TO COUNT

22 A 91 93 1

22 B 93 96 2

23 C 94 95 1

23 A 96 99 2

I Tried this.

LOOP AT EDU_TAB.

LOOP AT DETAIL_TAB WHERE PERNR EQ EDU_TAB-PERNR and COUNT EQ EDU_TAB-COUNT.

MOVE-CORRESPONDING EDU_TAB TO DETAIL_TAB.

MODIFY_TAB.

ENDLOOP.

LOOP AT EXP_TAB.

LOOP AT DETAIL_TAB WHERE PERNR EQ EXP_TAB-PERNR and COUNT EQ EXP_TAB-COUNT.

MOVE-CORRESPONDING EXP_TAB TO DETAIL_TAB.

MODIFY_TAB.

ENDLOOP.

ENDLOOP.

After above code DETAIL_TAB will be

PERNR NAME COUNT DEGREEE INSTITUION ORG FROM TO

22 XY 1 MAB FG A 91 93

23 AB 1 AC DM C 94 95

which is ok

Up to know I think it will work fine that is the Education and Expereince of each employee stores infront of his PERNR in DETAIL_TAB. But the problem is that Each perner can have more then one educations and job expereinces. For that we should Insert those records in DETAIL_TAB instead of MODIFYING DETAIL_TAB.

I tried this.

SORT DETAIL_TAB BY PERNR COUNT.

SORT EDU_TAB BY PERNR COUNT.

SORT EXP_TAB BY PERNR COUNT.

LOOP AT DETAIL_TAB.

LOOP AT EDU_TAB WHERE PERNR EQ DETAIL_TAB-PERNR AND COUNT NE DETAIL_TAB-COUNT.

DETAIL_TAB-PERNR = EDU_TAB-PERNR

DETAIL_TAB-DEGREE = EDU_TAB-DEGREE

DETAIL_TAB-INSTITUTION = EDU_TAB-INSTITUTION

DETAIL_TAB-PASSYEAR = EDU_TAB-PASSYEAR

DETAIl_TAB-COUNT = EDU_TAB-COUNT

INSERT DETAIL_TAB.

ENDLOOP.

ENDLOOP.

After this code there will be DETAIL_TAB ca be Like this

PERNR NAME COUNT DEGREEE INSTITUION ORG from to

22 XY 1 MAB FG A 91 93

22 2 MBA FG2

23 AB 1 AC DM C 94 95

23 2 ACCA FG

23 3 CA OP

Now I tries same code for EXP_TAB.

SORT DETAIL_TAB BY PERNR COUNT.

SORT EDU_TAB BY PERNR COUNT.

SORT EXP_TAB BY PERNR COUNT.

LOOP AT DETAIL_TAB.

LOOP AT EXP_TAB WHERE PERNR EQ DETAIL_TAB-PERNR AND COUNT NE DETAIL_TAB-COUNT.

DETAIL_TAB-PERNR = EXP_TAB-PERNR

DETAIL_TAB-ORGANIZATION = EXP_TAB-ORGANIZATION

DETAIL_TAB-JOIN = EXP_TAB-JOIN

DETAIL_TAB-LEAVE = EXP_TAB-LEAVE

DETAIl_TAB-COUNT = EXP_TAB-COUNT

INSERT DETAIL_TAB.

ENDLOOP.

ENDLOOP.

AND I belive thingswill start going BAD from here

e.g PERNER is 2 and COUNT =1 in first LOOP PASS of DETAIL_TAB then it will bring PERNR 22 and COUNT = 2 from EXP_TAB and inser that in detail tab but u ca nclearly see there is still aspace avialable in infront of PERNR 22 and COUNT 2 in DETAIL_TAB so this record can be modified there .

In siple words above logic is not working.

Please can some one give me a simple logic.

Also not that I m picking DETAIL_TAB EXP_TAB and EDU_TAB from 3 different tables, all those have PERNR but Inner join cant use there becasue it will bring wrong results.

Waiting for your expert opinion.

Thnx.