Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Field Routine

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

Result.PNG (43067 B)
Former Member
replied

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

1 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question