Skip to Content
avatar image
Former Member

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_AA 0REF_DOC_IT ZOBJNR 0REF_DOC_NR 6 1 ORXXXXXXXXXX 91000 6 1 KSYYYYYYYYYY 91000

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 (43.1 kB)
Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Best Answer
    Nov 03, 2015 at 06:59 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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