Application Development 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: 

how to find the checktable assigned to a field dynamically

former_member225253
Participant
0 Kudos
2,050

Hi Members ,

I have a requirement in which numerous validations have to applied before passing the values to a BAPI . i have to find a way to know checktable assigned to a field dynamically . I will explain it more clearly now .

eg . There is a structure KOMK . It has 363 fields in these fields around 200 have a check table assigned to them .

The requirement is to check the value in the excel sheet provided by user to first validated before passing to BAPI .

eg . if it is sales organisation . field : VKORG . The value provided by user should be in table TVKO which is checktable for this field ( displayed in Inputc help/check tab )  . In this way there are numerous other fields whose checks need to be applied . Plz Refer to screenshot below : 

i have the names of fields like VKORG , VTWEG , BRSCH stored in character in a internal table in one  single column .

i am looking for a dynamic way to find check table so that i can take care of 200+ fields. Maintaing these in Ztable is not an option for me frz .

Is it stored in some table or Link of tables or View or some Function Module .....

How to fulfill this Requirement ?

Would be grateful to your Replies ....

Kindly comment .

Thanks & Rgds ,

Dave

12 REPLIES 12

former_member225253
Participant
0 Kudos
793

Hi members ,

Any suggestions on the issue .

Thanks ,

Dave

0 Kudos
793

Hi Devendra,

You can make use of table DD03L to get information about the checktable of a particular field of a standard table.

Regards,

Richa

0 Kudos
793

Hi Richa ,

Thanks for the Reply . Can you plz help me the use of the FM suggested by Raymond / Loyd to achieve the objective . My query i just posted as the   latest reply and you can find that in trail in the Post .

Thanks & Rgds ,

Devendra Singh

Sandra_Rossi
Active Contributor
0 Kudos
793

I don't understand the requirement to do the checks before calling the BAPI. Doesn't the BAPI check the values too?

Foreign keys are primarily stored in tables DD08L and DD05S (value in field DD03L-CHECKTABLE being redundant with DD08L-CHECKTABLE)

0 Kudos
793

Hi Sandra / Members  ,

Thanks for the Reply . The BAPI i am using doesnot check for various fields so i have to apply this procedure of checking the value before passing BAPI . FM DDUT_INPUT_CHECK  solved the issue .

Thanks & Rgds ,

Devendra Singh

raymond_giuseppi
Active Contributor
793

Look at FM DDUT_INPUT_CHECK.

Regards,

Raymond

0 Kudos
793

Hi Raymond ,

Thanks so much Raymond for suggesting the FM   . I used it successfully to achieve the objective.


Grt !!


Rgds ,

Devendra Singh

kiran_k8
Active Contributor
0 Kudos
793

Devendra,

Can you please let us know what compelled you to take this approach of validating the field names with the respective check table field names ?

K.Kiran.

loyd_enochs3
Participant
793

Devendra,

You have an ITAB with the fieldnames you want to check, so may I suggest something along these lines:

Add another field to that ITAB with the poistion in the DB table for each field.  Then you can "walk" across each data record field by field and see what needs to be checked.

In the below example, I used funciton module DDUT_INPUT_CHECK that Raymond suggested in his earlier comment.  The FM has fairly good documentation.  Error handling can be done with the FAILURE_TAB or with the MSG procedure (which brings back the error text used in the FK check) or with the simple sy-subrc check I used - whatever fits your needs.

Good luck!

Loyd

DATA: wa_spfli TYPE spfli,
      it_spfli TYPE STANDARD TABLE OF spfli.

DATA: repid TYPE sy-repid.

DATA: BEGIN OF wa_fields,                                        "ITAB of fields to be checked
        pos       TYPE dd03l-position,
        fieldname TYPE dfies-lfieldname,                         "datatype is important to FM
      END OF wa_fields,
      it_fields LIKE STANDARD TABLE OF wa_fields.

FIELD-SYMBOLS: <fs_comp> TYPE any.                    "used to walk across the structure

