Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ABAP code help

Former Member
0 Likes
970

hi folks,

I need some help in the programming code. Here is the scenario.

DATA: BEGIN OF INT_P4002 OCCURS 0,

PERNR LIKE P4002-PERNR,

VACANCY LIKE PB4002-OBJID,

END OF INT_P4002.

data: BEGIN OF int_applicant OCCURS 0,

PERNR LIKE P4002-PERNR,

contest_number_id1(10),

contest_number_id2(10),

contest_number_id3(10),

contest_number_id4(10),

contest_number_id5(10),

END OF int_applicant.

I have declared two internal tables as shown. The first table (INT_P4002 ) contains the data of applicants that have applied for multipe vacancies like (sample data). I get the data into this table by reading it from Recruitment tables.

20000010, 50001234

20000010, 50001235

20000010, 50001236

20000010, 50001237

20000011, 50001235

20000012, 50001238

20000012, 50001239

20000012, 50001240

Since each applicant has applied to different vacancies, and I am collecting the data in the form of rows. However I need to present the data along different coulmns instead of rows like this...

I now have to write this data to the table (int_applicant) in this format

20000010, 50001234, 50001235, 50001236, 50001237,

20000011, 50001235,

20000012, 50001238, 50001239, 50001240,

How can I do this?

Thanks in advance,

VG

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
935

Vinu,

You have to do something like the following.

declare a data : xtabix like sy-tabix .

clear xtabix.

Loop at INT_P4002.

xtabix = xtabix + 1.

int_applicant-pernr = INT_P4002-pernr.

if xtabix eq 1.

int_applicant-contest_number_id1 = INT_P4002-VACANCY.

elseif xtabix eq 2.

int_applicant-contest_number_id2 = INT_P4002-VACANCY.

elseif xtabix eq 3.

int_applicant-contest_number_id3 = INT_P4002-VACANCY.

elseif xtabix eq 4.

int_applicant-contest_number_id4 = INT_P4002-VACANCY.

elseif xtabix eq 5.

int_applicant-contest_number_id5 = INT_P4002-VACANCY.

endif.

at end of pernr.

Append int_applicant.

clear xtabix.

end at.

endloop.

Now your int_application will have the data in your format.

Hope this helps

Vinodh Balakrishnan

8 REPLIES 8
Read only

Former Member
0 Likes
935

Hi vinu,

Try this.

loop at int_p4002.

if <id1_condition>.

int_applicant-id1 = id1.

elseif <id2_condition>.

.

..

..

at end of pernr.

append int_applicant.

endat.

endloop.

Hope this helps.

~goldie.

Read only

0 Likes
935

Thanks for the quick reply goldie. I did not understand your answer. Can you elaborate your logic?

-VG

Read only

0 Likes
935

you have your first internal table sorted. right?

then you loop at it.

and if you get your ids into one record of second internal table.

at the end of your pernr (the last record for a particular pernr in 1at itab), you append the current record to 2nd itab.

this you do for all the pernrs.

think this explains.

goldie.

Read only

Former Member
0 Likes
936

Vinu,

You have to do something like the following.

declare a data : xtabix like sy-tabix .

clear xtabix.

Loop at INT_P4002.

xtabix = xtabix + 1.

int_applicant-pernr = INT_P4002-pernr.

if xtabix eq 1.

int_applicant-contest_number_id1 = INT_P4002-VACANCY.

elseif xtabix eq 2.

int_applicant-contest_number_id2 = INT_P4002-VACANCY.

elseif xtabix eq 3.

int_applicant-contest_number_id3 = INT_P4002-VACANCY.

elseif xtabix eq 4.

int_applicant-contest_number_id4 = INT_P4002-VACANCY.

elseif xtabix eq 5.

int_applicant-contest_number_id5 = INT_P4002-VACANCY.

endif.

at end of pernr.

Append int_applicant.

clear xtabix.

end at.

endloop.

Now your int_application will have the data in your format.

Hope this helps

Vinodh Balakrishnan

Read only

0 Likes
935

Thanks guys for the reply.

Vinodh, it answers only a part of the logic, yes, if the first applicant has applied for '4' vacancies, the record lines from 1 to 4 will be filled in 'int_applicant-contest_number_id1' subsequently, however if the 'fifth' record is of a new applicant who has just '1' vacancy and the next two records is of another applicant applying for 2 vacanies, how can this is identified?

OR

If I understand correctly, the logic you have given.. 'at end of pernr' ... does this piece of code takes care of the issue that I mentioned above

Can you elaborate on this so that I can uderstand better?

Thanks again,

VG

Read only

Former Member
0 Likes
935

Vinu,

The solution will address your entire problem.

Before coming into the Loop, you would have sorted your internal table.

Say for example, your records are

20000010, 50001234

20000010, 50001235

20000010, 50001236

20000010, 50001237

20000010, 50001238

20000011, 50001235

20000012, 50001238

20000012, 50001239

20000012, 50001240

Pernr 20000012 has applied for five positions and 20000011 for one position and 20000012 for three.

When the loop hits the fifthe record of 20000010, control will go to AT END OF PERNR Block, there all the five records would be transfereed to your second internal table and the record will be appended as below

20000010, 50001234, 50001235, 50001236, 50001237, 50001238 .

And now the control goes back to LOOP at INT_P4002 for the sixth record, ie pernr 20000011 .....

This will continue.

Just try running the same in your program and see....

Hope this helps

Vinodh Balakrishnan

Read only

0 Likes
935

Thanks for the elaborate reply, I understood it. I shall run the program and will award the points.

Thanks,

VG

Read only

0 Likes
935

Thanks Vinodh, The logic worked and got to learn something new. Shall award the points.

VG