Skip to Content
author's profile photo Former Member
Former Member

ABAP code help

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 21, 2008 at 06:30 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Jan 21, 2008 at 06:13 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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.

  • author's profile photo Former Member
    Former Member
    Posted on Jan 21, 2008 at 07:29 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.