INITIALIZATION.                                                            "load the ITAB of fields to be checked
  wa_fields-pos       = '5'.
  wa_fields-fieldname = 'CITYFROM'.
  APPEND wa_fields TO it_fields.
  wa_fields-pos       = '8'.
  wa_fields-fieldname = 'CITYTO'.
  APPEND wa_fields TO it_fields.

START-OF-SELECTION.
  repid = sy-repid.
  SELECT * FROM spfli INTO TABLE it_spfli.               "get the real data
  LOOP AT it_spfli INTO wa_spfli.
    DO.
      ASSIGN COMPONENT sy-index OF STRUCTURE wa_spfli TO <fs_comp>.  "walk the struktur
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
      CLEAR wa_fields.
      READ TABLE it_fields INTO wa_fields WITH KEY pos = sy-index.
      IF sy-subrc = 0.                                                                                          "found a hit on ITAB
        CALL FUNCTION 'DDUT_INPUT_CHECK'
          EXPORTING
            tabname         = 'SPFLI'
            fieldname       = wa_fields-fieldname
            calling_program = repid
            value           = <fs_comp>
          EXCEPTIONS
            no_ddic_field   = 1
            illegal_move    = 2
            OTHERS          = 3.
        IF sy-subrc <> 0.
          WRITE: 'failed check', wa_fields-fieldname, <fs_comp>.
        ENDIF.
      ENDIF.
    ENDDO.
  ENDLOOP.

0 Kudos
793

Hi Loyd / ABAP members ,

Thanks so much Loyd for the Reply . I used your code to achieve the objective . However , I am facing an issue . It gives sy-subrc as zero ( success ) just after function module , even if i pass a value which is not maintained in check table . i mean i changed the value in degubber to a wrong value for CITYFROM which is not maintained in it checktable which is SGEOCITY to check for the error message , however it is always returning sy-subrc as zero . My error record when it is there in internal table it_spfli which i have maintained at runtime in <fs_comp> is not triggering sy-subrc as non-zero value . I have tried all these combination to reperesent tabname / strucname :

CALL FUNCTION 'DDUT_INPUT_CHECK'
           EXPORTING
             TABNAME                  'SPFLI'
               " TABNAME                  =  'WA_SPFLI'       commented
               " STRUCNAME                =  'WA_SPFLI'     commented
               " STRUCNAME                =  'SPFLI'        commented
             fieldname       = wa_fields-fieldname
             calling_program = repid
             value           = <fs_comp>
           EXCEPTIONS
             no_ddic_field   = 1
             illegal_move    = 2
             OTHERS          = 3.
         IF sy-subrc <> 0.
           WRITE: 'failed check', wa_fields-fieldname, <fs_comp>.
         ENDIF.


However , the issue persists . What mistake i am making . I also tried to debug but couldnot figure out . The code i am using which is the same as of Loyd gave & is rewritten below ( also attached with post )


Loyd / other members plz help .


Would be grateful for your Replies .


Thanks & Rgds ,

Devendra Singh

================================================================


REPORT ZTEST_INPUTCHECK.

DATA: wa_spfli TYPE spfli,
       it_spfli TYPE STANDARD TABLE OF spfli.

DATA: repid TYPE sy-repid.

DATA: BEGIN OF wa_fields,                                        "ITAB of fields to be checked
         pos       TYPE dd03l-position,
         fieldname TYPE dfies-lfieldname,                         "datatype is important to FM
       END OF wa_fields,
       it_fields LIKE STANDARD TABLE OF wa_fields.

FIELD-SYMBOLS: <fs_comp> TYPE any.                    "used to walk across the structure

INITIALIZATION.                                                            "load the ITAB of fields to be checked

   wa_fields-pos       = '5'.
   wa_fields-fieldname = 'CITYFROM'.
   APPEND wa_fields TO it_fields.
   wa_fields-pos       = '8'.
   wa_fields-fieldname = 'CITYTO'.
   APPEND wa_fields TO it_fields.

