cancel
Showing results for 
Search instead for 
Did you mean: 

Field Routine

Former Member
0 Kudos

Hi Experts,

How can I able to write this into Field routine. I have 4 fields below.

Given:

ZOBJNR (Object Number)                                       

0REF_DOC_AA  (Reference document:           

0REF_DOC_IT - Reference document item             

0REF_DOC_NR - Reference Document Number   

0REF_DOC_AA0REF_DOC_ITZOBJNR0REF_DOC_NR
61ORXXXXXXXXXX91000
61KSYYYYYYYYYY91000

Get only object number with “OR” as starting  value - find the value of

Derived costcenter from object number with “KS” as starting  value.

the result is last (10) digit KSXXXXXXXXXX if the have the same value of ORXXXXXXXXXX in the ff: fields 0REF_DOC_AA,  0REF_DOC_IT and 0REF_DOC_NR

              

RESULT = YYYYYYYYYY

Many Thanks

_whel

Accepted Solutions (1)

Accepted Solutions (1)

former_member183519
Contributor
0 Kudos

Hello Roel,

I think you have to go end routine in this scenario, because in field routine you will always get only one row at a time.

tell me one thing, in your data(shared screen shot), for combination of ref. doc , item & doc. no you always have

single KS & OR

or

multiple OR and single KS?  please analyze test data for the same.

let us know this, so based on that we can built code.

Regards,

Hitesh

Former Member
0 Kudos

Please see screen shots below sir Hitesh,

Their are multiple KS and OR sir, but every OR has corresponding KS. The KS(10)last 10 digit that I am going to extract are those who had the same value of REF_DOC_NR, REF_DOC_IT and REF_DOC_AA.

Thanks

Former Member
0 Kudos

Hi,

You have to use the offset operation on the field to check the first two value.

Processing Sections of Strings - ABAP Programming (BC-ABA) - SAP Library

for example ZOBJNR(2) should give you the first two digit that is KS or OR as you need them.

Please take help of ABAP person in your team.

Thanks,

-J

former_member183519
Contributor
0 Kudos

Hello Roel,

pls use below code , where i am using looping but based index  so it will not hamper performance.(parallel cursor method)

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

DATA :lv_index LIKE sy-index.

SORT RESUL_PACKAGE BY 0REF_DOC_NR  0REF_DOC_IT 0REF_DOC_AA  ZOBJNR .

lv_index = 0.

LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELLDS> FROM lv_index WHERE ZOBJNR = 'KS%' . "

  lv_index = lv_index + 1.

  LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELLDS_1>

       FROM  lv_index

       WHERE 0REF_DOC_NR = <RESULT_FIELLDS>-0REF_DOC_NR AND

             0REF_DOC_IT = <RESULT_FIELLDS>-0REF_DOC_IT AND

             0REF_DOC_AA = <RESULT_FIELLDS>-0REF_DOC_AA AND

             ZOBJNR      = 'OR%'.

  *****all below code it to copy forst 10 digits for object number

  *****so suppose if you have value KS1234567890

  *****then first you replace KS1234567890 with 001234567890   (KS replaced by 00) as mentioned  ****** below

   

       replace all occurrences of 'KS' in <RESULT_FIELLDS>-RESULT_FIELD_OBJNR with '00' .

   ******then replace all 00 if any using below code

       CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

         EXPORTING

           INPUT         = <RESULT_FIELLDS>-RESULT_FIELD_OBJNR

        IMPORTING

          OUTPUT        = <RESULT_FIELLDS>-RESULT_FIELD_OBJNR .

     ****** copy first 10 digits into result fields

       <RESULT_FIELLDS_1>-RESULT_FIELD_OBJNR =   <RESULT_FIELLDS>-RESULT_FIELD_OBJNR+0(10).

    ENDLOOP.  

ENDLOOP.

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

may require minor changes.. sit with abaper or let me know in case of any issues.

1) In above code we first sorted Result_package base on fields 0REF_DOC_NR  0REF_DOC_IT 0REF_DOC_AA  ZOBJNR.

due to this for a combination of fields 0REF_DOC_NR  0REF_DOC_IT 0REF_DOC_AA  , we get ZOBJNR fields always first field starting with 'KS********'

2) we search other records in internal table with same ref doc number, item no & accounting no... and ZOBJNR should be starting with OR*****

If we found any combination then we copy object number .....

Regards,

Hitesh

Answers (0)