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 for algorithm

Former Member
0 Likes
761

Hello,

everyone can any one help me with this coding of this algorithm .

i have tried many different ways to code but unable to find best solution.

1) read from table ZPAT the fields PID and FID where username=sy-user

2)check, if there is a row in ZCORE with PID and FID

information about tables:

ZCORE:

-PID

-FID

-BID

-a_ch (char)

-e_ch (char)

=>Comment: There Every line with  PID and FID has a different value of BID

ZPAT:

-PID

-FID

-username(char)

=>Comment: every username is only once in the table with exactly  one  PID and one FID

3 REPLIES 3
Read only

Former Member
0 Likes
644

Hi,

     Line 2 was not clear so i did with my considerations.

*************************************************************************************

considering only PID and FID is not initial.

*************************************************************************************

select * from ZPAT into table it_ZPAT where usernae = sy-user.
select count( * ) from ZCORE into zcore_count
where PID <> 0
or FID <> 0.
if sy-subrc = 0.
* YOUR LOGIC.
endif.

*************************************************************************************

OR : considering entries in ZPAT.

*************************************************************************************

select * from ZPAT into table it_ZPAT where usernae = sy-user.
select count( * ) from ZCORE into zcore_count
for all entries in it_ZPAT
where PID = it_ZPAT-PID
or FID <> it_ZPAT-FID.
if sy-subrc = 0.
* YOUR LOGIC.
endif.

HAPPY ABAPing

Vishal

Read only

former_member491621
Contributor
0 Likes
644

Hi Ojaswa,

First regarding tables.

     I hope the keys for the tables are properly identified(assuming that the comments depict the ways the table behaves i.e stores values).

Now, coming to the algorithm.

Algorithm :

DATA : wa_zpat TYPE zpat,

           wa_zcore TYPE zcore,

           wa_znew TYPE znew,

           w_hbid TYPE i.    "Highest BID

1) read from table ZPAT the fields PID and FID where username=sy-user

select single *

     from ZPAT

     into wa_zpat

     where username EQ sy-uname.

IF sy-subrc EQ 0.

2)check, if there is a row in ZCORE with PID and FID

3)if yes

               read BID FROM ZCORE where PID and FID

               check, i highest Dnr in ZNEW where PIDand FID is the same value as BID in ZCORE

               if no, in ZCORE set :

                       e_ch='n'  and  call screen 100

               if yes, call screen 100

4) if no

  add new row to ZCORE set:

   a_ch='n'

  e_ch='o'

  BID= highest_BID

(highest_BID is highest value of Dnr from ZNEW  where PID and FID)

call screen 100

     select single *

                 from ZCORE

                 into wa_zcore

              where PID EQ wa_zpat-PID

                 and FID EQ wa_zpat-FID.

                 IF sy-subrc EQ 0 AND NOT wa_zcore IS INITIAL.

                               select MAX( Dnr )

                                  from ZNEW

                                  into w_hbid

                               where PID EQ wa_zpat-PID

                                  and FID EQ wa_zpat-FID

                                  and BID EQ wa_zcore-BID.

                                   IF sy-subrc EQ 0 and NOT wa_zcore IS INITIAL.

                                                 CALL SCREEN 100.

                                   ELSE.

                                             wa_zcore-e_ch = 'n'.

                                             CALL SCREEN 100.

                                   ENDIF.

                 ELSE.

                        select MAX( Dnr )

                                  from ZNEW

                                  into w_hbid

                               where PID EQ wa_zpat-PID

                                  and FID EQ wa_zpat-FID.

                              IF sy-subrc EQ 0 and NOT w_hbid IS INITIAL.

                                   wa_zcore-BID = w_hbid.

                              ELSE.

                                   wa_zcore-BID = 1.          (first BID)

                              ENDIF.

                        wa_zcore-a_ch = 'n'.

                        wa_zcore-e_ch = 'o'.

                        wa_zcore-PID   = wa_zpat-PID.

                        wa_zcore-FID   = wa_zpat-FID.

                        ....you insert/call method to insert this wa_zcore into ZCORE.

                         CALL SCREEN 100.

                 ENDIF.

ELSE.

     .......error message

ENDIF.

The code/text in blue is your query. The text below that is the reply.

Hope this helps

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
644

Moderator Message: This is a kind of requirement dumping which is not allowed in forums,if you need a solution please let us know what you have tried so far before posting.


Members answering such queries are indirectly encouraging the OP's to post similar queries in future, please try to avoid answering such questions.

Points removed and thread locked.