START-OF-SELECTION.
   repid = sy-repid.
   SELECT * FROM spfli INTO TABLE it_spfli.               "get the real data

BREAK-POINT .

   LOOP AT it_spfli INTO wa_spfli.
     DO.
       ASSIGN COMPONENT sy-index OF STRUCTURE wa_spfli TO <fs_comp>"walk the struktur
       IF sy-subrc <> 0.
         EXIT.
       ENDIF.
       CLEAR wa_fields.
       READ TABLE it_fields INTO wa_fields WITH KEY pos = sy-index.

      BREAK-POINT .
       IF sy-subrc = 0.                                                                                          "found a hit on ITAB
         CALL FUNCTION 'DDUT_INPUT_CHECK'
           EXPORTING
             TABNAME                  'SPFLI'
             "TABNAME                  =  'WA_SPFLI'    " commented
             "STRUCNAME                =  'WA_SPFLI'   " commented
             "STRUCNAME                =  'SPFLI'          "commented
             fieldname       = wa_fields-fieldname
             calling_program = repid
             value           = <fs_comp>
           EXCEPTIONS
             no_ddic_field   = 1
             illegal_move    = 2
             OTHERS          = 3.
         IF sy-subrc <> 0.
           WRITE: 'failed check', wa_fields-fieldname, <fs_comp>.
         ENDIF.
       ENDIF.
     ENDDO.
   ENDLOOP.

   BREAK-POINT .

****  CALL FUNCTION 'DDUT_INPUT_CHECK'
*****   EXPORTING
*****     TABNAME                  =
*****     FIELDNAME                =
*****     CALLING_PROGRAM          =
*****     STRUCNAME                =
*****     VALUE                    =
*****     VALUE_IS_EXTERNAL        = ' '
*****     ACCEPT_ALL_INITIAL       = ' '
*****     VALUE_LIST               =
*****     NO_FORKEY_CHECK          = ' '
*****   IMPORTING
*****     MSGID                    =
*****     MSGTY                    =
*****     MSGNO                    =
*****     MSGV1                    =
*****     MSGV2                    =
*****     MSGV3                    =
*****     MSGV4                    =
*****     VALUE_INTERNAL           =
*****   TABLES
*****     FAILURE_TAB              =
*****   CHANGING
*****     ADDITIONAL_FIELDS        =
*****   EXCEPTIONS
*****     NO_DDIC_FIELD            = 1
*****     ILLEGAL_MOVE             = 2
*****     OTHERS                   = 3
****            .
****  IF SY-SUBRC <> 0.
***** Implement suitable error handling here
****  ENDIF.
****
****


0 Kudos
793

Thanks Loyd . I got the solution . In your code i have to check MSGTY also .

CALL FUNCTION 'DDUT_INPUT_CHECK'
           EXPORTING
            " TABNAME                  =  'SPFLI'
            " TABNAME                  =  'WA_SPFLI'
             STRUCNAME                'WA_SPFLI'
             "STRUCNAME                =  'SPFLI'
             fieldname       = wa_fields-fieldname
             calling_program = repid
             value           = <fs_comp>
         "    value_is_external        = 'X'
            IMPORTING
              MSGID                    MSGID
              MSGTY                    = MSGTY
              MSGNO                    = MSGNO
              MSGV1                    MSGV1
              MSGV2                    MSGV2
              MSGV3                    =   MSGV3
              MSGV4                    MSGV4
            "  VALUE_INTERNAL           =
           EXCEPTIONS
             no_ddic_field   = 1
             illegal_move    = 2
             OTHERS          = 3.
         IF MSGTY EQ 'E'.
           WRITE: 'failed check', wa_fields-fieldname, <fs_comp>.
         ENDIF.


Grt !!


Rgds ,

Devendra Singh

0 Kudos
793

good catch! glad you have your answer!